From 7f8f1ab2c114991ca213351112382938b7b03842 Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Thu, 14 Aug 2025 13:23:43 -0400 Subject: [PATCH 001/160] [`pyflakes`] Add secondary annotation showing previous definition (`F811`) (#19900) ## Summary This is a second attempt at a first use of a new diagnostic feature after #19886. I'll blame rustc for this one because it also has a similar diagnostic: image We end up with a very similar diagnostic: image ## Test Plan New snapshots and manual tests above --- crates/ruff/tests/lint.rs | 16 ++++++------- crates/ruff_db/src/diagnostic/mod.rs | 15 ++++++++++++ crates/ruff_db/src/diagnostic/render.rs | 7 +++++- crates/ruff_linter/src/checkers/ast/mod.rs | 13 ++++++++++- .../pyflakes/rules/redefined_while_unused.rs | 12 +++++++++- ...ules__pyflakes__tests__F811_F811_0.py.snap | 9 +++++++- ...ules__pyflakes__tests__F811_F811_1.py.snap | 6 +++-- ...les__pyflakes__tests__F811_F811_12.py.snap | 8 +++++-- ...les__pyflakes__tests__F811_F811_15.py.snap | 7 +++++- ...les__pyflakes__tests__F811_F811_16.py.snap | 9 +++++++- ...les__pyflakes__tests__F811_F811_17.py.snap | 16 ++++++++++--- ...ules__pyflakes__tests__F811_F811_2.py.snap | 6 +++-- ...les__pyflakes__tests__F811_F811_21.py.snap | 10 +++++++- ...les__pyflakes__tests__F811_F811_23.py.snap | 7 ++++-- ...les__pyflakes__tests__F811_F811_26.py.snap | 7 ++++-- ...les__pyflakes__tests__F811_F811_28.py.snap | 7 ++++-- ...es__pyflakes__tests__F811_F811_29.pyi.snap | 10 ++++++-- ...ules__pyflakes__tests__F811_F811_3.py.snap | 6 +++-- ...les__pyflakes__tests__F811_F811_30.py.snap | 23 ++++++++++++++----- ...les__pyflakes__tests__F811_F811_31.py.snap | 6 +++-- ...les__pyflakes__tests__F811_F811_32.py.snap | 5 ++-- ...ules__pyflakes__tests__F811_F811_4.py.snap | 6 +++-- ...ules__pyflakes__tests__F811_F811_5.py.snap | 6 +++-- ...ules__pyflakes__tests__F811_F811_6.py.snap | 6 +++-- ...ules__pyflakes__tests__F811_F811_8.py.snap | 5 ++-- ...shadowed_global_import_in_local_scope.snap | 7 ++++-- ...shadowed_import_shadow_in_local_scope.snap | 7 ++++-- ..._shadowed_local_import_in_local_scope.snap | 5 ++-- crates/ruff_linter/src/test.rs | 16 +++++++++---- 29 files changed, 200 insertions(+), 63 deletions(-) diff --git a/crates/ruff/tests/lint.rs b/crates/ruff/tests/lint.rs index 52a374477b97b..c3f908c7fe6db 100644 --- a/crates/ruff/tests/lint.rs +++ b/crates/ruff/tests/lint.rs @@ -5588,15 +5588,15 @@ fn cookiecutter_globbing() -> Result<()> { .args(STDIN_BASE_OPTIONS) .arg("--select=F811") .current_dir(tempdir.path()), @r" - success: false - exit_code: 1 - ----- stdout ----- - {{cookiecutter.repo_name}}/tests/maintest.py:3:8: F811 [*] Redefinition of unused `foo` from line 1 - Found 1 error. - [*] 1 fixable with the `--fix` option. + success: false + exit_code: 1 + ----- stdout ----- + {{cookiecutter.repo_name}}/tests/maintest.py:3:8: F811 [*] Redefinition of unused `foo` from line 1: `foo` redefined here + Found 1 error. + [*] 1 fixable with the `--fix` option. - ----- stderr ----- - "); + ----- stderr ----- + "); }); Ok(()) diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index ddbc8f61e45f7..53b4247adccae 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -254,6 +254,11 @@ impl Diagnostic { .find(|ann| ann.is_primary) } + /// Returns a mutable borrow of all annotations of this diagnostic. + pub fn annotations_mut(&mut self) -> impl Iterator { + Arc::make_mut(&mut self.inner).annotations.iter_mut() + } + /// Returns the "primary" span of this diagnostic if one exists. /// /// When there are multiple primary spans, then the first one that was @@ -310,6 +315,11 @@ impl Diagnostic { &self.inner.subs } + /// Returns a mutable borrow of the sub-diagnostics of this diagnostic. + pub fn sub_diagnostics_mut(&mut self) -> impl Iterator { + Arc::make_mut(&mut self.inner).subs.iter_mut() + } + /// Returns the fix for this diagnostic if it exists. pub fn fix(&self) -> Option<&Fix> { self.inner.fix.as_ref() @@ -621,6 +631,11 @@ impl SubDiagnostic { &self.inner.annotations } + /// Returns a mutable borrow of the annotations of this sub-diagnostic. + pub fn annotations_mut(&mut self) -> impl Iterator { + self.inner.annotations.iter_mut() + } + /// Returns a shared borrow of the "primary" annotation of this diagnostic /// if one exists. /// diff --git a/crates/ruff_db/src/diagnostic/render.rs b/crates/ruff_db/src/diagnostic/render.rs index eba3253c964cc..2b5230117e911 100644 --- a/crates/ruff_db/src/diagnostic/render.rs +++ b/crates/ruff_db/src/diagnostic/render.rs @@ -264,7 +264,12 @@ impl<'a> ResolvedDiagnostic<'a> { .annotations .iter() .filter_map(|ann| { - let path = ann.span.file.path(resolver); + let path = ann + .span + .file + .relative_path(resolver) + .to_str() + .unwrap_or_else(|| ann.span.file.path(resolver)); let diagnostic_source = ann.span.file.diagnostic_source(resolver); ResolvedAnnotation::new(path, &diagnostic_source, ann, resolver) }) diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 76c3e82462c69..1437b1655dd0c 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -28,7 +28,7 @@ use itertools::Itertools; use log::debug; use rustc_hash::{FxHashMap, FxHashSet}; -use ruff_db::diagnostic::Diagnostic; +use ruff_db::diagnostic::{Annotation, Diagnostic, IntoDiagnosticMessage, Span}; use ruff_diagnostics::{Applicability, Fix, IsolationLevel}; use ruff_notebook::{CellOffsets, NotebookIndex}; use ruff_python_ast::helpers::{collect_import_from_member, is_docstring_stmt, to_module_path}; @@ -3305,6 +3305,17 @@ impl DiagnosticGuard<'_, '_> { Err(err) => log::debug!("Failed to create fix for {}: {}", self.name(), err), } } + + /// Add a secondary annotation with the given message and range. + pub(crate) fn secondary_annotation<'a>( + &mut self, + message: impl IntoDiagnosticMessage + 'a, + range: impl Ranged, + ) { + let span = Span::from(self.context.source_file.clone()).with_range(range.range()); + let ann = Annotation::secondary(span).message(message); + self.diagnostic.as_mut().unwrap().annotate(ann); + } } impl std::ops::Deref for DiagnosticGuard<'_, '_> { diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs b/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs index a60b67f82d064..65019a997b2cc 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/redefined_while_unused.rs @@ -183,14 +183,24 @@ pub(crate) fn redefined_while_unused(checker: &Checker, scope_id: ScopeId, scope // Create diagnostics for each statement. for (source, entries) in &redefinitions { for (shadowed, binding) in entries { + let name = binding.name(checker.source()); let mut diagnostic = checker.report_diagnostic( RedefinedWhileUnused { - name: binding.name(checker.source()).to_string(), + name: name.to_string(), row: checker.compute_source_row(shadowed.start()), }, binding.range(), ); + diagnostic.secondary_annotation( + format_args!("previous definition of `{name}` here"), + shadowed, + ); + + if let Some(ann) = diagnostic.primary_annotation_mut() { + ann.set_message(format_args!("`{name}` redefined here")); + } + if let Some(range) = binding.parent_range(checker.semantic()) { diagnostic.set_parent(range.start()); } diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap index 9dbabf2cf26a1..08c6403c54bdf 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_0.py.snap @@ -5,7 +5,14 @@ F811 Redefinition of unused `bar` from line 6 --> F811_0.py:10:5 | 10 | def bar(): - | ^^^ + | ^^^ `bar` redefined here 11 | pass | + ::: F811_0.py:6:5 + | + 5 | @foo + 6 | def bar(): + | --- previous definition of `bar` here + 7 | pass + | help: Remove definition: `bar` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap index e666db4b813b0..5b01c3bdc7839 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_1.py.snap @@ -2,9 +2,11 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `FU` from line 1 - --> F811_1.py:1:25 + --> F811_1.py:1:14 | 1 | import fu as FU, bar as FU - | ^^ + | -- ^^ `FU` redefined here + | | + | previous definition of `FU` here | help: Remove definition: `FU` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap index 58f521edf0ff7..8be7749183963 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_12.py.snap @@ -2,12 +2,16 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `mixer` from line 2 - --> F811_12.py:6:20 + --> F811_12.py:2:20 | +1 | try: +2 | from aa import mixer + | ----- previous definition of `mixer` here +3 | except ImportError: 4 | pass 5 | else: 6 | from bb import mixer - | ^^^^^ + | ^^^^^ `mixer` redefined here 7 | mixer(123) | help: Remove definition: `mixer` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap index d457a39a20b0f..e48bf8e55ed59 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_15.py.snap @@ -5,7 +5,12 @@ F811 Redefinition of unused `fu` from line 1 --> F811_15.py:4:5 | 4 | def fu(): - | ^^ + | ^^ `fu` redefined here 5 | pass | + ::: F811_15.py:1:8 + | +1 | import fu + | -- previous definition of `fu` here + | help: Remove definition: `fu` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap index f8a1351dff7b0..704155bf81c73 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_16.py.snap @@ -7,7 +7,14 @@ F811 Redefinition of unused `fu` from line 3 6 | def bar(): 7 | def baz(): 8 | def fu(): - | ^^ + | ^^ `fu` redefined here 9 | pass | + ::: F811_16.py:3:8 + | +1 | """Test that shadowing a global with a nested function generates a warning.""" +2 | +3 | import fu + | -- previous definition of `fu` here + | help: Remove definition: `fu` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap index 6e16f5399270e..70cee8d8c0a5d 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_17.py.snap @@ -6,10 +6,16 @@ F811 [*] Redefinition of unused `fu` from line 2 | 5 | def bar(): 6 | import fu - | ^^ + | ^^ `fu` redefined here 7 | 8 | def baz(): | + ::: F811_17.py:2:8 + | +1 | """Test that shadowing a global name with a nested function generates a warning.""" +2 | import fu + | -- previous definition of `fu` here + | help: Remove definition: `fu` ℹ Safe fix @@ -22,11 +28,15 @@ help: Remove definition: `fu` 9 8 | def fu(): F811 Redefinition of unused `fu` from line 6 - --> F811_17.py:9:13 + --> F811_17.py:6:12 | + 5 | def bar(): + 6 | import fu + | -- previous definition of `fu` here + 7 | 8 | def baz(): 9 | def fu(): - | ^^ + | ^^ `fu` redefined here 10 | pass | help: Remove definition: `fu` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap index 05ec31f26c1b1..7aa2e1019d4b6 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_2.py.snap @@ -2,9 +2,11 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `FU` from line 1 - --> F811_2.py:1:34 + --> F811_2.py:1:23 | 1 | from moo import fu as FU, bar as FU - | ^^ + | -- ^^ `FU` redefined here + | | + | previous definition of `FU` here | help: Remove definition: `FU` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap index 9cf6effbe6b7a..196596c3ce078 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_21.py.snap @@ -7,9 +7,17 @@ F811 [*] Redefinition of unused `Sequence` from line 26 30 | from typing import ( 31 | List, # noqa: F811 32 | Sequence, - | ^^^^^^^^ + | ^^^^^^^^ `Sequence` redefined here 33 | ) | + ::: F811_21.py:26:5 + | +24 | from typing import ( +25 | List, # noqa +26 | Sequence, # noqa + | -------- previous definition of `Sequence` here +27 | ) + | help: Remove definition: `Sequence` ℹ Safe fix diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap index d56b340e5b1fd..46b2551427257 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_23.py.snap @@ -2,10 +2,13 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `foo` from line 3 - --> F811_23.py:4:15 + --> F811_23.py:3:15 | +1 | """Test that shadowing an explicit re-export produces a warning.""" +2 | 3 | import foo as foo + | --- previous definition of `foo` here 4 | import bar as foo - | ^^^ + | ^^^ `foo` redefined here | help: Remove definition: `foo` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_26.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_26.py.snap index 2a8febc47ca9e..1025efb9fdebf 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_26.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_26.py.snap @@ -2,12 +2,15 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `func` from line 2 - --> F811_26.py:5:9 + --> F811_26.py:2:9 | +1 | class Class: +2 | def func(self): + | ---- previous definition of `func` here 3 | pass 4 | 5 | def func(self): - | ^^^^ + | ^^^^ `func` redefined here 6 | pass | help: Remove definition: `func` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_28.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_28.py.snap index 302c8ebf9f742..cf120b2cd7ea0 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_28.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_28.py.snap @@ -2,11 +2,14 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `datetime` from line 3 - --> F811_28.py:4:22 + --> F811_28.py:3:8 | +1 | """Regression test for: https://github.com/astral-sh/ruff/issues/10384""" +2 | 3 | import datetime + | -------- previous definition of `datetime` here 4 | from datetime import datetime - | ^^^^^^^^ + | ^^^^^^^^ `datetime` redefined here 5 | 6 | datetime(1, 2, 3) | diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_29.pyi.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_29.pyi.snap index d2a1b5e0cac73..a7e005d2693a0 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_29.pyi.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_29.pyi.snap @@ -2,11 +2,17 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `Bar` from line 3 - --> F811_29.pyi:8:1 + --> F811_29.pyi:3:24 | +1 | """Regression test for: https://github.com/astral-sh/ruff/issues/10509""" +2 | +3 | from foo import Bar as Bar + | --- previous definition of `Bar` here +4 | +5 | class Eggs: 6 | Bar: int # OK 7 | 8 | Bar = 1 # F811 - | ^^^ + | ^^^ `Bar` redefined here | help: Remove definition: `Bar` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap index 2e51c6831c08d..df164062ceadb 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_3.py.snap @@ -2,9 +2,11 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `fu` from line 1 - --> F811_3.py:1:12 + --> F811_3.py:1:8 | 1 | import fu; fu = 3 - | ^^ + | -- ^^ `fu` redefined here + | | + | previous definition of `fu` here | help: Remove definition: `fu` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_30.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_30.py.snap index 09bae7b5149e1..d0de3c478622b 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_30.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_30.py.snap @@ -2,32 +2,43 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `bar` from line 10 - --> F811_30.py:12:9 + --> F811_30.py:10:5 | + 8 | """Foo.""" + 9 | 10 | bar = foo + | --- previous definition of `bar` here 11 | 12 | def bar(self) -> None: - | ^^^ + | ^^^ `bar` redefined here 13 | """Bar.""" | help: Remove definition: `bar` F811 Redefinition of unused `baz` from line 18 - --> F811_30.py:21:5 + --> F811_30.py:18:9 | +16 | class B: +17 | """B.""" +18 | def baz(self) -> None: + | --- previous definition of `baz` here 19 | """Baz.""" 20 | 21 | baz = 1 - | ^^^ + | ^^^ `baz` redefined here | help: Remove definition: `baz` F811 Redefinition of unused `foo` from line 26 - --> F811_30.py:29:12 + --> F811_30.py:26:9 | +24 | class C: +25 | """C.""" +26 | def foo(self) -> None: + | --- previous definition of `foo` here 27 | """Foo.""" 28 | 29 | bar = (foo := 1) - | ^^^ + | ^^^ `foo` redefined here | help: Remove definition: `foo` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_31.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_31.py.snap index 7a08ea3888c08..1e8be05daaaad 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_31.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_31.py.snap @@ -2,12 +2,14 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `baz` from line 17 - --> F811_31.py:19:29 + --> F811_31.py:17:5 | +16 | try: 17 | baz = None + | --- previous definition of `baz` here 18 | 19 | from some_module import baz - | ^^^ + | ^^^ `baz` redefined here 20 | except ImportError: 21 | pass | diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_32.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_32.py.snap index 6b00fc2d31197..c6a3a8d8fb45a 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_32.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_32.py.snap @@ -2,12 +2,13 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 [*] Redefinition of unused `List` from line 4 - --> F811_32.py:5:5 + --> F811_32.py:4:5 | 3 | from typing import ( 4 | List, + | ---- previous definition of `List` here 5 | List, - | ^^^^ + | ^^^^ `List` redefined here 6 | ) | help: Remove definition: `List` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_4.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_4.py.snap index 11bb7bd8244c8..0148e0bde126c 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_4.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_4.py.snap @@ -2,9 +2,11 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `fu` from line 1 - --> F811_4.py:1:12 + --> F811_4.py:1:8 | 1 | import fu; fu, bar = 3 - | ^^ + | -- ^^ `fu` redefined here + | | + | previous definition of `fu` here | help: Remove definition: `fu` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_5.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_5.py.snap index 908d45c1bb073..420172d79e8a5 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_5.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_5.py.snap @@ -2,9 +2,11 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 Redefinition of unused `fu` from line 1 - --> F811_5.py:1:13 + --> F811_5.py:1:8 | 1 | import fu; [fu, bar] = 3 - | ^^ + | -- ^^ `fu` redefined here + | | + | previous definition of `fu` here | help: Remove definition: `fu` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap index e2c3c0cf88450..cd6894d8c03b0 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_6.py.snap @@ -2,12 +2,14 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 [*] Redefinition of unused `os` from line 5 - --> F811_6.py:6:12 + --> F811_6.py:5:12 | +3 | i = 2 4 | if i == 1: 5 | import os + | -- previous definition of `os` here 6 | import os - | ^^ + | ^^ `os` redefined here 7 | os.path | help: Remove definition: `os` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap index a3236f8fbe7f0..e198880e3779b 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F811_F811_8.py.snap @@ -2,12 +2,13 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 [*] Redefinition of unused `os` from line 4 - --> F811_8.py:5:12 + --> F811_8.py:4:12 | 3 | try: 4 | import os + | -- previous definition of `os` here 5 | import os - | ^^ + | ^^ `os` redefined here 6 | except: 7 | pass | diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap index e7ed86bd467b9..e8abef0b5368d 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_global_import_in_local_scope.snap @@ -19,11 +19,14 @@ help: Remove unused import: `os` 5 4 | import os F811 [*] Redefinition of unused `os` from line 2 - --> :5:12 + --> :2:8 | +2 | import os + | -- previous definition of `os` here +3 | 4 | def f(): 5 | import os - | ^^ + | ^^ `os` redefined here 6 | 7 | # Despite this `del`, `import os` in `f` should still be flagged as shadowing an unused | diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_import_shadow_in_local_scope.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_import_shadow_in_local_scope.snap index 7076d537084c3..02e03119dcc67 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_import_shadow_in_local_scope.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_import_shadow_in_local_scope.snap @@ -19,11 +19,14 @@ help: Remove unused import: `os` 5 4 | os = 1 F811 Redefinition of unused `os` from line 2 - --> :5:5 + --> :2:8 | +2 | import os + | -- previous definition of `os` here +3 | 4 | def f(): 5 | os = 1 - | ^^ + | ^^ `os` redefined here 6 | print(os) | help: Remove definition: `os` diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap index e96cdc07f7f11..41041f52628a9 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__del_shadowed_local_import_in_local_scope.snap @@ -2,12 +2,13 @@ source: crates/ruff_linter/src/rules/pyflakes/mod.rs --- F811 [*] Redefinition of unused `os` from line 3 - --> :4:12 + --> :3:12 | 2 | def f(): 3 | import os + | -- previous definition of `os` here 4 | import os - | ^^ + | ^^ `os` redefined here 5 | 6 | # Despite this `del`, `import os` should still be flagged as shadowing an unused | diff --git a/crates/ruff_linter/src/test.rs b/crates/ruff_linter/src/test.rs index 02eca4ca05848..2dee7dcbb26ae 100644 --- a/crates/ruff_linter/src/test.rs +++ b/crates/ruff_linter/src/test.rs @@ -9,7 +9,7 @@ use anyhow::Result; use itertools::Itertools; use rustc_hash::FxHashMap; -use ruff_db::diagnostic::Diagnostic; +use ruff_db::diagnostic::{Diagnostic, Span}; use ruff_notebook::Notebook; #[cfg(not(fuzzing))] use ruff_notebook::NotebookError; @@ -281,10 +281,16 @@ Either ensure you always emit a fix or change `Violation::FIX_AVAILABILITY` to e // noqa offset and the source file let range = diagnostic.expect_range(); diagnostic.set_noqa_offset(directives.noqa_line_for.resolve(range.start())); - if let Some(annotation) = diagnostic.primary_annotation_mut() { - annotation.set_span( - ruff_db::diagnostic::Span::from(source_code.clone()).with_range(range), - ); + // This part actually is necessary to avoid long relative paths in snapshots. + for annotation in diagnostic.annotations_mut() { + let range = annotation.get_span().range().unwrap(); + annotation.set_span(Span::from(source_code.clone()).with_range(range)); + } + for sub in diagnostic.sub_diagnostics_mut() { + for annotation in sub.annotations_mut() { + let range = annotation.get_span().range().unwrap(); + annotation.set_span(Span::from(source_code.clone()).with_range(range)); + } } diagnostic From ce938fe2056ded2a471a74922293e5ec9d61e6b0 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 14 Aug 2025 20:38:39 +0200 Subject: [PATCH 002/160] [ty] Speedup project file discovery (#19913) --- crates/ruff_db/src/files.rs | 7 +++-- crates/ty_project/src/db.rs | 10 ++++++ crates/ty_project/src/walk.rs | 57 ++++++++++++----------------------- 3 files changed, 33 insertions(+), 41 deletions(-) diff --git a/crates/ruff_db/src/files.rs b/crates/ruff_db/src/files.rs index 9f6bcbbdd15ff..ff8c9c8fc394a 100644 --- a/crates/ruff_db/src/files.rs +++ b/crates/ruff_db/src/files.rs @@ -87,11 +87,12 @@ impl Files { .system_by_path .entry(absolute.clone()) .or_insert_with(|| { - tracing::trace!("Adding file '{path}'"); - let metadata = db.system().path_metadata(path); + + tracing::trace!("Adding file '{absolute}'"); + let durability = self - .root(db, path) + .root(db, &absolute) .map_or(Durability::default(), |root| root.durability(db)); let builder = File::builder(FilePath::System(absolute)) diff --git a/crates/ty_project/src/db.rs b/crates/ty_project/src/db.rs index 1315811866798..a59006689bbac 100644 --- a/crates/ty_project/src/db.rs +++ b/crates/ty_project/src/db.rs @@ -21,6 +21,8 @@ mod changes; #[salsa::db] pub trait Db: SemanticDb { fn project(&self) -> Project; + + fn dyn_clone(&self) -> Box; } #[salsa::db] @@ -484,6 +486,10 @@ impl Db for ProjectDatabase { fn project(&self) -> Project { self.project.unwrap() } + + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } } #[cfg(feature = "format")] @@ -611,6 +617,10 @@ pub(crate) mod tests { fn project(&self) -> Project { self.project.unwrap() } + + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } } #[salsa::db] diff --git a/crates/ty_project/src/walk.rs b/crates/ty_project/src/walk.rs index ea161e187d7f4..8c9958c4166c6 100644 --- a/crates/ty_project/src/walk.rs +++ b/crates/ty_project/src/walk.rs @@ -4,7 +4,7 @@ use ruff_db::files::{File, system_path_to_file}; use ruff_db::system::walk_directory::{ErrorKind, WalkDirectoryBuilder, WalkState}; use ruff_db::system::{SystemPath, SystemPathBuf}; use ruff_python_ast::PySourceType; -use rustc_hash::{FxBuildHasher, FxHashSet}; +use rustc_hash::FxHashSet; use std::path::PathBuf; use thiserror::Error; @@ -163,20 +163,24 @@ impl<'a> ProjectFilesWalker<'a> { /// Walks the project paths and collects the paths of all files that /// are included in the project. - pub(crate) fn walk_paths(self) -> (Vec, Vec) { - let paths = std::sync::Mutex::new(Vec::new()); + pub(crate) fn collect_vec(self, db: &dyn Db) -> (Vec, Vec) { + let files = std::sync::Mutex::new(Vec::new()); let diagnostics = std::sync::Mutex::new(Vec::new()); self.walker.run(|| { - Box::new(|entry| { + let db = db.dyn_clone(); + let filter = &self.filter; + let files = &files; + let diagnostics = &diagnostics; + + Box::new(move |entry| { match entry { Ok(entry) => { // Skip excluded directories unless they were explicitly passed to the walker // (which is the case passed to `ty check `). if entry.file_type().is_directory() { if entry.depth() > 0 { - let directory_included = self - .filter + let directory_included = filter .is_directory_included(entry.path(), GlobFilterCheckMode::TopDown); return match directory_included { IncludeResult::Included => WalkState::Continue, @@ -210,8 +214,7 @@ impl<'a> ProjectFilesWalker<'a> { // For all files, except the ones that were explicitly passed to the walker (CLI), // check if they're included in the project. if entry.depth() > 0 { - match self - .filter + match filter .is_file_included(entry.path(), GlobFilterCheckMode::TopDown) { IncludeResult::Included => {}, @@ -232,8 +235,11 @@ impl<'a> ProjectFilesWalker<'a> { } } - let mut paths = paths.lock().unwrap(); - paths.push(entry.into_path()); + // If this returns `Err`, then the file was deleted between now and when the walk callback was called. + // We can ignore this. + if let Ok(file) = system_path_to_file(&*db, entry.path()) { + files.lock().unwrap().push(file); + } } } Err(error) => match error.kind() { @@ -274,39 +280,14 @@ impl<'a> ProjectFilesWalker<'a> { }); ( - paths.into_inner().unwrap(), + files.into_inner().unwrap(), diagnostics.into_inner().unwrap(), ) } - pub(crate) fn collect_vec(self, db: &dyn Db) -> (Vec, Vec) { - let (paths, diagnostics) = self.walk_paths(); - - ( - paths - .into_iter() - .filter_map(move |path| { - // If this returns `None`, then the file was deleted between the `walk_directory` call and now. - // We can ignore this. - system_path_to_file(db, &path).ok() - }) - .collect(), - diagnostics, - ) - } - pub(crate) fn collect_set(self, db: &dyn Db) -> (FxHashSet, Vec) { - let (paths, diagnostics) = self.walk_paths(); - - let mut files = FxHashSet::with_capacity_and_hasher(paths.len(), FxBuildHasher); - - for path in paths { - if let Ok(file) = system_path_to_file(db, &path) { - files.insert(file); - } - } - - (files, diagnostics) + let (files, diagnostics) = self.collect_vec(db); + (files.into_iter().collect(), diagnostics) } } From 82350a398e2bd8ed57db8fed94b0eae2071b446f Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 14 Aug 2025 22:14:31 +0100 Subject: [PATCH 003/160] [ty] Remove use of `ClassBase::try_from_type` from `super()` machinery (#19902) --- .../resources/mdtest/class/super.md | 16 ++++++++ crates/ty_python_semantic/src/types.rs | 41 +++++++++++-------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/class/super.md b/crates/ty_python_semantic/resources/mdtest/class/super.md index ecffca0fb65d1..c7b6e0ef803af 100644 --- a/crates/ty_python_semantic/resources/mdtest/class/super.md +++ b/crates/ty_python_semantic/resources/mdtest/class/super.md @@ -331,6 +331,9 @@ instance or a subclass of the first. If either condition is violated, a `TypeErr runtime. ```py +import typing +import collections + def f(x: int): # error: [invalid-super-argument] "`int` is not a valid class" super(x, x) @@ -367,6 +370,19 @@ reveal_type(super(B, A)) reveal_type(super(B, object)) super(object, object()).__class__ + +# Not all objects valid in a class's bases list are valid as the first argument to `super()`. +# For example, it's valid to inherit from `typing.ChainMap`, but it's not valid as the first argument to `super()`. +# +# error: [invalid-super-argument] "`typing.ChainMap` is not a valid class" +reveal_type(super(typing.ChainMap, collections.ChainMap())) # revealed: Unknown + +# Meanwhile, it's not valid to inherit from unsubscripted `typing.Generic`, +# but it *is* valid as the first argument to `super()`. +reveal_type(super(typing.Generic, typing.SupportsInt)) # revealed: > + +def _(x: type[typing.Any], y: typing.Any): + reveal_type(super(x, y)) # revealed: ``` ### Instance Member Access via `super` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 3c6a9d2e8caec..2ae65d7f90557 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -9526,23 +9526,32 @@ impl<'db> BoundSuperType<'db> { )); } - // TODO: having to get a class-literal just to pass it in here is silly. - // `BoundSuperType` should probably not be using `ClassBase::try_from_type` here; - // this also leads to false negatives in some cases. See discussion in - // . - let pivot_class = ClassBase::try_from_type( - db, - pivot_class_type, - KnownClass::Object - .to_class_literal(db) - .into_class_literal() - .expect("`object` should always exist in typeshed"), - ) - .ok_or({ - BoundSuperError::InvalidPivotClassType { - pivot_class: pivot_class_type, + // We don't use `Classbase::try_from_type` here because: + // - There are objects that may validly be present in a class's bases list + // but are not valid as pivot classes, e.g. `typing.ChainMap` + // - There are objects that are not valid in a class's bases list + // but are valid as pivot classes, e.g. unsubscripted `typing.Generic` + let pivot_class = match pivot_class_type { + Type::ClassLiteral(class) => ClassBase::Class(ClassType::NonGeneric(class)), + Type::GenericAlias(class) => ClassBase::Class(ClassType::Generic(class)), + Type::SubclassOf(subclass_of) if subclass_of.subclass_of().is_dynamic() => { + ClassBase::Dynamic( + subclass_of + .subclass_of() + .into_dynamic() + .expect("Checked in branch arm"), + ) } - })?; + Type::SpecialForm(SpecialFormType::Protocol) => ClassBase::Protocol, + Type::SpecialForm(SpecialFormType::Generic) => ClassBase::Generic, + Type::SpecialForm(SpecialFormType::TypedDict) => ClassBase::TypedDict, + Type::Dynamic(dynamic) => ClassBase::Dynamic(dynamic), + _ => { + return Err(BoundSuperError::InvalidPivotClassType { + pivot_class: pivot_class_type, + }); + } + }; let owner = SuperOwnerKind::try_from_type(db, owner_type) .and_then(|owner| { From f6093452edf5e54463e3d3ad2a3ada9d89b97ae5 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 14 Aug 2025 22:25:45 +0100 Subject: [PATCH 004/160] [ty] Synthesize read-only properties for all declared members on `NamedTuple` classes (#19899) --- .../resources/mdtest/named_tuple.md | 63 ++++++++++++++++++- crates/ty_python_semantic/src/types/class.rs | 16 ++++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/named_tuple.md b/crates/ty_python_semantic/resources/mdtest/named_tuple.md index 3530ac4da4f1f..e642b25b2eb8d 100644 --- a/crates/ty_python_semantic/resources/mdtest/named_tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/named_tuple.md @@ -74,8 +74,16 @@ Person(3, "Eve", 99, "extra") # error: [invalid-argument-type] Person(id="3", name="Eve") -# TODO: over-writing NamedTuple fields should be an error +reveal_type(Person.id) # revealed: property +reveal_type(Person.name) # revealed: property +reveal_type(Person.age) # revealed: property + +# TODO... the error is correct, but this is not the friendliest error message +# for assigning to a read-only property :-) +# +# error: [invalid-assignment] "Invalid assignment to data descriptor attribute `id` on type `Person` with custom `__set__` method" alice.id = 42 +# error: [invalid-assignment] bob.age = None ``` @@ -151,9 +159,42 @@ from typing import NamedTuple class User(NamedTuple): id: int name: str + age: int | None + nickname: str class SuperUser(User): - id: int # this should be an error + # TODO: this should be an error because it implies that the `id` attribute on + # `SuperUser` is mutable, but the read-only `id` property from the superclass + # has not been overridden in the class body + id: int + + # this is fine; overriding a read-only attribute with a mutable one + # does not conflict with the Liskov Substitution Principle + name: str = "foo" + + # this is also fine + @property + def age(self) -> int: + return super().age or 42 + + def now_called_robert(self): + self.name = "Robert" # fine because overridden with a mutable attribute + + # TODO: this should cause us to emit an error as we're assigning to a read-only property + # inherited from the `NamedTuple` superclass (requires https://github.com/astral-sh/ty/issues/159) + self.nickname = "Bob" + +james = SuperUser(0, "James", 42, "Jimmy") + +# fine because the property on the superclass was overridden with a mutable attribute +# on the subclass +james.name = "Robert" + +# TODO: the error is correct (can't assign to the read-only property inherited from the superclass) +# but the error message could be friendlier :-) +# +# error: [invalid-assignment] "Invalid assignment to data descriptor attribute `nickname` on type `SuperUser` with custom `__set__` method" +james.nickname = "Bob" ``` ### Generic named tuples @@ -164,13 +205,29 @@ python-version = "3.12" ``` ```py -from typing import NamedTuple +from typing import NamedTuple, Generic, TypeVar class Property[T](NamedTuple): name: str value: T reveal_type(Property("height", 3.4)) # revealed: Property[float] +reveal_type(Property.value) # revealed: property +reveal_type(Property.value.fget) # revealed: (self, /) -> Unknown +reveal_type(Property[str].value.fget) # revealed: (self, /) -> str +reveal_type(Property("height", 3.4).value) # revealed: float + +T = TypeVar("T") + +class LegacyProperty(NamedTuple, Generic[T]): + name: str + value: T + +reveal_type(LegacyProperty("height", 42)) # revealed: LegacyProperty[int] +reveal_type(LegacyProperty.value) # revealed: property +reveal_type(LegacyProperty.value.fget) # revealed: (self, /) -> Unknown +reveal_type(LegacyProperty[str].value.fget) # revealed: (self, /) -> str +reveal_type(LegacyProperty("height", 3.4).value) # revealed: float ``` ## Attributes on `NamedTuple` diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 0940ec1f6def9..60cf7c491e417 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -24,8 +24,8 @@ use crate::types::tuple::{TupleSpec, TupleType}; use crate::types::{ ApplyTypeMappingVisitor, BareTypeAliasType, Binding, BoundSuperError, BoundSuperType, CallableType, DataclassParams, DeprecatedInstance, HasRelationToVisitor, KnownInstanceType, - NormalizedVisitor, StringLiteralType, TypeAliasType, TypeMapping, TypeRelation, - TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, declaration_type, + NormalizedVisitor, PropertyInstanceType, StringLiteralType, TypeAliasType, TypeMapping, + TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, declaration_type, infer_definition_types, todo_type, }; use crate::{ @@ -1862,6 +1862,18 @@ impl<'db> ClassLiteral<'db> { .with_qualifiers(TypeQualifiers::CLASS_VAR); } + if CodeGeneratorKind::NamedTuple.matches(db, self) { + if let Some(field) = self.own_fields(db, specialization).get(name) { + let property_getter_signature = Signature::new( + Parameters::new([Parameter::positional_only(Some(Name::new_static("self")))]), + Some(field.declared_ty), + ); + let property_getter = CallableType::single(db, property_getter_signature); + let property = PropertyInstanceType::new(db, Some(property_getter), None); + return Place::bound(Type::PropertyInstance(property)).into(); + } + } + let body_scope = self.body_scope(db); let symbol = class_symbol(db, body_scope, name).map_type(|ty| { // The `__new__` and `__init__` members of a non-specialized generic class are handled From 957320c0f17080a9ccfd788b9d6ed998050b0052 Mon Sep 17 00:00:00 2001 From: Andrii Turov Date: Fri, 15 Aug 2025 00:38:33 +0300 Subject: [PATCH 005/160] [ty] Add diagnostics for invalid `await` expressions (#19711) ## Summary This PR adds a new lint, `invalid-await`, for all sorts of reasons why an object may not be `await`able, as discussed in astral-sh/ty#919. Precisely, `__await__` is guarded against being missing, possibly unbound, or improperly defined (expects additional arguments or doesn't return an iterator). Of course, diagnostics need to be fine-tuned. If `__await__` cannot be called with no extra arguments, it indicates an error (or a quirk?) in the method signature, not at the call site. Without any doubt, such an object is not `Awaitable`, but I feel like talking about arguments for an *implicit* call is a bit leaky. I didn't reference any actual diagnostic messages in the lint definition, because I want to hear feedback first. Also, there's no mention of the actual required method signature for `__await__` anywhere in the docs. The only reference I had is the `typing` stub. I basically ended up linking `[Awaitable]` to ["must implement `__await__`"](https://docs.python.org/3/library/collections.abc.html#collections.abc.Awaitable), which is insufficient on its own. ## Test Plan The following code was tested: ```python import asyncio import typing class Awaitable: def __await__(self) -> typing.Generator[typing.Any, None, int]: yield None return 5 class NoDunderMethod: pass class InvalidAwaitArgs: def __await__(self, value: int) -> int: return value class InvalidAwaitReturn: def __await__(self) -> int: return 5 class InvalidAwaitReturnImplicit: def __await__(self): pass async def main() -> None: result = await Awaitable() # valid result = await NoDunderMethod() # `__await__` is missing result = await InvalidAwaitReturn() # `__await__` returns `int`, which is not a valid iterator result = await InvalidAwaitArgs() # `__await__` expects additional arguments and cannot be called implicitly result = await InvalidAwaitReturnImplicit() # `__await__` returns `Unknown`, which is not a valid iterator asyncio.run(main()) ``` --------- Co-authored-by: Carl Meyer --- crates/ty/docs/rules.md | 154 +++++++++++------- .../mdtest/diagnostics/invalid_await.md | 105 ++++++++++++ ...2\200\246_-_Basic_(f15db7dc447d0795).snap" | 41 +++++ ...h_mis\342\200\246_(9ce1ee3cd1c9c8d1).snap" | 41 +++++ ...h_pos\342\200\246_(e3444b7a7f960d04).snap" | 47 ++++++ ...eturn\342\200\246_(fedf62ffaca0f2d7).snap" | 45 +++++ ..._awai\342\200\246_(d78580fb6720e4ea).snap" | 35 ++++ ...initi\342\200\246_(15b05c126b6ae968).snap" | 43 +++++ ...initi\342\200\246_(ccb69f512135dd61).snap" | 43 +++++ crates/ty_python_semantic/src/types.rs | 143 +++++++++++++--- .../src/types/diagnostic.rs | 31 ++++ .../ty_python_semantic/src/types/function.rs | 1 - crates/ty_python_semantic/src/types/infer.rs | 6 +- ty.schema.json | 10 ++ 14 files changed, 661 insertions(+), 84 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_mis\342\200\246_(9ce1ee3cd1c9c8d1).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_pos\342\200\246_(e3444b7a7f960d04).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Invalid_union_return\342\200\246_(fedf62ffaca0f2d7).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Non-callable_`__awai\342\200\246_(d78580fb6720e4ea).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(15b05c126b6ae968).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(ccb69f512135dd61).snap" diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index 3db6a2b32b1bb..9aadce2eca419 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -36,7 +36,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-non-callable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L101) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L102) **What it does** @@ -58,7 +58,7 @@ Calling a non-callable object will raise a `TypeError` at runtime. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-argument-forms) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L145) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L146) **What it does** @@ -88,7 +88,7 @@ f(int) # error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-declarations) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L171) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L172) **What it does** @@ -117,7 +117,7 @@ a = 1 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L196) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L197) **What it does** @@ -147,7 +147,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20cyclic-class-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L222) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L223) **What it does** @@ -177,7 +177,7 @@ class B(A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L287) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L288) **What it does** @@ -202,7 +202,7 @@ class B(A, A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-kw-only) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L308) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L309) **What it does** @@ -306,7 +306,7 @@ def test(): -> "Literal[5]": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20inconsistent-mro) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L450) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L451) **What it does** @@ -334,7 +334,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20index-out-of-bounds) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L474) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L475) **What it does** @@ -358,7 +358,7 @@ t[3] # IndexError: tuple index out of range Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20instance-layout-conflict) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L340) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L341) **What it does** @@ -445,7 +445,7 @@ an atypical memory layout. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-argument-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L519) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L520) **What it does** @@ -470,7 +470,7 @@ func("foo") # error: [invalid-argument-type] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-assignment) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L559) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L560) **What it does** @@ -496,7 +496,7 @@ a: int = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-attribute-access) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1563) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1594) **What it does** @@ -523,12 +523,46 @@ C().instance_var = 3 # okay C.instance_var = 3 # error: Cannot assign to instance variable ``` +## `invalid-await` + + +Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · +[Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-await) · +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L582) + + +**What it does** + +Checks for `await` being used with types that are not [Awaitable]. + +**Why is this bad?** + +Such expressions will lead to `TypeError` being raised at runtime. + +**Examples** + +```python +import asyncio + +class InvalidAwait: + def __await__(self) -> int: + return 5 + +async def main() -> None: + await InvalidAwait() # error: [invalid-await] + await 42 # error: [invalid-await] + +asyncio.run(main()) +``` + +[Awaitable]: https://docs.python.org/3/library/collections.abc.html#collections.abc.Awaitable + ## `invalid-base` Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L581) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L612) **What it does** @@ -550,7 +584,7 @@ class A(42): ... # error: [invalid-base] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-context-manager) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L632) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L663) **What it does** @@ -575,7 +609,7 @@ with 1: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-declaration) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L653) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L684) **What it does** @@ -602,7 +636,7 @@ a: str Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-exception-caught) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L676) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L707) **What it does** @@ -644,7 +678,7 @@ except ZeroDivisionError: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-generic-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L712) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L743) **What it does** @@ -675,7 +709,7 @@ class C[U](Generic[T]): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-key) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L494) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L495) **What it does** @@ -704,7 +738,7 @@ alice["height"] # KeyError: 'height' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-legacy-type-variable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L738) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L769) **What it does** @@ -737,7 +771,7 @@ def f(t: TypeVar("U")): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L787) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L818) **What it does** @@ -769,7 +803,7 @@ class B(metaclass=f): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L814) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L845) **What it does** @@ -817,7 +851,7 @@ def foo(x: int) -> int: ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-parameter-default) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L857) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L888) **What it does** @@ -841,7 +875,7 @@ def f(a: int = ''): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-protocol) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L422) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L423) **What it does** @@ -873,7 +907,7 @@ TypeError: Protocols can only inherit from other protocols, got Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-raise) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L877) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L908) Checks for `raise` statements that raise non-exceptions or use invalid @@ -920,7 +954,7 @@ def g(): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-return-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L540) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L541) **What it does** @@ -943,7 +977,7 @@ def func() -> int: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-super-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L920) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L951) **What it does** @@ -997,7 +1031,7 @@ TODO #14889 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-alias-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L766) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L797) **What it does** @@ -1022,7 +1056,7 @@ NewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name mus Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-checking-constant) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L959) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L990) **What it does** @@ -1050,7 +1084,7 @@ TYPE_CHECKING = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-form) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L983) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1014) **What it does** @@ -1078,7 +1112,7 @@ b: Annotated[int] # `Annotated` expects at least two arguments Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1035) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1066) **What it does** @@ -1110,7 +1144,7 @@ f(10) # Error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1007) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1038) **What it does** @@ -1142,7 +1176,7 @@ class C: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-variable-constraints) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1063) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1094) **What it does** @@ -1175,7 +1209,7 @@ T = TypeVar('T', bound=str) # valid bound TypeVar Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1092) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1123) **What it does** @@ -1198,7 +1232,7 @@ func() # TypeError: func() missing 1 required positional argument: 'x' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20no-matching-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1111) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1142) **What it does** @@ -1225,7 +1259,7 @@ func("string") # error: [no-matching-overload] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20non-subscriptable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1134) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1165) **What it does** @@ -1247,7 +1281,7 @@ Subscripting an object that does not support it will raise a `TypeError` at runt Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20not-iterable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1152) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1183) **What it does** @@ -1271,7 +1305,7 @@ for i in 34: # TypeError: 'int' object is not iterable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20parameter-already-assigned) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1203) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1234) **What it does** @@ -1325,7 +1359,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20static-assert-error) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1539) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1570) **What it does** @@ -1353,7 +1387,7 @@ static_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known tr Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20subclass-of-final-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1294) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1325) **What it does** @@ -1380,7 +1414,7 @@ class B(A): ... # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20too-many-positional-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1339) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1370) **What it does** @@ -1405,7 +1439,7 @@ f("foo") # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20type-assertion-failure) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1317) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1348) **What it does** @@ -1431,7 +1465,7 @@ def _(x: int): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unavailable-implicit-super-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1360) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1391) **What it does** @@ -1475,7 +1509,7 @@ class A: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unknown-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1417) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1448) **What it does** @@ -1500,7 +1534,7 @@ f(x=1, y=2) # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1438) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1469) **What it does** @@ -1526,7 +1560,7 @@ A().foo # AttributeError: 'A' object has no attribute 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1460) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1491) **What it does** @@ -1549,7 +1583,7 @@ import foo # ModuleNotFoundError: No module named 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1479) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1510) **What it does** @@ -1572,7 +1606,7 @@ print(x) # NameError: name 'x' is not defined Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-bool-conversion) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1172) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1203) **What it does** @@ -1607,7 +1641,7 @@ b1 < b2 < b1 # exception raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-operator) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1498) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1529) **What it does** @@ -1633,7 +1667,7 @@ A() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20zero-stepsize-in-slice) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1520) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1551) **What it does** @@ -1656,7 +1690,7 @@ l[1:10:0] # ValueError: slice step cannot be zero Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20deprecated) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L266) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L267) **What it does** @@ -1709,7 +1743,7 @@ a = 20 / 0 # type: ignore Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1224) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1255) **What it does** @@ -1735,7 +1769,7 @@ A.c # AttributeError: type object 'A' has no attribute 'c' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-implicit-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L119) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L120) **What it does** @@ -1765,7 +1799,7 @@ A()[0] # TypeError: 'A' object is not subscriptable Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1246) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1277) **What it does** @@ -1795,7 +1829,7 @@ from module import a # ImportError: cannot import name 'a' from 'module' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20redundant-cast) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1591) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1622) **What it does** @@ -1820,7 +1854,7 @@ cast(int, f()) # Redundant Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20undefined-reveal) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1399) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1430) **What it does** @@ -1871,7 +1905,7 @@ a = 20 / 0 # ty: ignore[division-by-zero] Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-global) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1612) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1643) **What it does** @@ -1925,7 +1959,7 @@ def g(): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L599) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L630) **What it does** @@ -1962,7 +1996,7 @@ class D(C): ... # error: [unsupported-base] Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20division-by-zero) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L248) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L249) **What it does** @@ -1984,7 +2018,7 @@ Dividing by zero raises a `ZeroDivisionError` at runtime. Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1272) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1303) **What it does** diff --git a/crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md b/crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md new file mode 100644 index 0000000000000..60d3439366f17 --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md @@ -0,0 +1,105 @@ +# Invalid await diagnostics + + + +## Basic + +This is a test showcasing a primitive case where an object is not awaitable. + +```py +async def main() -> None: + await 1 # error: [invalid-await] +``` + +## Custom type with missing `__await__` + +This diagnostic also points to the class definition if available. + +```py +class MissingAwait: + pass + +async def main() -> None: + await MissingAwait() # error: [invalid-await] +``` + +## Custom type with possibly unbound `__await__` + +This diagnostic also points to the method definition if available. + +```py +from datetime import datetime + +class PossiblyUnbound: + if datetime.today().weekday() == 0: + def __await__(self): + yield + +async def main() -> None: + await PossiblyUnbound() # error: [invalid-await] +``` + +## `__await__` definition with extra arguments + +Currently, the signature of `__await__` isn't checked for conformity with the `Awaitable` protocol +directly. Instead, individual anomalies are reported, such as the following. Here, the diagnostic +reports that the object is not implicitly awaitable, while also pointing at the function parameters. + +```py +class InvalidAwaitArgs: + def __await__(self, value: int): + yield value + +async def main() -> None: + await InvalidAwaitArgs() # error: [invalid-await] +``` + +## Non-callable `__await__` + +This diagnostic doesn't point to the attribute definition, but complains about it being possibly not +awaitable. + +```py +class NonCallableAwait: + __await__ = 42 + +async def main() -> None: + await NonCallableAwait() # error: [invalid-await] +``` + +## `__await__` definition with explicit invalid return type + +`__await__` must return a valid iterator. This diagnostic also points to the method definition if +available. + +```py +class InvalidAwaitReturn: + def __await__(self) -> int: + return 5 + +async def main() -> None: + await InvalidAwaitReturn() # error: [invalid-await] +``` + +## Invalid union return type + +When multiple potential definitions of `__await__` exist, all of them must be proper in order for an +instance to be awaitable. In this specific case, no specific function definition is highlighted. + +```py +import typing +from datetime import datetime + +class UnawaitableUnion: + if datetime.today().weekday() == 6: + + def __await__(self) -> typing.Generator[typing.Any, None, None]: + yield + else: + + def __await__(self) -> int: + return 5 + +async def main() -> None: + await UnawaitableUnion() # error: [invalid-await] +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" new file mode 100644 index 0000000000000..c4304a77ee004 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" @@ -0,0 +1,41 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: invalid_await.md - Invalid await diagnostics - Basic +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md +--- + +# Python source files + +## mdtest_snippet.py + +``` +1 | async def main() -> None: +2 | await 1 # error: [invalid-await] +``` + +# Diagnostics + +``` +error[invalid-await]: `Literal[1]` is not awaitable + --> src/mdtest_snippet.py:2:11 + | + 1 | async def main() -> None: + 2 | await 1 # error: [invalid-await] + | ^ + | + ::: stdlib/builtins.pyi:337:7 + | +335 | _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed +336 | +337 | class int: + | --- type defined here +338 | """int([x]) -> integer +339 | int(x, base=10) -> integer + | +info: `__await__` is missing +info: rule `invalid-await` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_mis\342\200\246_(9ce1ee3cd1c9c8d1).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_mis\342\200\246_(9ce1ee3cd1c9c8d1).snap" new file mode 100644 index 0000000000000..fcf21676b7e7b --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_mis\342\200\246_(9ce1ee3cd1c9c8d1).snap" @@ -0,0 +1,41 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: invalid_await.md - Invalid await diagnostics - Custom type with missing `__await__` +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md +--- + +# Python source files + +## mdtest_snippet.py + +``` +1 | class MissingAwait: +2 | pass +3 | +4 | async def main() -> None: +5 | await MissingAwait() # error: [invalid-await] +``` + +# Diagnostics + +``` +error[invalid-await]: `MissingAwait` is not awaitable + --> src/mdtest_snippet.py:5:11 + | +4 | async def main() -> None: +5 | await MissingAwait() # error: [invalid-await] + | ^^^^^^^^^^^^^^ + | + ::: src/mdtest_snippet.py:1:7 + | +1 | class MissingAwait: + | ------------ type defined here +2 | pass + | +info: `__await__` is missing +info: rule `invalid-await` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_pos\342\200\246_(e3444b7a7f960d04).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_pos\342\200\246_(e3444b7a7f960d04).snap" new file mode 100644 index 0000000000000..22233a6acda59 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Custom_type_with_pos\342\200\246_(e3444b7a7f960d04).snap" @@ -0,0 +1,47 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: invalid_await.md - Invalid await diagnostics - Custom type with possibly unbound `__await__` +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md +--- + +# Python source files + +## mdtest_snippet.py + +``` +1 | from datetime import datetime +2 | +3 | class PossiblyUnbound: +4 | if datetime.today().weekday() == 0: +5 | def __await__(self): +6 | yield +7 | +8 | async def main() -> None: +9 | await PossiblyUnbound() # error: [invalid-await] +``` + +# Diagnostics + +``` +error[invalid-await]: `PossiblyUnbound` is not awaitable + --> src/mdtest_snippet.py:9:11 + | +8 | async def main() -> None: +9 | await PossiblyUnbound() # error: [invalid-await] + | ^^^^^^^^^^^^^^^^^ + | + ::: src/mdtest_snippet.py:5:13 + | +3 | class PossiblyUnbound: +4 | if datetime.today().weekday() == 0: +5 | def __await__(self): + | --------------- method defined here +6 | yield + | +info: `__await__` is possibly unbound +info: rule `invalid-await` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Invalid_union_return\342\200\246_(fedf62ffaca0f2d7).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Invalid_union_return\342\200\246_(fedf62ffaca0f2d7).snap" new file mode 100644 index 0000000000000..302b21afc7e6d --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Invalid_union_return\342\200\246_(fedf62ffaca0f2d7).snap" @@ -0,0 +1,45 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: invalid_await.md - Invalid await diagnostics - Invalid union return type +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md +--- + +# Python source files + +## mdtest_snippet.py + +``` + 1 | import typing + 2 | from datetime import datetime + 3 | + 4 | class UnawaitableUnion: + 5 | if datetime.today().weekday() == 6: + 6 | + 7 | def __await__(self) -> typing.Generator[typing.Any, None, None]: + 8 | yield + 9 | else: +10 | +11 | def __await__(self) -> int: +12 | return 5 +13 | +14 | async def main() -> None: +15 | await UnawaitableUnion() # error: [invalid-await] +``` + +# Diagnostics + +``` +error[invalid-await]: `UnawaitableUnion` is not awaitable + --> src/mdtest_snippet.py:15:11 + | +14 | async def main() -> None: +15 | await UnawaitableUnion() # error: [invalid-await] + | ^^^^^^^^^^^^^^^^^^ + | +info: `__await__` returns `Generator[Any, None, None] | int`, which is not a valid iterator +info: rule `invalid-await` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Non-callable_`__awai\342\200\246_(d78580fb6720e4ea).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Non-callable_`__awai\342\200\246_(d78580fb6720e4ea).snap" new file mode 100644 index 0000000000000..890ea11b49759 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Non-callable_`__awai\342\200\246_(d78580fb6720e4ea).snap" @@ -0,0 +1,35 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: invalid_await.md - Invalid await diagnostics - Non-callable `__await__` +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md +--- + +# Python source files + +## mdtest_snippet.py + +``` +1 | class NonCallableAwait: +2 | __await__ = 42 +3 | +4 | async def main() -> None: +5 | await NonCallableAwait() # error: [invalid-await] +``` + +# Diagnostics + +``` +error[invalid-await]: `NonCallableAwait` is not awaitable + --> src/mdtest_snippet.py:5:11 + | +4 | async def main() -> None: +5 | await NonCallableAwait() # error: [invalid-await] + | ^^^^^^^^^^^^^^^^^^ + | +info: `__await__` is possibly not callable +info: rule `invalid-await` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(15b05c126b6ae968).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(15b05c126b6ae968).snap" new file mode 100644 index 0000000000000..c5fe4db415df7 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(15b05c126b6ae968).snap" @@ -0,0 +1,43 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: invalid_await.md - Invalid await diagnostics - `__await__` definition with extra arguments +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md +--- + +# Python source files + +## mdtest_snippet.py + +``` +1 | class InvalidAwaitArgs: +2 | def __await__(self, value: int): +3 | yield value +4 | +5 | async def main() -> None: +6 | await InvalidAwaitArgs() # error: [invalid-await] +``` + +# Diagnostics + +``` +error[invalid-await]: `InvalidAwaitArgs` is not awaitable + --> src/mdtest_snippet.py:6:11 + | +5 | async def main() -> None: +6 | await InvalidAwaitArgs() # error: [invalid-await] + | ^^^^^^^^^^^^^^^^^^ + | + ::: src/mdtest_snippet.py:2:18 + | +1 | class InvalidAwaitArgs: +2 | def __await__(self, value: int): + | ------------------ parameters here +3 | yield value + | +info: `__await__` requires arguments and cannot be called implicitly +info: rule `invalid-await` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(ccb69f512135dd61).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(ccb69f512135dd61).snap" new file mode 100644 index 0000000000000..b7fa723787875 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_`__await__`_definiti\342\200\246_(ccb69f512135dd61).snap" @@ -0,0 +1,43 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: invalid_await.md - Invalid await diagnostics - `__await__` definition with explicit invalid return type +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/invalid_await.md +--- + +# Python source files + +## mdtest_snippet.py + +``` +1 | class InvalidAwaitReturn: +2 | def __await__(self) -> int: +3 | return 5 +4 | +5 | async def main() -> None: +6 | await InvalidAwaitReturn() # error: [invalid-await] +``` + +# Diagnostics + +``` +error[invalid-await]: `InvalidAwaitReturn` is not awaitable + --> src/mdtest_snippet.py:6:11 + | +5 | async def main() -> None: +6 | await InvalidAwaitReturn() # error: [invalid-await] + | ^^^^^^^^^^^^^^^^^^^^ + | + ::: src/mdtest_snippet.py:2:9 + | +1 | class InvalidAwaitReturn: +2 | def __await__(self) -> int: + | ---------------------- method defined here +3 | return 5 + | +info: `__await__` returns `int`, which is not a valid iterator +info: rule `invalid-await` is enabled by default + +``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 2ae65d7f90557..89b66a6b343a3 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -41,7 +41,7 @@ use crate::types::call::{Binding, Bindings, CallArguments, CallableBinding}; use crate::types::class::{CodeGeneratorKind, Field}; pub(crate) use crate::types::class_base::ClassBase; use crate::types::context::{LintDiagnosticGuard, LintDiagnosticGuardBuilder}; -use crate::types::diagnostic::{INVALID_TYPE_FORM, UNSUPPORTED_BOOL_CONVERSION}; +use crate::types::diagnostic::{INVALID_AWAIT, INVALID_TYPE_FORM, UNSUPPORTED_BOOL_CONVERSION}; use crate::types::enums::{enum_metadata, is_single_member_enum}; use crate::types::function::{ DataclassTransformerParams, FunctionSpans, FunctionType, KnownFunction, @@ -4778,20 +4778,24 @@ impl<'db> Type<'db> { mode: EvaluationMode, ) -> Result>, IterationError<'db>> { if mode.is_async() { - let try_call_dunder_anext_on_iterator = |iterator: Type<'db>| { + let try_call_dunder_anext_on_iterator = |iterator: Type<'db>| -> Result< + Result, AwaitError<'db>>, + CallDunderError<'db>, + > { iterator .try_call_dunder(db, "__anext__", CallArguments::none()) - .map(|dunder_anext_outcome| { - dunder_anext_outcome.return_type(db).resolve_await(db) - }) + .map(|dunder_anext_outcome| dunder_anext_outcome.return_type(db).try_await(db)) }; return match self.try_call_dunder(db, "__aiter__", CallArguments::none()) { Ok(dunder_aiter_bindings) => { let iterator = dunder_aiter_bindings.return_type(db); match try_call_dunder_anext_on_iterator(iterator) { - Ok(result) => Ok(Cow::Owned(TupleSpec::homogeneous(result))), - Err(dunder_anext_error) => { + Ok(Ok(result)) => Ok(Cow::Owned(TupleSpec::homogeneous(result))), + Ok(Err(AwaitError::InvalidReturnType(..))) => { + Err(IterationError::UnboundAiterError) + } // TODO: __anext__ is bound, but is not properly awaitable + Err(dunder_anext_error) | Ok(Err(AwaitError::Call(dunder_anext_error))) => { Err(IterationError::IterReturnsInvalidIterator { iterator, dunder_error: dunder_anext_error, @@ -4996,7 +5000,7 @@ impl<'db> Type<'db> { (Ok(enter), Ok(_)) => { let ty = enter.return_type(db); Ok(if mode.is_async() { - ty.resolve_await(db) + ty.try_await(db).unwrap_or(Type::unknown()) } else { ty }) @@ -5005,7 +5009,7 @@ impl<'db> Type<'db> { let ty = enter.return_type(db); Err(ContextManagerError::Exit { enter_return_type: if mode.is_async() { - ty.resolve_await(db) + ty.try_await(db).unwrap_or(Type::unknown()) } else { ty }, @@ -5024,15 +5028,17 @@ impl<'db> Type<'db> { } /// Resolve the type of an `await …` expression where `self` is the type of the awaitable. - fn resolve_await(self, db: &'db dyn Db) -> Type<'db> { - // TODO: Add proper error handling and rename this method to `try_await`. - self.try_call_dunder(db, "__await__", CallArguments::none()) - .map_or(Type::unknown(), |result| { - result - .return_type(db) - .generator_return_type(db) - .unwrap_or_else(Type::unknown) - }) + fn try_await(self, db: &'db dyn Db) -> Result, AwaitError<'db>> { + let await_result = self.try_call_dunder(db, "__await__", CallArguments::none()); + match await_result { + Ok(bindings) => { + let return_type = bindings.return_type(db); + Ok(return_type.generator_return_type(db).ok_or_else(|| { + AwaitError::InvalidReturnType(return_type, Box::new(bindings)) + })?) + } + Err(call_error) => Err(AwaitError::Call(call_error)), + } } /// Get the return type of a `yield from …` expression where `self` is the type of the generator. @@ -5068,6 +5074,8 @@ impl<'db> Type<'db> { None } } + Type::Union(union) => union.try_map(db, |ty| ty.generator_return_type(db)), + ty @ (Type::Dynamic(_) | Type::Never) => Some(ty), _ => None, } } @@ -7224,6 +7232,97 @@ impl<'db> TypeVarBoundOrConstraints<'db> { } } +/// Error returned if a type is not awaitable. +#[derive(Debug)] +enum AwaitError<'db> { + /// `__await__` is either missing, potentially unbound or cannot be called with provided + /// arguments. + Call(CallDunderError<'db>), + /// `__await__` resolved successfully, but its return type is known not to be a generator. + InvalidReturnType(Type<'db>, Box>), +} + +impl<'db> AwaitError<'db> { + fn report_diagnostic( + &self, + context: &InferContext<'db, '_>, + context_expression_type: Type<'db>, + context_expression_node: ast::AnyNodeRef, + ) { + let Some(builder) = context.report_lint(&INVALID_AWAIT, context_expression_node) else { + return; + }; + + let db = context.db(); + + let mut diag = builder.into_diagnostic( + format_args!("`{type}` is not awaitable", type = context_expression_type.display(db)), + ); + match self { + Self::Call(CallDunderError::CallError(CallErrorKind::BindingError, bindings)) => { + diag.info("`__await__` requires arguments and cannot be called implicitly"); + if let Some(definition_spans) = bindings.callable_type().function_spans(db) { + diag.annotate( + Annotation::secondary(definition_spans.parameters) + .message("parameters here"), + ); + } + } + Self::Call(CallDunderError::CallError( + kind @ (CallErrorKind::NotCallable | CallErrorKind::PossiblyNotCallable), + bindings, + )) => { + let possibly = if matches!(kind, CallErrorKind::PossiblyNotCallable) { + " possibly" + } else { + "" + }; + diag.info(format_args!("`__await__` is{possibly} not callable")); + if let Some(definition) = bindings.callable_type().definition(db) { + if let Some(definition_range) = definition.focus_range(db) { + diag.annotate( + Annotation::secondary(definition_range.into()) + .message("attribute defined here"), + ); + } + } + } + Self::Call(CallDunderError::PossiblyUnbound(bindings)) => { + diag.info("`__await__` is possibly unbound"); + if let Some(definition_spans) = bindings.callable_type().function_spans(db) { + diag.annotate( + Annotation::secondary(definition_spans.signature) + .message("method defined here"), + ); + } + } + Self::Call(CallDunderError::MethodNotAvailable) => { + diag.info("`__await__` is missing"); + if let Some(type_definition) = context_expression_type.definition(db) { + if let Some(definition_range) = type_definition.focus_range(db) { + diag.annotate( + Annotation::secondary(definition_range.into()) + .message("type defined here"), + ); + } + } + } + Self::InvalidReturnType(return_type, bindings) => { + diag.info(format_args!( + "`__await__` returns `{return_type}`, which is not a valid iterator", + return_type = return_type.display(db) + )); + if let Some(definition_spans) = bindings.callable_type().function_spans(db) { + diag.annotate( + Annotation::secondary(definition_spans.signature) + .message("method defined here"), + ); + } + } + } + } +} + /// Error returned if a type is not (or may not be) a context manager. #[derive(Debug)] enum ContextManagerError<'db> { @@ -7447,11 +7546,11 @@ impl<'db> IterationError<'db> { match self { Self::IterReturnsInvalidIterator { dunder_error, mode, .. - } => dunder_error.return_type(db).map(|ty| { + } => dunder_error.return_type(db).and_then(|ty| { if mode.is_async() { - ty.resolve_await(db) + ty.try_await(db).ok() } else { - ty + Some(ty) } }), @@ -7466,7 +7565,7 @@ impl<'db> IterationError<'db> { "__anext__", CallArguments::none(), )) - .map(|ty| ty.resolve_await(db)) + .and_then(|ty| ty.try_await(db).ok()) } else { return_type(dunder_iter_bindings.return_type(db).try_call_dunder( db, diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index 6339383005bf3..113d0fa508a7b 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -45,6 +45,7 @@ pub(crate) fn register_lints(registry: &mut LintRegistryBuilder) { registry.register_lint(&INVALID_ARGUMENT_TYPE); registry.register_lint(&INVALID_RETURN_TYPE); registry.register_lint(&INVALID_ASSIGNMENT); + registry.register_lint(&INVALID_AWAIT); registry.register_lint(&INVALID_BASE); registry.register_lint(&INVALID_CONTEXT_MANAGER); registry.register_lint(&INVALID_DECLARATION); @@ -578,6 +579,36 @@ declare_lint! { } } +declare_lint! { + /// ## What it does + /// Checks for `await` being used with types that are not [Awaitable]. + /// + /// ## Why is this bad? + /// Such expressions will lead to `TypeError` being raised at runtime. + /// + /// ## Examples + /// ```python + /// import asyncio + /// + /// class InvalidAwait: + /// def __await__(self) -> int: + /// return 5 + /// + /// async def main() -> None: + /// await InvalidAwait() # error: [invalid-await] + /// await 42 # error: [invalid-await] + /// + /// asyncio.run(main()) + /// ``` + /// + /// [Awaitable]: https://docs.python.org/3/library/collections.abc.html#collections.abc.Awaitable + pub(crate) static INVALID_AWAIT = { + summary: "detects awaiting on types that don't support it", + status: LintStatus::preview("1.0.0"), + default_level: Level::Error, + } +} + declare_lint! { /// ## What it does /// Checks for class definitions that have bases which are not instances of `type`. diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 8a38ea0a84f67..632425f16c3be 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -94,7 +94,6 @@ pub(crate) struct FunctionSpans { pub(crate) name: Span, /// The span of the parameter list, including the opening and /// closing parentheses. - #[expect(dead_code)] pub(crate) parameters: Span, /// The span of the annotated return type, if present. pub(crate) return_type: Option, diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 8bba369c3b819..3f8ade1195f34 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -6380,7 +6380,11 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { node_index: _, value, } = await_expression; - self.infer_expression(value).resolve_await(self.db()) + let expr_type = self.infer_expression(value); + expr_type.try_await(self.db()).unwrap_or_else(|err| { + err.report_diagnostic(&self.context, expr_type, value.as_ref().into()); + Type::unknown() + }) } // Perform narrowing with applicable constraints between the current scope and the enclosing scope. diff --git a/ty.schema.json b/ty.schema.json index bcec1c768522d..d94057ef9e1b3 100644 --- a/ty.schema.json +++ b/ty.schema.json @@ -461,6 +461,16 @@ } ] }, + "invalid-await": { + "title": "detects awaiting on types that don't support it", + "description": "## What it does\nChecks for `await` being used with types that are not [Awaitable].\n\n## Why is this bad?\nSuch expressions will lead to `TypeError` being raised at runtime.\n\n## Examples\n```python\nimport asyncio\n\nclass InvalidAwait:\n def __await__(self) -> int:\n return 5\n\nasync def main() -> None:\n await InvalidAwait() # error: [invalid-await]\n await 42 # error: [invalid-await]\n\nasyncio.run(main())\n```\n\n[Awaitable]: https://docs.python.org/3/library/collections.abc.html#collections.abc.Awaitable", + "default": "error", + "oneOf": [ + { + "$ref": "#/definitions/Level" + } + ] + }, "invalid-base": { "title": "detects class bases that will cause the class definition to raise an exception at runtime", "description": "## What it does\nChecks for class definitions that have bases which are not instances of `type`.\n\n## Why is this bad?\nClass definitions with bases like this will lead to `TypeError` being raised at runtime.\n\n## Examples\n```python\nclass A(42): ... # error: [invalid-base]\n```", From 0e5577ab562303f4767d8be4d310d698e01a2329 Mon Sep 17 00:00:00 2001 From: Shunsuke Shibayama <45118249+mtshiba@users.noreply.github.com> Date: Fri, 15 Aug 2025 09:52:52 +0900 Subject: [PATCH 006/160] [ty] fix lazy snapshot sweeping in nested scopes (#19908) ## Summary This PR closes astral-sh/ty#955. ## Test Plan New test cases in `narrowing/conditionals/nested.md`. --- .../mdtest/narrow/conditionals/nested.md | 21 +++++++++++++ .../ty_python_semantic/src/semantic_index.rs | 30 +++++++++---------- .../src/semantic_index/builder.rs | 28 ++++++++++++----- 3 files changed, 56 insertions(+), 23 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md b/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md index ea674c8df3ffb..4ab60f5e2c163 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md @@ -240,6 +240,21 @@ def f(x: str | None): # When there is a reassignment, any narrowing constraints on the place are invalidated in lazy scopes. x = None + +def f(x: str | None): + def _(): + if x is not None: + def closure(): + reveal_type(x) # revealed: str | None + x = None + +def f(x: str | None): + class C: + def _(): + if x is not None: + def closure(): + reveal_type(x) # revealed: str + x = None # This assignment is not visible in the inner lazy scope, so narrowing is still valid. ``` If a variable defined in a private scope is never reassigned, narrowing remains in effect in the @@ -256,6 +271,12 @@ def f(const: str | None): reveal_type(const) # revealed: str [reveal_type(const) for _ in range(1)] # revealed: str + +def f(const: str | None): + def _(): + if const is not None: + def closure(): + reveal_type(const) # revealed: str ``` And even if there is an attribute or subscript assignment to the variable, narrowing of the variable diff --git a/crates/ty_python_semantic/src/semantic_index.rs b/crates/ty_python_semantic/src/semantic_index.rs index c195059b38d18..71ab64f736a5a 100644 --- a/crates/ty_python_semantic/src/semantic_index.rs +++ b/crates/ty_python_semantic/src/semantic_index.rs @@ -165,7 +165,7 @@ pub(crate) fn attribute_scopes<'db, 's>( let index = semantic_index(db, file); let class_scope_id = class_body_scope.file_scope_id(db); - ChildrenIter::new(index, class_scope_id).filter_map(move |(child_scope_id, scope)| { + ChildrenIter::new(&index.scopes, class_scope_id).filter_map(move |(child_scope_id, scope)| { let (function_scope_id, function_scope) = if scope.node().scope_kind() == ScopeKind::TypeParams { // This could be a generic method with a type-params scope. @@ -372,18 +372,18 @@ impl<'db> SemanticIndex<'db> { /// Returns an iterator over the descendent scopes of `scope`. #[allow(unused)] pub(crate) fn descendent_scopes(&self, scope: FileScopeId) -> DescendantsIter<'_> { - DescendantsIter::new(self, scope) + DescendantsIter::new(&self.scopes, scope) } /// Returns an iterator over the direct child scopes of `scope`. #[allow(unused)] pub(crate) fn child_scopes(&self, scope: FileScopeId) -> ChildrenIter<'_> { - ChildrenIter::new(self, scope) + ChildrenIter::new(&self.scopes, scope) } /// Returns an iterator over all ancestors of `scope`, starting with `scope` itself. pub(crate) fn ancestor_scopes(&self, scope: FileScopeId) -> AncestorsIter<'_> { - AncestorsIter::new(self, scope) + AncestorsIter::new(&self.scopes, scope) } /// Returns an iterator over ancestors of `scope` that are visible for name resolution, @@ -401,7 +401,7 @@ impl<'db> SemanticIndex<'db> { /// ``` /// The `method` function can see the global scope but not the class scope. pub(crate) fn visible_ancestor_scopes(&self, scope: FileScopeId) -> VisibleAncestorsIter<'_> { - VisibleAncestorsIter::new(self, scope) + VisibleAncestorsIter::new(&self.scopes, scope) } /// Returns the [`definition::Definition`] salsa ingredient(s) for `definition_key`. @@ -542,9 +542,9 @@ pub(crate) struct AncestorsIter<'a> { } impl<'a> AncestorsIter<'a> { - fn new(module_table: &'a SemanticIndex, start: FileScopeId) -> Self { + fn new(scopes: &'a IndexSlice, start: FileScopeId) -> Self { Self { - scopes: &module_table.scopes, + scopes, next_id: Some(start), } } @@ -571,10 +571,10 @@ pub(crate) struct VisibleAncestorsIter<'a> { } impl<'a> VisibleAncestorsIter<'a> { - fn new(module_table: &'a SemanticIndex, start: FileScopeId) -> Self { - let starting_scope = &module_table.scopes[start]; + fn new(scopes: &'a IndexSlice, start: FileScopeId) -> Self { + let starting_scope = &scopes[start]; Self { - inner: AncestorsIter::new(module_table, start), + inner: AncestorsIter::new(scopes, start), starting_scope_kind: starting_scope.kind(), yielded_count: 0, } @@ -617,9 +617,9 @@ pub(crate) struct DescendantsIter<'a> { } impl<'a> DescendantsIter<'a> { - fn new(index: &'a SemanticIndex, scope_id: FileScopeId) -> Self { - let scope = &index.scopes[scope_id]; - let scopes = &index.scopes[scope.descendants()]; + fn new(scopes: &'a IndexSlice, scope_id: FileScopeId) -> Self { + let scope = &scopes[scope_id]; + let scopes = &scopes[scope.descendants()]; Self { next_id: scope_id + 1, @@ -654,8 +654,8 @@ pub(crate) struct ChildrenIter<'a> { } impl<'a> ChildrenIter<'a> { - pub(crate) fn new(module_index: &'a SemanticIndex, parent: FileScopeId) -> Self { - let descendants = DescendantsIter::new(module_index, parent); + pub(crate) fn new(scopes: &'a IndexSlice, parent: FileScopeId) -> Self { + let descendants = DescendantsIter::new(scopes, parent); Self { parent, diff --git a/crates/ty_python_semantic/src/semantic_index/builder.rs b/crates/ty_python_semantic/src/semantic_index/builder.rs index 1a9b6b01a91b6..943715fd11bc0 100644 --- a/crates/ty_python_semantic/src/semantic_index/builder.rs +++ b/crates/ty_python_semantic/src/semantic_index/builder.rs @@ -47,7 +47,7 @@ use crate::semantic_index::symbol::{ScopedSymbolId, Symbol}; use crate::semantic_index::use_def::{ EnclosingSnapshotKey, FlowSnapshot, ScopedEnclosingSnapshotId, UseDefMapBuilder, }; -use crate::semantic_index::{ExpressionsScopeMap, SemanticIndex}; +use crate::semantic_index::{ExpressionsScopeMap, SemanticIndex, VisibleAncestorsIter}; use crate::semantic_model::HasTrackedScope; use crate::unpack::{EvaluationMode, Unpack, UnpackKind, UnpackPosition, UnpackValue}; use crate::{Db, Program}; @@ -400,16 +400,28 @@ impl<'db, 'ast> SemanticIndexBuilder<'db, 'ast> { } } - /// Any lazy snapshots of places that have been reassigned or modified are no longer valid, so delete them. + /// Any lazy snapshots of places that have been reassigned are no longer valid, so delete them. fn sweep_lazy_snapshots(&mut self, popped_scope_id: FileScopeId) { + // Retain only snapshots that are either eager + // || (enclosing_scope != popped_scope && popped_scope is not a visible ancestor of enclosing_scope) + // || enclosing_place is not a symbol or not reassigned + // <=> remove those that are lazy + // && (enclosing_scope == popped_scope || popped_scope is a visible ancestor of enclosing_scope) + // && enclosing_place is a symbol and reassigned self.enclosing_snapshots.retain(|key, _| { - let place_table = &self.place_tables[key.enclosing_scope]; + let popped_place_table = &self.place_tables[popped_scope_id]; key.nested_laziness.is_eager() - || key.enclosing_scope != popped_scope_id - || !key - .enclosing_place - .as_symbol() - .is_some_and(|symbol_id| place_table.symbol(symbol_id).is_reassigned()) + || (key.enclosing_scope != popped_scope_id + && VisibleAncestorsIter::new(&self.scopes, key.enclosing_scope) + .all(|(ancestor, _)| ancestor != popped_scope_id)) + || !key.enclosing_place.as_symbol().is_some_and(|symbol_id| { + let name = &self.place_tables[key.enclosing_scope] + .symbol(symbol_id) + .name(); + popped_place_table.symbol_id(name).is_some_and(|symbol_id| { + popped_place_table.symbol(symbol_id).is_reassigned() + }) + }) }); } From bd4506aac56228af83d8ad76569530b3b32be473 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 14 Aug 2025 18:09:35 -0700 Subject: [PATCH 007/160] [ty] Sync vendored typeshed stubs (#19923) Close and reopen this PR to trigger CI --------- Co-authored-by: typeshedbot <> Co-authored-by: Carl Meyer --- crates/ty_ide/src/goto_type_definition.rs | 112 +- .../resources/mdtest/call/methods.md | 2 +- .../vendor/typeshed/source_commit.txt | 2 +- .../vendor/typeshed/stdlib/_compression.pyi | 3 +- .../vendor/typeshed/stdlib/_contextvars.pyi | 2 +- .../vendor/typeshed/stdlib/_ctypes.pyi | 3 + .../typeshed/stdlib/_frozen_importlib.pyi | 11 + .../stdlib/_frozen_importlib_external.pyi | 17 +- .../vendor/typeshed/stdlib/_gdbm.pyi | 3 +- .../typeshed/stdlib/_interpchannels.pyi | 12 +- .../vendor/typeshed/stdlib/_interpreters.pyi | 4 +- .../vendor/typeshed/stdlib/_io.pyi | 1 + .../vendor/typeshed/stdlib/_msi.pyi | 5 + .../vendor/typeshed/stdlib/_operator.pyi | 1 + .../vendor/typeshed/stdlib/_pickle.pyi | 1 + .../vendor/typeshed/stdlib/_socket.pyi | 1053 ++++++++--------- .../vendor/typeshed/stdlib/_ssl.pyi | 214 ++-- .../vendor/typeshed/stdlib/_tkinter.pyi | 3 +- .../vendor/typeshed/stdlib/_winapi.pyi | 3 + .../vendor/typeshed/stdlib/_zstd.pyi | 10 +- .../vendor/typeshed/stdlib/array.pyi | 31 +- .../vendor/typeshed/stdlib/ast.pyi | 19 +- .../typeshed/stdlib/asyncio/coroutines.pyi | 3 +- .../vendor/typeshed/stdlib/asyncio/events.pyi | 6 +- .../stdlib/asyncio/format_helpers.pyi | 3 +- .../typeshed/stdlib/asyncio/streams.pyi | 3 +- .../vendor/typeshed/stdlib/asyncio/tasks.pyi | 5 +- .../vendor/typeshed/stdlib/asyncio/trsock.pyi | 31 +- .../vendor/typeshed/stdlib/bdb.pyi | 4 +- .../vendor/typeshed/stdlib/binascii.pyi | 6 +- .../vendor/typeshed/stdlib/builtins.pyi | 22 + .../vendor/typeshed/stdlib/bz2.pyi | 4 +- .../vendor/typeshed/stdlib/codecs.pyi | 12 +- .../typeshed/stdlib/collections/__init__.pyi | 5 +- .../stdlib/concurrent/futures/_base.pyi | 3 +- .../stdlib/concurrent/futures/interpreter.pyi | 59 +- .../vendor/typeshed/stdlib/configparser.pyi | 29 +- .../vendor/typeshed/stdlib/dataclasses.pyi | 1 + .../vendor/typeshed/stdlib/dbm/__init__.pyi | 1 + .../typeshed/stdlib/email/headerregistry.pyi | 3 +- .../vendor/typeshed/stdlib/email/message.pyi | 4 +- .../typeshed/stdlib/encodings/__init__.pyi | 4 + .../vendor/typeshed/stdlib/fcntl.pyi | 172 +-- .../vendor/typeshed/stdlib/functools.pyi | 6 +- .../vendor/typeshed/stdlib/gettext.pyi | 19 +- .../vendor/typeshed/stdlib/glob.pyi | 12 +- .../vendor/typeshed/stdlib/gzip.pyi | 3 +- .../vendor/typeshed/stdlib/hashlib.pyi | 4 +- .../vendor/typeshed/stdlib/html/parser.pyi | 6 +- .../vendor/typeshed/stdlib/imp.pyi | 3 +- .../typeshed/stdlib/importlib/__init__.pyi | 2 + .../vendor/typeshed/stdlib/importlib/_abc.pyi | 5 + .../vendor/typeshed/stdlib/importlib/abc.pyi | 9 +- .../stdlib/importlib/metadata/__init__.pyi | 5 +- .../vendor/typeshed/stdlib/importlib/util.pyi | 14 +- .../vendor/typeshed/stdlib/inspect.pyi | 7 +- .../vendor/typeshed/stdlib/locale.pyi | 22 +- .../typeshed/stdlib/logging/__init__.pyi | 4 +- .../typeshed/stdlib/logging/handlers.pyi | 3 +- .../vendor/typeshed/stdlib/mailbox.pyi | 5 +- .../typeshed/stdlib/multiprocessing/heap.pyi | 3 +- .../stdlib/multiprocessing/sharedctypes.pyi | 4 +- .../ty_vendored/vendor/typeshed/stdlib/nt.pyi | 3 + .../vendor/typeshed/stdlib/numbers.pyi | 16 +- .../vendor/typeshed/stdlib/os/__init__.pyi | 2 + .../typeshed/stdlib/pathlib/__init__.pyi | 37 +- .../vendor/typeshed/stdlib/pkgutil.pyi | 53 +- .../vendor/typeshed/stdlib/platform.pyi | 45 +- .../vendor/typeshed/stdlib/pty.pyi | 42 +- .../vendor/typeshed/stdlib/pydoc.pyi | 3 +- .../vendor/typeshed/stdlib/quopri.pyi | 3 +- .../ty_vendored/vendor/typeshed/stdlib/re.pyi | 11 +- .../vendor/typeshed/stdlib/shutil.pyi | 7 +- .../vendor/typeshed/stdlib/smtpd.pyi | 3 +- .../vendor/typeshed/stdlib/smtplib.pyi | 3 +- .../vendor/typeshed/stdlib/socket.pyi | 4 +- .../typeshed/stdlib/sqlite3/__init__.pyi | 4 + .../vendor/typeshed/stdlib/ssl.pyi | 161 +-- .../vendor/typeshed/stdlib/sys/__init__.pyi | 13 + .../vendor/typeshed/stdlib/termios.pyi | 533 ++++----- .../vendor/typeshed/stdlib/time.pyi | 3 +- .../typeshed/stdlib/tkinter/__init__.pyi | 6 + .../vendor/typeshed/stdlib/tkinter/dnd.pyi | 3 +- .../vendor/typeshed/stdlib/tkinter/font.pyi | 4 +- .../vendor/typeshed/stdlib/tkinter/ttk.pyi | 6 +- .../vendor/typeshed/stdlib/tty.pyi | 14 +- .../vendor/typeshed/stdlib/turtle.pyi | 7 +- .../vendor/typeshed/stdlib/typing.pyi | 32 +- .../typeshed/stdlib/typing_extensions.pyi | 6 +- .../vendor/typeshed/stdlib/unittest/case.pyi | 3 +- .../vendor/typeshed/stdlib/unittest/main.pyi | 3 +- .../vendor/typeshed/stdlib/unittest/mock.pyi | 4 +- .../typeshed/stdlib/unittest/runner.pyi | 4 +- .../vendor/typeshed/stdlib/urllib/request.pyi | 7 +- .../vendor/typeshed/stdlib/winreg.pyi | 2 +- .../typeshed/stdlib/xml/dom/minidom.pyi | 4 +- .../stdlib/xml/etree/ElementInclude.pyi | 3 +- .../typeshed/stdlib/xml/etree/ElementTree.pyi | 1 + .../typeshed/stdlib/xml/sax/__init__.pyi | 3 +- .../vendor/typeshed/stdlib/xmlrpc/client.pyi | 3 +- .../vendor/typeshed/stdlib/xmlrpc/server.pyi | 8 +- .../typeshed/stdlib/zipfile/__init__.pyi | 10 +- .../vendor/typeshed/stdlib/zipimport.pyi | 98 +- .../vendor/typeshed/stdlib/zlib.pyi | 12 +- .../typeshed/stdlib/zoneinfo/_common.pyi | 3 +- 105 files changed, 1832 insertions(+), 1388 deletions(-) diff --git a/crates/ty_ide/src/goto_type_definition.rs b/crates/ty_ide/src/goto_type_definition.rs index 1ec3e85db3dbb..4d8f06f354577 100644 --- a/crates/ty_ide/src/goto_type_definition.rs +++ b/crates/ty_ide/src/goto_type_definition.rs @@ -197,16 +197,16 @@ mod tests { "#, ); - assert_snapshot!(test.goto_type_definition(), @r#" + assert_snapshot!(test.goto_type_definition(), @r###" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:892:7 + --> stdlib/builtins.pyi:901:7 | - 890 | def __getitem__(self, key: int, /) -> str | int | None: ... - 891 | - 892 | class str(Sequence[str]): + 899 | def __getitem__(self, key: int, /) -> str | int | None: ... + 900 | + 901 | class str(Sequence[str]): | ^^^ - 893 | """str(object='') -> str - 894 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 902 | """str(object='') -> str + 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:4:13 @@ -216,7 +216,7 @@ mod tests { 4 | a | ^ | - "#); + "###); } #[test] fn goto_type_of_expression_with_literal_node() { @@ -226,16 +226,16 @@ mod tests { "#, ); - assert_snapshot!(test.goto_type_definition(), @r#" + assert_snapshot!(test.goto_type_definition(), @r###" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:892:7 + --> stdlib/builtins.pyi:901:7 | - 890 | def __getitem__(self, key: int, /) -> str | int | None: ... - 891 | - 892 | class str(Sequence[str]): + 899 | def __getitem__(self, key: int, /) -> str | int | None: ... + 900 | + 901 | class str(Sequence[str]): | ^^^ - 893 | """str(object='') -> str - 894 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 902 | """str(object='') -> str + 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:2:22 @@ -243,7 +243,7 @@ mod tests { 2 | a: str = "test" | ^^^^^^ | - "#); + "###); } #[test] @@ -342,16 +342,16 @@ mod tests { "#, ); - assert_snapshot!(test.goto_type_definition(), @r#" + assert_snapshot!(test.goto_type_definition(), @r###" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:892:7 + --> stdlib/builtins.pyi:901:7 | - 890 | def __getitem__(self, key: int, /) -> str | int | None: ... - 891 | - 892 | class str(Sequence[str]): + 899 | def __getitem__(self, key: int, /) -> str | int | None: ... + 900 | + 901 | class str(Sequence[str]): | ^^^ - 893 | """str(object='') -> str - 894 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 902 | """str(object='') -> str + 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:4:18 @@ -361,7 +361,7 @@ mod tests { 4 | test(a= "123") | ^ | - "#); + "###); } #[test] @@ -411,16 +411,16 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r#" + assert_snapshot!(test.goto_type_definition(), @r###" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:2890:7 + --> stdlib/builtins.pyi:2901:7 | - 2888 | """See PEP 585""" - 2889 | - 2890 | class dict(MutableMapping[_KT, _VT]): + 2899 | """See PEP 585""" + 2900 | + 2901 | class dict(MutableMapping[_KT, _VT]): | ^^^^ - 2891 | """dict() -> new empty dictionary - 2892 | dict(mapping) -> new dictionary initialized from a mapping object's + 2902 | """dict() -> new empty dictionary + 2903 | dict(mapping) -> new dictionary initialized from a mapping object's | info: Source --> main.py:6:5 @@ -430,7 +430,7 @@ f(**kwargs) 6 | f(**kwargs) | ^^^^^^ | - "#); + "###); } #[test] @@ -442,16 +442,16 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r#" + assert_snapshot!(test.goto_type_definition(), @r###" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:892:7 + --> stdlib/builtins.pyi:901:7 | - 890 | def __getitem__(self, key: int, /) -> str | int | None: ... - 891 | - 892 | class str(Sequence[str]): + 899 | def __getitem__(self, key: int, /) -> str | int | None: ... + 900 | + 901 | class str(Sequence[str]): | ^^^ - 893 | """str(object='') -> str - 894 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 902 | """str(object='') -> str + 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:3:17 @@ -460,7 +460,7 @@ f(**kwargs) 3 | a | ^ | - "#); + "###); } #[test] @@ -535,16 +535,16 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r#" + assert_snapshot!(test.goto_type_definition(), @r###" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:892:7 + --> stdlib/builtins.pyi:901:7 | - 890 | def __getitem__(self, key: int, /) -> str | int | None: ... - 891 | - 892 | class str(Sequence[str]): + 899 | def __getitem__(self, key: int, /) -> str | int | None: ... + 900 | + 901 | class str(Sequence[str]): | ^^^ - 893 | """str(object='') -> str - 894 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 902 | """str(object='') -> str + 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:4:27 @@ -554,7 +554,7 @@ f(**kwargs) 4 | print(a) | ^ | - "#); + "###); } #[test] @@ -566,7 +566,7 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r#" + assert_snapshot!(test.goto_type_definition(), @r###" info[goto-type-definition]: Type definition --> stdlib/types.pyi:922:11 | @@ -585,14 +585,14 @@ f(**kwargs) | info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:892:7 + --> stdlib/builtins.pyi:901:7 | - 890 | def __getitem__(self, key: int, /) -> str | int | None: ... - 891 | - 892 | class str(Sequence[str]): + 899 | def __getitem__(self, key: int, /) -> str | int | None: ... + 900 | + 901 | class str(Sequence[str]): | ^^^ - 893 | """str(object='') -> str - 894 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 902 | """str(object='') -> str + 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:3:17 @@ -601,7 +601,7 @@ f(**kwargs) 3 | a | ^ | - "#); + "###); } impl CursorTest { diff --git a/crates/ty_python_semantic/resources/mdtest/call/methods.md b/crates/ty_python_semantic/resources/mdtest/call/methods.md index 1d6b020832be2..9bac69ea59393 100644 --- a/crates/ty_python_semantic/resources/mdtest/call/methods.md +++ b/crates/ty_python_semantic/resources/mdtest/call/methods.md @@ -198,7 +198,7 @@ python-version = "3.12" ```py type IntOrStr = int | str -reveal_type(IntOrStr.__or__) # revealed: bound method typing.TypeAliasType.__or__(right: Any) -> _SpecialForm +reveal_type(IntOrStr.__or__) # revealed: bound method typing.TypeAliasType.__or__(right: Any, /) -> _SpecialForm ``` ## Method calls on types not disjoint from `None` diff --git a/crates/ty_vendored/vendor/typeshed/source_commit.txt b/crates/ty_vendored/vendor/typeshed/source_commit.txt index 01a13b0ad731f..b09efe98fe9b4 100644 --- a/crates/ty_vendored/vendor/typeshed/source_commit.txt +++ b/crates/ty_vendored/vendor/typeshed/source_commit.txt @@ -1 +1 @@ -3f08a4ed10b321c378107c236a06a33584869a9b +893b9a760deb3be64d13c748318e95a752230961 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_compression.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_compression.pyi index de5f90fcdefad..12eafa626744d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_compression.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_compression.pyi @@ -5,10 +5,11 @@ from _typeshed import Incomplete, WriteableBuffer from collections.abc import Callable from io import DEFAULT_BUFFER_SIZE, BufferedIOBase, RawIOBase -from typing import Any, Protocol +from typing import Any, Protocol, type_check_only BUFFER_SIZE = DEFAULT_BUFFER_SIZE +@type_check_only class _Reader(Protocol): def read(self, n: int, /) -> bytes: ... def seekable(self) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_contextvars.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_contextvars.pyi index 7c00448f38dcd..a46b110a8c128 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_contextvars.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_contextvars.pyi @@ -68,7 +68,7 @@ class Token(Generic[_T]): """Enter into Token context manager.""" def __exit__( - self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None + self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, / ) -> None: """Exit from Token context manager, restore the linked ContextVar.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi index cce031feed544..ba3f209bef962 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi @@ -131,7 +131,10 @@ class _SimpleCData(_CData, Generic[_T], metaclass=_PyCSimpleType): def __init__(self, value: _T = ...) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] def __ctypes_from_outparam__(self, /) -> _T: ... # type: ignore[override] +@type_check_only class _CanCastTo(_CData): ... + +@type_check_only class _PointerLike(_CanCastTo): ... # This type is not exposed. It calls itself _ctypes.PyCPointerType. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib.pyi index a6f58ca3f8b95..84326d57da611 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib.pyi @@ -15,6 +15,7 @@ from _typeshed.importlib import LoaderProtocol from collections.abc import Mapping, Sequence from types import ModuleType from typing import Any, ClassVar +from typing_extensions import deprecated # Signature of `builtins.__import__` should be kept identical to `importlib.__import__` def __import__( @@ -117,6 +118,7 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader) # MetaPathFinder if sys.version_info < (3, 12): @classmethod + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.") def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: """Find the built-in module. @@ -153,6 +155,10 @@ class BuiltinImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader) # Loader if sys.version_info < (3, 12): @staticmethod + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "The module spec is now used by the import machinery to generate a module repr." + ) def module_repr(module: types.ModuleType) -> str: """Return repr for the module. @@ -187,6 +193,7 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader): # MetaPathFinder if sys.version_info < (3, 12): @classmethod + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.") def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: """Find a frozen module. @@ -221,6 +228,10 @@ class FrozenImporter(importlib.abc.MetaPathFinder, importlib.abc.InspectLoader): # Loader if sys.version_info < (3, 12): @staticmethod + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "The module spec is now used by the import machinery to generate a module repr." + ) def module_repr(m: types.ModuleType) -> str: """Return repr for the module. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi index 7db0d7a7b0955..8986a981e9ffa 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi @@ -97,6 +97,7 @@ class WindowsRegistryFinder(importlib.abc.MetaPathFinder): if sys.version_info < (3, 12): @classmethod + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.") def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: """Find module named in the registry. @@ -157,6 +158,7 @@ class PathFinder(importlib.abc.MetaPathFinder): """ if sys.version_info < (3, 12): @classmethod + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.") def find_module(cls, fullname: str, path: Sequence[str] | None = None) -> importlib.abc.Loader | None: """find the module on sys.path or 'path' based on sys.path_hooks and sys.path_importer_cache. @@ -374,7 +376,10 @@ if sys.version_info >= (3, 11): def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ... if sys.version_info < (3, 12): @staticmethod - @deprecated("module_repr() is deprecated, and has been removed in Python 3.12") + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "The module spec is now used by the import machinery to generate a module repr." + ) def module_repr(module: types.ModuleType) -> str: """Return repr for the module. @@ -404,7 +409,10 @@ else: """ if sys.version_info >= (3, 10): @staticmethod - @deprecated("module_repr() is deprecated, and has been removed in Python 3.12") + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "The module spec is now used by the import machinery to generate a module repr." + ) def module_repr(module: types.ModuleType) -> str: """Return repr for the module. @@ -415,7 +423,10 @@ else: def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ... else: @classmethod - @deprecated("module_repr() is deprecated, and has been removed in Python 3.12") + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "The module spec is now used by the import machinery to generate a module repr." + ) def module_repr(cls, module: types.ModuleType) -> str: """Return repr for the module. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_gdbm.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_gdbm.pyi index cb7174535c383..58bd1d41d3588 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_gdbm.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_gdbm.pyi @@ -13,7 +13,7 @@ values() methods are not supported. import sys from _typeshed import ReadOnlyBuffer, StrOrBytesPath from types import TracebackType -from typing import TypeVar, overload +from typing import TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias if sys.platform != "win32": @@ -25,6 +25,7 @@ if sys.platform != "win32": class error(OSError): ... # Actual typename gdbm, not exposed by the implementation + @type_check_only class _gdbm: def firstkey(self) -> bytes | None: ... def nextkey(self, key: _KeyType) -> bytes | None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_interpchannels.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_interpchannels.pyi index 3b4a9abc8a8c8..987ca4566c1a0 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_interpchannels.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_interpchannels.pyi @@ -29,9 +29,9 @@ class ChannelID: def recv(self) -> Self: """the 'recv' end of the channel""" - def __eq__(self, other: object) -> bool: ... - def __ge__(self, other: ChannelID) -> bool: ... - def __gt__(self, other: ChannelID) -> bool: ... + def __eq__(self, other: object, /) -> bool: ... + def __ge__(self, other: ChannelID, /) -> bool: ... + def __gt__(self, other: ChannelID, /) -> bool: ... def __hash__(self) -> int: ... def __index__(self) -> int: """Return self converted to an integer, if self is suitable for use as an index into a list.""" @@ -39,9 +39,9 @@ class ChannelID: def __int__(self) -> int: """int(self)""" - def __le__(self, other: ChannelID) -> bool: ... - def __lt__(self, other: ChannelID) -> bool: ... - def __ne__(self, other: object) -> bool: ... + def __le__(self, other: ChannelID, /) -> bool: ... + def __lt__(self, other: ChannelID, /) -> bool: ... + def __ne__(self, other: object, /) -> bool: ... @final class ChannelInfo(structseq[int], tuple[bool, bool, bool, int, int, int, int, int]): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi index 6ddd89b7acab8..be2e5f184c86a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi @@ -123,8 +123,8 @@ def exec( def call( id: SupportsIndex, callable: Callable[..., _R], - args: tuple[object, ...] | None = None, - kwargs: dict[str, object] | None = None, + args: tuple[Any, ...] | None = None, + kwargs: dict[str, Any] | None = None, *, restrict: bool = False, ) -> tuple[_R, types.SimpleNamespace]: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi index 44c25aca9c7be..ef07b92aaf339 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi @@ -367,6 +367,7 @@ class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] Returns the new absolute position. """ +@type_check_only class _BufferedReaderStream(Protocol): def read(self, n: int = ..., /) -> bytes: ... # Optional: def readall(self) -> bytes: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi index 2ed64bbad48f9..b828147122bd5 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi @@ -1,10 +1,12 @@ """Documentation""" import sys +from typing import type_check_only if sys.platform == "win32": class MSIError(Exception): ... # Actual typename View, not exposed by the implementation + @type_check_only class _View: def Execute(self, params: _Record | None = ...) -> None: ... def GetColumnInfo(self, kind: int) -> _Record: ... @@ -16,6 +18,7 @@ if sys.platform == "win32": __init__: None # type: ignore[assignment] # Actual typename SummaryInformation, not exposed by the implementation + @type_check_only class _SummaryInformation: def GetProperty(self, field: int) -> int | bytes | None: ... def GetPropertyCount(self) -> int: ... @@ -26,6 +29,7 @@ if sys.platform == "win32": __init__: None # type: ignore[assignment] # Actual typename Database, not exposed by the implementation + @type_check_only class _Database: def OpenView(self, sql: str) -> _View: ... def Commit(self) -> None: ... @@ -36,6 +40,7 @@ if sys.platform == "win32": __init__: None # type: ignore[assignment] # Actual typename Record, not exposed by the implementation + @type_check_only class _Record: def GetFieldCount(self) -> int: ... def GetInteger(self, field: int) -> int: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_operator.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_operator.pyi index ca4bbcf6d3404..7e893a6e4211d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_operator.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_operator.pyi @@ -37,6 +37,7 @@ class _SupportsDunderGT(Protocol): class _SupportsDunderLE(Protocol): def __le__(self, other: Any, /) -> Any: ... +@type_check_only class _SupportsDunderGE(Protocol): def __ge__(self, other: Any, /) -> Any: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi index 58d7d02b33331..de25ab866c53f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi @@ -6,6 +6,7 @@ from pickle import PickleBuffer as PickleBuffer from typing import Any, Protocol, type_check_only from typing_extensions import TypeAlias +@type_check_only class _ReadableFileobj(Protocol): def read(self, n: int, /) -> bytes: ... def readline(self) -> bytes: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi index a024ff0b82004..f5abc17748389 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi @@ -7,7 +7,7 @@ import sys from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterable from socket import error as error, gaierror as gaierror, herror as herror, timeout as timeout -from typing import Any, SupportsIndex, overload +from typing import Any, Final, SupportsIndex, overload from typing_extensions import CapsuleType, TypeAlias _CMSG: TypeAlias = tuple[int, int, bytes] @@ -24,23 +24,23 @@ _RetAddress: TypeAlias = Any # https://docs.python.org/3/library/socket.html#constants if sys.platform != "win32": - AF_UNIX: int + AF_UNIX: Final[int] -AF_INET: int -AF_INET6: int +AF_INET: Final[int] +AF_INET6: Final[int] -AF_UNSPEC: int +AF_UNSPEC: Final[int] -SOCK_STREAM: int -SOCK_DGRAM: int -SOCK_RAW: int -SOCK_RDM: int -SOCK_SEQPACKET: int +SOCK_STREAM: Final[int] +SOCK_DGRAM: Final[int] +SOCK_RAW: Final[int] +SOCK_RDM: Final[int] +SOCK_SEQPACKET: Final[int] if sys.platform == "linux": # Availability: Linux >= 2.6.27 - SOCK_CLOEXEC: int - SOCK_NONBLOCK: int + SOCK_CLOEXEC: Final[int] + SOCK_NONBLOCK: Final[int] # -------------------- # Many constants of these forms, documented in the Unix documentation on @@ -61,329 +61,329 @@ if sys.platform == "linux": # TCP_* # -------------------- -SO_ACCEPTCONN: int -SO_BROADCAST: int -SO_DEBUG: int -SO_DONTROUTE: int -SO_ERROR: int -SO_KEEPALIVE: int -SO_LINGER: int -SO_OOBINLINE: int -SO_RCVBUF: int -SO_RCVLOWAT: int -SO_RCVTIMEO: int -SO_REUSEADDR: int -SO_SNDBUF: int -SO_SNDLOWAT: int -SO_SNDTIMEO: int -SO_TYPE: int +SO_ACCEPTCONN: Final[int] +SO_BROADCAST: Final[int] +SO_DEBUG: Final[int] +SO_DONTROUTE: Final[int] +SO_ERROR: Final[int] +SO_KEEPALIVE: Final[int] +SO_LINGER: Final[int] +SO_OOBINLINE: Final[int] +SO_RCVBUF: Final[int] +SO_RCVLOWAT: Final[int] +SO_RCVTIMEO: Final[int] +SO_REUSEADDR: Final[int] +SO_SNDBUF: Final[int] +SO_SNDLOWAT: Final[int] +SO_SNDTIMEO: Final[int] +SO_TYPE: Final[int] if sys.platform != "linux": - SO_USELOOPBACK: int + SO_USELOOPBACK: Final[int] if sys.platform == "win32": - SO_EXCLUSIVEADDRUSE: int + SO_EXCLUSIVEADDRUSE: Final[int] if sys.platform != "win32": - SO_REUSEPORT: int + SO_REUSEPORT: Final[int] if sys.platform != "darwin" or sys.version_info >= (3, 13): - SO_BINDTODEVICE: int + SO_BINDTODEVICE: Final[int] if sys.platform != "win32" and sys.platform != "darwin": - SO_DOMAIN: int - SO_MARK: int - SO_PASSCRED: int - SO_PASSSEC: int - SO_PEERCRED: int - SO_PEERSEC: int - SO_PRIORITY: int - SO_PROTOCOL: int + SO_DOMAIN: Final[int] + SO_MARK: Final[int] + SO_PASSCRED: Final[int] + SO_PASSSEC: Final[int] + SO_PEERCRED: Final[int] + SO_PEERSEC: Final[int] + SO_PRIORITY: Final[int] + SO_PROTOCOL: Final[int] if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": - SO_SETFIB: int + SO_SETFIB: Final[int] if sys.platform == "linux" and sys.version_info >= (3, 13): - SO_BINDTOIFINDEX: int + SO_BINDTOIFINDEX: Final[int] -SOMAXCONN: int +SOMAXCONN: Final[int] -MSG_CTRUNC: int -MSG_DONTROUTE: int -MSG_OOB: int -MSG_PEEK: int -MSG_TRUNC: int -MSG_WAITALL: int +MSG_CTRUNC: Final[int] +MSG_DONTROUTE: Final[int] +MSG_OOB: Final[int] +MSG_PEEK: Final[int] +MSG_TRUNC: Final[int] +MSG_WAITALL: Final[int] if sys.platform != "win32": - MSG_DONTWAIT: int - MSG_EOR: int - MSG_NOSIGNAL: int # Sometimes this exists on darwin, sometimes not + MSG_DONTWAIT: Final[int] + MSG_EOR: Final[int] + MSG_NOSIGNAL: Final[int] # Sometimes this exists on darwin, sometimes not if sys.platform != "darwin": - MSG_ERRQUEUE: int + MSG_ERRQUEUE: Final[int] if sys.platform == "win32": - MSG_BCAST: int - MSG_MCAST: int + MSG_BCAST: Final[int] + MSG_MCAST: Final[int] if sys.platform != "win32" and sys.platform != "darwin": - MSG_CMSG_CLOEXEC: int - MSG_CONFIRM: int - MSG_FASTOPEN: int - MSG_MORE: int + MSG_CMSG_CLOEXEC: Final[int] + MSG_CONFIRM: Final[int] + MSG_FASTOPEN: Final[int] + MSG_MORE: Final[int] if sys.platform != "win32" and sys.platform != "linux": - MSG_EOF: int + MSG_EOF: Final[int] if sys.platform != "win32" and sys.platform != "linux" and sys.platform != "darwin": - MSG_NOTIFICATION: int - MSG_BTAG: int # Not FreeBSD either - MSG_ETAG: int # Not FreeBSD either - -SOL_IP: int -SOL_SOCKET: int -SOL_TCP: int -SOL_UDP: int + MSG_NOTIFICATION: Final[int] + MSG_BTAG: Final[int] # Not FreeBSD either + MSG_ETAG: Final[int] # Not FreeBSD either + +SOL_IP: Final[int] +SOL_SOCKET: Final[int] +SOL_TCP: Final[int] +SOL_UDP: Final[int] if sys.platform != "win32" and sys.platform != "darwin": # Defined in socket.h for Linux, but these aren't always present for # some reason. - SOL_ATALK: int - SOL_AX25: int - SOL_HCI: int - SOL_IPX: int - SOL_NETROM: int - SOL_ROSE: int + SOL_ATALK: Final[int] + SOL_AX25: Final[int] + SOL_HCI: Final[int] + SOL_IPX: Final[int] + SOL_NETROM: Final[int] + SOL_ROSE: Final[int] if sys.platform != "win32": - SCM_RIGHTS: int + SCM_RIGHTS: Final[int] if sys.platform != "win32" and sys.platform != "darwin": - SCM_CREDENTIALS: int + SCM_CREDENTIALS: Final[int] if sys.platform != "win32" and sys.platform != "linux": - SCM_CREDS: int - -IPPROTO_ICMP: int -IPPROTO_IP: int -IPPROTO_RAW: int -IPPROTO_TCP: int -IPPROTO_UDP: int -IPPROTO_AH: int -IPPROTO_DSTOPTS: int -IPPROTO_EGP: int -IPPROTO_ESP: int -IPPROTO_FRAGMENT: int -IPPROTO_HOPOPTS: int -IPPROTO_ICMPV6: int -IPPROTO_IDP: int -IPPROTO_IGMP: int -IPPROTO_IPV6: int -IPPROTO_NONE: int -IPPROTO_PIM: int -IPPROTO_PUP: int -IPPROTO_ROUTING: int -IPPROTO_SCTP: int + SCM_CREDS: Final[int] + +IPPROTO_ICMP: Final[int] +IPPROTO_IP: Final[int] +IPPROTO_RAW: Final[int] +IPPROTO_TCP: Final[int] +IPPROTO_UDP: Final[int] +IPPROTO_AH: Final[int] +IPPROTO_DSTOPTS: Final[int] +IPPROTO_EGP: Final[int] +IPPROTO_ESP: Final[int] +IPPROTO_FRAGMENT: Final[int] +IPPROTO_HOPOPTS: Final[int] +IPPROTO_ICMPV6: Final[int] +IPPROTO_IDP: Final[int] +IPPROTO_IGMP: Final[int] +IPPROTO_IPV6: Final[int] +IPPROTO_NONE: Final[int] +IPPROTO_PIM: Final[int] +IPPROTO_PUP: Final[int] +IPPROTO_ROUTING: Final[int] +IPPROTO_SCTP: Final[int] if sys.platform != "linux": - IPPROTO_GGP: int - IPPROTO_IPV4: int - IPPROTO_MAX: int - IPPROTO_ND: int + IPPROTO_GGP: Final[int] + IPPROTO_IPV4: Final[int] + IPPROTO_MAX: Final[int] + IPPROTO_ND: Final[int] if sys.platform == "win32": - IPPROTO_CBT: int - IPPROTO_ICLFXBM: int - IPPROTO_IGP: int - IPPROTO_L2TP: int - IPPROTO_PGM: int - IPPROTO_RDP: int - IPPROTO_ST: int + IPPROTO_CBT: Final[int] + IPPROTO_ICLFXBM: Final[int] + IPPROTO_IGP: Final[int] + IPPROTO_L2TP: Final[int] + IPPROTO_PGM: Final[int] + IPPROTO_RDP: Final[int] + IPPROTO_ST: Final[int] if sys.platform != "win32": - IPPROTO_GRE: int - IPPROTO_IPIP: int - IPPROTO_RSVP: int - IPPROTO_TP: int + IPPROTO_GRE: Final[int] + IPPROTO_IPIP: Final[int] + IPPROTO_RSVP: Final[int] + IPPROTO_TP: Final[int] if sys.platform != "win32" and sys.platform != "linux": - IPPROTO_EON: int - IPPROTO_HELLO: int - IPPROTO_IPCOMP: int - IPPROTO_XTP: int + IPPROTO_EON: Final[int] + IPPROTO_HELLO: Final[int] + IPPROTO_IPCOMP: Final[int] + IPPROTO_XTP: Final[int] if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": - IPPROTO_BIP: int # Not FreeBSD either - IPPROTO_MOBILE: int # Not FreeBSD either - IPPROTO_VRRP: int # Not FreeBSD either + IPPROTO_BIP: Final[int] # Not FreeBSD either + IPPROTO_MOBILE: Final[int] # Not FreeBSD either + IPPROTO_VRRP: Final[int] # Not FreeBSD either if sys.platform == "linux": # Availability: Linux >= 2.6.20, FreeBSD >= 10.1 - IPPROTO_UDPLITE: int + IPPROTO_UDPLITE: Final[int] if sys.version_info >= (3, 10) and sys.platform == "linux": - IPPROTO_MPTCP: int - -IPPORT_RESERVED: int -IPPORT_USERRESERVED: int - -INADDR_ALLHOSTS_GROUP: int -INADDR_ANY: int -INADDR_BROADCAST: int -INADDR_LOOPBACK: int -INADDR_MAX_LOCAL_GROUP: int -INADDR_NONE: int -INADDR_UNSPEC_GROUP: int - -IP_ADD_MEMBERSHIP: int -IP_DROP_MEMBERSHIP: int -IP_HDRINCL: int -IP_MULTICAST_IF: int -IP_MULTICAST_LOOP: int -IP_MULTICAST_TTL: int -IP_OPTIONS: int + IPPROTO_MPTCP: Final[int] + +IPPORT_RESERVED: Final[int] +IPPORT_USERRESERVED: Final[int] + +INADDR_ALLHOSTS_GROUP: Final[int] +INADDR_ANY: Final[int] +INADDR_BROADCAST: Final[int] +INADDR_LOOPBACK: Final[int] +INADDR_MAX_LOCAL_GROUP: Final[int] +INADDR_NONE: Final[int] +INADDR_UNSPEC_GROUP: Final[int] + +IP_ADD_MEMBERSHIP: Final[int] +IP_DROP_MEMBERSHIP: Final[int] +IP_HDRINCL: Final[int] +IP_MULTICAST_IF: Final[int] +IP_MULTICAST_LOOP: Final[int] +IP_MULTICAST_TTL: Final[int] +IP_OPTIONS: Final[int] if sys.platform != "linux": - IP_RECVDSTADDR: int + IP_RECVDSTADDR: Final[int] if sys.version_info >= (3, 10): - IP_RECVTOS: int -IP_TOS: int -IP_TTL: int + IP_RECVTOS: Final[int] +IP_TOS: Final[int] +IP_TTL: Final[int] if sys.platform != "win32": - IP_DEFAULT_MULTICAST_LOOP: int - IP_DEFAULT_MULTICAST_TTL: int - IP_MAX_MEMBERSHIPS: int - IP_RECVOPTS: int - IP_RECVRETOPTS: int - IP_RETOPTS: int + IP_DEFAULT_MULTICAST_LOOP: Final[int] + IP_DEFAULT_MULTICAST_TTL: Final[int] + IP_MAX_MEMBERSHIPS: Final[int] + IP_RECVOPTS: Final[int] + IP_RECVRETOPTS: Final[int] + IP_RETOPTS: Final[int] if sys.version_info >= (3, 13) and sys.platform == "linux": - CAN_RAW_ERR_FILTER: int + CAN_RAW_ERR_FILTER: Final[int] if sys.version_info >= (3, 14): - IP_RECVTTL: int + IP_RECVTTL: Final[int] if sys.platform == "win32" or sys.platform == "linux": - IPV6_RECVERR: int - IP_RECVERR: int - SO_ORIGINAL_DST: int + IPV6_RECVERR: Final[int] + IP_RECVERR: Final[int] + SO_ORIGINAL_DST: Final[int] if sys.platform == "win32": - SOL_RFCOMM: int - SO_BTH_ENCRYPT: int - SO_BTH_MTU: int - SO_BTH_MTU_MAX: int - SO_BTH_MTU_MIN: int - TCP_QUICKACK: int + SOL_RFCOMM: Final[int] + SO_BTH_ENCRYPT: Final[int] + SO_BTH_MTU: Final[int] + SO_BTH_MTU_MAX: Final[int] + SO_BTH_MTU_MIN: Final[int] + TCP_QUICKACK: Final[int] if sys.platform == "linux": - IP_FREEBIND: int - IP_RECVORIGDSTADDR: int - VMADDR_CID_LOCAL: int + IP_FREEBIND: Final[int] + IP_RECVORIGDSTADDR: Final[int] + VMADDR_CID_LOCAL: Final[int] if sys.platform != "win32" and sys.platform != "darwin": - IP_TRANSPARENT: int + IP_TRANSPARENT: Final[int] if sys.platform != "win32" and sys.platform != "darwin" and sys.version_info >= (3, 11): - IP_BIND_ADDRESS_NO_PORT: int + IP_BIND_ADDRESS_NO_PORT: Final[int] if sys.version_info >= (3, 12): - IP_ADD_SOURCE_MEMBERSHIP: int - IP_BLOCK_SOURCE: int - IP_DROP_SOURCE_MEMBERSHIP: int - IP_PKTINFO: int - IP_UNBLOCK_SOURCE: int - -IPV6_CHECKSUM: int -IPV6_JOIN_GROUP: int -IPV6_LEAVE_GROUP: int -IPV6_MULTICAST_HOPS: int -IPV6_MULTICAST_IF: int -IPV6_MULTICAST_LOOP: int -IPV6_RECVTCLASS: int -IPV6_TCLASS: int -IPV6_UNICAST_HOPS: int -IPV6_V6ONLY: int -IPV6_DONTFRAG: int -IPV6_HOPLIMIT: int -IPV6_HOPOPTS: int -IPV6_PKTINFO: int -IPV6_RECVRTHDR: int -IPV6_RTHDR: int + IP_ADD_SOURCE_MEMBERSHIP: Final[int] + IP_BLOCK_SOURCE: Final[int] + IP_DROP_SOURCE_MEMBERSHIP: Final[int] + IP_PKTINFO: Final[int] + IP_UNBLOCK_SOURCE: Final[int] + +IPV6_CHECKSUM: Final[int] +IPV6_JOIN_GROUP: Final[int] +IPV6_LEAVE_GROUP: Final[int] +IPV6_MULTICAST_HOPS: Final[int] +IPV6_MULTICAST_IF: Final[int] +IPV6_MULTICAST_LOOP: Final[int] +IPV6_RECVTCLASS: Final[int] +IPV6_TCLASS: Final[int] +IPV6_UNICAST_HOPS: Final[int] +IPV6_V6ONLY: Final[int] +IPV6_DONTFRAG: Final[int] +IPV6_HOPLIMIT: Final[int] +IPV6_HOPOPTS: Final[int] +IPV6_PKTINFO: Final[int] +IPV6_RECVRTHDR: Final[int] +IPV6_RTHDR: Final[int] if sys.platform != "win32": - IPV6_RTHDR_TYPE_0: int - IPV6_DSTOPTS: int - IPV6_NEXTHOP: int - IPV6_PATHMTU: int - IPV6_RECVDSTOPTS: int - IPV6_RECVHOPLIMIT: int - IPV6_RECVHOPOPTS: int - IPV6_RECVPATHMTU: int - IPV6_RECVPKTINFO: int - IPV6_RTHDRDSTOPTS: int + IPV6_RTHDR_TYPE_0: Final[int] + IPV6_DSTOPTS: Final[int] + IPV6_NEXTHOP: Final[int] + IPV6_PATHMTU: Final[int] + IPV6_RECVDSTOPTS: Final[int] + IPV6_RECVHOPLIMIT: Final[int] + IPV6_RECVHOPOPTS: Final[int] + IPV6_RECVPATHMTU: Final[int] + IPV6_RECVPKTINFO: Final[int] + IPV6_RTHDRDSTOPTS: Final[int] if sys.platform != "win32" and sys.platform != "linux": - IPV6_USE_MIN_MTU: int - -EAI_AGAIN: int -EAI_BADFLAGS: int -EAI_FAIL: int -EAI_FAMILY: int -EAI_MEMORY: int -EAI_NODATA: int -EAI_NONAME: int -EAI_SERVICE: int -EAI_SOCKTYPE: int + IPV6_USE_MIN_MTU: Final[int] + +EAI_AGAIN: Final[int] +EAI_BADFLAGS: Final[int] +EAI_FAIL: Final[int] +EAI_FAMILY: Final[int] +EAI_MEMORY: Final[int] +EAI_NODATA: Final[int] +EAI_NONAME: Final[int] +EAI_SERVICE: Final[int] +EAI_SOCKTYPE: Final[int] if sys.platform != "win32": - EAI_ADDRFAMILY: int - EAI_OVERFLOW: int - EAI_SYSTEM: int + EAI_ADDRFAMILY: Final[int] + EAI_OVERFLOW: Final[int] + EAI_SYSTEM: Final[int] if sys.platform != "win32" and sys.platform != "linux": - EAI_BADHINTS: int - EAI_MAX: int - EAI_PROTOCOL: int - -AI_ADDRCONFIG: int -AI_ALL: int -AI_CANONNAME: int -AI_NUMERICHOST: int -AI_NUMERICSERV: int -AI_PASSIVE: int -AI_V4MAPPED: int + EAI_BADHINTS: Final[int] + EAI_MAX: Final[int] + EAI_PROTOCOL: Final[int] + +AI_ADDRCONFIG: Final[int] +AI_ALL: Final[int] +AI_CANONNAME: Final[int] +AI_NUMERICHOST: Final[int] +AI_NUMERICSERV: Final[int] +AI_PASSIVE: Final[int] +AI_V4MAPPED: Final[int] if sys.platform != "win32" and sys.platform != "linux": - AI_DEFAULT: int - AI_MASK: int - AI_V4MAPPED_CFG: int - -NI_DGRAM: int -NI_MAXHOST: int -NI_MAXSERV: int -NI_NAMEREQD: int -NI_NOFQDN: int -NI_NUMERICHOST: int -NI_NUMERICSERV: int + AI_DEFAULT: Final[int] + AI_MASK: Final[int] + AI_V4MAPPED_CFG: Final[int] + +NI_DGRAM: Final[int] +NI_MAXHOST: Final[int] +NI_MAXSERV: Final[int] +NI_NAMEREQD: Final[int] +NI_NOFQDN: Final[int] +NI_NUMERICHOST: Final[int] +NI_NUMERICSERV: Final[int] if sys.platform == "linux" and sys.version_info >= (3, 13): - NI_IDN: int + NI_IDN: Final[int] -TCP_FASTOPEN: int -TCP_KEEPCNT: int -TCP_KEEPINTVL: int -TCP_MAXSEG: int -TCP_NODELAY: int +TCP_FASTOPEN: Final[int] +TCP_KEEPCNT: Final[int] +TCP_KEEPINTVL: Final[int] +TCP_MAXSEG: Final[int] +TCP_NODELAY: Final[int] if sys.platform != "win32": - TCP_NOTSENT_LOWAT: int + TCP_NOTSENT_LOWAT: Final[int] if sys.platform != "darwin": - TCP_KEEPIDLE: int + TCP_KEEPIDLE: Final[int] if sys.version_info >= (3, 10) and sys.platform == "darwin": - TCP_KEEPALIVE: int + TCP_KEEPALIVE: Final[int] if sys.version_info >= (3, 11) and sys.platform == "darwin": - TCP_CONNECTION_INFO: int + TCP_CONNECTION_INFO: Final[int] if sys.platform != "win32" and sys.platform != "darwin": - TCP_CONGESTION: int - TCP_CORK: int - TCP_DEFER_ACCEPT: int - TCP_INFO: int - TCP_LINGER2: int - TCP_QUICKACK: int - TCP_SYNCNT: int - TCP_USER_TIMEOUT: int - TCP_WINDOW_CLAMP: int + TCP_CONGESTION: Final[int] + TCP_CORK: Final[int] + TCP_DEFER_ACCEPT: Final[int] + TCP_INFO: Final[int] + TCP_LINGER2: Final[int] + TCP_QUICKACK: Final[int] + TCP_SYNCNT: Final[int] + TCP_USER_TIMEOUT: Final[int] + TCP_WINDOW_CLAMP: Final[int] if sys.platform == "linux" and sys.version_info >= (3, 12): - TCP_CC_INFO: int - TCP_FASTOPEN_CONNECT: int - TCP_FASTOPEN_KEY: int - TCP_FASTOPEN_NO_COOKIE: int - TCP_INQ: int - TCP_MD5SIG: int - TCP_MD5SIG_EXT: int - TCP_QUEUE_SEQ: int - TCP_REPAIR: int - TCP_REPAIR_OPTIONS: int - TCP_REPAIR_QUEUE: int - TCP_REPAIR_WINDOW: int - TCP_SAVED_SYN: int - TCP_SAVE_SYN: int - TCP_THIN_DUPACK: int - TCP_THIN_LINEAR_TIMEOUTS: int - TCP_TIMESTAMP: int - TCP_TX_DELAY: int - TCP_ULP: int - TCP_ZEROCOPY_RECEIVE: int + TCP_CC_INFO: Final[int] + TCP_FASTOPEN_CONNECT: Final[int] + TCP_FASTOPEN_KEY: Final[int] + TCP_FASTOPEN_NO_COOKIE: Final[int] + TCP_INQ: Final[int] + TCP_MD5SIG: Final[int] + TCP_MD5SIG_EXT: Final[int] + TCP_QUEUE_SEQ: Final[int] + TCP_REPAIR: Final[int] + TCP_REPAIR_OPTIONS: Final[int] + TCP_REPAIR_QUEUE: Final[int] + TCP_REPAIR_WINDOW: Final[int] + TCP_SAVED_SYN: Final[int] + TCP_SAVE_SYN: Final[int] + TCP_THIN_DUPACK: Final[int] + TCP_THIN_LINEAR_TIMEOUTS: Final[int] + TCP_TIMESTAMP: Final[int] + TCP_TX_DELAY: Final[int] + TCP_ULP: Final[int] + TCP_ZEROCOPY_RECEIVE: Final[int] # -------------------- # Specifically documented constants @@ -391,250 +391,250 @@ if sys.platform == "linux" and sys.version_info >= (3, 12): if sys.platform == "linux": # Availability: Linux >= 2.6.25, NetBSD >= 8 - AF_CAN: int - PF_CAN: int - SOL_CAN_BASE: int - SOL_CAN_RAW: int - CAN_EFF_FLAG: int - CAN_EFF_MASK: int - CAN_ERR_FLAG: int - CAN_ERR_MASK: int - CAN_RAW: int - CAN_RAW_FILTER: int - CAN_RAW_LOOPBACK: int - CAN_RAW_RECV_OWN_MSGS: int - CAN_RTR_FLAG: int - CAN_SFF_MASK: int + AF_CAN: Final[int] + PF_CAN: Final[int] + SOL_CAN_BASE: Final[int] + SOL_CAN_RAW: Final[int] + CAN_EFF_FLAG: Final[int] + CAN_EFF_MASK: Final[int] + CAN_ERR_FLAG: Final[int] + CAN_ERR_MASK: Final[int] + CAN_RAW: Final[int] + CAN_RAW_FILTER: Final[int] + CAN_RAW_LOOPBACK: Final[int] + CAN_RAW_RECV_OWN_MSGS: Final[int] + CAN_RTR_FLAG: Final[int] + CAN_SFF_MASK: Final[int] if sys.version_info < (3, 11): - CAN_RAW_ERR_FILTER: int + CAN_RAW_ERR_FILTER: Final[int] if sys.platform == "linux": # Availability: Linux >= 2.6.25 - CAN_BCM: int - CAN_BCM_TX_SETUP: int - CAN_BCM_TX_DELETE: int - CAN_BCM_TX_READ: int - CAN_BCM_TX_SEND: int - CAN_BCM_RX_SETUP: int - CAN_BCM_RX_DELETE: int - CAN_BCM_RX_READ: int - CAN_BCM_TX_STATUS: int - CAN_BCM_TX_EXPIRED: int - CAN_BCM_RX_STATUS: int - CAN_BCM_RX_TIMEOUT: int - CAN_BCM_RX_CHANGED: int - CAN_BCM_SETTIMER: int - CAN_BCM_STARTTIMER: int - CAN_BCM_TX_COUNTEVT: int - CAN_BCM_TX_ANNOUNCE: int - CAN_BCM_TX_CP_CAN_ID: int - CAN_BCM_RX_FILTER_ID: int - CAN_BCM_RX_CHECK_DLC: int - CAN_BCM_RX_NO_AUTOTIMER: int - CAN_BCM_RX_ANNOUNCE_RESUME: int - CAN_BCM_TX_RESET_MULTI_IDX: int - CAN_BCM_RX_RTR_FRAME: int - CAN_BCM_CAN_FD_FRAME: int + CAN_BCM: Final[int] + CAN_BCM_TX_SETUP: Final[int] + CAN_BCM_TX_DELETE: Final[int] + CAN_BCM_TX_READ: Final[int] + CAN_BCM_TX_SEND: Final[int] + CAN_BCM_RX_SETUP: Final[int] + CAN_BCM_RX_DELETE: Final[int] + CAN_BCM_RX_READ: Final[int] + CAN_BCM_TX_STATUS: Final[int] + CAN_BCM_TX_EXPIRED: Final[int] + CAN_BCM_RX_STATUS: Final[int] + CAN_BCM_RX_TIMEOUT: Final[int] + CAN_BCM_RX_CHANGED: Final[int] + CAN_BCM_SETTIMER: Final[int] + CAN_BCM_STARTTIMER: Final[int] + CAN_BCM_TX_COUNTEVT: Final[int] + CAN_BCM_TX_ANNOUNCE: Final[int] + CAN_BCM_TX_CP_CAN_ID: Final[int] + CAN_BCM_RX_FILTER_ID: Final[int] + CAN_BCM_RX_CHECK_DLC: Final[int] + CAN_BCM_RX_NO_AUTOTIMER: Final[int] + CAN_BCM_RX_ANNOUNCE_RESUME: Final[int] + CAN_BCM_TX_RESET_MULTI_IDX: Final[int] + CAN_BCM_RX_RTR_FRAME: Final[int] + CAN_BCM_CAN_FD_FRAME: Final[int] if sys.platform == "linux": # Availability: Linux >= 3.6 - CAN_RAW_FD_FRAMES: int + CAN_RAW_FD_FRAMES: Final[int] # Availability: Linux >= 4.1 - CAN_RAW_JOIN_FILTERS: int + CAN_RAW_JOIN_FILTERS: Final[int] # Availability: Linux >= 2.6.25 - CAN_ISOTP: int + CAN_ISOTP: Final[int] # Availability: Linux >= 5.4 - CAN_J1939: int - - J1939_MAX_UNICAST_ADDR: int - J1939_IDLE_ADDR: int - J1939_NO_ADDR: int - J1939_NO_NAME: int - J1939_PGN_REQUEST: int - J1939_PGN_ADDRESS_CLAIMED: int - J1939_PGN_ADDRESS_COMMANDED: int - J1939_PGN_PDU1_MAX: int - J1939_PGN_MAX: int - J1939_NO_PGN: int - - SO_J1939_FILTER: int - SO_J1939_PROMISC: int - SO_J1939_SEND_PRIO: int - SO_J1939_ERRQUEUE: int - - SCM_J1939_DEST_ADDR: int - SCM_J1939_DEST_NAME: int - SCM_J1939_PRIO: int - SCM_J1939_ERRQUEUE: int - - J1939_NLA_PAD: int - J1939_NLA_BYTES_ACKED: int - J1939_EE_INFO_NONE: int - J1939_EE_INFO_TX_ABORT: int - J1939_FILTER_MAX: int + CAN_J1939: Final[int] + + J1939_MAX_UNICAST_ADDR: Final[int] + J1939_IDLE_ADDR: Final[int] + J1939_NO_ADDR: Final[int] + J1939_NO_NAME: Final[int] + J1939_PGN_REQUEST: Final[int] + J1939_PGN_ADDRESS_CLAIMED: Final[int] + J1939_PGN_ADDRESS_COMMANDED: Final[int] + J1939_PGN_PDU1_MAX: Final[int] + J1939_PGN_MAX: Final[int] + J1939_NO_PGN: Final[int] + + SO_J1939_FILTER: Final[int] + SO_J1939_PROMISC: Final[int] + SO_J1939_SEND_PRIO: Final[int] + SO_J1939_ERRQUEUE: Final[int] + + SCM_J1939_DEST_ADDR: Final[int] + SCM_J1939_DEST_NAME: Final[int] + SCM_J1939_PRIO: Final[int] + SCM_J1939_ERRQUEUE: Final[int] + + J1939_NLA_PAD: Final[int] + J1939_NLA_BYTES_ACKED: Final[int] + J1939_EE_INFO_NONE: Final[int] + J1939_EE_INFO_TX_ABORT: Final[int] + J1939_FILTER_MAX: Final[int] if sys.version_info >= (3, 12) and sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin": # Availability: FreeBSD >= 14.0 - AF_DIVERT: int - PF_DIVERT: int + AF_DIVERT: Final[int] + PF_DIVERT: Final[int] if sys.platform == "linux": # Availability: Linux >= 2.2 - AF_PACKET: int - PF_PACKET: int - PACKET_BROADCAST: int - PACKET_FASTROUTE: int - PACKET_HOST: int - PACKET_LOOPBACK: int - PACKET_MULTICAST: int - PACKET_OTHERHOST: int - PACKET_OUTGOING: int + AF_PACKET: Final[int] + PF_PACKET: Final[int] + PACKET_BROADCAST: Final[int] + PACKET_FASTROUTE: Final[int] + PACKET_HOST: Final[int] + PACKET_LOOPBACK: Final[int] + PACKET_MULTICAST: Final[int] + PACKET_OTHERHOST: Final[int] + PACKET_OUTGOING: Final[int] if sys.version_info >= (3, 12) and sys.platform == "linux": - ETH_P_ALL: int + ETH_P_ALL: Final[int] if sys.platform == "linux": # Availability: Linux >= 2.6.30 - AF_RDS: int - PF_RDS: int - SOL_RDS: int + AF_RDS: Final[int] + PF_RDS: Final[int] + SOL_RDS: Final[int] # These are present in include/linux/rds.h but don't always show up # here. - RDS_CANCEL_SENT_TO: int - RDS_CMSG_RDMA_ARGS: int - RDS_CMSG_RDMA_DEST: int - RDS_CMSG_RDMA_MAP: int - RDS_CMSG_RDMA_STATUS: int - RDS_CONG_MONITOR: int - RDS_FREE_MR: int - RDS_GET_MR: int - RDS_GET_MR_FOR_DEST: int - RDS_RDMA_DONTWAIT: int - RDS_RDMA_FENCE: int - RDS_RDMA_INVALIDATE: int - RDS_RDMA_NOTIFY_ME: int - RDS_RDMA_READWRITE: int - RDS_RDMA_SILENT: int - RDS_RDMA_USE_ONCE: int - RDS_RECVERR: int + RDS_CANCEL_SENT_TO: Final[int] + RDS_CMSG_RDMA_ARGS: Final[int] + RDS_CMSG_RDMA_DEST: Final[int] + RDS_CMSG_RDMA_MAP: Final[int] + RDS_CMSG_RDMA_STATUS: Final[int] + RDS_CONG_MONITOR: Final[int] + RDS_FREE_MR: Final[int] + RDS_GET_MR: Final[int] + RDS_GET_MR_FOR_DEST: Final[int] + RDS_RDMA_DONTWAIT: Final[int] + RDS_RDMA_FENCE: Final[int] + RDS_RDMA_INVALIDATE: Final[int] + RDS_RDMA_NOTIFY_ME: Final[int] + RDS_RDMA_READWRITE: Final[int] + RDS_RDMA_SILENT: Final[int] + RDS_RDMA_USE_ONCE: Final[int] + RDS_RECVERR: Final[int] # This is supported by CPython but doesn't seem to be a real thing. # The closest existing constant in rds.h is RDS_CMSG_CONG_UPDATE - # RDS_CMSG_RDMA_UPDATE: int + # RDS_CMSG_RDMA_UPDATE: Final[int] if sys.platform == "win32": - SIO_RCVALL: int - SIO_KEEPALIVE_VALS: int - SIO_LOOPBACK_FAST_PATH: int - RCVALL_MAX: int - RCVALL_OFF: int - RCVALL_ON: int - RCVALL_SOCKETLEVELONLY: int + SIO_RCVALL: Final[int] + SIO_KEEPALIVE_VALS: Final[int] + SIO_LOOPBACK_FAST_PATH: Final[int] + RCVALL_MAX: Final[int] + RCVALL_OFF: Final[int] + RCVALL_ON: Final[int] + RCVALL_SOCKETLEVELONLY: Final[int] if sys.platform == "linux": - AF_TIPC: int - SOL_TIPC: int - TIPC_ADDR_ID: int - TIPC_ADDR_NAME: int - TIPC_ADDR_NAMESEQ: int - TIPC_CFG_SRV: int - TIPC_CLUSTER_SCOPE: int - TIPC_CONN_TIMEOUT: int - TIPC_CRITICAL_IMPORTANCE: int - TIPC_DEST_DROPPABLE: int - TIPC_HIGH_IMPORTANCE: int - TIPC_IMPORTANCE: int - TIPC_LOW_IMPORTANCE: int - TIPC_MEDIUM_IMPORTANCE: int - TIPC_NODE_SCOPE: int - TIPC_PUBLISHED: int - TIPC_SRC_DROPPABLE: int - TIPC_SUBSCR_TIMEOUT: int - TIPC_SUB_CANCEL: int - TIPC_SUB_PORTS: int - TIPC_SUB_SERVICE: int - TIPC_TOP_SRV: int - TIPC_WAIT_FOREVER: int - TIPC_WITHDRAWN: int - TIPC_ZONE_SCOPE: int + AF_TIPC: Final[int] + SOL_TIPC: Final[int] + TIPC_ADDR_ID: Final[int] + TIPC_ADDR_NAME: Final[int] + TIPC_ADDR_NAMESEQ: Final[int] + TIPC_CFG_SRV: Final[int] + TIPC_CLUSTER_SCOPE: Final[int] + TIPC_CONN_TIMEOUT: Final[int] + TIPC_CRITICAL_IMPORTANCE: Final[int] + TIPC_DEST_DROPPABLE: Final[int] + TIPC_HIGH_IMPORTANCE: Final[int] + TIPC_IMPORTANCE: Final[int] + TIPC_LOW_IMPORTANCE: Final[int] + TIPC_MEDIUM_IMPORTANCE: Final[int] + TIPC_NODE_SCOPE: Final[int] + TIPC_PUBLISHED: Final[int] + TIPC_SRC_DROPPABLE: Final[int] + TIPC_SUBSCR_TIMEOUT: Final[int] + TIPC_SUB_CANCEL: Final[int] + TIPC_SUB_PORTS: Final[int] + TIPC_SUB_SERVICE: Final[int] + TIPC_TOP_SRV: Final[int] + TIPC_WAIT_FOREVER: Final[int] + TIPC_WITHDRAWN: Final[int] + TIPC_ZONE_SCOPE: Final[int] if sys.platform == "linux": # Availability: Linux >= 2.6.38 - AF_ALG: int - SOL_ALG: int - ALG_OP_DECRYPT: int - ALG_OP_ENCRYPT: int - ALG_OP_SIGN: int - ALG_OP_VERIFY: int - ALG_SET_AEAD_ASSOCLEN: int - ALG_SET_AEAD_AUTHSIZE: int - ALG_SET_IV: int - ALG_SET_KEY: int - ALG_SET_OP: int - ALG_SET_PUBKEY: int + AF_ALG: Final[int] + SOL_ALG: Final[int] + ALG_OP_DECRYPT: Final[int] + ALG_OP_ENCRYPT: Final[int] + ALG_OP_SIGN: Final[int] + ALG_OP_VERIFY: Final[int] + ALG_SET_AEAD_ASSOCLEN: Final[int] + ALG_SET_AEAD_AUTHSIZE: Final[int] + ALG_SET_IV: Final[int] + ALG_SET_KEY: Final[int] + ALG_SET_OP: Final[int] + ALG_SET_PUBKEY: Final[int] if sys.platform == "linux": # Availability: Linux >= 4.8 (or maybe 3.9, CPython docs are confusing) - AF_VSOCK: int - IOCTL_VM_SOCKETS_GET_LOCAL_CID: int - VMADDR_CID_ANY: int - VMADDR_CID_HOST: int - VMADDR_PORT_ANY: int - SO_VM_SOCKETS_BUFFER_MAX_SIZE: int - SO_VM_SOCKETS_BUFFER_SIZE: int - SO_VM_SOCKETS_BUFFER_MIN_SIZE: int - VM_SOCKETS_INVALID_VERSION: int # undocumented + AF_VSOCK: Final[int] + IOCTL_VM_SOCKETS_GET_LOCAL_CID: Final = 0x7B9 + VMADDR_CID_ANY: Final = 0xFFFFFFFF + VMADDR_CID_HOST: Final = 2 + VMADDR_PORT_ANY: Final = 0xFFFFFFFF + SO_VM_SOCKETS_BUFFER_MAX_SIZE: Final = 2 + SO_VM_SOCKETS_BUFFER_SIZE: Final = 0 + SO_VM_SOCKETS_BUFFER_MIN_SIZE: Final = 1 + VM_SOCKETS_INVALID_VERSION: Final = 0xFFFFFFFF # undocumented # Documented as only available on BSD, macOS, but empirically sometimes # available on Windows if sys.platform != "linux": - AF_LINK: int + AF_LINK: Final[int] has_ipv6: bool if sys.platform != "darwin" and sys.platform != "linux": - BDADDR_ANY: str - BDADDR_LOCAL: str + BDADDR_ANY: Final = "00:00:00:00:00:00" + BDADDR_LOCAL: Final = "00:00:00:FF:FF:FF" if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": - HCI_FILTER: int # not in NetBSD or DragonFlyBSD - HCI_TIME_STAMP: int # not in FreeBSD, NetBSD, or DragonFlyBSD - HCI_DATA_DIR: int # not in FreeBSD, NetBSD, or DragonFlyBSD + HCI_FILTER: Final[int] # not in NetBSD or DragonFlyBSD + HCI_TIME_STAMP: Final[int] # not in FreeBSD, NetBSD, or DragonFlyBSD + HCI_DATA_DIR: Final[int] # not in FreeBSD, NetBSD, or DragonFlyBSD if sys.platform == "linux": - AF_QIPCRTR: int # Availability: Linux >= 4.7 + AF_QIPCRTR: Final[int] # Availability: Linux >= 4.7 if sys.version_info >= (3, 11) and sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin": # FreeBSD - SCM_CREDS2: int - LOCAL_CREDS: int - LOCAL_CREDS_PERSISTENT: int + SCM_CREDS2: Final[int] + LOCAL_CREDS: Final[int] + LOCAL_CREDS_PERSISTENT: Final[int] if sys.version_info >= (3, 11) and sys.platform == "linux": - SO_INCOMING_CPU: int # Availability: Linux >= 3.9 + SO_INCOMING_CPU: Final[int] # Availability: Linux >= 3.9 if sys.version_info >= (3, 12) and sys.platform == "win32": # Availability: Windows - AF_HYPERV: int - HV_PROTOCOL_RAW: int - HVSOCKET_CONNECT_TIMEOUT: int - HVSOCKET_CONNECT_TIMEOUT_MAX: int - HVSOCKET_CONNECTED_SUSPEND: int - HVSOCKET_ADDRESS_FLAG_PASSTHRU: int - HV_GUID_ZERO: str - HV_GUID_WILDCARD: str - HV_GUID_BROADCAST: str - HV_GUID_CHILDREN: str - HV_GUID_LOOPBACK: str - HV_GUID_PARENT: str + AF_HYPERV: Final[int] + HV_PROTOCOL_RAW: Final[int] + HVSOCKET_CONNECT_TIMEOUT: Final[int] + HVSOCKET_CONNECT_TIMEOUT_MAX: Final[int] + HVSOCKET_CONNECTED_SUSPEND: Final[int] + HVSOCKET_ADDRESS_FLAG_PASSTHRU: Final[int] + HV_GUID_ZERO: Final = "00000000-0000-0000-0000-000000000000" + HV_GUID_WILDCARD: Final = "00000000-0000-0000-0000-000000000000" + HV_GUID_BROADCAST: Final = "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF" + HV_GUID_CHILDREN: Final = "90DB8B89-0D35-4F79-8CE9-49EA0AC8B7CD" + HV_GUID_LOOPBACK: Final = "E0E16197-DD56-4A10-9195-5EE7A155A838" + HV_GUID_PARENT: Final = "A42E7CDA-D03F-480C-9CC2-A4DE20ABB878" if sys.version_info >= (3, 12): if sys.platform != "win32": # Availability: Linux, FreeBSD, macOS - ETHERTYPE_ARP: int - ETHERTYPE_IP: int - ETHERTYPE_IPV6: int - ETHERTYPE_VLAN: int + ETHERTYPE_ARP: Final[int] + ETHERTYPE_IP: Final[int] + ETHERTYPE_IPV6: Final[int] + ETHERTYPE_VLAN: Final[int] # -------------------- # Semi-documented constants @@ -644,95 +644,95 @@ if sys.version_info >= (3, 12): if sys.platform == "linux": # Netlink is defined by Linux - AF_NETLINK: int - NETLINK_CRYPTO: int - NETLINK_DNRTMSG: int - NETLINK_FIREWALL: int - NETLINK_IP6_FW: int - NETLINK_NFLOG: int - NETLINK_ROUTE: int - NETLINK_USERSOCK: int - NETLINK_XFRM: int + AF_NETLINK: Final[int] + NETLINK_CRYPTO: Final[int] + NETLINK_DNRTMSG: Final[int] + NETLINK_FIREWALL: Final[int] + NETLINK_IP6_FW: Final[int] + NETLINK_NFLOG: Final[int] + NETLINK_ROUTE: Final[int] + NETLINK_USERSOCK: Final[int] + NETLINK_XFRM: Final[int] # Technically still supported by CPython - # NETLINK_ARPD: int # linux 2.0 to 2.6.12 (EOL August 2005) - # NETLINK_ROUTE6: int # linux 2.2 to 2.6.12 (EOL August 2005) - # NETLINK_SKIP: int # linux 2.0 to 2.6.12 (EOL August 2005) - # NETLINK_TAPBASE: int # linux 2.2 to 2.6.12 (EOL August 2005) - # NETLINK_TCPDIAG: int # linux 2.6.0 to 2.6.13 (EOL December 2005) - # NETLINK_W1: int # linux 2.6.13 to 2.6.17 (EOL October 2006) + # NETLINK_ARPD: Final[int] # linux 2.0 to 2.6.12 (EOL August 2005) + # NETLINK_ROUTE6: Final[int] # linux 2.2 to 2.6.12 (EOL August 2005) + # NETLINK_SKIP: Final[int] # linux 2.0 to 2.6.12 (EOL August 2005) + # NETLINK_TAPBASE: Final[int] # linux 2.2 to 2.6.12 (EOL August 2005) + # NETLINK_TCPDIAG: Final[int] # linux 2.6.0 to 2.6.13 (EOL December 2005) + # NETLINK_W1: Final[int] # linux 2.6.13 to 2.6.17 (EOL October 2006) if sys.platform == "darwin": - PF_SYSTEM: int - SYSPROTO_CONTROL: int + PF_SYSTEM: Final[int] + SYSPROTO_CONTROL: Final[int] if sys.platform != "darwin" and sys.platform != "linux": - AF_BLUETOOTH: int + AF_BLUETOOTH: Final[int] if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": # Linux and some BSD support is explicit in the docs # Windows and macOS do not support in practice - BTPROTO_HCI: int - BTPROTO_L2CAP: int - BTPROTO_SCO: int # not in FreeBSD + BTPROTO_HCI: Final[int] + BTPROTO_L2CAP: Final[int] + BTPROTO_SCO: Final[int] # not in FreeBSD if sys.platform != "darwin" and sys.platform != "linux": - BTPROTO_RFCOMM: int + BTPROTO_RFCOMM: Final[int] if sys.platform == "linux": - UDPLITE_RECV_CSCOV: int - UDPLITE_SEND_CSCOV: int + UDPLITE_RECV_CSCOV: Final[int] + UDPLITE_SEND_CSCOV: Final[int] # -------------------- # Documented under socket.shutdown # -------------------- -SHUT_RD: int -SHUT_RDWR: int -SHUT_WR: int +SHUT_RD: Final[int] +SHUT_RDWR: Final[int] +SHUT_WR: Final[int] # -------------------- # Undocumented constants # -------------------- # Undocumented address families -AF_APPLETALK: int -AF_DECnet: int -AF_IPX: int -AF_SNA: int +AF_APPLETALK: Final[int] +AF_DECnet: Final[int] +AF_IPX: Final[int] +AF_SNA: Final[int] if sys.platform != "win32": - AF_ROUTE: int + AF_ROUTE: Final[int] if sys.platform == "darwin": - AF_SYSTEM: int + AF_SYSTEM: Final[int] if sys.platform != "darwin": - AF_IRDA: int + AF_IRDA: Final[int] if sys.platform != "win32" and sys.platform != "darwin": - AF_ASH: int - AF_ATMPVC: int - AF_ATMSVC: int - AF_AX25: int - AF_BRIDGE: int - AF_ECONET: int - AF_KEY: int - AF_LLC: int - AF_NETBEUI: int - AF_NETROM: int - AF_PPPOX: int - AF_ROSE: int - AF_SECURITY: int - AF_WANPIPE: int - AF_X25: int + AF_ASH: Final[int] + AF_ATMPVC: Final[int] + AF_ATMSVC: Final[int] + AF_AX25: Final[int] + AF_BRIDGE: Final[int] + AF_ECONET: Final[int] + AF_KEY: Final[int] + AF_LLC: Final[int] + AF_NETBEUI: Final[int] + AF_NETROM: Final[int] + AF_PPPOX: Final[int] + AF_ROSE: Final[int] + AF_SECURITY: Final[int] + AF_WANPIPE: Final[int] + AF_X25: Final[int] # Miscellaneous undocumented if sys.platform != "win32" and sys.platform != "linux": - LOCAL_PEERCRED: int + LOCAL_PEERCRED: Final[int] if sys.platform != "win32" and sys.platform != "darwin": # Defined in linux socket.h, but this isn't always present for # some reason. - IPX_TYPE: int + IPX_TYPE: Final[int] # ===== Classes ===== @@ -800,10 +800,10 @@ class socket: """the socket timeout""" if sys.platform == "win32": def __init__( - self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | bytes | None = ... + self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | bytes | None = None ) -> None: ... else: - def __init__(self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | None = ...) -> None: ... + def __init__(self, family: int = ..., type: int = ..., proto: int = ..., fileno: SupportsIndex | None = None) -> None: ... def bind(self, address: _Address, /) -> None: """bind(address) @@ -907,7 +907,7 @@ class socket: connections. If not specified, a default reasonable value is chosen. """ - def recv(self, bufsize: int, flags: int = ..., /) -> bytes: + def recv(self, bufsize: int, flags: int = 0, /) -> bytes: """recv(buffersize[, flags]) -> data Receive up to buffersize bytes from the socket. For the optional flags @@ -916,13 +916,13 @@ class socket: the remote end is closed and all data is read, return the empty string. """ - def recvfrom(self, bufsize: int, flags: int = ..., /) -> tuple[bytes, _RetAddress]: + def recvfrom(self, bufsize: int, flags: int = 0, /) -> tuple[bytes, _RetAddress]: """recvfrom(buffersize[, flags]) -> (data, address info) Like recv(buffersize, flags) but also return the sender's address info. """ if sys.platform != "win32": - def recvmsg(self, bufsize: int, ancbufsize: int = ..., flags: int = ..., /) -> tuple[bytes, list[_CMSG], int, Any]: + def recvmsg(self, bufsize: int, ancbufsize: int = 0, flags: int = 0, /) -> tuple[bytes, list[_CMSG], int, Any]: """recvmsg(bufsize[, ancbufsize[, flags]]) -> (data, ancdata, msg_flags, address) Receive normal data (up to bufsize bytes) and ancillary data from the @@ -953,7 +953,7 @@ class socket: """ def recvmsg_into( - self, buffers: Iterable[WriteableBuffer], ancbufsize: int = ..., flags: int = ..., / + self, buffers: Iterable[WriteableBuffer], ancbufsize: int = 0, flags: int = 0, / ) -> tuple[int, list[_CMSG], int, Any]: """recvmsg_into(buffers[, ancbufsize[, flags]]) -> (nbytes, ancdata, msg_flags, address) @@ -988,13 +988,13 @@ class socket: SCM_RIGHTS mechanism. """ - def recvfrom_into(self, buffer: WriteableBuffer, nbytes: int = ..., flags: int = ...) -> tuple[int, _RetAddress]: + def recvfrom_into(self, buffer: WriteableBuffer, nbytes: int = 0, flags: int = 0) -> tuple[int, _RetAddress]: """recvfrom_into(buffer[, nbytes[, flags]]) -> (nbytes, address info) Like recv_into(buffer[, nbytes[, flags]]) but also return the sender's address info. """ - def recv_into(self, buffer: WriteableBuffer, nbytes: int = ..., flags: int = ...) -> int: + def recv_into(self, buffer: WriteableBuffer, nbytes: int = 0, flags: int = 0) -> int: """recv_into(buffer, [nbytes[, flags]]) -> nbytes_read A version of recv() that stores its data into a buffer rather than creating @@ -1004,7 +1004,7 @@ class socket: See recv() for documentation about the flags. """ - def send(self, data: ReadableBuffer, flags: int = ..., /) -> int: + def send(self, data: ReadableBuffer, flags: int = 0, /) -> int: """send(data[, flags]) -> count Send a data string to the socket. For the optional flags @@ -1012,7 +1012,7 @@ class socket: sent; this may be less than len(data) if the network is busy. """ - def sendall(self, data: ReadableBuffer, flags: int = ..., /) -> None: + def sendall(self, data: ReadableBuffer, flags: int = 0, /) -> None: """sendall(data[, flags]) Send a data string to the socket. For the optional flags @@ -1036,8 +1036,8 @@ class socket: self, buffers: Iterable[ReadableBuffer], ancdata: Iterable[_CMSGArg] = ..., - flags: int = ..., - address: _Address | None = ..., + flags: int = 0, + address: _Address | None = None, /, ) -> int: """sendmsg(buffers[, ancdata[, flags[, address]]]) -> count @@ -1058,7 +1058,7 @@ class socket: """ if sys.platform == "linux": def sendmsg_afalg( - self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ... + self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = 0 ) -> int: """sendmsg_afalg([msg], *, op[, iv[, assoclen[, flags=MSG_MORE]]]) @@ -1133,12 +1133,7 @@ def dup(fd: SupportsIndex, /) -> int: # the 5th tuple item is an address def getaddrinfo( - host: bytes | str | None, - port: bytes | str | int | None, - family: int = ..., - type: int = ..., - proto: int = ..., - flags: int = ..., + host: bytes | str | None, port: bytes | str | int | None, family: int = ..., type: int = 0, proto: int = 0, flags: int = 0 ) -> list[tuple[int, int, int, str, tuple[str, int] | tuple[str, int, int, int] | tuple[int, bytes]]]: """getaddrinfo(host, port [, family, type, proto, flags]) -> list of (family, type, proto, canonname, sockaddr) @@ -1278,7 +1273,7 @@ if sys.platform != "win32": range of values. """ - def socketpair(family: int = ..., type: int = ..., proto: int = ..., /) -> tuple[socket, socket]: + def socketpair(family: int = ..., type: int = ..., proto: int = 0, /) -> tuple[socket, socket]: """socketpair([family[, type [, proto]]]) -> (socket object, socket object) Create a pair of socket objects from the sockets returned by the platform diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi index 179dc961b2c09..d700e8f8c55b3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi @@ -16,14 +16,15 @@ from ssl import ( SSLWantWriteError as SSLWantWriteError, SSLZeroReturnError as SSLZeroReturnError, ) -from typing import Any, ClassVar, Literal, TypedDict, final, overload -from typing_extensions import NotRequired, Self, TypeAlias +from typing import Any, ClassVar, Final, Literal, TypedDict, final, overload, type_check_only +from typing_extensions import NotRequired, Self, TypeAlias, deprecated _PasswordType: TypeAlias = Callable[[], str | bytes | bytearray] | str | bytes | bytearray _PCTRTT: TypeAlias = tuple[tuple[str, str], ...] _PCTRTTT: TypeAlias = tuple[_PCTRTT, ...] _PeerCertRetDictType: TypeAlias = dict[str, str | _PCTRTTT | _PCTRTT] +@type_check_only class _Cipher(TypedDict): aead: bool alg_bits: int @@ -37,6 +38,7 @@ class _Cipher(TypedDict): strength_bits: int symmetric: str +@type_check_only class _CertInfo(TypedDict): subject: tuple[tuple[tuple[str, str], ...], ...] issuer: tuple[tuple[tuple[str, str], ...], ...] @@ -60,6 +62,7 @@ def RAND_bytes(n: int, /) -> bytes: """Generate n cryptographically strong pseudo-random bytes.""" if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.6; removed in Python 3.12. Use `ssl.RAND_bytes()` instead.") def RAND_pseudo_bytes(n: int, /) -> tuple[bytes, bool]: """Generate n pseudo-random bytes. @@ -252,135 +255,134 @@ if sys.version_info < (3, 12): err_names_to_codes: dict[str, tuple[int, int]] lib_codes_to_names: dict[int, str] -_DEFAULT_CIPHERS: str +_DEFAULT_CIPHERS: Final[str] # SSL error numbers -SSL_ERROR_ZERO_RETURN: int -SSL_ERROR_WANT_READ: int -SSL_ERROR_WANT_WRITE: int -SSL_ERROR_WANT_X509_LOOKUP: int -SSL_ERROR_SYSCALL: int -SSL_ERROR_SSL: int -SSL_ERROR_WANT_CONNECT: int -SSL_ERROR_EOF: int -SSL_ERROR_INVALID_ERROR_CODE: int +SSL_ERROR_ZERO_RETURN: Final = 6 +SSL_ERROR_WANT_READ: Final = 2 +SSL_ERROR_WANT_WRITE: Final = 3 +SSL_ERROR_WANT_X509_LOOKUP: Final = 4 +SSL_ERROR_SYSCALL: Final = 5 +SSL_ERROR_SSL: Final = 1 +SSL_ERROR_WANT_CONNECT: Final = 7 +SSL_ERROR_EOF: Final = 8 +SSL_ERROR_INVALID_ERROR_CODE: Final = 10 # verify modes -CERT_NONE: int -CERT_OPTIONAL: int -CERT_REQUIRED: int +CERT_NONE: Final = 0 +CERT_OPTIONAL: Final = 1 +CERT_REQUIRED: Final = 2 # verify flags -VERIFY_DEFAULT: int -VERIFY_CRL_CHECK_LEAF: int -VERIFY_CRL_CHECK_CHAIN: int -VERIFY_X509_STRICT: int -VERIFY_X509_TRUSTED_FIRST: int +VERIFY_DEFAULT: Final = 0 +VERIFY_CRL_CHECK_LEAF: Final = 0x4 +VERIFY_CRL_CHECK_CHAIN: Final = 0x8 +VERIFY_X509_STRICT: Final = 0x20 +VERIFY_X509_TRUSTED_FIRST: Final = 0x8000 if sys.version_info >= (3, 10): - VERIFY_ALLOW_PROXY_CERTS: int - VERIFY_X509_PARTIAL_CHAIN: int + VERIFY_ALLOW_PROXY_CERTS: Final = 0x40 + VERIFY_X509_PARTIAL_CHAIN: Final = 0x80000 # alert descriptions -ALERT_DESCRIPTION_CLOSE_NOTIFY: int -ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: int -ALERT_DESCRIPTION_BAD_RECORD_MAC: int -ALERT_DESCRIPTION_RECORD_OVERFLOW: int -ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: int -ALERT_DESCRIPTION_HANDSHAKE_FAILURE: int -ALERT_DESCRIPTION_BAD_CERTIFICATE: int -ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: int -ALERT_DESCRIPTION_CERTIFICATE_REVOKED: int -ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: int -ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: int -ALERT_DESCRIPTION_ILLEGAL_PARAMETER: int -ALERT_DESCRIPTION_UNKNOWN_CA: int -ALERT_DESCRIPTION_ACCESS_DENIED: int -ALERT_DESCRIPTION_DECODE_ERROR: int -ALERT_DESCRIPTION_DECRYPT_ERROR: int -ALERT_DESCRIPTION_PROTOCOL_VERSION: int -ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: int -ALERT_DESCRIPTION_INTERNAL_ERROR: int -ALERT_DESCRIPTION_USER_CANCELLED: int -ALERT_DESCRIPTION_NO_RENEGOTIATION: int -ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: int -ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: int -ALERT_DESCRIPTION_UNRECOGNIZED_NAME: int -ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: int -ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: int -ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: int +ALERT_DESCRIPTION_CLOSE_NOTIFY: Final = 0 +ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: Final = 10 +ALERT_DESCRIPTION_BAD_RECORD_MAC: Final = 20 +ALERT_DESCRIPTION_RECORD_OVERFLOW: Final = 22 +ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: Final = 30 +ALERT_DESCRIPTION_HANDSHAKE_FAILURE: Final = 40 +ALERT_DESCRIPTION_BAD_CERTIFICATE: Final = 42 +ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: Final = 43 +ALERT_DESCRIPTION_CERTIFICATE_REVOKED: Final = 44 +ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: Final = 45 +ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: Final = 46 +ALERT_DESCRIPTION_ILLEGAL_PARAMETER: Final = 47 +ALERT_DESCRIPTION_UNKNOWN_CA: Final = 48 +ALERT_DESCRIPTION_ACCESS_DENIED: Final = 49 +ALERT_DESCRIPTION_DECODE_ERROR: Final = 50 +ALERT_DESCRIPTION_DECRYPT_ERROR: Final = 51 +ALERT_DESCRIPTION_PROTOCOL_VERSION: Final = 70 +ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: Final = 71 +ALERT_DESCRIPTION_INTERNAL_ERROR: Final = 80 +ALERT_DESCRIPTION_USER_CANCELLED: Final = 90 +ALERT_DESCRIPTION_NO_RENEGOTIATION: Final = 100 +ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: Final = 110 +ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: Final = 111 +ALERT_DESCRIPTION_UNRECOGNIZED_NAME: Final = 112 +ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: Final = 113 +ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: Final = 114 +ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: Final = 115 # protocol versions -PROTOCOL_SSLv23: int -PROTOCOL_TLS: int -PROTOCOL_TLS_CLIENT: int -PROTOCOL_TLS_SERVER: int -PROTOCOL_TLSv1: int -PROTOCOL_TLSv1_1: int -PROTOCOL_TLSv1_2: int +PROTOCOL_SSLv23: Final = 2 +PROTOCOL_TLS: Final = 2 +PROTOCOL_TLS_CLIENT: Final = 16 +PROTOCOL_TLS_SERVER: Final = 17 +PROTOCOL_TLSv1: Final = 3 +PROTOCOL_TLSv1_1: Final = 4 +PROTOCOL_TLSv1_2: Final = 5 # protocol options -OP_ALL: int -OP_NO_SSLv2: int -OP_NO_SSLv3: int -OP_NO_TLSv1: int -OP_NO_TLSv1_1: int -OP_NO_TLSv1_2: int -OP_NO_TLSv1_3: int -OP_CIPHER_SERVER_PREFERENCE: int -OP_SINGLE_DH_USE: int -OP_NO_TICKET: int -OP_SINGLE_ECDH_USE: int -OP_NO_COMPRESSION: int -OP_ENABLE_MIDDLEBOX_COMPAT: int -OP_NO_RENEGOTIATION: int +OP_ALL: Final = 0x80000050 +OP_NO_SSLv2: Final = 0x0 +OP_NO_SSLv3: Final = 0x2000000 +OP_NO_TLSv1: Final = 0x4000000 +OP_NO_TLSv1_1: Final = 0x10000000 +OP_NO_TLSv1_2: Final = 0x8000000 +OP_NO_TLSv1_3: Final = 0x20000000 +OP_CIPHER_SERVER_PREFERENCE: Final = 0x400000 +OP_SINGLE_DH_USE: Final = 0x0 +OP_NO_TICKET: Final = 0x4000 +OP_SINGLE_ECDH_USE: Final = 0x0 +OP_NO_COMPRESSION: Final = 0x20000 +OP_ENABLE_MIDDLEBOX_COMPAT: Final = 0x100000 +OP_NO_RENEGOTIATION: Final = 0x40000000 if sys.version_info >= (3, 11) or sys.platform == "linux": - OP_IGNORE_UNEXPECTED_EOF: int + OP_IGNORE_UNEXPECTED_EOF: Final = 0x80 if sys.version_info >= (3, 12): - OP_LEGACY_SERVER_CONNECT: int - OP_ENABLE_KTLS: int + OP_LEGACY_SERVER_CONNECT: Final = 0x4 + OP_ENABLE_KTLS: Final = 0x8 # host flags -HOSTFLAG_ALWAYS_CHECK_SUBJECT: int -HOSTFLAG_NEVER_CHECK_SUBJECT: int -HOSTFLAG_NO_WILDCARDS: int -HOSTFLAG_NO_PARTIAL_WILDCARDS: int -HOSTFLAG_MULTI_LABEL_WILDCARDS: int -HOSTFLAG_SINGLE_LABEL_SUBDOMAINS: int +HOSTFLAG_ALWAYS_CHECK_SUBJECT: Final = 0x1 +HOSTFLAG_NEVER_CHECK_SUBJECT: Final = 0x20 +HOSTFLAG_NO_WILDCARDS: Final = 0x2 +HOSTFLAG_NO_PARTIAL_WILDCARDS: Final = 0x4 +HOSTFLAG_MULTI_LABEL_WILDCARDS: Final = 0x8 +HOSTFLAG_SINGLE_LABEL_SUBDOMAINS: Final = 0x10 if sys.version_info >= (3, 10): # certificate file types - # Typed as Literal so the overload on Certificate.public_bytes can work properly. - ENCODING_PEM: Literal[1] - ENCODING_DER: Literal[2] + ENCODING_PEM: Final = 1 + ENCODING_DER: Final = 2 # protocol versions -PROTO_MINIMUM_SUPPORTED: int -PROTO_MAXIMUM_SUPPORTED: int -PROTO_SSLv3: int -PROTO_TLSv1: int -PROTO_TLSv1_1: int -PROTO_TLSv1_2: int -PROTO_TLSv1_3: int +PROTO_MINIMUM_SUPPORTED: Final = -2 +PROTO_MAXIMUM_SUPPORTED: Final = -1 +PROTO_SSLv3: Final[int] +PROTO_TLSv1: Final[int] +PROTO_TLSv1_1: Final[int] +PROTO_TLSv1_2: Final[int] +PROTO_TLSv1_3: Final[int] # feature support -HAS_SNI: bool -HAS_TLS_UNIQUE: bool -HAS_ECDH: bool -HAS_NPN: bool +HAS_SNI: Final[bool] +HAS_TLS_UNIQUE: Final[bool] +HAS_ECDH: Final[bool] +HAS_NPN: Final[bool] if sys.version_info >= (3, 13): - HAS_PSK: bool -HAS_ALPN: bool -HAS_SSLv2: bool -HAS_SSLv3: bool -HAS_TLSv1: bool -HAS_TLSv1_1: bool -HAS_TLSv1_2: bool -HAS_TLSv1_3: bool + HAS_PSK: Final[bool] +HAS_ALPN: Final[bool] +HAS_SSLv2: Final[bool] +HAS_SSLv3: Final[bool] +HAS_TLSv1: Final[bool] +HAS_TLSv1_1: Final[bool] +HAS_TLSv1_2: Final[bool] +HAS_TLSv1_3: Final[bool] if sys.version_info >= (3, 14): - HAS_PHA: bool + HAS_PHA: Final[bool] # version info -OPENSSL_VERSION_NUMBER: int -OPENSSL_VERSION_INFO: tuple[int, int, int, int, int] -OPENSSL_VERSION: str -_OPENSSL_API_VERSION: tuple[int, int, int, int, int] +OPENSSL_VERSION_NUMBER: Final[int] +OPENSSL_VERSION_INFO: Final[tuple[int, int, int, int, int]] +OPENSSL_VERSION: Final[str] +_OPENSSL_API_VERSION: Final[tuple[int, int, int, int, int]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_tkinter.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_tkinter.pyi index 2663e7552c0c3..c0683e900c142 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_tkinter.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_tkinter.pyi @@ -1,7 +1,7 @@ import sys from collections.abc import Callable from typing import Any, ClassVar, Final, final -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, deprecated # _tkinter is meant to be only used internally by tkinter, but some tkinter # functions e.g. return _tkinter.Tcl_Obj objects. Tcl_Obj represents a Tcl @@ -87,6 +87,7 @@ class TkappType: def record(self, script, /): ... def setvar(self, *ags, **kwargs): ... if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.") def split(self, arg, /): ... def splitlist(self, arg, /): ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi index 29c121859d6ce..14140f58a76d6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi @@ -172,6 +172,9 @@ if sys.platform == "win32": ERROR_ACCESS_DENIED: Final = 5 ERROR_PRIVILEGE_NOT_HELD: Final = 1314 + if sys.version_info >= (3, 14): + COPY_FILE_DIRECTORY: Final = 0x00000080 + def CloseHandle(handle: int, /) -> None: """Close handle.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi index 99cbb8e83fb5f..2bfc6b6337bcf 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi @@ -217,7 +217,7 @@ class ZstdDict: 1. Prefix is compatible with long distance matching, while dictionary is not. 2. It only works for the first frame, then the compressor/decompressor will return to no prefix state. - 3. When decompressing, must use the same prefix as when compressing." + 3. When decompressing, must use the same prefix as when compressing. """ @property @@ -239,11 +239,13 @@ class ZstdDict: @property def dict_id(self) -> int: - """the Zstandard dictionary, an int between 0 and 2**32. + """The Zstandard dictionary, an int between 0 and 2**32. - A non-zero value represents an ordinary Zstandard dictionary, conforming to the standardised format. + A non-zero value represents an ordinary Zstandard dictionary, + conforming to the standardised format. - The special value '0' means a 'raw content' dictionary,without any restrictions on format or content. + A value of zero indicates a 'raw content' dictionary, + without any restrictions on format or content. """ class ZstdError(Exception): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi index fe537bfe46621..947cc6a1ccb12 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi @@ -9,11 +9,14 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Iterable, MutableSequence from types import GenericAlias from typing import Any, ClassVar, Literal, SupportsIndex, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated _IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] _FloatTypeCode: TypeAlias = Literal["f", "d"] -_UnicodeTypeCode: TypeAlias = Literal["u"] +if sys.version_info >= (3, 13): + _UnicodeTypeCode: TypeAlias = Literal["u", "w"] +else: + _UnicodeTypeCode: TypeAlias = Literal["u"] _TypeCode: TypeAlias = _IntTypeCode | _FloatTypeCode | _UnicodeTypeCode _T = TypeVar("_T", int, float, str) @@ -95,10 +98,23 @@ class array(MutableSequence[_T]): def __new__( cls: type[array[float]], typecode: _FloatTypeCode, initializer: bytes | bytearray | Iterable[float] = ..., / ) -> array[float]: ... - @overload - def __new__( - cls: type[array[str]], typecode: _UnicodeTypeCode, initializer: bytes | bytearray | Iterable[str] = ..., / - ) -> array[str]: ... + if sys.version_info >= (3, 13): + @overload + def __new__( + cls: type[array[str]], typecode: Literal["w"], initializer: bytes | bytearray | Iterable[str] = ..., / + ) -> array[str]: ... + @overload + @deprecated("Deprecated since Python 3.3; will be removed in Python 3.16. Use 'w' typecode instead.") + def __new__( + cls: type[array[str]], typecode: Literal["u"], initializer: bytes | bytearray | Iterable[str] = ..., / + ) -> array[str]: ... + else: + @overload + @deprecated("Deprecated since Python 3.3; will be removed in Python 3.16.") + def __new__( + cls: type[array[str]], typecode: Literal["u"], initializer: bytes | bytearray | Iterable[str] = ..., / + ) -> array[str]: ... + @overload def __new__(cls, typecode: str, initializer: Iterable[_T], /) -> Self: ... @overload @@ -181,6 +197,9 @@ class array(MutableSequence[_T]): unicode string from an array of some other type. """ __hash__: ClassVar[None] # type: ignore[assignment] + def __contains__(self, value: object, /) -> bool: + """Return bool(key in self).""" + def __len__(self) -> int: """Return len(self).""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi index 262ea22b9d8e2..0f66829027d90 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi @@ -33,7 +33,7 @@ from _ast import ( ) from _typeshed import ReadableBuffer, Unused from collections.abc import Iterable, Iterator, Sequence -from typing import Any, ClassVar, Generic, Literal, TypedDict, TypeVar as _TypeVar, overload +from typing import Any, ClassVar, Generic, Literal, TypedDict, TypeVar as _TypeVar, overload, type_check_only from typing_extensions import Self, Unpack, deprecated if sys.version_info >= (3, 13): @@ -43,6 +43,7 @@ if sys.version_info >= (3, 13): _EndPositionT = typing_extensions.TypeVar("_EndPositionT", int, int | None, default=int | None) # Corresponds to the names in the `_attributes` class variable which is non-empty in certain AST nodes +@type_check_only class _Attributes(TypedDict, Generic[_EndPositionT], total=False): lineno: int col_offset: int @@ -1330,19 +1331,21 @@ class Constant(expr): kind: str | None if sys.version_info < (3, 14): # Aliases for value, for backwards compatibility - @deprecated("Will be removed in Python 3.14; use value instead") @property + @deprecated("Will be removed in Python 3.14. Use `value` instead.") def n(self) -> _ConstantValue: """Deprecated. Use value instead.""" @n.setter + @deprecated("Will be removed in Python 3.14. Use `value` instead.") def n(self, value: _ConstantValue) -> None: ... - @deprecated("Will be removed in Python 3.14; use value instead") @property + @deprecated("Will be removed in Python 3.14. Use `value` instead.") def s(self) -> _ConstantValue: """Deprecated. Use value instead.""" @s.setter + @deprecated("Will be removed in Python 3.14. Use `value` instead.") def s(self, value: _ConstantValue) -> None: ... def __init__(self, value: _ConstantValue, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ... @@ -2121,8 +2124,14 @@ if sys.version_info >= (3, 12): ) -> Self: """Return a copy of the AST node with new values for the specified fields.""" -class _ABC(type): - def __init__(cls, *args: Unused) -> None: ... +if sys.version_info >= (3, 14): + @type_check_only + class _ABC(type): + def __init__(cls, *args: Unused) -> None: ... + +else: + class _ABC(type): + def __init__(cls, *args: Unused) -> None: ... if sys.version_info < (3, 14): @deprecated("Replaced by ast.Constant; removed in Python 3.14") diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/coroutines.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/coroutines.pyi index 2908051fdd397..d1db48fb9cfad 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/coroutines.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/coroutines.pyi @@ -1,7 +1,7 @@ import sys from collections.abc import Awaitable, Callable, Coroutine from typing import Any, TypeVar, overload -from typing_extensions import ParamSpec, TypeGuard, TypeIs +from typing_extensions import ParamSpec, TypeGuard, TypeIs, deprecated # Keep asyncio.__all__ updated with any changes to __all__ here if sys.version_info >= (3, 11): @@ -14,6 +14,7 @@ _FunctionT = TypeVar("_FunctionT", bound=Callable[..., Any]) _P = ParamSpec("_P") if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `async def` instead.") def coroutine(func: _FunctionT) -> _FunctionT: """Decorator to mark coroutines. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi index 789923832dc7e..de3e1dec92d2e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi @@ -14,7 +14,7 @@ from collections.abc import Callable, Sequence from concurrent.futures import Executor from contextvars import Context from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket -from typing import IO, Any, Literal, Protocol, TypeVar, overload +from typing import IO, Any, Literal, Protocol, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias, TypeVarTuple, Unpack, deprecated from . import _AwaitableLike, _CoroutineLike @@ -70,6 +70,7 @@ _ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], object] _ProtocolFactory: TypeAlias = Callable[[], BaseProtocol] _SSLContext: TypeAlias = bool | None | ssl.SSLContext +@type_check_only class _TaskFactory(Protocol): def __call__(self, loop: AbstractEventLoop, factory: _CoroutineLike[_T], /) -> Future[_T]: ... @@ -936,6 +937,9 @@ class AbstractEventLoop: async def shutdown_default_executor(self) -> None: """Schedule the shutdown of the default executor.""" +# This class does not exist at runtime, but stubtest complains if it's marked as +# @type_check_only because it has an alias that does exist at runtime. See mypy#19568. +# @type_check_only class _AbstractEventLoopPolicy: """Abstract policy for accessing the event loop.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/format_helpers.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/format_helpers.pyi index d9550f113420c..9213dcbd43196 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/format_helpers.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/format_helpers.pyi @@ -3,9 +3,10 @@ import sys import traceback from collections.abc import Iterable from types import FrameType, FunctionType -from typing import Any, overload +from typing import Any, overload, type_check_only from typing_extensions import TypeAlias +@type_check_only class _HasWrapper: __wrapper__: _HasWrapper | FunctionType diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi index d889ff09605fc..7c145f01cbb7a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import ReadableBuffer, StrPath from collections.abc import Awaitable, Callable, Iterable, Sequence, Sized from types import ModuleType -from typing import Any, Protocol, SupportsIndex +from typing import Any, Protocol, SupportsIndex, type_check_only from typing_extensions import Self, TypeAlias from . import events, protocols, transports @@ -25,6 +25,7 @@ else: _ClientConnectedCallback: TypeAlias = Callable[[StreamReader, StreamWriter], Awaitable[None] | None] +@type_check_only class _ReaduntilBuffer(ReadableBuffer, Sized, Protocol): ... if sys.version_info >= (3, 10): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi index 292d0f759610c..ebe927041ae0a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi @@ -10,7 +10,7 @@ from _asyncio import ( _unregister_task as _unregister_task, ) from collections.abc import AsyncIterator, Awaitable, Coroutine, Generator, Iterable, Iterator -from typing import Any, Literal, Protocol, TypeVar, overload +from typing import Any, Literal, Protocol, TypeVar, overload, type_check_only from typing_extensions import TypeAlias from . import _CoroutineLike @@ -89,6 +89,7 @@ FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION ALL_COMPLETED = concurrent.futures.ALL_COMPLETED if sys.version_info >= (3, 13): + @type_check_only class _SyncAndAsyncIterator(Iterator[_T_co], AsyncIterator[_T_co], Protocol[_T_co]): ... def as_completed(fs: Iterable[_FutureLike[_T]], *, timeout: float | None = None) -> _SyncAndAsyncIterator[Future[_T]]: @@ -741,6 +742,7 @@ elif sys.version_info >= (3, 12): if sys.version_info >= (3, 12): _TaskT_co = TypeVar("_TaskT_co", bound=Task[Any], covariant=True) + @type_check_only class _CustomTaskConstructor(Protocol[_TaskT_co]): def __call__( self, @@ -753,6 +755,7 @@ if sys.version_info >= (3, 12): eager_start: bool, ) -> _TaskT_co: ... + @type_check_only class _EagerTaskFactoryType(Protocol[_TaskT_co]): def __call__( self, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi index 0832062a9a824..c78f931c8555e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi @@ -5,7 +5,7 @@ from builtins import type as Type # alias to avoid name clashes with property n from collections.abc import Iterable from types import TracebackType from typing import Any, BinaryIO, NoReturn, overload -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, deprecated # These are based in socket, maybe move them out into _typeshed.pyi or such _Address: TypeAlias = socket._Address @@ -49,53 +49,82 @@ class TransportSocket: def setblocking(self, flag: bool) -> None: ... if sys.version_info < (3, 11): def _na(self, what: str) -> None: ... + @deprecated("Removed in Python 3.11") def accept(self) -> tuple[socket.socket, _RetAddress]: ... + @deprecated("Removed in Python 3.11") def connect(self, address: _Address) -> None: ... + @deprecated("Removed in Python 3.11") def connect_ex(self, address: _Address) -> int: ... + @deprecated("Removed in Python 3.11") def bind(self, address: _Address) -> None: ... if sys.platform == "win32": + @deprecated("Removed in Python 3.11") def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> None: ... else: + @deprecated("Removed in Python 3.11") def ioctl(self, control: int, option: int | tuple[int, int, int] | bool) -> NoReturn: ... + @deprecated("Removed in Python 3.11") def listen(self, backlog: int = ..., /) -> None: ... + @deprecated("Removed in Python 3.11") def makefile(self) -> BinaryIO: ... + @deprecated("Rmoved in Python 3.11") def sendfile(self, file: BinaryIO, offset: int = ..., count: int | None = ...) -> int: ... + @deprecated("Removed in Python 3.11") def close(self) -> None: ... + @deprecated("Removed in Python 3.11") def detach(self) -> int: ... if sys.platform == "linux": + @deprecated("Removed in Python 3.11") def sendmsg_afalg( self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ... ) -> int: ... else: + @deprecated("Removed in Python 3.11.") def sendmsg_afalg( self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ... ) -> NoReturn: ... + @deprecated("Removed in Python 3.11.") def sendmsg( self, buffers: Iterable[ReadableBuffer], ancdata: Iterable[_CMSG] = ..., flags: int = ..., address: _Address = ..., / ) -> int: ... @overload + @deprecated("Removed in Python 3.11.") def sendto(self, data: ReadableBuffer, address: _Address) -> int: ... @overload + @deprecated("Removed in Python 3.11.") def sendto(self, data: ReadableBuffer, flags: int, address: _Address) -> int: ... + @deprecated("Removed in Python 3.11.") def send(self, data: ReadableBuffer, flags: int = ...) -> int: ... + @deprecated("Removed in Python 3.11.") def sendall(self, data: ReadableBuffer, flags: int = ...) -> None: ... + @deprecated("Removed in Python 3.11.") def set_inheritable(self, inheritable: bool) -> None: ... if sys.platform == "win32": + @deprecated("Removed in Python 3.11.") def share(self, process_id: int) -> bytes: ... else: + @deprecated("Removed in Python 3.11.") def share(self, process_id: int) -> NoReturn: ... + @deprecated("Removed in Python 3.11.") def recv_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> int: ... + @deprecated("Removed in Python 3.11.") def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> tuple[int, _RetAddress]: ... + @deprecated("Removed in Python 3.11.") def recvmsg_into( self, buffers: Iterable[_WriteBuffer], ancbufsize: int = ..., flags: int = ..., / ) -> tuple[int, list[_CMSG], int, Any]: ... + @deprecated("Removed in Python 3.11.") def recvmsg(self, bufsize: int, ancbufsize: int = ..., flags: int = ..., /) -> tuple[bytes, list[_CMSG], int, Any]: ... + @deprecated("Removed in Python 3.11.") def recvfrom(self, bufsize: int, flags: int = ...) -> tuple[bytes, _RetAddress]: ... + @deprecated("Removed in Python 3.11.") def recv(self, bufsize: int, flags: int = ...) -> bytes: ... + @deprecated("Removed in Python 3.11.") def __enter__(self) -> socket.socket: ... + @deprecated("Removed in Python 3.11.") def __exit__( self, exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/bdb.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/bdb.pyi index 2857aff0f6f0e..e9ff8da0e462d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/bdb.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/bdb.pyi @@ -255,13 +255,13 @@ class Bdb: If no breakpoints are set, return an empty list. """ - def get_file_breaks(self, filename: str) -> list[Breakpoint]: + def get_file_breaks(self, filename: str) -> list[int]: """Return all lines with breakpoints for filename. If no breakpoints are set, return an empty list. """ - def get_all_breaks(self) -> list[Breakpoint]: + def get_all_breaks(self) -> dict[str, list[int]]: """Return all breakpoints that are set.""" def get_stack(self, f: FrameType | None, t: TracebackType | None) -> tuple[list[tuple[FrameType, int]], int]: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi index 9ccfc7ecc74c0..136c245253a89 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import ReadableBuffer -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, deprecated # Many functions in binascii accept buffer objects # or ASCII-only strings. @@ -42,15 +42,19 @@ def b2a_qp(data: ReadableBuffer, quotetabs: bool = False, istext: bool = True, h """ if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.9; removed in Python 3.11.") def a2b_hqx(data: _AsciiBuffer, /) -> bytes: """Decode .hqx coding.""" + @deprecated("Deprecated since Python 3.9; removed in Python 3.11.") def rledecode_hqx(data: ReadableBuffer, /) -> bytes: """Decode hexbin RLE-coded string.""" + @deprecated("Deprecated since Python 3.9; removed in Python 3.11.") def rlecode_hqx(data: ReadableBuffer, /) -> bytes: """Binhex RLE-code binary data.""" + @deprecated("Deprecated since Python 3.9; removed in Python 3.11.") def b2a_hqx(data: ReadableBuffer, /) -> bytes: """Encode .hqx data.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi index 5df63f805dfe7..5226fadaf6b93 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi @@ -643,6 +643,9 @@ class int: def __index__(self) -> int: """Return self converted to an integer, if self is suitable for use as an index into a list.""" + def __format__(self, format_spec: str, /) -> str: + """Convert to a string according to format_spec.""" + class float: """Convert a string or number to a floating-point number, if possible.""" @@ -795,6 +798,9 @@ class float: def __hash__(self) -> int: ... def __bool__(self) -> bool: """True if self else False""" + + def __format__(self, format_spec: str, /) -> str: + """Formats the float according to format_spec.""" if sys.version_info >= (3, 14): @classmethod def from_number(cls, number: float | SupportsIndex | SupportsFloat, /) -> Self: @@ -873,6 +879,9 @@ class complex: def __hash__(self) -> int: ... def __bool__(self) -> bool: """True if self else False""" + + def __format__(self, format_spec: str, /) -> str: + """Convert to a string according to format_spec.""" if sys.version_info >= (3, 11): def __complex__(self) -> complex: """Convert this value to exact type complex.""" @@ -1418,6 +1427,8 @@ class str(Sequence[str]): @overload def __rmul__(self, value: SupportsIndex, /) -> str: ... # type: ignore[misc] def __getnewargs__(self) -> tuple[str]: ... + def __format__(self, format_spec: str, /) -> str: + """Return a formatted version of the string as described by format_spec.""" class bytes(Sequence[int]): """bytes(iterable_of_ints) -> bytes @@ -3324,6 +3335,9 @@ class property: def __delete__(self, instance: Any, /) -> None: """Delete an attribute of instance.""" +# This class does not exist at runtime, but stubtest complains if it's marked as +# @type_check_only because it has an alias that does exist at runtime. See mypy#19568. +# @type_check_only @final class _NotImplementedType(Any): __call__: None @@ -3683,6 +3697,7 @@ def input(prompt: object = "", /) -> str: On *nix systems, readline is used if available. """ +@type_check_only class _GetItemIterable(Protocol[_T_co]): def __getitem__(self, i: int, /) -> _T_co: ... @@ -4121,6 +4136,7 @@ def open( def ord(c: str | bytes | bytearray, /) -> int: """Return the Unicode code point for a one-character string.""" +@type_check_only class _SupportsWriteAndFlush(SupportsWrite[_T_contra], SupportsFlush, Protocol[_T_contra]): ... @overload @@ -4151,12 +4167,15 @@ def print( _E_contra = TypeVar("_E_contra", contravariant=True) _M_contra = TypeVar("_M_contra", contravariant=True) +@type_check_only class _SupportsPow2(Protocol[_E_contra, _T_co]): def __pow__(self, other: _E_contra, /) -> _T_co: ... +@type_check_only class _SupportsPow3NoneOnly(Protocol[_E_contra, _T_co]): def __pow__(self, other: _E_contra, modulo: None = None, /) -> _T_co: ... +@type_check_only class _SupportsPow3(Protocol[_E_contra, _M_contra, _T_co]): def __pow__(self, other: _E_contra, modulo: _M_contra, /) -> _T_co: ... @@ -4238,9 +4257,11 @@ def repr(obj: object, /) -> str: # and https://github.com/python/typeshed/pull/9151 # on why we don't use `SupportsRound` from `typing.pyi` +@type_check_only class _SupportsRound1(Protocol[_T_co]): def __round__(self) -> _T_co: ... +@type_check_only class _SupportsRound2(Protocol[_T_co]): def __round__(self, ndigits: int, /) -> _T_co: ... @@ -4279,6 +4300,7 @@ def sorted(iterable: Iterable[_T], /, *, key: Callable[[_T], SupportsRichCompari _AddableT1 = TypeVar("_AddableT1", bound=SupportsAdd[Any, Any]) _AddableT2 = TypeVar("_AddableT2", bound=SupportsAdd[Any, Any]) +@type_check_only class _SupportsSumWithNoDefaultGiven(SupportsAdd[Any, Any], SupportsRAdd[int, Any], Protocol): ... _SupportsSumNoDefaultT = TypeVar("_SupportsSumNoDefaultT", bound=_SupportsSumWithNoDefaultGiven) diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/bz2.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/bz2.pyi index ad86b66dc1f71..84b3b4e30ec8b 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/bz2.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/bz2.pyi @@ -9,7 +9,7 @@ from _bz2 import BZ2Compressor as BZ2Compressor, BZ2Decompressor as BZ2Decompres from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer from collections.abc import Iterable from io import TextIOWrapper -from typing import IO, Literal, Protocol, SupportsIndex, overload +from typing import IO, Literal, Protocol, SupportsIndex, overload, type_check_only from typing_extensions import Self, TypeAlias if sys.version_info >= (3, 14): @@ -22,8 +22,10 @@ __all__ = ["BZ2File", "BZ2Compressor", "BZ2Decompressor", "open", "compress", "d # The following attributes and methods are optional: # def fileno(self) -> int: ... # def close(self) -> object: ... +@type_check_only class _ReadableFileobj(_Reader, Protocol): ... +@type_check_only class _WritableFileobj(Protocol): def write(self, b: bytes, /) -> object: ... # The following attributes and methods are optional: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi index eb90d7c5f19b6..e6ae5d53ac326 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi @@ -12,7 +12,7 @@ from _codecs import * from _typeshed import ReadableBuffer from abc import abstractmethod from collections.abc import Callable, Generator, Iterable -from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO, overload +from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO, overload, type_check_only from typing_extensions import Self, TypeAlias __all__ = [ @@ -82,16 +82,19 @@ _BufferedEncoding: TypeAlias = Literal[ "utf-8-sig", ] +@type_check_only class _WritableStream(Protocol): def write(self, data: bytes, /) -> object: ... def seek(self, offset: int, whence: int, /) -> object: ... def close(self) -> object: ... +@type_check_only class _ReadableStream(Protocol): def read(self, size: int = ..., /) -> bytes: ... def seek(self, offset: int, whence: int, /) -> object: ... def close(self) -> object: ... +@type_check_only class _Stream(_WritableStream, _ReadableStream, Protocol): ... # TODO: this only satisfies the most common interface, where @@ -100,24 +103,31 @@ class _Stream(_WritableStream, _ReadableStream, Protocol): ... # There *are* bytes->bytes and str->str encodings in the standard library. # They were much more common in Python 2 than in Python 3. +@type_check_only class _Encoder(Protocol): def __call__(self, input: str, errors: str = ..., /) -> tuple[bytes, int]: ... # signature of Codec().encode +@type_check_only class _Decoder(Protocol): def __call__(self, input: ReadableBuffer, errors: str = ..., /) -> tuple[str, int]: ... # signature of Codec().decode +@type_check_only class _StreamReader(Protocol): def __call__(self, stream: _ReadableStream, errors: str = ..., /) -> StreamReader: ... +@type_check_only class _StreamWriter(Protocol): def __call__(self, stream: _WritableStream, errors: str = ..., /) -> StreamWriter: ... +@type_check_only class _IncrementalEncoder(Protocol): def __call__(self, errors: str = ...) -> IncrementalEncoder: ... +@type_check_only class _IncrementalDecoder(Protocol): def __call__(self, errors: str = ...) -> IncrementalDecoder: ... +@type_check_only class _BufferedIncrementalDecoder(Protocol): def __call__(self, errors: str = ...) -> BufferedIncrementalDecoder: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi index 6e35e647709b7..c6b3b2a15c699 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi @@ -18,7 +18,7 @@ import sys from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from types import GenericAlias -from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload +from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload, type_check_only from typing_extensions import Self if sys.version_info >= (3, 10): @@ -631,14 +631,17 @@ class _OrderedDictValuesView(ValuesView[_VT_co]): # but they are not exposed anywhere) # pyright doesn't have a specific error code for subclassing error! @final +@type_check_only class _odict_keys(dict_keys[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] def __reversed__(self) -> Iterator[_KT_co]: ... @final +@type_check_only class _odict_items(dict_items[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] def __reversed__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ... @final +@type_check_only class _odict_values(dict_values[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] def __reversed__(self) -> Iterator[_VT_co]: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi index 15c15f414011e..40a0525266eee 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi @@ -4,7 +4,7 @@ from _typeshed import Unused from collections.abc import Callable, Iterable, Iterator from logging import Logger from types import GenericAlias, TracebackType -from typing import Any, Final, Generic, NamedTuple, Protocol, TypeVar +from typing import Any, Final, Generic, NamedTuple, Protocol, TypeVar, type_check_only from typing_extensions import ParamSpec, Self FIRST_COMPLETED: Final = "FIRST_COMPLETED" @@ -249,6 +249,7 @@ class Executor: self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None ) -> bool | None: ... +@type_check_only class _AsCompletedFuture(Protocol[_T_co]): # as_completed only mutates non-generic aspects of passed Futures and does not do any nominal # checks. Therefore, we can use a Protocol here to allow as_completed to act covariantly. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/interpreter.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/interpreter.pyi index 636147c979000..20ff4dd679c37 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/interpreter.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/interpreter.pyi @@ -1,12 +1,15 @@ """Implements InterpreterPoolExecutor.""" import sys -from collections.abc import Callable, Mapping +from collections.abc import Callable from concurrent.futures import ThreadPoolExecutor -from typing import Literal, Protocol, overload, type_check_only +from typing import Any, Literal, Protocol, overload, type_check_only from typing_extensions import ParamSpec, Self, TypeAlias, TypeVar, TypeVarTuple, Unpack _Task: TypeAlias = tuple[bytes, Literal["function", "script"]] +_Ts = TypeVarTuple("_Ts") +_P = ParamSpec("_P") +_R = TypeVar("_R") @type_check_only class _TaskFunc(Protocol): @@ -15,47 +18,26 @@ class _TaskFunc(Protocol): @overload def __call__(self, fn: str) -> tuple[bytes, Literal["script"]]: ... -_Ts = TypeVarTuple("_Ts") -_P = ParamSpec("_P") -_R = TypeVar("_R") - -# A `type.simplenamespace` with `__name__` attribute. -@type_check_only -class _HasName(Protocol): - __name__: str - -# `_interpreters.exec` technically gives us a simple namespace. -@type_check_only -class _ExcInfo(Protocol): - formatted: str - msg: str - type: _HasName - if sys.version_info >= (3, 14): from concurrent.futures.thread import BrokenThreadPool, WorkerContext as ThreadWorkerContext + from concurrent.interpreters import Interpreter, Queue - from _interpreters import InterpreterError - - class ExecutionFailed(InterpreterError): - def __init__(self, excinfo: _ExcInfo) -> None: ... # type: ignore[override] + def do_call(results: Queue, func: Callable[..., _R], args: tuple[Any, ...], kwargs: dict[str, Any]) -> _R: ... class WorkerContext(ThreadWorkerContext): - # Parent class doesn't have `shared` argument, - @overload # type: ignore[override] + interp: Interpreter | None + results: Queue | None + @overload # type: ignore[override] @classmethod def prepare( - cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]], shared: Mapping[str, object] + cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]] ) -> tuple[Callable[[], Self], _TaskFunc]: ... - @overload # type: ignore[override] + @overload @classmethod - def prepare( - cls, initializer: Callable[[], object], initargs: tuple[()], shared: Mapping[str, object] - ) -> tuple[Callable[[], Self], _TaskFunc]: ... - def __init__( - self, initdata: tuple[bytes, Literal["function", "script"]], shared: Mapping[str, object] | None = None - ) -> None: ... # type: ignore[override] + def prepare(cls, initializer: Callable[[], object], initargs: tuple[()]) -> tuple[Callable[[], Self], _TaskFunc]: ... + def __init__(self, initdata: _Task) -> None: ... def __del__(self) -> None: ... - def run(self, task: _Task) -> None: ... # type: ignore[override] + def run(self, task: _Task) -> None: ... # type: ignore[override] class BrokenInterpreterPool(BrokenThreadPool): """ @@ -65,15 +47,15 @@ if sys.version_info >= (3, 14): class InterpreterPoolExecutor(ThreadPoolExecutor): BROKEN: type[BrokenInterpreterPool] - @overload # type: ignore[override] + @overload # type: ignore[override] @classmethod def prepare_context( - cls, initializer: Callable[[], object], initargs: tuple[()], shared: Mapping[str, object] + cls, initializer: Callable[[], object], initargs: tuple[()] ) -> tuple[Callable[[], WorkerContext], _TaskFunc]: ... - @overload # type: ignore[override] + @overload @classmethod def prepare_context( - cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]], shared: Mapping[str, object] + cls, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]] ) -> tuple[Callable[[], WorkerContext], _TaskFunc]: ... @overload def __init__( @@ -82,7 +64,6 @@ if sys.version_info >= (3, 14): thread_name_prefix: str = "", initializer: Callable[[], object] | None = None, initargs: tuple[()] = (), - shared: Mapping[str, object] | None = None, ) -> None: """Initializes a new InterpreterPoolExecutor instance. @@ -103,7 +84,6 @@ if sys.version_info >= (3, 14): *, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]], - shared: Mapping[str, object] | None = None, ) -> None: ... @overload def __init__( @@ -112,5 +92,4 @@ if sys.version_info >= (3, 14): thread_name_prefix: str, initializer: Callable[[Unpack[_Ts]], object], initargs: tuple[Unpack[_Ts]], - shared: Mapping[str, object] | None = None, ) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi index 7df1e3d361b89..979c97359ecad 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi @@ -147,8 +147,8 @@ import sys from _typeshed import MaybeNone, StrOrBytesPath, SupportsWrite from collections.abc import Callable, ItemsView, Iterable, Iterator, Mapping, MutableMapping, Sequence from re import Pattern -from typing import Any, ClassVar, Final, Literal, TypeVar, overload -from typing_extensions import TypeAlias +from typing import Any, ClassVar, Final, Literal, TypeVar, overload, type_check_only +from typing_extensions import TypeAlias, deprecated if sys.version_info >= (3, 14): __all__ = ( @@ -249,7 +249,9 @@ else: ] if sys.version_info >= (3, 13): + @type_check_only class _UNNAMED_SECTION: ... + UNNAMED_SECTION: _UNNAMED_SECTION _SectionName: TypeAlias = str | _UNNAMED_SECTION @@ -300,6 +302,9 @@ class ExtendedInterpolation(Interpolation): """ if sys.version_info < (3, 13): + @deprecated( + "Deprecated since Python 3.2; removed in Python 3.13. Use `BasicInterpolation` or `ExtendedInterpolation` instead." + ) class LegacyInterpolation(Interpolation): """Deprecated interpolation used in old versions of ConfigParser. Use BasicInterpolation or ExtendedInterpolation instead. @@ -494,6 +499,7 @@ class RawConfigParser(_Parser): dictionary being read. """ if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `parser.read_file()` instead.") def readfp(self, fp: Iterable[str], filename: str | None = None) -> None: """Deprecated, use read_file instead.""" # These get* methods are partially applied (with the same names) in @@ -613,7 +619,8 @@ class ConfigParser(RawConfigParser): ) -> str | _T: ... if sys.version_info < (3, 12): - class SafeConfigParser(ConfigParser): # deprecated alias + @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `ConfigParser` instead.") + class SafeConfigParser(ConfigParser): """ConfigParser alias for backwards compatibility purposes.""" class SectionProxy(MutableMapping[str, str]): @@ -776,10 +783,24 @@ class ParsingError(Error): elif sys.version_info >= (3, 12): def __init__(self, source: str) -> None: ... else: - def __init__(self, source: str | None = None, filename: str | None = None) -> None: ... + @overload + def __init__(self, source: str, filename: None = None) -> None: ... + @overload + @deprecated("The `filename` parameter removed in Python 3.12. Use `source` instead.") + def __init__(self, source: None = None, filename: str = ...) -> None: ... def append(self, lineno: int, line: str) -> None: ... + if sys.version_info < (3, 12): + @property + @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `source` instead.") + def filename(self) -> str: + """Deprecated, use `source'.""" + + @filename.setter + @deprecated("Deprecated since Python 3.2; removed in Python 3.12. Use `source` instead.") + def filename(self, value: str) -> None: ... + class MissingSectionHeaderError(ParsingError): """Raised when a key-value pair is found before any section header.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi index 6a749a73a8c4e..3728c9d6d1bef 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi @@ -243,6 +243,7 @@ else: ) -> Callable[[type[_T]], type[_T]]: ... # See https://github.com/python/mypy/issues/10750 +@type_check_only class _DefaultFactory(Protocol[_T_co]): def __call__(self) -> _T_co: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/dbm/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/dbm/__init__.pyi index 698c231519e01..3c41015fcd043 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/dbm/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/dbm/__init__.pyi @@ -105,6 +105,7 @@ _TFlags: TypeAlias = Literal[ "nusf", ] +@type_check_only class _Database(MutableMapping[_KeyType, bytes]): def close(self) -> None: ... def __getitem__(self, key: _KeyType) -> bytes: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/email/headerregistry.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/email/headerregistry.pyi index 2b1e0d615fbe2..801bf612dba00 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/email/headerregistry.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/email/headerregistry.pyi @@ -19,7 +19,7 @@ from email._header_value_parser import ( ) from email.errors import MessageDefect from email.policy import Policy -from typing import Any, ClassVar, Literal, Protocol +from typing import Any, ClassVar, Literal, Protocol, type_check_only from typing_extensions import Self class BaseHeader(str): @@ -248,6 +248,7 @@ class MessageIDHeader: def value_parser(value: str) -> MessageID: """message-id = "Message-ID:" msg-id CRLF""" +@type_check_only class _HeaderParser(Protocol): max_count: ClassVar[Literal[1] | None] @staticmethod diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/email/message.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/email/message.pyi index a67f17fd64541..308c21ad163c9 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/email/message.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/email/message.pyi @@ -7,7 +7,7 @@ from email.charset import Charset from email.contentmanager import ContentManager from email.errors import MessageDefect from email.policy import Policy -from typing import Any, Generic, Literal, Protocol, TypeVar, overload +from typing import Any, Generic, Literal, Protocol, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias __all__ = ["Message", "EmailMessage"] @@ -26,9 +26,11 @@ _EncodedPayloadType: TypeAlias = Message | bytes _MultipartPayloadType: TypeAlias = list[_PayloadType] _CharsetType: TypeAlias = Charset | str | None +@type_check_only class _SupportsEncodeToPayload(Protocol): def encode(self, encoding: str, /) -> _PayloadType | _MultipartPayloadType | _SupportsDecodeToPayload: ... +@type_check_only class _SupportsDecodeToPayload(Protocol): def decode(self, encoding: str, errors: str, /) -> _PayloadType | _MultipartPayloadType: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/encodings/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/encodings/__init__.pyi index c45ae99601796..7d26d92022bf7 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/encodings/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/encodings/__init__.pyi @@ -28,6 +28,7 @@ Written by Marc-Andre Lemburg (mal@lemburg.com). """ +import sys from codecs import CodecInfo class CodecRegistryError(LookupError, SystemError): ... @@ -46,5 +47,8 @@ def normalize_encoding(encoding: str | bytes) -> str: def search_function(encoding: str) -> CodecInfo | None: ... +if sys.version_info >= (3, 14) and sys.platform == "win32": + def win32_code_page_search_function(encoding: str) -> CodecInfo | None: ... + # Needed for submodules def __getattr__(name: str): ... # incomplete module diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/fcntl.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/fcntl.pyi index 279f7a99e8d58..561e6585c8975 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/fcntl.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/fcntl.pyi @@ -10,107 +10,107 @@ from typing import Any, Final, Literal, overload from typing_extensions import Buffer if sys.platform != "win32": - FASYNC: int - FD_CLOEXEC: int - F_DUPFD: int - F_DUPFD_CLOEXEC: int - F_GETFD: int - F_GETFL: int - F_GETLK: int - F_GETOWN: int - F_RDLCK: int - F_SETFD: int - F_SETFL: int - F_SETLK: int - F_SETLKW: int - F_SETOWN: int - F_UNLCK: int - F_WRLCK: int - - F_GETLEASE: int - F_SETLEASE: int + FASYNC: Final[int] + FD_CLOEXEC: Final[int] + F_DUPFD: Final[int] + F_DUPFD_CLOEXEC: Final[int] + F_GETFD: Final[int] + F_GETFL: Final[int] + F_GETLK: Final[int] + F_GETOWN: Final[int] + F_RDLCK: Final[int] + F_SETFD: Final[int] + F_SETFL: Final[int] + F_SETLK: Final[int] + F_SETLKW: Final[int] + F_SETOWN: Final[int] + F_UNLCK: Final[int] + F_WRLCK: Final[int] + + F_GETLEASE: Final[int] + F_SETLEASE: Final[int] if sys.platform == "darwin": - F_FULLFSYNC: int - F_NOCACHE: int - F_GETPATH: int + F_FULLFSYNC: Final[int] + F_NOCACHE: Final[int] + F_GETPATH: Final[int] if sys.platform == "linux": - F_SETLKW64: int - F_SETSIG: int - F_SHLCK: int - F_SETLK64: int - F_GETSIG: int - F_NOTIFY: int - F_EXLCK: int - F_GETLK64: int - F_ADD_SEALS: int - F_GET_SEALS: int - F_SEAL_GROW: int - F_SEAL_SEAL: int - F_SEAL_SHRINK: int - F_SEAL_WRITE: int + F_SETLKW64: Final[int] + F_SETSIG: Final[int] + F_SHLCK: Final[int] + F_SETLK64: Final[int] + F_GETSIG: Final[int] + F_NOTIFY: Final[int] + F_EXLCK: Final[int] + F_GETLK64: Final[int] + F_ADD_SEALS: Final[int] + F_GET_SEALS: Final[int] + F_SEAL_GROW: Final[int] + F_SEAL_SEAL: Final[int] + F_SEAL_SHRINK: Final[int] + F_SEAL_WRITE: Final[int] F_OFD_GETLK: Final[int] F_OFD_SETLK: Final[int] F_OFD_SETLKW: Final[int] if sys.version_info >= (3, 10): - F_GETPIPE_SZ: int - F_SETPIPE_SZ: int - - DN_ACCESS: int - DN_ATTRIB: int - DN_CREATE: int - DN_DELETE: int - DN_MODIFY: int - DN_MULTISHOT: int - DN_RENAME: int - - LOCK_EX: int - LOCK_NB: int - LOCK_SH: int - LOCK_UN: int + F_GETPIPE_SZ: Final[int] + F_SETPIPE_SZ: Final[int] + + DN_ACCESS: Final[int] + DN_ATTRIB: Final[int] + DN_CREATE: Final[int] + DN_DELETE: Final[int] + DN_MODIFY: Final[int] + DN_MULTISHOT: Final[int] + DN_RENAME: Final[int] + + LOCK_EX: Final[int] + LOCK_NB: Final[int] + LOCK_SH: Final[int] + LOCK_UN: Final[int] if sys.platform == "linux": - LOCK_MAND: int - LOCK_READ: int - LOCK_RW: int - LOCK_WRITE: int + LOCK_MAND: Final[int] + LOCK_READ: Final[int] + LOCK_RW: Final[int] + LOCK_WRITE: Final[int] if sys.platform == "linux": # Constants for the POSIX STREAMS interface. Present in glibc until 2.29 (released February 2019). # Never implemented on BSD, and considered "obsolescent" starting in POSIX 2008. # Probably still used on Solaris. - I_ATMARK: int - I_CANPUT: int - I_CKBAND: int - I_FDINSERT: int - I_FIND: int - I_FLUSH: int - I_FLUSHBAND: int - I_GETBAND: int - I_GETCLTIME: int - I_GETSIG: int - I_GRDOPT: int - I_GWROPT: int - I_LINK: int - I_LIST: int - I_LOOK: int - I_NREAD: int - I_PEEK: int - I_PLINK: int - I_POP: int - I_PUNLINK: int - I_PUSH: int - I_RECVFD: int - I_SENDFD: int - I_SETCLTIME: int - I_SETSIG: int - I_SRDOPT: int - I_STR: int - I_SWROPT: int - I_UNLINK: int + I_ATMARK: Final[int] + I_CANPUT: Final[int] + I_CKBAND: Final[int] + I_FDINSERT: Final[int] + I_FIND: Final[int] + I_FLUSH: Final[int] + I_FLUSHBAND: Final[int] + I_GETBAND: Final[int] + I_GETCLTIME: Final[int] + I_GETSIG: Final[int] + I_GRDOPT: Final[int] + I_GWROPT: Final[int] + I_LINK: Final[int] + I_LIST: Final[int] + I_LOOK: Final[int] + I_NREAD: Final[int] + I_PEEK: Final[int] + I_PLINK: Final[int] + I_POP: Final[int] + I_PUNLINK: Final[int] + I_PUSH: Final[int] + I_RECVFD: Final[int] + I_SENDFD: Final[int] + I_SETCLTIME: Final[int] + I_SETSIG: Final[int] + I_SRDOPT: Final[int] + I_STR: Final[int] + I_SWROPT: Final[int] + I_UNLINK: Final[int] if sys.version_info >= (3, 12) and sys.platform == "linux": - FICLONE: int - FICLONERANGE: int + FICLONE: Final[int] + FICLONERANGE: Final[int] if sys.version_info >= (3, 13) and sys.platform == "linux": F_OWNER_TID: Final = 0 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi index 5f5d58288b816..171c5d6fc3368 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi @@ -5,7 +5,7 @@ import types from _typeshed import SupportsAllComparisons, SupportsItems from collections.abc import Callable, Hashable, Iterable, Sized from types import GenericAlias -from typing import Any, Final, Generic, Literal, NamedTuple, TypedDict, TypeVar, final, overload +from typing import Any, Final, Generic, Literal, NamedTuple, TypedDict, TypeVar, final, overload, type_check_only from typing_extensions import ParamSpec, Self, TypeAlias __all__ = [ @@ -81,6 +81,7 @@ class _CacheInfo(NamedTuple): maxsize: int | None currsize: int +@type_check_only class _CacheParameters(TypedDict): maxsize: int typed: bool @@ -170,6 +171,7 @@ else: WRAPPER_UPDATES: tuple[Literal["__dict__"]] +@type_check_only class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): __wrapped__: Callable[_PWrapped, _RWrapped] def __call__(self, *args: _PWrapper.args, **kwargs: _PWrapper.kwargs) -> _RWrapper: ... @@ -177,6 +179,7 @@ class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): __name__: str __qualname__: str +@type_check_only class _Wrapper(Generic[_PWrapped, _RWrapped]): def __call__(self, f: Callable[_PWrapper, _RWrapper]) -> _Wrapped[_PWrapped, _RWrapped, _PWrapper, _RWrapper]: ... @@ -345,6 +348,7 @@ if sys.version_info >= (3, 11): else: _RegType: TypeAlias = type[Any] +@type_check_only class _SingleDispatchCallable(Generic[_T]): registry: types.MappingProxyType[Any, Callable[..., _T]] def dispatch(self, cls: Any) -> Callable[..., _T]: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi index e103513790211..c5db318457879 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi @@ -15,6 +15,7 @@ import sys from _typeshed import StrPath from collections.abc import Callable, Container, Iterable, Sequence from typing import Any, Final, Literal, Protocol, TypeVar, overload, type_check_only +from typing_extensions import deprecated __all__ = [ "NullTranslations", @@ -55,9 +56,13 @@ class NullTranslations: def info(self) -> dict[str, str]: ... def charset(self) -> str | None: ... if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.8; removed in Python 3.11.") def output_charset(self) -> str | None: ... + @deprecated("Deprecated since Python 3.8; removed in Python 3.11.") def set_output_charset(self, charset: str) -> None: ... + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `gettext()` instead.") def lgettext(self, message: str) -> str: ... + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `ngettext()` instead.") def lngettext(self, msgid1: str, msgid2: str, n: int) -> str: ... def install(self, names: Container[str] | None = None) -> None: ... @@ -157,9 +162,16 @@ else: fallback: bool = False, codeset: str | None = None, ) -> NullTranslations: ... + @overload def install( - domain: str, localedir: StrPath | None = None, codeset: str | None = None, names: Container[str] | None = None + domain: str, localedir: StrPath | None = None, codeset: None = None, names: Container[str] | None = None ) -> None: ... + @overload + @deprecated("The `codeset` parameter is deprecated since Python 3.8; removed in Python 3.11.") + def install(domain: str, localedir: StrPath | None, codeset: str, /, names: Container[str] | None = None) -> None: ... + @overload + @deprecated("The `codeset` parameter is deprecated since Python 3.8; removed in Python 3.11.") + def install(domain: str, localedir: StrPath | None = None, *, codeset: str, names: Container[str] | None = None) -> None: ... def textdomain(domain: str | None = None) -> str: ... def bindtextdomain(domain: str, localedir: StrPath | None = None) -> str: ... @@ -173,10 +185,15 @@ def npgettext(context: str, msgid1: str, msgid2: str, n: int) -> str: ... def dnpgettext(domain: str, context: str, msgid1: str, msgid2: str, n: int) -> str: ... if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `gettext()` instead.") def lgettext(message: str) -> str: ... + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `dgettext()` instead.") def ldgettext(domain: str, message: str) -> str: ... + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `ngettext()` instead.") def lngettext(msgid1: str, msgid2: str, n: int) -> str: ... + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `dngettext()` instead.") def ldngettext(domain: str, msgid1: str, msgid2: str, n: int) -> str: ... + @deprecated("Deprecated since Python 3.8; removed in Python 3.11. Use `bindtextdomain()` instead.") def bind_textdomain_codeset(domain: str, codeset: str | None = None) -> str: ... Catalog = translation diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi index a1ca7a6de6338..d9863ba3b284f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi @@ -4,14 +4,22 @@ import sys from _typeshed import StrOrBytesPath from collections.abc import Iterator, Sequence from typing import AnyStr +from typing_extensions import deprecated __all__ = ["escape", "glob", "iglob"] if sys.version_info >= (3, 13): __all__ += ["translate"] -def glob0(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... -def glob1(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... +if sys.version_info >= (3, 10): + @deprecated("Will be removed in Python 3.15; Use `glob.glob` and pass *root_dir* argument instead.") + def glob0(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... + @deprecated("Will be removed in Python 3.15; Use `glob.glob` and pass *root_dir* argument instead.") + def glob1(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... + +else: + def glob0(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... + def glob1(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... if sys.version_info >= (3, 11): def glob( diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/gzip.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/gzip.pyi index 90bdf80f8926b..ac3fe1a3c0908 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/gzip.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/gzip.pyi @@ -9,7 +9,7 @@ import zlib from _typeshed import ReadableBuffer, SizedBuffer, StrOrBytesPath, WriteableBuffer from io import FileIO, TextIOWrapper from typing import Final, Literal, Protocol, overload, type_check_only -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, deprecated if sys.version_info >= (3, 14): from compression._common._streams import BaseStream, DecompressReader @@ -216,6 +216,7 @@ class GzipFile(BaseStream): ) -> None: ... if sys.version_info < (3, 12): @property + @deprecated("Deprecated since Python 2.6; removed in Python 3.12. Use `name` attribute instead.") def filename(self) -> str: ... @property diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/hashlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/hashlib.pyi index 9f68beea56ac0..faeafece16a43 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/hashlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/hashlib.pyi @@ -71,7 +71,7 @@ from _hashlib import ( ) from _typeshed import ReadableBuffer from collections.abc import Callable, Set as AbstractSet -from typing import Protocol +from typing import Protocol, type_check_only if sys.version_info >= (3, 11): __all__ = ( @@ -126,9 +126,11 @@ algorithms_guaranteed: AbstractSet[str] algorithms_available: AbstractSet[str] if sys.version_info >= (3, 11): + @type_check_only class _BytesIOLike(Protocol): def getbuffer(self) -> ReadableBuffer: ... + @type_check_only class _FileDigestFileObj(Protocol): def readinto(self, buf: bytearray, /) -> int: ... def readable(self) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/html/parser.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/html/parser.pyi index 45805ddf1f3b5..cc71c2cb41f4c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/html/parser.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/html/parser.pyi @@ -30,7 +30,8 @@ class HTMLParser(ParserBase): """ CDATA_CONTENT_ELEMENTS: Final[tuple[str, ...]] - if sys.version_info >= (3, 14): + if sys.version_info >= (3, 13): + # Added in 3.13.6 RCDATA_CONTENT_ELEMENTS: Final[tuple[str, ...]] def __init__(self, *, convert_charrefs: bool = True) -> None: @@ -70,7 +71,8 @@ class HTMLParser(ParserBase): def parse_html_declaration(self, i: int) -> int: ... # undocumented def parse_pi(self, i: int) -> int: ... # undocumented def parse_starttag(self, i: int) -> int: ... # undocumented - if sys.version_info >= (3, 14): + if sys.version_info >= (3, 13): + # `escapable` parameter added in 3.13.6 def set_cdata_mode(self, elem: str, *, escapable: bool = False) -> None: ... # undocumented else: def set_cdata_mode(self, elem: str) -> None: ... # undocumented diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi index 64fe67d765e52..0131b6ae8af65 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi @@ -21,7 +21,7 @@ from _imp import ( from _typeshed import StrPath from os import PathLike from types import TracebackType -from typing import IO, Any, Protocol +from typing import IO, Any, Protocol, type_check_only SEARCH_ERROR: int PY_SOURCE: int @@ -95,6 +95,7 @@ class NullImporter: # Technically, a text file has to support a slightly different set of operations than a binary file, # but we ignore that here. +@type_check_only class _FileLike(Protocol): closed: bool mode: str diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/__init__.pyi index abd6e4348f305..11d7bf3c480fc 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/__init__.pyi @@ -4,6 +4,7 @@ import sys from importlib._bootstrap import __import__ as __import__ from importlib.abc import Loader from types import ModuleType +from typing_extensions import deprecated __all__ = ["__import__", "import_module", "invalidate_caches", "reload"] @@ -18,6 +19,7 @@ def import_module(name: str, package: str | None = None) -> ModuleType: """ if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `importlib.util.find_spec()` instead.") def find_loader(name: str, path: str | None = None) -> Loader | None: """Return the loader for the specified module. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/_abc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/_abc.pyi index a6c01e6b90b11..c85e8004cd37c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/_abc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/_abc.pyi @@ -4,6 +4,7 @@ import sys import types from abc import ABCMeta from importlib.machinery import ModuleSpec +from typing_extensions import deprecated if sys.version_info >= (3, 10): class Loader(metaclass=ABCMeta): @@ -23,6 +24,10 @@ if sys.version_info >= (3, 10): """ if sys.version_info < (3, 12): + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "The module spec is now used by the import machinery to generate a module repr." + ) def module_repr(self, module: types.ModuleType) -> str: """Return a module's repr. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi index 14f15176135ad..5dfe7c7272c05 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi @@ -69,6 +69,7 @@ else: def exec_module(self, module: types.ModuleType) -> None: ... if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.3; removed in Python 3.12. Use `MetaPathFinder` or `PathEntryFinder` instead.") class Finder(metaclass=ABCMeta): """Legacy abstract base class for import finders. @@ -83,10 +84,13 @@ if sys.version_info < (3, 12): @deprecated("Deprecated as of Python 3.7: Use importlib.resources.abc.TraversableResources instead.") class ResourceLoader(Loader): """Abstract base class for loaders which can return data from their - back-end storage. + back-end storage to facilitate reading data to perform an import. This ABC represents one of the optional protocols specified by PEP 302. + For directly loading resources, use TraversableResources instead. This class + primarily exists for backwards compatibility with other ABCs in this module. + """ @abstractmethod @@ -204,6 +208,7 @@ if sys.version_info >= (3, 10): """Abstract base class for import finders on sys.meta_path.""" if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `MetaPathFinder.find_spec()` instead.") def find_module(self, fullname: str, path: Sequence[str] | None) -> Loader | None: """Return a loader for the module. @@ -229,6 +234,7 @@ if sys.version_info >= (3, 10): """Abstract base class for path entry finders used by PathFinder.""" if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `PathEntryFinder.find_spec()` instead.") def find_module(self, fullname: str) -> Loader | None: """Try to find a loader for the specified module by delegating to self.find_loader(). @@ -237,6 +243,7 @@ if sys.version_info >= (3, 10): """ + @deprecated("Deprecated since Python 3.4; removed in Python 3.12. Use `find_spec()` instead.") def find_loader(self, fullname: str) -> tuple[Loader | None, Sequence[str]]: """Return (loader, namespace portion) for the path entry. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi index 2c6f68cd49ce7..478aa35139f61 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi @@ -11,7 +11,7 @@ from os import PathLike from pathlib import Path from re import Pattern from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, deprecated _T = TypeVar("_T") _KT = TypeVar("_KT") @@ -153,8 +153,8 @@ class EntryPoint(_EntryPointBase): """ def __hash__(self) -> int: ... - def __eq__(self, other: object) -> bool: ... if sys.version_info >= (3, 11): + def __eq__(self, other: object) -> bool: ... def __lt__(self, other: object) -> bool: ... if sys.version_info < (3, 12): def __iter__(self) -> Iterator[Any]: # result of iter((str, Self)), really @@ -311,6 +311,7 @@ if sys.version_info >= (3, 10) and sys.version_info < (3, 12): def keys(self) -> dict_keys[_KT, _VT]: ... def values(self) -> dict_values[_KT, _VT]: ... + @deprecated("Deprecated since Python 3.10; removed in Python 3.12. Use `select` instead.") class SelectableGroups(Deprecated[str, EntryPoints], dict[str, EntryPoints]): # use as dict is deprecated since 3.10 """ A backward- and forward-compatible result from diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/util.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/util.pyi index 3b4f835210454..73acc3a83a030 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/util.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/util.pyi @@ -14,11 +14,15 @@ from importlib._bootstrap_external import ( spec_from_file_location as spec_from_file_location, ) from importlib.abc import Loader -from typing_extensions import ParamSpec +from typing_extensions import ParamSpec, deprecated _P = ParamSpec("_P") if sys.version_info < (3, 12): + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "`__name__`, `__package__` and `__loader__` are now set automatically." + ) def module_for_loader(fxn: Callable[_P, types.ModuleType]) -> Callable[_P, types.ModuleType]: """Decorator to handle selecting the proper module for loaders. @@ -38,6 +42,10 @@ if sys.version_info < (3, 12): """ + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "`__name__`, `__package__` and `__loader__` are now set automatically." + ) def set_loader(fxn: Callable[_P, types.ModuleType]) -> Callable[_P, types.ModuleType]: """Set __loader__ on the returned module. @@ -45,6 +53,10 @@ if sys.version_info < (3, 12): """ + @deprecated( + "Deprecated since Python 3.4; removed in Python 3.12. " + "`__name__`, `__package__` and `__loader__` are now set automatically." + ) def set_package(fxn: Callable[_P, types.ModuleType]) -> Callable[_P, types.ModuleType]: """Set __package__ on the returned module. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi index 508470d1bdd6a..bfa55f2f72642 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi @@ -54,7 +54,7 @@ from types import ( WrapperDescriptorType, ) from typing import Any, ClassVar, Final, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only -from typing_extensions import ParamSpec, Self, TypeAlias, TypeGuard, TypeIs +from typing_extensions import ParamSpec, Self, TypeAlias, TypeGuard, TypeIs, deprecated if sys.version_info >= (3, 14): from annotationlib import Format @@ -948,6 +948,7 @@ def getargs(co: CodeType) -> Arguments: """ if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.0; removed in Python 3.11.") class ArgSpec(NamedTuple): """ArgSpec(args, varargs, keywords, defaults)""" @@ -956,6 +957,7 @@ if sys.version_info < (3, 11): keywords: str | None defaults: tuple[Any, ...] + @deprecated("Deprecated since Python 3.0; removed in Python 3.11. Use `inspect.signature()` instead.") def getargspec(func: object) -> ArgSpec: """Get the names and default values of a function's parameters. @@ -1031,6 +1033,9 @@ else: def formatannotationrelativeto(object: object) -> Callable[[object], str]: ... if sys.version_info < (3, 11): + @deprecated( + "Deprecated since Python 3.5; removed in Python 3.11. Use `inspect.signature()` and the `Signature` class instead." + ) def formatargspec( args: list[str], varargs: str | None = None, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/locale.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/locale.pyi index c121dabe86963..ed836048f435e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/locale.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/locale.pyi @@ -30,6 +30,7 @@ from builtins import str as _str from collections.abc import Callable, Iterable from decimal import Decimal from typing import Any +from typing_extensions import deprecated if sys.version_info >= (3, 11): from _locale import getencoding as getencoding @@ -210,15 +211,26 @@ def normalize(localename: _str) -> _str: """ if sys.version_info < (3, 13): - def resetlocale(category: int = ...) -> None: - """Sets the locale for category to the default setting. + if sys.version_info >= (3, 11): + @deprecated("Deprecated since Python 3.11; removed in Python 3.13. Use `locale.setlocale(locale.LC_ALL, '')` instead.") + def resetlocale(category: int = ...) -> None: + """Sets the locale for category to the default setting. - The default setting is determined by calling - getdefaultlocale(). category defaults to LC_ALL. + The default setting is determined by calling + getdefaultlocale(). category defaults to LC_ALL. - """ + """ + else: + def resetlocale(category: int = ...) -> None: + """Sets the locale for category to the default setting. + + The default setting is determined by calling + getdefaultlocale(). category defaults to LC_ALL. + + """ if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.7; removed in Python 3.12. Use `locale.format_string()` instead.") def format(percent: _str, value: float | Decimal, grouping: bool = False, monetary: bool = False, *additional: Any) -> _str: """Deprecated, use format_string instead.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi index 2edd351345ba2..0c47d8bd6540e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi @@ -16,7 +16,7 @@ from re import Pattern from string import Template from time import struct_time from types import FrameType, GenericAlias, TracebackType -from typing import Any, ClassVar, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload +from typing import Any, ClassVar, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias, deprecated __all__ = [ @@ -76,11 +76,13 @@ _Level: TypeAlias = int | str _FormatStyle: TypeAlias = Literal["%", "{", "$"] if sys.version_info >= (3, 12): + @type_check_only class _SupportsFilter(Protocol): def filter(self, record: LogRecord, /) -> bool | LogRecord: ... _FilterType: TypeAlias = Filter | Callable[[LogRecord], bool | LogRecord] | _SupportsFilter else: + @type_check_only class _SupportsFilter(Protocol): def filter(self, record: LogRecord, /) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi index ce2ef4bfa6fe7..26d811b3ce8b6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi @@ -18,7 +18,7 @@ from re import Pattern from socket import SocketKind, socket from threading import Thread from types import TracebackType -from typing import Any, ClassVar, Final, Protocol, TypeVar +from typing import Any, ClassVar, Final, Protocol, TypeVar, type_check_only from typing_extensions import Self _T = TypeVar("_T") @@ -594,6 +594,7 @@ class HTTPHandler(Handler): there is a proxy. """ +@type_check_only class _QueueLike(Protocol[_T]): def get(self) -> _T: ... def put_nowait(self, item: _T, /) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/mailbox.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/mailbox.pyi index ef31fcf83da65..01570c1c2ed67 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/mailbox.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/mailbox.pyi @@ -8,7 +8,7 @@ from abc import ABCMeta, abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from email._policybase import _MessageT from types import GenericAlias, TracebackType -from typing import IO, Any, AnyStr, Generic, Literal, Protocol, TypeVar, overload +from typing import IO, Any, AnyStr, Generic, Literal, Protocol, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias __all__ = [ @@ -33,13 +33,16 @@ __all__ = [ _T = TypeVar("_T") +@type_check_only class _SupportsReadAndReadline(SupportsRead[bytes], SupportsNoArgReadline[bytes], Protocol): ... _MessageData: TypeAlias = email.message.Message | bytes | str | io.StringIO | _SupportsReadAndReadline +@type_check_only class _HasIteritems(Protocol): def iteritems(self) -> Iterator[tuple[str, _MessageData]]: ... +@type_check_only class _HasItems(Protocol): def items(self) -> Iterator[tuple[str, _MessageData]]: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/heap.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/heap.pyi index dc1da4d251501..894d2dfc622b3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/heap.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/heap.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Incomplete from collections.abc import Callable from mmap import mmap -from typing import Protocol +from typing import Protocol, type_check_only from typing_extensions import TypeAlias __all__ = ["BufferWrapper"] @@ -24,6 +24,7 @@ class Arena: _Block: TypeAlias = tuple[Arena, int, int] if sys.platform != "win32": + @type_check_only class _SupportsDetach(Protocol): def detach(self) -> int: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/sharedctypes.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/sharedctypes.pyi index 9ebd2de2f9368..7349cb2711eb6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/sharedctypes.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/sharedctypes.pyi @@ -5,7 +5,7 @@ from ctypes import _SimpleCData, c_char from multiprocessing.context import BaseContext from multiprocessing.synchronize import _LockLike from types import TracebackType -from typing import Any, Generic, Literal, Protocol, TypeVar, overload +from typing import Any, Generic, Literal, Protocol, TypeVar, overload, type_check_only __all__ = ["RawValue", "RawArray", "Value", "Array", "copy", "synchronized"] @@ -97,7 +97,7 @@ def synchronized( ) -> SynchronizedArray[_T]: ... @overload def synchronized(obj: _CT, lock: _LockLike | None = None, ctx: Any | None = None) -> SynchronizedBase[_CT]: ... - +@type_check_only class _AcquireFunc(Protocol): def __call__(self, block: bool = ..., timeout: float | None = ..., /) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/nt.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/nt.pyi index 8d2eee0183486..c10b791bd4683 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/nt.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/nt.pyi @@ -116,4 +116,7 @@ if sys.platform == "win32": if sys.version_info >= (3, 13): from os import fchmod as fchmod, lchmod as lchmod + if sys.version_info >= (3, 14): + from os import readinto as readinto + environ: dict[str, str] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi index 3b68484ed731a..9565050b2bdbb 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi @@ -13,7 +13,7 @@ TODO: Fill out more detailed documentation on the operators. # nor `float` as a subtype of `numbers.Real`, etc.) from abc import ABCMeta, abstractmethod -from typing import ClassVar, Literal, Protocol, overload +from typing import ClassVar, Literal, Protocol, overload, type_check_only __all__ = ["Number", "Complex", "Real", "Rational", "Integral"] @@ -27,6 +27,7 @@ __all__ = ["Number", "Complex", "Real", "Rational", "Integral"] # NOTE: We can't include `__complex__` here, # as we want `int` to be seen as a subtype of `_ComplexLike`, # and `int.__complex__` does not exist :( +@type_check_only class _ComplexLike(Protocol): def __neg__(self) -> _ComplexLike: ... def __pos__(self) -> _ComplexLike: ... @@ -34,6 +35,7 @@ class _ComplexLike(Protocol): # _RealLike is a structural-typing approximation # of the `Real` ABC, which is not (and cannot be) a protocol +@type_check_only class _RealLike(_ComplexLike, Protocol): def __trunc__(self) -> _IntegralLike: ... def __floor__(self) -> _IntegralLike: ... @@ -46,6 +48,7 @@ class _RealLike(_ComplexLike, Protocol): # _IntegralLike is a structural-typing approximation # of the `Integral` ABC, which is not (and cannot be) a protocol +@type_check_only class _IntegralLike(_RealLike, Protocol): def __invert__(self) -> _IntegralLike: ... def __int__(self) -> int: ... @@ -289,10 +292,17 @@ class Rational(Real): @property @abstractmethod - def numerator(self) -> _IntegralLike: ... + def numerator(self) -> _IntegralLike: + """The numerator of a rational number in lowest terms.""" + @property @abstractmethod - def denominator(self) -> _IntegralLike: ... + def denominator(self) -> _IntegralLike: + """The denominator of a rational number in lowest terms. + + This denominator should be positive. + """ + def __float__(self) -> float: """float(self) = self.numerator / self.denominator diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi index a5ffaab3484ca..187f60d7974f8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi @@ -62,6 +62,7 @@ from typing import ( final, overload, runtime_checkable, + type_check_only, ) from typing_extensions import Self, TypeAlias, Unpack, deprecated @@ -2000,6 +2001,7 @@ def rmdir(path: StrOrBytesPath, *, dir_fd: int | None = None) -> None: """ @final +@type_check_only class _ScandirIterator(Generic[AnyStr]): def __del__(self) -> None: ... def __iter__(self) -> Self: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi index b55211baf718b..6d9b4eccee3c1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi @@ -136,11 +136,20 @@ class PurePath(PathLike[str]): """True if the path is absolute (has both a root and, if applicable, a drive). """ - - def is_reserved(self) -> bool: - """Return True if the path contains one of the special names reserved - by the system, if any. - """ + if sys.version_info >= (3, 13): + @deprecated( + "Deprecated since Python 3.13; will be removed in Python 3.15. " + "Use `os.path.isreserved()` to detect reserved paths on Windows." + ) + def is_reserved(self) -> bool: + """Return True if the path contains one of the special names reserved + by the system, if any. + """ + else: + def is_reserved(self) -> bool: + """Return True if the path contains one of the special names reserved + by the system, if any. + """ if sys.version_info >= (3, 14): def is_relative_to(self, other: StrPath) -> bool: """Return True if the path is relative to another path or False.""" @@ -417,7 +426,6 @@ class Path(PurePath): Create a new directory at this given path. """ if sys.version_info >= (3, 14): - @property def info(self) -> PathInfo: """ @@ -518,9 +526,20 @@ class Path(PurePath): self, mode: str, buffering: int = -1, encoding: str | None = None, errors: str | None = None, newline: str | None = None ) -> IO[Any]: ... - # These methods do "exist" on Windows on <3.13, but they always raise NotImplementedError. + # These methods do "exist" on Windows, but they always raise NotImplementedError. if sys.platform == "win32": - if sys.version_info < (3, 13): + if sys.version_info >= (3, 13): + # raises UnsupportedOperation: + def owner(self: Never, *, follow_symlinks: bool = True) -> str: # type: ignore[misc] + """ + Return the login name of the file owner. + """ + + def group(self: Never, *, follow_symlinks: bool = True) -> str: # type: ignore[misc] + """ + Return the group name of the file gid. + """ + else: def owner(self: Never) -> str: # type: ignore[misc] """ Return the login name of the file owner. @@ -692,7 +711,7 @@ class Path(PurePath): """ if sys.version_info < (3, 12): if sys.version_info >= (3, 10): - @deprecated("Deprecated as of Python 3.10 and removed in Python 3.12. Use hardlink_to() instead.") + @deprecated("Deprecated since Python 3.10; removed in Python 3.12. Use `hardlink_to()` instead.") def link_to(self, target: StrOrBytesPath) -> None: """ Make the target path a hard link pointing to this path. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pkgutil.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pkgutil.pyi index 3aef575b3b278..955d0862fa4ea 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pkgutil.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pkgutil.pyi @@ -65,6 +65,7 @@ def extend_path(path: _PathT, name: str) -> _PathT: """ if sys.version_info < (3, 12): + @deprecated("Deprecated since Python 3.3; removed in Python 3.12. Use the `importlib` module instead.") class ImpImporter: """PEP 302 Finder that wraps Python's "classic" import algorithm @@ -78,29 +79,47 @@ if sys.version_info < (3, 12): def __init__(self, path: StrOrBytesPath | None = None) -> None: ... + @deprecated("Deprecated since Python 3.3; removed in Python 3.12. Use the `importlib` module instead.") class ImpLoader: """PEP 302 Loader that wraps Python's "classic" import algorithm""" def __init__(self, fullname: str, file: IO[str], filename: StrOrBytesPath, etc: tuple[str, str, int]) -> None: ... if sys.version_info < (3, 14): - @deprecated("Use importlib.util.find_spec() instead. Will be removed in Python 3.14.") - def find_loader(fullname: str) -> LoaderProtocol | None: - """Find a "loader" object for fullname - - This is a backwards compatibility wrapper around - importlib.util.find_spec that converts most failures to ImportError - and only returns the loader rather than the full spec - """ - - @deprecated("Use importlib.util.find_spec() instead. Will be removed in Python 3.14.") - def get_loader(module_or_name: str) -> LoaderProtocol | None: - """Get a "loader" object for module_or_name - - Returns None if the module cannot be found or imported. - If the named module is not already imported, its containing package - (if any) is imported, in order to establish the package __path__. - """ + if sys.version_info >= (3, 12): + @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `importlib.util.find_spec()` instead.") + def find_loader(fullname: str) -> LoaderProtocol | None: + """Find a "loader" object for fullname + + This is a backwards compatibility wrapper around + importlib.util.find_spec that converts most failures to ImportError + and only returns the loader rather than the full spec + """ + + @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `importlib.util.find_spec()` instead.") + def get_loader(module_or_name: str) -> LoaderProtocol | None: + """Get a "loader" object for module_or_name + + Returns None if the module cannot be found or imported. + If the named module is not already imported, its containing package + (if any) is imported, in order to establish the package __path__. + """ + else: + def find_loader(fullname: str) -> LoaderProtocol | None: + """Find a "loader" object for fullname + + This is a backwards compatibility wrapper around + importlib.util.find_spec that converts most failures to ImportError + and only returns the loader rather than the full spec + """ + + def get_loader(module_or_name: str) -> LoaderProtocol | None: + """Get a "loader" object for module_or_name + + Returns None if the module cannot be found or imported. + If the named module is not already imported, its containing package + (if any) is imported, in order to establish the package __path__. + """ def get_importer(path_item: StrOrBytesPath) -> PathEntryFinderProtocol | None: """Retrieve a finder for the given path item diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi index f4646f70ec2e5..bb9cd3d717b7c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi @@ -9,7 +9,7 @@ format is usable as part of a filename. import sys from typing import NamedTuple, type_check_only -from typing_extensions import Self +from typing_extensions import Self, deprecated def libc_ver(executable: str | None = None, lib: str = "", version: str = "", chunksize: int = 16384) -> tuple[str, str]: """Tries to determine the libc version that the file executable @@ -40,19 +40,42 @@ def mac_ver( which default to ''. All tuple entries are strings. """ -def java_ver( - release: str = "", vendor: str = "", vminfo: tuple[str, str, str] = ("", "", ""), osinfo: tuple[str, str, str] = ("", "", "") -) -> tuple[str, str, tuple[str, str, str], tuple[str, str, str]]: - """Version interface for Jython. +if sys.version_info >= (3, 13): + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + def java_ver( + release: str = "", + vendor: str = "", + vminfo: tuple[str, str, str] = ("", "", ""), + osinfo: tuple[str, str, str] = ("", "", ""), + ) -> tuple[str, str, tuple[str, str, str], tuple[str, str, str]]: + """Version interface for Jython. - Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being - a tuple (vm_name, vm_release, vm_vendor) and osinfo being a - tuple (os_name, os_version, os_arch). + Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being + a tuple (vm_name, vm_release, vm_vendor) and osinfo being a + tuple (os_name, os_version, os_arch). - Values which cannot be determined are set to the defaults - given as parameters (which all default to ''). + Values which cannot be determined are set to the defaults + given as parameters (which all default to ''). - """ + """ + +else: + def java_ver( + release: str = "", + vendor: str = "", + vminfo: tuple[str, str, str] = ("", "", ""), + osinfo: tuple[str, str, str] = ("", "", ""), + ) -> tuple[str, str, tuple[str, str, str], tuple[str, str, str]]: + """Version interface for Jython. + + Returns a tuple (release, vendor, vminfo, osinfo) with vminfo being + a tuple (vm_name, vm_release, vm_vendor) and osinfo being a + tuple (os_name, os_version, os_arch). + + Values which cannot be determined are set to the defaults + given as parameters (which all default to ''). + + """ def system_alias(system: str, release: str, version: str) -> tuple[str, str, str]: """Returns (system, release, version) aliased to common diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pty.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pty.pyi index 0038f4a77ebda..28d5ae4280124 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pty.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pty.pyi @@ -19,20 +19,34 @@ if sys.platform != "win32": Open a pty master/slave pair, using os.openpty() if possible. """ if sys.version_info < (3, 14): - @deprecated("Deprecated in 3.12, to be removed in 3.14; use openpty() instead") - def master_open() -> tuple[int, str]: - """master_open() -> (master_fd, slave_name) - Open a pty master and return the fd, and the filename of the slave end. - Deprecated, use openpty() instead. - """ - - @deprecated("Deprecated in 3.12, to be removed in 3.14; use openpty() instead") - def slave_open(tty_name: str) -> int: - """slave_open(tty_name) -> slave_fd - Open the pty slave and acquire the controlling terminal, returning - opened filedescriptor. - Deprecated, use openpty() instead. - """ + if sys.version_info >= (3, 12): + @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `openpty()` instead.") + def master_open() -> tuple[int, str]: + """master_open() -> (master_fd, slave_name) + Open a pty master and return the fd, and the filename of the slave end. + Deprecated, use openpty() instead. + """ + + @deprecated("Deprecated since Python 3.12; removed in Python 3.14. Use `openpty()` instead.") + def slave_open(tty_name: str) -> int: + """slave_open(tty_name) -> slave_fd + Open the pty slave and acquire the controlling terminal, returning + opened filedescriptor. + Deprecated, use openpty() instead. + """ + else: + def master_open() -> tuple[int, str]: + """master_open() -> (master_fd, slave_name) + Open a pty master and return the fd, and the filename of the slave end. + Deprecated, use openpty() instead. + """ + + def slave_open(tty_name: str) -> int: + """slave_open(tty_name) -> slave_fd + Open the pty slave and acquire the controlling terminal, returning + opened filedescriptor. + Deprecated, use openpty() instead. + """ def fork() -> tuple[int, int]: """fork() -> (pid, master_fd) diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi index 8a57f8289f728..0a056f84f9a1d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi @@ -44,7 +44,7 @@ from builtins import list as _list # "list" conflicts with method name from collections.abc import Callable, Container, Mapping, MutableMapping from reprlib import Repr from types import MethodType, ModuleType, TracebackType -from typing import IO, Any, AnyStr, Final, NoReturn, Protocol, TypeVar +from typing import IO, Any, AnyStr, Final, NoReturn, Protocol, TypeVar, type_check_only from typing_extensions import TypeGuard, deprecated __all__ = ["help"] @@ -56,6 +56,7 @@ __date__: Final[str] __version__: Final[str] __credits__: Final[str] +@type_check_only class _Pager(Protocol): def __call__(self, text: str, title: str = "") -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/quopri.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/quopri.pyi index 68b18731771c3..4594503f76e3c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/quopri.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/quopri.pyi @@ -1,10 +1,11 @@ """Conversions to/from quoted-printable transport encoding as per RFC 1521.""" from _typeshed import ReadableBuffer, SupportsNoArgReadline, SupportsRead, SupportsWrite -from typing import Protocol +from typing import Protocol, type_check_only __all__ = ["encode", "decode", "encodestring", "decodestring"] +@type_check_only class _Input(SupportsRead[bytes], SupportsNoArgReadline[bytes], Protocol): ... def encode(input: _Input, output: SupportsWrite[bytes], quotetabs: int, header: bool = False) -> None: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/re.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/re.pyi index 19d5fdade7e56..af6be98d28d49 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/re.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/re.pyi @@ -114,7 +114,7 @@ from _typeshed import MaybeNone, ReadableBuffer from collections.abc import Callable, Iterator, Mapping from types import GenericAlias from typing import Any, AnyStr, Final, Generic, Literal, TypeVar, final, overload -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, deprecated __all__ = [ "match", @@ -564,5 +564,10 @@ def purge() -> None: """Clear the regular expression caches""" if sys.version_info < (3, 13): - def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = 0) -> Pattern[AnyStr]: - """Compile a template pattern, returning a Pattern object, deprecated""" + if sys.version_info >= (3, 11): + @deprecated("Deprecated since Python 3.11; removed in Python 3.13. Use `re.compile()` instead.") + def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = 0) -> Pattern[AnyStr]: # undocumented + """Compile a template pattern, returning a Pattern object, deprecated""" + else: + def template(pattern: AnyStr | Pattern[AnyStr], flags: _FlagsType = 0) -> Pattern[AnyStr]: # undocumented + """Compile a template pattern, returning a Pattern object""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/shutil.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/shutil.pyi index 81fb8d861675c..8a79660dff987 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/shutil.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/shutil.pyi @@ -9,7 +9,7 @@ import sys from _typeshed import BytesPath, ExcInfo, FileDescriptorOrPath, MaybeNone, StrOrBytesPath, StrPath, SupportsRead, SupportsWrite from collections.abc import Callable, Iterable, Sequence from tarfile import _TarfileFilter -from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeVar, overload +from typing import Any, AnyStr, NamedTuple, NoReturn, Protocol, TypeVar, overload, type_check_only from typing_extensions import TypeAlias, deprecated __all__ = [ @@ -193,6 +193,7 @@ def copytree( _OnErrorCallback: TypeAlias = Callable[[Callable[..., Any], str, ExcInfo], object] _OnExcCallback: TypeAlias = Callable[[Callable[..., Any], str, BaseException], object] +@type_check_only class _RmtreeType(Protocol): avoids_symlink_attacks: bool if sys.version_info >= (3, 12): @@ -393,7 +394,7 @@ def make_archive( 'base_name' is the name of the file to create, minus any format-specific extension; 'format' is the archive format: one of "zip", "tar", "gztar", - "bztar", "zstdtar", or "xztar". Or any other registered format. + "bztar", "xztar", or "zstdtar". Or any other registered format. 'root_dir' is a directory that will be the root directory of the archive; ie. we typically chdir into 'root_dir' before creating the @@ -441,7 +442,7 @@ def unpack_archive( is unpacked. If not provided, the current working directory is used. `format` is the archive format: one of "zip", "tar", "gztar", "bztar", - or "xztar". Or any other registered format. If not provided, + "xztar", or "zstdtar". Or any other registered format. If not provided, unpack_archive will use the filename extension and see if an unpacker was registered for that extension. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/smtpd.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/smtpd.pyi index 242544fb72a1b..b201659d1b2fe 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/smtpd.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/smtpd.pyi @@ -49,7 +49,7 @@ import socket import sys from collections import defaultdict from typing import Any -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, deprecated if sys.version_info >= (3, 11): __all__ = ["SMTPChannel", "SMTPServer", "DebuggingServer", "PureProxy"] @@ -160,5 +160,6 @@ class PureProxy(SMTPServer): def process_message(self, peer: _Address, mailfrom: str, rcpttos: list[str], data: bytes | str) -> str | None: ... # type: ignore[override] if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.9; removed in Python 3.11.") class MailmanProxy(PureProxy): def process_message(self, peer: _Address, mailfrom: str, rcpttos: list[str], data: bytes | str) -> str | None: ... # type: ignore[override] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi index b134010a9b115..9c5dc852c248a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi @@ -39,7 +39,7 @@ from re import Pattern from socket import socket from ssl import SSLContext from types import TracebackType -from typing import Any, Protocol, overload +from typing import Any, Protocol, overload, type_check_only from typing_extensions import Self, TypeAlias __all__ = [ @@ -154,6 +154,7 @@ def quotedata(data: str) -> str: internet CRLF end-of-line. """ +@type_check_only class _AuthObject(Protocol): @overload def __call__(self, challenge: None = None, /) -> str | None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi index 7bed33aec346a..95551819860b7 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi @@ -1098,14 +1098,12 @@ if sys.version_info >= (3, 14): if sys.platform == "linux": from _socket import ( - CAN_RAW_ERR_FILTER as CAN_RAW_ERR_FILTER, IP_FREEBIND as IP_FREEBIND, IP_RECVORIGDSTADDR as IP_RECVORIGDSTADDR, - SO_ORIGINAL_DST as SO_ORIGINAL_DST, VMADDR_CID_LOCAL as VMADDR_CID_LOCAL, ) - __all__ += ["CAN_RAW_ERR_FILTER", "IP_FREEBIND", "IP_RECVORIGDSTADDR", "VMADDR_CID_LOCAL"] + __all__ += ["IP_FREEBIND", "IP_RECVORIGDSTADDR", "VMADDR_CID_LOCAL"] # Re-exported from errno EBADF: int diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi index ff9fec4735db2..ae46b544a5dec 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi @@ -257,22 +257,26 @@ _Parameters: TypeAlias = SupportsLenAndGetItem[_AdaptedInputData] | Mapping[str, # Controls the legacy transaction handling mode of sqlite3. _IsolationLevel: TypeAlias = Literal["DEFERRED", "EXCLUSIVE", "IMMEDIATE"] | None +@type_check_only class _AnyParamWindowAggregateClass(Protocol): def step(self, *args: Any) -> object: ... def inverse(self, *args: Any) -> object: ... def value(self) -> _SqliteData: ... def finalize(self) -> _SqliteData: ... +@type_check_only class _WindowAggregateClass(Protocol): step: Callable[..., object] inverse: Callable[..., object] def value(self) -> _SqliteData: ... def finalize(self) -> _SqliteData: ... +@type_check_only class _AggregateProtocol(Protocol): def step(self, value: int, /) -> object: ... def finalize(self) -> int: ... +@type_check_only class _SingleParamWindowAggregateClass(Protocol): def step(self, param: Any, /) -> object: ... def inverse(self, param: Any, /) -> object: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi index bb22a067e37e3..f81f51970a1ad 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi @@ -117,7 +117,7 @@ from _ssl import ( ) from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer from collections.abc import Callable, Iterable -from typing import Any, Literal, NamedTuple, TypedDict, overload, type_check_only +from typing import Any, Final, Literal, NamedTuple, TypedDict, overload, type_check_only from typing_extensions import Never, Self, TypeAlias, deprecated if sys.version_info >= (3, 13): @@ -140,6 +140,7 @@ _SrvnmeCbType: TypeAlias = Callable[[SSLSocket | SSLObject, str | None, SSLSocke socket_error = OSError +@type_check_only class _Cipher(TypedDict): aead: bool alg_bits: int @@ -275,9 +276,9 @@ class VerifyMode(enum.IntEnum): CERT_OPTIONAL = 1 CERT_REQUIRED = 2 -CERT_NONE: VerifyMode -CERT_OPTIONAL: VerifyMode -CERT_REQUIRED: VerifyMode +CERT_NONE: Final = VerifyMode.CERT_NONE +CERT_OPTIONAL: Final = VerifyMode.CERT_OPTIONAL +CERT_REQUIRED: Final = VerifyMode.CERT_REQUIRED class VerifyFlags(enum.IntFlag): """An enumeration.""" @@ -291,15 +292,15 @@ class VerifyFlags(enum.IntFlag): VERIFY_ALLOW_PROXY_CERTS = 64 VERIFY_X509_PARTIAL_CHAIN = 524288 -VERIFY_DEFAULT: VerifyFlags -VERIFY_CRL_CHECK_LEAF: VerifyFlags -VERIFY_CRL_CHECK_CHAIN: VerifyFlags -VERIFY_X509_STRICT: VerifyFlags -VERIFY_X509_TRUSTED_FIRST: VerifyFlags +VERIFY_DEFAULT: Final = VerifyFlags.VERIFY_DEFAULT +VERIFY_CRL_CHECK_LEAF: Final = VerifyFlags.VERIFY_CRL_CHECK_LEAF +VERIFY_CRL_CHECK_CHAIN: Final = VerifyFlags.VERIFY_CRL_CHECK_CHAIN +VERIFY_X509_STRICT: Final = VerifyFlags.VERIFY_X509_STRICT +VERIFY_X509_TRUSTED_FIRST: Final = VerifyFlags.VERIFY_X509_TRUSTED_FIRST if sys.version_info >= (3, 10): - VERIFY_ALLOW_PROXY_CERTS: VerifyFlags - VERIFY_X509_PARTIAL_CHAIN: VerifyFlags + VERIFY_ALLOW_PROXY_CERTS: Final = VerifyFlags.VERIFY_ALLOW_PROXY_CERTS + VERIFY_X509_PARTIAL_CHAIN: Final = VerifyFlags.VERIFY_X509_PARTIAL_CHAIN class _SSLMethod(enum.IntEnum): """An enumeration.""" @@ -314,15 +315,15 @@ class _SSLMethod(enum.IntEnum): PROTOCOL_TLS_CLIENT = 16 PROTOCOL_TLS_SERVER = 17 -PROTOCOL_SSLv23: _SSLMethod -PROTOCOL_SSLv2: _SSLMethod -PROTOCOL_SSLv3: _SSLMethod -PROTOCOL_TLSv1: _SSLMethod -PROTOCOL_TLSv1_1: _SSLMethod -PROTOCOL_TLSv1_2: _SSLMethod -PROTOCOL_TLS: _SSLMethod -PROTOCOL_TLS_CLIENT: _SSLMethod -PROTOCOL_TLS_SERVER: _SSLMethod +PROTOCOL_SSLv23: Final = _SSLMethod.PROTOCOL_SSLv23 +PROTOCOL_SSLv2: Final = _SSLMethod.PROTOCOL_SSLv2 +PROTOCOL_SSLv3: Final = _SSLMethod.PROTOCOL_SSLv3 +PROTOCOL_TLSv1: Final = _SSLMethod.PROTOCOL_TLSv1 +PROTOCOL_TLSv1_1: Final = _SSLMethod.PROTOCOL_TLSv1_1 +PROTOCOL_TLSv1_2: Final = _SSLMethod.PROTOCOL_TLSv1_2 +PROTOCOL_TLS: Final = _SSLMethod.PROTOCOL_TLS +PROTOCOL_TLS_CLIENT: Final = _SSLMethod.PROTOCOL_TLS_CLIENT +PROTOCOL_TLS_SERVER: Final = _SSLMethod.PROTOCOL_TLS_SERVER class Options(enum.IntFlag): """An enumeration.""" @@ -347,29 +348,29 @@ class Options(enum.IntFlag): if sys.version_info >= (3, 11) or sys.platform == "linux": OP_IGNORE_UNEXPECTED_EOF = 128 -OP_ALL: Options -OP_NO_SSLv2: Options -OP_NO_SSLv3: Options -OP_NO_TLSv1: Options -OP_NO_TLSv1_1: Options -OP_NO_TLSv1_2: Options -OP_NO_TLSv1_3: Options -OP_CIPHER_SERVER_PREFERENCE: Options -OP_SINGLE_DH_USE: Options -OP_SINGLE_ECDH_USE: Options -OP_NO_COMPRESSION: Options -OP_NO_TICKET: Options -OP_NO_RENEGOTIATION: Options -OP_ENABLE_MIDDLEBOX_COMPAT: Options +OP_ALL: Final = Options.OP_ALL +OP_NO_SSLv2: Final = Options.OP_NO_SSLv2 +OP_NO_SSLv3: Final = Options.OP_NO_SSLv3 +OP_NO_TLSv1: Final = Options.OP_NO_TLSv1 +OP_NO_TLSv1_1: Final = Options.OP_NO_TLSv1_1 +OP_NO_TLSv1_2: Final = Options.OP_NO_TLSv1_2 +OP_NO_TLSv1_3: Final = Options.OP_NO_TLSv1_3 +OP_CIPHER_SERVER_PREFERENCE: Final = Options.OP_CIPHER_SERVER_PREFERENCE +OP_SINGLE_DH_USE: Final = Options.OP_SINGLE_DH_USE +OP_SINGLE_ECDH_USE: Final = Options.OP_SINGLE_ECDH_USE +OP_NO_COMPRESSION: Final = Options.OP_NO_COMPRESSION +OP_NO_TICKET: Final = Options.OP_NO_TICKET +OP_NO_RENEGOTIATION: Final = Options.OP_NO_RENEGOTIATION +OP_ENABLE_MIDDLEBOX_COMPAT: Final = Options.OP_ENABLE_MIDDLEBOX_COMPAT if sys.version_info >= (3, 12): - OP_LEGACY_SERVER_CONNECT: Options - OP_ENABLE_KTLS: Options + OP_LEGACY_SERVER_CONNECT: Final = Options.OP_LEGACY_SERVER_CONNECT + OP_ENABLE_KTLS: Final = Options.OP_ENABLE_KTLS if sys.version_info >= (3, 11) or sys.platform == "linux": - OP_IGNORE_UNEXPECTED_EOF: Options + OP_IGNORE_UNEXPECTED_EOF: Final = Options.OP_IGNORE_UNEXPECTED_EOF -HAS_NEVER_CHECK_COMMON_NAME: bool +HAS_NEVER_CHECK_COMMON_NAME: Final[bool] -CHANNEL_BINDING_TYPES: list[str] +CHANNEL_BINDING_TYPES: Final[list[str]] class AlertDescription(enum.IntEnum): """An enumeration.""" @@ -402,33 +403,33 @@ class AlertDescription(enum.IntEnum): ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION = 110 ALERT_DESCRIPTION_USER_CANCELLED = 90 -ALERT_DESCRIPTION_HANDSHAKE_FAILURE: AlertDescription -ALERT_DESCRIPTION_INTERNAL_ERROR: AlertDescription -ALERT_DESCRIPTION_ACCESS_DENIED: AlertDescription -ALERT_DESCRIPTION_BAD_CERTIFICATE: AlertDescription -ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: AlertDescription -ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: AlertDescription -ALERT_DESCRIPTION_BAD_RECORD_MAC: AlertDescription -ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: AlertDescription -ALERT_DESCRIPTION_CERTIFICATE_REVOKED: AlertDescription -ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: AlertDescription -ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: AlertDescription -ALERT_DESCRIPTION_CLOSE_NOTIFY: AlertDescription -ALERT_DESCRIPTION_DECODE_ERROR: AlertDescription -ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: AlertDescription -ALERT_DESCRIPTION_DECRYPT_ERROR: AlertDescription -ALERT_DESCRIPTION_ILLEGAL_PARAMETER: AlertDescription -ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: AlertDescription -ALERT_DESCRIPTION_NO_RENEGOTIATION: AlertDescription -ALERT_DESCRIPTION_PROTOCOL_VERSION: AlertDescription -ALERT_DESCRIPTION_RECORD_OVERFLOW: AlertDescription -ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: AlertDescription -ALERT_DESCRIPTION_UNKNOWN_CA: AlertDescription -ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: AlertDescription -ALERT_DESCRIPTION_UNRECOGNIZED_NAME: AlertDescription -ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: AlertDescription -ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: AlertDescription -ALERT_DESCRIPTION_USER_CANCELLED: AlertDescription +ALERT_DESCRIPTION_HANDSHAKE_FAILURE: Final = AlertDescription.ALERT_DESCRIPTION_HANDSHAKE_FAILURE +ALERT_DESCRIPTION_INTERNAL_ERROR: Final = AlertDescription.ALERT_DESCRIPTION_INTERNAL_ERROR +ALERT_DESCRIPTION_ACCESS_DENIED: Final = AlertDescription.ALERT_DESCRIPTION_ACCESS_DENIED +ALERT_DESCRIPTION_BAD_CERTIFICATE: Final = AlertDescription.ALERT_DESCRIPTION_BAD_CERTIFICATE +ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE: Final = AlertDescription.ALERT_DESCRIPTION_BAD_CERTIFICATE_HASH_VALUE +ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE: Final = AlertDescription.ALERT_DESCRIPTION_BAD_CERTIFICATE_STATUS_RESPONSE +ALERT_DESCRIPTION_BAD_RECORD_MAC: Final = AlertDescription.ALERT_DESCRIPTION_BAD_RECORD_MAC +ALERT_DESCRIPTION_CERTIFICATE_EXPIRED: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_EXPIRED +ALERT_DESCRIPTION_CERTIFICATE_REVOKED: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_REVOKED +ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_UNKNOWN +ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE: Final = AlertDescription.ALERT_DESCRIPTION_CERTIFICATE_UNOBTAINABLE +ALERT_DESCRIPTION_CLOSE_NOTIFY: Final = AlertDescription.ALERT_DESCRIPTION_CLOSE_NOTIFY +ALERT_DESCRIPTION_DECODE_ERROR: Final = AlertDescription.ALERT_DESCRIPTION_DECODE_ERROR +ALERT_DESCRIPTION_DECOMPRESSION_FAILURE: Final = AlertDescription.ALERT_DESCRIPTION_DECOMPRESSION_FAILURE +ALERT_DESCRIPTION_DECRYPT_ERROR: Final = AlertDescription.ALERT_DESCRIPTION_DECRYPT_ERROR +ALERT_DESCRIPTION_ILLEGAL_PARAMETER: Final = AlertDescription.ALERT_DESCRIPTION_ILLEGAL_PARAMETER +ALERT_DESCRIPTION_INSUFFICIENT_SECURITY: Final = AlertDescription.ALERT_DESCRIPTION_INSUFFICIENT_SECURITY +ALERT_DESCRIPTION_NO_RENEGOTIATION: Final = AlertDescription.ALERT_DESCRIPTION_NO_RENEGOTIATION +ALERT_DESCRIPTION_PROTOCOL_VERSION: Final = AlertDescription.ALERT_DESCRIPTION_PROTOCOL_VERSION +ALERT_DESCRIPTION_RECORD_OVERFLOW: Final = AlertDescription.ALERT_DESCRIPTION_RECORD_OVERFLOW +ALERT_DESCRIPTION_UNEXPECTED_MESSAGE: Final = AlertDescription.ALERT_DESCRIPTION_UNEXPECTED_MESSAGE +ALERT_DESCRIPTION_UNKNOWN_CA: Final = AlertDescription.ALERT_DESCRIPTION_UNKNOWN_CA +ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY: Final = AlertDescription.ALERT_DESCRIPTION_UNKNOWN_PSK_IDENTITY +ALERT_DESCRIPTION_UNRECOGNIZED_NAME: Final = AlertDescription.ALERT_DESCRIPTION_UNRECOGNIZED_NAME +ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE: Final = AlertDescription.ALERT_DESCRIPTION_UNSUPPORTED_CERTIFICATE +ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION: Final = AlertDescription.ALERT_DESCRIPTION_UNSUPPORTED_EXTENSION +ALERT_DESCRIPTION_USER_CANCELLED: Final = AlertDescription.ALERT_DESCRIPTION_USER_CANCELLED # This class is not exposed. It calls itself ssl._ASN1Object. @type_check_only @@ -894,20 +895,20 @@ class SSLErrorNumber(enum.IntEnum): SSL_ERROR_WANT_X509_LOOKUP = 4 SSL_ERROR_ZERO_RETURN = 6 -SSL_ERROR_EOF: SSLErrorNumber # undocumented -SSL_ERROR_INVALID_ERROR_CODE: SSLErrorNumber # undocumented -SSL_ERROR_SSL: SSLErrorNumber # undocumented -SSL_ERROR_SYSCALL: SSLErrorNumber # undocumented -SSL_ERROR_WANT_CONNECT: SSLErrorNumber # undocumented -SSL_ERROR_WANT_READ: SSLErrorNumber # undocumented -SSL_ERROR_WANT_WRITE: SSLErrorNumber # undocumented -SSL_ERROR_WANT_X509_LOOKUP: SSLErrorNumber # undocumented -SSL_ERROR_ZERO_RETURN: SSLErrorNumber # undocumented +SSL_ERROR_EOF: Final = SSLErrorNumber.SSL_ERROR_EOF # undocumented +SSL_ERROR_INVALID_ERROR_CODE: Final = SSLErrorNumber.SSL_ERROR_INVALID_ERROR_CODE # undocumented +SSL_ERROR_SSL: Final = SSLErrorNumber.SSL_ERROR_SSL # undocumented +SSL_ERROR_SYSCALL: Final = SSLErrorNumber.SSL_ERROR_SYSCALL # undocumented +SSL_ERROR_WANT_CONNECT: Final = SSLErrorNumber.SSL_ERROR_WANT_CONNECT # undocumented +SSL_ERROR_WANT_READ: Final = SSLErrorNumber.SSL_ERROR_WANT_READ # undocumented +SSL_ERROR_WANT_WRITE: Final = SSLErrorNumber.SSL_ERROR_WANT_WRITE # undocumented +SSL_ERROR_WANT_X509_LOOKUP: Final = SSLErrorNumber.SSL_ERROR_WANT_X509_LOOKUP # undocumented +SSL_ERROR_ZERO_RETURN: Final = SSLErrorNumber.SSL_ERROR_ZERO_RETURN # undocumented def get_protocol_name(protocol_code: int) -> str: ... -PEM_FOOTER: str -PEM_HEADER: str -SOCK_STREAM: int -SOL_SOCKET: int -SO_TYPE: int +PEM_FOOTER: Final[str] +PEM_HEADER: Final[str] +SOCK_STREAM: Final = socket.SOCK_STREAM +SOL_SOCKET: Final = socket.SOL_SOCKET +SO_TYPE: Final = socket.SO_TYPE diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi index 4a61b2efbd3c2..6f8783c351dd7 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi @@ -289,6 +289,18 @@ class _flags(_UninstantiableStructseq, tuple[int, ...]): @property def safe_path(self) -> bool: """-P""" + if sys.version_info >= (3, 13): + @property + def gil(self) -> Literal[0, 1]: + """-X gil""" + if sys.version_info >= (3, 14): + @property + def thread_inherit_context(self) -> Literal[0, 1]: + """-X thread_inherit_context""" + + @property + def context_aware_warnings(self) -> Literal[0, 1]: + """-X context_aware_warnings""" # Whether or not this exists on lower versions of Python # may depend on which patch release you're using # (it was backported to all Python versions on 3.8+ as a security fix) @@ -688,6 +700,7 @@ def settrace(function: TraceFunction | None, /) -> None: if sys.platform == "win32": # A tuple of length 5, even though it has more than 5 attributes. @final + @type_check_only class _WinVersion(_UninstantiableStructseq, tuple[int, int, int, int, str]): @property def major(self) -> int: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/termios.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/termios.pyi index e8113ccde2266..a8c402ab07309 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/termios.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/termios.pyi @@ -10,7 +10,7 @@ sys.stdin.fileno(), or a file object, such as sys.stdin itself. import sys from _typeshed import FileDescriptorLike -from typing import Any +from typing import Any, Final from typing_extensions import TypeAlias # Must be a list of length 7, containing 6 ints and a list of NCCS 1-character bytes or ints. @@ -19,286 +19,287 @@ _Attr: TypeAlias = list[int | list[bytes | int]] | list[int | list[bytes]] | lis _AttrReturn: TypeAlias = list[Any] if sys.platform != "win32": - B0: int - B110: int - B115200: int - B1200: int - B134: int - B150: int - B1800: int - B19200: int - B200: int - B230400: int - B2400: int - B300: int - B38400: int - B4800: int - B50: int - B57600: int - B600: int - B75: int - B9600: int - BRKINT: int - BS0: int - BS1: int - BSDLY: int - CDSUSP: int - CEOF: int - CEOL: int - CEOT: int - CERASE: int - CFLUSH: int - CINTR: int - CKILL: int - CLNEXT: int - CLOCAL: int - CQUIT: int - CR0: int - CR1: int - CR2: int - CR3: int - CRDLY: int - CREAD: int - CRPRNT: int - CRTSCTS: int - CS5: int - CS6: int - CS7: int - CS8: int - CSIZE: int - CSTART: int - CSTOP: int - CSTOPB: int - CSUSP: int - CWERASE: int - ECHO: int - ECHOCTL: int - ECHOE: int - ECHOK: int - ECHOKE: int - ECHONL: int - ECHOPRT: int - EXTA: int - EXTB: int - FF0: int - FF1: int - FFDLY: int - FIOASYNC: int - FIOCLEX: int - FIONBIO: int - FIONCLEX: int - FIONREAD: int - FLUSHO: int - HUPCL: int - ICANON: int - ICRNL: int - IEXTEN: int - IGNBRK: int - IGNCR: int - IGNPAR: int - IMAXBEL: int - INLCR: int - INPCK: int - ISIG: int - ISTRIP: int - IXANY: int - IXOFF: int - IXON: int - NCCS: int - NL0: int - NL1: int - NLDLY: int - NOFLSH: int - OCRNL: int - OFDEL: int - OFILL: int - ONLCR: int - ONLRET: int - ONOCR: int - OPOST: int - PARENB: int - PARMRK: int - PARODD: int - PENDIN: int - TAB0: int - TAB1: int - TAB2: int - TAB3: int - TABDLY: int - TCIFLUSH: int - TCIOFF: int - TCIOFLUSH: int - TCION: int - TCOFLUSH: int - TCOOFF: int - TCOON: int - TCSADRAIN: int - TCSAFLUSH: int - TCSANOW: int - TIOCCONS: int - TIOCEXCL: int - TIOCGETD: int - TIOCGPGRP: int - TIOCGWINSZ: int - TIOCM_CAR: int - TIOCM_CD: int - TIOCM_CTS: int - TIOCM_DSR: int - TIOCM_DTR: int - TIOCM_LE: int - TIOCM_RI: int - TIOCM_RNG: int - TIOCM_RTS: int - TIOCM_SR: int - TIOCM_ST: int - TIOCMBIC: int - TIOCMBIS: int - TIOCMGET: int - TIOCMSET: int - TIOCNOTTY: int - TIOCNXCL: int - TIOCOUTQ: int - TIOCPKT_DATA: int - TIOCPKT_DOSTOP: int - TIOCPKT_FLUSHREAD: int - TIOCPKT_FLUSHWRITE: int - TIOCPKT_NOSTOP: int - TIOCPKT_START: int - TIOCPKT_STOP: int - TIOCPKT: int - TIOCSCTTY: int - TIOCSETD: int - TIOCSPGRP: int - TIOCSTI: int - TIOCSWINSZ: int - TOSTOP: int - VDISCARD: int - VEOF: int - VEOL: int - VEOL2: int - VERASE: int - VINTR: int - VKILL: int - VLNEXT: int - VMIN: int - VQUIT: int - VREPRINT: int - VSTART: int - VSTOP: int - VSUSP: int - VT0: int - VT1: int - VTDLY: int - VTIME: int - VWERASE: int + # Values depends on the platform + B0: Final[int] + B110: Final[int] + B115200: Final[int] + B1200: Final[int] + B134: Final[int] + B150: Final[int] + B1800: Final[int] + B19200: Final[int] + B200: Final[int] + B230400: Final[int] + B2400: Final[int] + B300: Final[int] + B38400: Final[int] + B4800: Final[int] + B50: Final[int] + B57600: Final[int] + B600: Final[int] + B75: Final[int] + B9600: Final[int] + BRKINT: Final[int] + BS0: Final[int] + BS1: Final[int] + BSDLY: Final[int] + CDSUSP: Final[int] + CEOF: Final[int] + CEOL: Final[int] + CEOT: Final[int] + CERASE: Final[int] + CFLUSH: Final[int] + CINTR: Final[int] + CKILL: Final[int] + CLNEXT: Final[int] + CLOCAL: Final[int] + CQUIT: Final[int] + CR0: Final[int] + CR1: Final[int] + CR2: Final[int] + CR3: Final[int] + CRDLY: Final[int] + CREAD: Final[int] + CRPRNT: Final[int] + CRTSCTS: Final[int] + CS5: Final[int] + CS6: Final[int] + CS7: Final[int] + CS8: Final[int] + CSIZE: Final[int] + CSTART: Final[int] + CSTOP: Final[int] + CSTOPB: Final[int] + CSUSP: Final[int] + CWERASE: Final[int] + ECHO: Final[int] + ECHOCTL: Final[int] + ECHOE: Final[int] + ECHOK: Final[int] + ECHOKE: Final[int] + ECHONL: Final[int] + ECHOPRT: Final[int] + EXTA: Final[int] + EXTB: Final[int] + FF0: Final[int] + FF1: Final[int] + FFDLY: Final[int] + FIOASYNC: Final[int] + FIOCLEX: Final[int] + FIONBIO: Final[int] + FIONCLEX: Final[int] + FIONREAD: Final[int] + FLUSHO: Final[int] + HUPCL: Final[int] + ICANON: Final[int] + ICRNL: Final[int] + IEXTEN: Final[int] + IGNBRK: Final[int] + IGNCR: Final[int] + IGNPAR: Final[int] + IMAXBEL: Final[int] + INLCR: Final[int] + INPCK: Final[int] + ISIG: Final[int] + ISTRIP: Final[int] + IXANY: Final[int] + IXOFF: Final[int] + IXON: Final[int] + NCCS: Final[int] + NL0: Final[int] + NL1: Final[int] + NLDLY: Final[int] + NOFLSH: Final[int] + OCRNL: Final[int] + OFDEL: Final[int] + OFILL: Final[int] + ONLCR: Final[int] + ONLRET: Final[int] + ONOCR: Final[int] + OPOST: Final[int] + PARENB: Final[int] + PARMRK: Final[int] + PARODD: Final[int] + PENDIN: Final[int] + TAB0: Final[int] + TAB1: Final[int] + TAB2: Final[int] + TAB3: Final[int] + TABDLY: Final[int] + TCIFLUSH: Final[int] + TCIOFF: Final[int] + TCIOFLUSH: Final[int] + TCION: Final[int] + TCOFLUSH: Final[int] + TCOOFF: Final[int] + TCOON: Final[int] + TCSADRAIN: Final[int] + TCSAFLUSH: Final[int] + TCSANOW: Final[int] + TIOCCONS: Final[int] + TIOCEXCL: Final[int] + TIOCGETD: Final[int] + TIOCGPGRP: Final[int] + TIOCGWINSZ: Final[int] + TIOCM_CAR: Final[int] + TIOCM_CD: Final[int] + TIOCM_CTS: Final[int] + TIOCM_DSR: Final[int] + TIOCM_DTR: Final[int] + TIOCM_LE: Final[int] + TIOCM_RI: Final[int] + TIOCM_RNG: Final[int] + TIOCM_RTS: Final[int] + TIOCM_SR: Final[int] + TIOCM_ST: Final[int] + TIOCMBIC: Final[int] + TIOCMBIS: Final[int] + TIOCMGET: Final[int] + TIOCMSET: Final[int] + TIOCNOTTY: Final[int] + TIOCNXCL: Final[int] + TIOCOUTQ: Final[int] + TIOCPKT_DATA: Final[int] + TIOCPKT_DOSTOP: Final[int] + TIOCPKT_FLUSHREAD: Final[int] + TIOCPKT_FLUSHWRITE: Final[int] + TIOCPKT_NOSTOP: Final[int] + TIOCPKT_START: Final[int] + TIOCPKT_STOP: Final[int] + TIOCPKT: Final[int] + TIOCSCTTY: Final[int] + TIOCSETD: Final[int] + TIOCSPGRP: Final[int] + TIOCSTI: Final[int] + TIOCSWINSZ: Final[int] + TOSTOP: Final[int] + VDISCARD: Final[int] + VEOF: Final[int] + VEOL: Final[int] + VEOL2: Final[int] + VERASE: Final[int] + VINTR: Final[int] + VKILL: Final[int] + VLNEXT: Final[int] + VMIN: Final[int] + VQUIT: Final[int] + VREPRINT: Final[int] + VSTART: Final[int] + VSTOP: Final[int] + VSUSP: Final[int] + VT0: Final[int] + VT1: Final[int] + VTDLY: Final[int] + VTIME: Final[int] + VWERASE: Final[int] if sys.version_info >= (3, 13): - EXTPROC: int - IUTF8: int + EXTPROC: Final[int] + IUTF8: Final[int] if sys.platform == "darwin" and sys.version_info >= (3, 13): - ALTWERASE: int - B14400: int - B28800: int - B7200: int - B76800: int - CCAR_OFLOW: int - CCTS_OFLOW: int - CDSR_OFLOW: int - CDTR_IFLOW: int - CIGNORE: int - CRTS_IFLOW: int - MDMBUF: int - NL2: int - NL3: int - NOKERNINFO: int - ONOEOT: int - OXTABS: int - VDSUSP: int - VSTATUS: int + ALTWERASE: Final[int] + B14400: Final[int] + B28800: Final[int] + B7200: Final[int] + B76800: Final[int] + CCAR_OFLOW: Final[int] + CCTS_OFLOW: Final[int] + CDSR_OFLOW: Final[int] + CDTR_IFLOW: Final[int] + CIGNORE: Final[int] + CRTS_IFLOW: Final[int] + MDMBUF: Final[int] + NL2: Final[int] + NL3: Final[int] + NOKERNINFO: Final[int] + ONOEOT: Final[int] + OXTABS: Final[int] + VDSUSP: Final[int] + VSTATUS: Final[int] if sys.platform == "darwin" and sys.version_info >= (3, 11): - TIOCGSIZE: int - TIOCSSIZE: int + TIOCGSIZE: Final[int] + TIOCSSIZE: Final[int] if sys.platform == "linux": - B1152000: int - B576000: int - CBAUD: int - CBAUDEX: int - CIBAUD: int - IOCSIZE_MASK: int - IOCSIZE_SHIFT: int - IUCLC: int - N_MOUSE: int - N_PPP: int - N_SLIP: int - N_STRIP: int - N_TTY: int - NCC: int - OLCUC: int - TCFLSH: int - TCGETA: int - TCGETS: int - TCSBRK: int - TCSBRKP: int - TCSETA: int - TCSETAF: int - TCSETAW: int - TCSETS: int - TCSETSF: int - TCSETSW: int - TCXONC: int - TIOCGICOUNT: int - TIOCGLCKTRMIOS: int - TIOCGSERIAL: int - TIOCGSOFTCAR: int - TIOCINQ: int - TIOCLINUX: int - TIOCMIWAIT: int - TIOCTTYGSTRUCT: int - TIOCSER_TEMT: int - TIOCSERCONFIG: int - TIOCSERGETLSR: int - TIOCSERGETMULTI: int - TIOCSERGSTRUCT: int - TIOCSERGWILD: int - TIOCSERSETMULTI: int - TIOCSERSWILD: int - TIOCSLCKTRMIOS: int - TIOCSSERIAL: int - TIOCSSOFTCAR: int - VSWTC: int - VSWTCH: int - XCASE: int - XTABS: int + B1152000: Final[int] + B576000: Final[int] + CBAUD: Final[int] + CBAUDEX: Final[int] + CIBAUD: Final[int] + IOCSIZE_MASK: Final[int] + IOCSIZE_SHIFT: Final[int] + IUCLC: Final[int] + N_MOUSE: Final[int] + N_PPP: Final[int] + N_SLIP: Final[int] + N_STRIP: Final[int] + N_TTY: Final[int] + NCC: Final[int] + OLCUC: Final[int] + TCFLSH: Final[int] + TCGETA: Final[int] + TCGETS: Final[int] + TCSBRK: Final[int] + TCSBRKP: Final[int] + TCSETA: Final[int] + TCSETAF: Final[int] + TCSETAW: Final[int] + TCSETS: Final[int] + TCSETSF: Final[int] + TCSETSW: Final[int] + TCXONC: Final[int] + TIOCGICOUNT: Final[int] + TIOCGLCKTRMIOS: Final[int] + TIOCGSERIAL: Final[int] + TIOCGSOFTCAR: Final[int] + TIOCINQ: Final[int] + TIOCLINUX: Final[int] + TIOCMIWAIT: Final[int] + TIOCTTYGSTRUCT: Final[int] + TIOCSER_TEMT: Final[int] + TIOCSERCONFIG: Final[int] + TIOCSERGETLSR: Final[int] + TIOCSERGETMULTI: Final[int] + TIOCSERGSTRUCT: Final[int] + TIOCSERGWILD: Final[int] + TIOCSERSETMULTI: Final[int] + TIOCSERSWILD: Final[int] + TIOCSLCKTRMIOS: Final[int] + TIOCSSERIAL: Final[int] + TIOCSSOFTCAR: Final[int] + VSWTC: Final[int] + VSWTCH: Final[int] + XCASE: Final[int] + XTABS: Final[int] if sys.platform != "darwin": - B1000000: int - B1500000: int - B2000000: int - B2500000: int - B3000000: int - B3500000: int - B4000000: int - B460800: int - B500000: int - B921600: int + B1000000: Final[int] + B1500000: Final[int] + B2000000: Final[int] + B2500000: Final[int] + B3000000: Final[int] + B3500000: Final[int] + B4000000: Final[int] + B460800: Final[int] + B500000: Final[int] + B921600: Final[int] if sys.platform != "linux": - TCSASOFT: int + TCSASOFT: Final[int] if sys.platform != "darwin" and sys.platform != "linux": # not available on FreeBSD either. - CDEL: int - CEOL2: int - CESC: int - CNUL: int - COMMON: int - CSWTCH: int - IBSHIFT: int - INIT_C_CC: int - NSWTCH: int + CDEL: Final[int] + CEOL2: Final[int] + CESC: Final[int] + CNUL: Final[int] + COMMON: Final[int] + CSWTCH: Final[int] + IBSHIFT: Final[int] + INIT_C_CC: Final[int] + NSWTCH: Final[int] def tcgetattr(fd: FileDescriptorLike, /) -> _AttrReturn: """Get the tty attributes for file descriptor fd. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi index 796248b6aba06..5046965453766 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi @@ -24,7 +24,7 @@ if it is -1, mktime() should guess based on the date and time. import sys from _typeshed import structseq -from typing import Any, Final, Literal, Protocol, final +from typing import Any, Final, Literal, Protocol, final, type_check_only from typing_extensions import TypeAlias _TimeTuple: TypeAlias = tuple[int, int, int, int, int, int, int, int, int] @@ -250,6 +250,7 @@ if sys.platform != "win32": should not be relied on. """ +@type_check_only class _ClockInfo(Protocol): adjustable: bool implementation: str diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi index d7e6a912ad686..5625aac9c1253 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi @@ -589,12 +589,14 @@ def getboolean(s): _Ts = TypeVarTuple("_Ts") +@type_check_only class _GridIndexInfo(TypedDict, total=False): minsize: _ScreenUnits pad: _ScreenUnits uniform: str | None weight: int +@type_check_only class _BusyInfo(TypedDict): cursor: _Cursor @@ -2286,6 +2288,7 @@ class Tk(Misc, Wm): def loadtk(self) -> None: ... def record(self, script, /): ... if sys.version_info < (3, 11): + @deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.") def split(self, arg, /): ... def splitlist(self, arg, /): ... @@ -2298,6 +2301,7 @@ def Tcl(screenName: str | None = None, baseName: str | None = None, className: s _InMiscTotal = TypedDict("_InMiscTotal", {"in": Misc}) _InMiscNonTotal = TypedDict("_InMiscNonTotal", {"in": Misc}, total=False) +@type_check_only class _PackInfo(_InMiscTotal): # 'before' and 'after' never appear in _PackInfo anchor: _Anchor @@ -2365,6 +2369,7 @@ class Pack: forget = pack_forget propagate = Misc.pack_propagate +@type_check_only class _PlaceInfo(_InMiscNonTotal): # empty dict if widget hasn't been placed anchor: _Anchor bordermode: Literal["inside", "outside", "ignore"] @@ -2433,6 +2438,7 @@ class Place: place = place_configure info = place_info +@type_check_only class _GridInfo(_InMiscNonTotal): # empty dict if widget hasn't been gridded column: int columnspan: int diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/dnd.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/dnd.pyi index aafa9144f0aa0..18906bd604937 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/dnd.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/dnd.pyi @@ -100,10 +100,11 @@ active; it will never call dnd_commit(). """ from tkinter import Event, Misc, Tk, Widget -from typing import ClassVar, Protocol +from typing import ClassVar, Protocol, type_check_only __all__ = ["dnd_start", "DndHandler"] +@type_check_only class _DndSource(Protocol): def dnd_end(self, target: Widget | None, event: Event[Misc] | None, /) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/font.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/font.pyi index dd9deae85d2d2..879f51b1e6e60 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/font.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/font.pyi @@ -2,7 +2,7 @@ import _tkinter import itertools import sys import tkinter -from typing import Any, ClassVar, Final, Literal, TypedDict, overload +from typing import Any, ClassVar, Final, Literal, TypedDict, overload, type_check_only from typing_extensions import TypeAlias, Unpack __all__ = ["NORMAL", "ROMAN", "BOLD", "ITALIC", "nametofont", "Font", "families", "names"] @@ -23,6 +23,7 @@ _FontDescription: TypeAlias = ( | _tkinter.Tcl_Obj # A font object constructed in Tcl ) +@type_check_only class _FontDict(TypedDict): family: str size: int @@ -31,6 +32,7 @@ class _FontDict(TypedDict): underline: bool overstrike: bool +@type_check_only class _MetricsDict(TypedDict): ascent: int descent: int diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/ttk.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/ttk.pyi index c59ebf0969142..2a3f476235d81 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/ttk.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/ttk.pyi @@ -17,7 +17,7 @@ import tkinter from _typeshed import Incomplete, MaybeNone from collections.abc import Callable from tkinter.font import _FontDescription -from typing import Any, Literal, TypedDict, overload +from typing import Any, Literal, TypedDict, overload, type_check_only from typing_extensions import TypeAlias __all__ = [ @@ -1679,6 +1679,7 @@ class Spinbox(Entry): def set(self, value: Any) -> None: """Sets the value of the Spinbox to value.""" +@type_check_only class _TreeviewItemDict(TypedDict): text: str image: list[str] | Literal[""] # no idea why it's wrapped in list @@ -1686,6 +1687,7 @@ class _TreeviewItemDict(TypedDict): open: bool # actually 0 or 1 tags: list[str] | Literal[""] +@type_check_only class _TreeviewTagDict(TypedDict): # There is also 'text' and 'anchor', but they don't seem to do anything, using them is likely a bug foreground: str @@ -1693,6 +1695,7 @@ class _TreeviewTagDict(TypedDict): font: _FontDescription image: str # not wrapped in list :D +@type_check_only class _TreeviewHeaderDict(TypedDict): text: str image: list[str] | Literal[""] @@ -1700,6 +1703,7 @@ class _TreeviewHeaderDict(TypedDict): command: str state: str # Doesn't seem to appear anywhere else than in these dicts +@type_check_only class _TreeviewColumnDict(TypedDict): width: int minwidth: int diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tty.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tty.pyi index 00ef5c39dfbc4..0219428d92bba 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tty.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tty.pyi @@ -17,13 +17,13 @@ if sys.platform != "win32": _FD: TypeAlias = int | IO[str] # XXX: Undocumented integer constants - IFLAG: Final[int] - OFLAG: Final[int] - CFLAG: Final[int] - LFLAG: Final[int] - ISPEED: Final[int] - OSPEED: Final[int] - CC: Final[int] + IFLAG: Final = 0 + OFLAG: Final = 1 + CFLAG: Final = 2 + LFLAG: Final = 3 + ISPEED: Final = 4 + OSPEED: Final = 5 + CC: Final = 6 def setraw(fd: _FD, when: int = 2) -> _ModeSetterReturn: """Put terminal into raw mode.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi index 24f098d7bac76..8fbdfbc3bef03 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi @@ -80,8 +80,8 @@ from _typeshed import StrPath from collections.abc import Callable, Generator, Sequence from contextlib import contextmanager from tkinter import Canvas, Frame, Misc, PhotoImage, Scrollbar -from typing import Any, ClassVar, Literal, TypedDict, overload -from typing_extensions import Self, TypeAlias +from typing import Any, ClassVar, Literal, TypedDict, overload, type_check_only +from typing_extensions import Self, TypeAlias, deprecated __all__ = [ "ScrolledCanvas", @@ -223,6 +223,7 @@ if sys.version_info < (3, 13): _Color: TypeAlias = str | tuple[float, float, float] _AnyColor: TypeAlias = Any +@type_check_only class _PenState(TypedDict): shown: bool pendown: bool @@ -1725,6 +1726,7 @@ class RawTurtle(TPen, TNavigator): # type: ignore[misc] # Conflicting methods """ if sys.version_info < (3, 13): + @deprecated("Deprecated since Python 3.1; removed in Python 3.13. Use `tiltangle()` instead.") def settiltangle(self, angle: float) -> None: """Rotate the turtleshape to point in the specified direction @@ -3619,6 +3621,7 @@ def get_shapepoly() -> _PolygonCoords | None: """ if sys.version_info < (3, 13): + @deprecated("Deprecated since Python 3.1; removed in Python 3.13. Use `tiltangle()` instead.") def settiltangle(angle: float) -> None: """Rotate the turtleshape to point in the specified direction diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi index f62f5a72b751b..90743a7cc371f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi @@ -310,15 +310,15 @@ class TypeVar: contravariant: bool = False, ) -> None: ... if sys.version_info >= (3, 10): - def __or__(self, right: Any) -> _SpecialForm: # AnnotationForm + def __or__(self, right: Any, /) -> _SpecialForm: # AnnotationForm """Return self|value.""" - def __ror__(self, left: Any) -> _SpecialForm: # AnnotationForm + def __ror__(self, left: Any, /) -> _SpecialForm: # AnnotationForm """Return value|self.""" if sys.version_info >= (3, 11): - def __typing_subst__(self, arg: Any) -> Any: ... + def __typing_subst__(self, arg: Any, /) -> Any: ... if sys.version_info >= (3, 13): - def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ... + def __typing_prepare_subst__(self, alias: Any, args: Any, /) -> tuple[Any, ...]: ... def has_default(self) -> bool: ... if sys.version_info >= (3, 14): @property @@ -422,8 +422,8 @@ if sys.version_info >= (3, 11): def __iter__(self) -> Any: """Implement iter(self).""" - def __typing_subst__(self, arg: Never) -> Never: ... - def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ... + def __typing_subst__(self, arg: Never, /) -> Never: ... + def __typing_prepare_subst__(self, alias: Any, args: Any, /) -> tuple[Any, ...]: ... if sys.version_info >= (3, 14): @property def evaluate_default(self) -> EvaluateFunc | None: ... @@ -452,7 +452,7 @@ if sys.version_info >= (3, 10): else: def __init__(self, origin: ParamSpec) -> None: ... - def __eq__(self, other: object) -> bool: ... + def __eq__(self, other: object, /) -> bool: ... __hash__: ClassVar[None] # type: ignore[assignment] @final @@ -478,7 +478,7 @@ if sys.version_info >= (3, 10): else: def __init__(self, origin: ParamSpec) -> None: ... - def __eq__(self, other: object) -> bool: ... + def __eq__(self, other: object, /) -> bool: ... __hash__: ClassVar[None] # type: ignore[assignment] @final @@ -598,13 +598,13 @@ if sys.version_info >= (3, 10): def kwargs(self) -> ParamSpecKwargs: """Represents keyword arguments.""" if sys.version_info >= (3, 11): - def __typing_subst__(self, arg: Any) -> Any: ... - def __typing_prepare_subst__(self, alias: Any, args: Any) -> tuple[Any, ...]: ... + def __typing_subst__(self, arg: Any, /) -> Any: ... + def __typing_prepare_subst__(self, alias: Any, args: Any, /) -> tuple[Any, ...]: ... - def __or__(self, right: Any) -> _SpecialForm: + def __or__(self, right: Any, /) -> _SpecialForm: """Return self|value.""" - def __ror__(self, left: Any) -> _SpecialForm: + def __ror__(self, left: Any, /) -> _SpecialForm: """Return value|self.""" if sys.version_info >= (3, 13): def has_default(self) -> bool: ... @@ -738,6 +738,7 @@ def type_check_only(func_or_cls: _FT) -> _FT: ... # Type aliases and type constructors +@type_check_only class _Alias: # Class for defining generic aliases for library types. def __getitem__(self, typeargs: Any) -> Any: ... @@ -1993,13 +1994,13 @@ if sys.version_info >= (3, 12): # It's writable on types, but not on instances of TypeAliasType. @property def __module__(self) -> str | None: ... # type: ignore[override] - def __getitem__(self, parameters: Any) -> GenericAlias: # AnnotationForm + def __getitem__(self, parameters: Any, /) -> GenericAlias: # AnnotationForm """Return self[key].""" - def __or__(self, right: Any) -> _SpecialForm: + def __or__(self, right: Any, /) -> _SpecialForm: """Return self|value.""" - def __ror__(self, left: Any) -> _SpecialForm: + def __ror__(self, left: Any, /) -> _SpecialForm: """Return value|self.""" if sys.version_info >= (3, 14): @property @@ -2037,6 +2038,7 @@ if sys.version_info >= (3, 13): """ @final + @type_check_only class _NoDefaultType: ... NoDefault: _NoDefaultType diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi index 862f678795933..49a80fcd14b3c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi @@ -901,6 +901,7 @@ else: """ @final + @type_check_only class _NoDefaultType: ... NoDefault: _NoDefaultType @@ -1122,8 +1123,8 @@ else: def __getitem__(self, parameters: Incomplete | tuple[Incomplete, ...]) -> AnnotationForm: ... def __init_subclass__(cls, *args: Unused, **kwargs: Unused) -> NoReturn: ... if sys.version_info >= (3, 10): - def __or__(self, right: Any) -> _SpecialForm: ... - def __ror__(self, left: Any) -> _SpecialForm: ... + def __or__(self, right: Any, /) -> _SpecialForm: ... + def __ror__(self, left: Any, /) -> _SpecialForm: ... # PEP 727 class Doc: @@ -1150,6 +1151,7 @@ class Doc: def __eq__(self, other: object) -> bool: ... # PEP 728 +@type_check_only class _NoExtraItemsType: ... NoExtraItems: _NoExtraItemsType diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/case.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/case.pyi index 5cc1f2cf18552..9f738eb049046 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/case.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/case.pyi @@ -9,7 +9,7 @@ from collections.abc import Callable, Container, Iterable, Mapping, Sequence, Se from contextlib import AbstractContextManager from re import Pattern from types import GenericAlias, TracebackType -from typing import Any, AnyStr, Final, Generic, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload +from typing import Any, AnyStr, Final, Generic, NoReturn, Protocol, SupportsAbs, SupportsRound, TypeVar, overload, type_check_only from typing_extensions import Never, ParamSpec, Self from unittest._log import _AssertLogsContext, _LoggingWatcher from warnings import WarningMessage @@ -90,6 +90,7 @@ class SkipTest(Exception): def __init__(self, reason: str) -> None: ... +@type_check_only class _SupportsAbsAndDunderGE(SupportsDunderGE[Any], SupportsAbs[Any], Protocol): ... class TestCase: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi index cd55eae32a32d..924967d7f294d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi @@ -7,12 +7,13 @@ import unittest.result import unittest.suite from collections.abc import Iterable from types import ModuleType -from typing import Any, Final, Protocol +from typing import Any, Final, Protocol, type_check_only from typing_extensions import deprecated MAIN_EXAMPLES: Final[str] MODULE_EXAMPLES: Final[str] +@type_check_only class _TestRunner(Protocol): def run(self, test: unittest.suite.TestSuite | unittest.case.TestCase, /) -> unittest.result.TestResult: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi index be34f90126ad1..ba2ba19d86427 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi @@ -3,7 +3,7 @@ from _typeshed import MaybeNone from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, Sequence from contextlib import _GeneratorContextManager from types import TracebackType -from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload +from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload, type_check_only from typing_extensions import ParamSpec, Self, TypeAlias _T = TypeVar("_T") @@ -456,6 +456,7 @@ class _patch(Generic[_T]): # This class does not exist at runtime, it's a hack to make this work: # @patch("foo") # def bar(..., mock: MagicMock) -> None: ... +@type_check_only class _patch_pass_arg(_patch[_T]): @overload def __call__(self, func: _TT) -> _TT: ... @@ -514,6 +515,7 @@ class _patch_dict: # This class does not exist at runtime, it's a hack to add methods to the # patch() function. +@type_check_only class _patcher: TEST_PREFIX: str dict: type[_patch_dict] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/runner.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/runner.pyi index e98d381cf3f4f..3f5a9406879f2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/runner.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/runner.pyi @@ -6,15 +6,17 @@ import unittest.result import unittest.suite from _typeshed import SupportsFlush, SupportsWrite from collections.abc import Callable, Iterable -from typing import Any, Generic, Protocol, TypeVar +from typing import Any, Generic, Protocol, TypeVar, type_check_only from typing_extensions import Never, TypeAlias from warnings import _ActionKind _ResultClassType: TypeAlias = Callable[[_TextTestStream, bool, int], TextTestResult[Any]] +@type_check_only class _SupportsWriteAndFlush(SupportsWrite[str], SupportsFlush, Protocol): ... # All methods used by unittest.runner.TextTestResult's stream +@type_check_only class _TextTestStream(_SupportsWriteAndFlush, Protocol): def writeln(self, arg: str | None = None, /) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/urllib/request.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/urllib/request.pyi index 71e3273b5b960..4d9636102ed5c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/urllib/request.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/urllib/request.pyi @@ -75,7 +75,7 @@ from email.message import Message from http.client import HTTPConnection, HTTPMessage, HTTPResponse from http.cookiejar import CookieJar from re import Pattern -from typing import IO, Any, ClassVar, NoReturn, Protocol, TypeVar, overload +from typing import IO, Any, ClassVar, NoReturn, Protocol, TypeVar, overload, type_check_only from typing_extensions import TypeAlias, deprecated from urllib.error import HTTPError as HTTPError from urllib.response import addclosehook, addinfourl @@ -482,6 +482,7 @@ class ProxyDigestAuthHandler(BaseHandler, AbstractDigestAuthHandler): auth_header: ClassVar[str] # undocumented def http_error_407(self, req: Request, fp: IO[bytes], code: int, msg: str, headers: HTTPMessage) -> _UrlopenRet | None: ... +@type_check_only class _HTTPConnectionProtocol(Protocol): def __call__( self, @@ -594,7 +595,7 @@ def urlcleanup() -> None: """Clean up temporary files from urlretrieve calls.""" if sys.version_info < (3, 14): - @deprecated("Deprecated since Python 3.3; Removed in 3.14; Use newer urlopen functions and methods.") + @deprecated("Deprecated since Python 3.3; removed in Python 3.14. Use newer `urlopen` functions and methods.") class URLopener: """Class to open URLs. This is a class rather than just a subroutine because we may need @@ -667,7 +668,7 @@ if sys.version_info < (3, 14): def __del__(self) -> None: ... - @deprecated("Deprecated since Python 3.3; Removed in 3.14; Use newer urlopen functions and methods.") + @deprecated("Deprecated since Python 3.3; removed in Python 3.14. Use newer `urlopen` functions and methods.") class FancyURLopener(URLopener): """Derived class with handlers for errors we can handle (perhaps).""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi index 328e1313869d4..ca9a49b033e04 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi @@ -550,7 +550,7 @@ if sys.platform == "win32": def __enter__(self) -> Self: ... def __exit__( - self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None + self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None, / ) -> bool | None: ... def Close(self) -> None: """Closes the underlying Windows handle. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi index 0db4877863b83..e455f0f4b2cd1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi @@ -20,7 +20,7 @@ from _collections_abc import dict_keys, dict_values from _typeshed import Incomplete, ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Iterable, Sequence from types import TracebackType -from typing import Any, ClassVar, Generic, Literal, NoReturn, Protocol, TypeVar, overload +from typing import Any, ClassVar, Generic, Literal, NoReturn, Protocol, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias from xml.dom.minicompat import EmptyNodeList, NodeList from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS @@ -57,9 +57,11 @@ _ImportableNodeVar = TypeVar( | Notation, ) +@type_check_only class _DOMErrorHandler(Protocol): def handleError(self, error: Exception) -> bool: ... +@type_check_only class _UserDataHandler(Protocol): def handle(self, operation: int, key: str, data: Any, src: Node, dst: Node) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi index 8f20ee15a14e5..fd829fdaa5ffc 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi @@ -1,7 +1,8 @@ from _typeshed import FileDescriptorOrPath -from typing import Final, Literal, Protocol, overload +from typing import Final, Literal, Protocol, overload, type_check_only from xml.etree.ElementTree import Element +@type_check_only class _Loader(Protocol): @overload def __call__(self, href: FileDescriptorOrPath, parse: Literal["xml"], encoding: str | None = None) -> Element: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi index 68576c31a3774..a92ae79cbd1ea 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi @@ -663,6 +663,7 @@ class C14NWriterTarget: # The target type is tricky, because the implementation doesn't # require any particular attribute to be present. This documents the attributes # that can be present, but uncommenting any of them would require them. +@type_check_only class _Target(Protocol): # start: Callable[str, dict[str, str], Any] | None # end: Callable[[str], Any] | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi index 720ca5c57cf15..e9f5a4de555ea 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi @@ -22,7 +22,7 @@ expatreader -- Driver that allows use of the Expat parser with SAX. import sys from _typeshed import ReadableBuffer, StrPath, SupportsRead, _T_co from collections.abc import Iterable -from typing import Protocol +from typing import Protocol, type_check_only from typing_extensions import TypeAlias from xml.sax._exceptions import ( SAXException as SAXException, @@ -34,6 +34,7 @@ from xml.sax._exceptions import ( from xml.sax.handler import ContentHandler as ContentHandler, ErrorHandler as ErrorHandler from xml.sax.xmlreader import InputSource as InputSource, XMLReader +@type_check_only class _SupportsReadClose(SupportsRead[_T_co], Protocol[_T_co]): def close(self) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/client.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/client.pyi index 02c4e94bebd6f..7a00f503ef763 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/client.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/client.pyi @@ -48,9 +48,10 @@ from collections.abc import Callable, Iterable, Mapping from datetime import datetime from io import BytesIO from types import TracebackType -from typing import Any, ClassVar, Final, Literal, Protocol, overload +from typing import Any, ClassVar, Final, Literal, Protocol, overload, type_check_only from typing_extensions import Self, TypeAlias +@type_check_only class _SupportsTimeTuple(Protocol): def timetuple(self) -> time.struct_time: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/server.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/server.pyi index 0f9592e53a8c6..8b0c3fc8ee8d3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/server.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xmlrpc/server.pyi @@ -107,28 +107,34 @@ import socketserver from _typeshed import ReadableBuffer from collections.abc import Callable, Iterable, Mapping from re import Pattern -from typing import Any, ClassVar, Protocol +from typing import Any, ClassVar, Protocol, type_check_only from typing_extensions import TypeAlias from xmlrpc.client import Fault, _Marshallable # The dispatch accepts anywhere from 0 to N arguments, no easy way to allow this in mypy +@type_check_only class _DispatchArity0(Protocol): def __call__(self) -> _Marshallable: ... +@type_check_only class _DispatchArity1(Protocol): def __call__(self, arg1: _Marshallable, /) -> _Marshallable: ... +@type_check_only class _DispatchArity2(Protocol): def __call__(self, arg1: _Marshallable, arg2: _Marshallable, /) -> _Marshallable: ... +@type_check_only class _DispatchArity3(Protocol): def __call__(self, arg1: _Marshallable, arg2: _Marshallable, arg3: _Marshallable, /) -> _Marshallable: ... +@type_check_only class _DispatchArity4(Protocol): def __call__( self, arg1: _Marshallable, arg2: _Marshallable, arg3: _Marshallable, arg4: _Marshallable, / ) -> _Marshallable: ... +@type_check_only class _DispatchArityN(Protocol): def __call__(self, *args: _Marshallable) -> _Marshallable: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi index 1e01e76c5ab29..945c3d7365a4f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi @@ -11,7 +11,7 @@ from collections.abc import Callable, Iterable, Iterator from io import TextIOWrapper from os import PathLike from types import TracebackType -from typing import IO, Final, Literal, Protocol, overload +from typing import IO, Final, Literal, Protocol, overload, type_check_only from typing_extensions import Self, TypeAlias __all__ = [ @@ -51,6 +51,7 @@ class LargeZipFile(Exception): and those extensions are disabled. """ +@type_check_only class _ZipStream(Protocol): def read(self, n: int, /) -> bytes: ... # The following methods are optional: @@ -59,11 +60,13 @@ class _ZipStream(Protocol): # def seek(self, n: int, /) -> object: ... # Stream shape as required by _EndRecData() and _EndRecData64(). +@type_check_only class _SupportsReadSeekTell(Protocol): def read(self, n: int = ..., /) -> bytes: ... def seek(self, cookie: int, whence: int, /) -> object: ... def tell(self) -> int: ... +@type_check_only class _ClosableZipStream(_ZipStream, Protocol): def close(self) -> object: ... @@ -120,18 +123,23 @@ class ZipExtFile(io.BufferedIOBase): def seek(self, offset: int, whence: int = 0) -> int: ... +@type_check_only class _Writer(Protocol): def write(self, s: str, /) -> object: ... +@type_check_only class _ZipReadable(Protocol): def seek(self, offset: int, whence: int = 0, /) -> int: ... def read(self, n: int = -1, /) -> bytes: ... +@type_check_only class _ZipTellable(Protocol): def tell(self) -> int: ... +@type_check_only class _ZipReadableTellable(_ZipReadable, _ZipTellable, Protocol): ... +@type_check_only class _ZipWritable(Protocol): def flush(self) -> None: ... def close(self) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/zipimport.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/zipimport.pyi index 1cd54d940bb3c..d0025b07f0521 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/zipimport.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/zipimport.pyi @@ -53,30 +53,54 @@ class zipimporter(_LoaderBasics): def __init__(self, path: StrOrBytesPath) -> None: ... if sys.version_info < (3, 12): - def find_loader(self, fullname: str, path: str | None = None) -> tuple[zipimporter | None, list[str]]: # undocumented - """find_loader(fullname, path=None) -> self, str or None. - - Search for a module specified by 'fullname'. 'fullname' must be the - fully qualified (dotted) module name. It returns the zipimporter - instance itself if the module was found, a string containing the - full path name if it's possibly a portion of a namespace package, - or None otherwise. The optional 'path' argument is ignored -- it's - there for compatibility with the importer protocol. - - Deprecated since Python 3.10. Use find_spec() instead. - """ - - def find_module(self, fullname: str, path: str | None = None) -> zipimporter | None: - """find_module(fullname, path=None) -> self or None. - - Search for a module specified by 'fullname'. 'fullname' must be the - fully qualified (dotted) module name. It returns the zipimporter - instance itself if the module was found, or None if it wasn't. - The optional 'path' argument is ignored -- it's there for compatibility - with the importer protocol. - - Deprecated since Python 3.10. Use find_spec() instead. - """ + if sys.version_info >= (3, 10): + @deprecated("Deprecated since Python 3.10; removed in Python 3.12. Use `find_spec()` instead.") + def find_loader(self, fullname: str, path: str | None = None) -> tuple[zipimporter | None, list[str]]: + """find_loader(fullname, path=None) -> self, str or None. + + Search for a module specified by 'fullname'. 'fullname' must be the + fully qualified (dotted) module name. It returns the zipimporter + instance itself if the module was found, a string containing the + full path name if it's possibly a portion of a namespace package, + or None otherwise. The optional 'path' argument is ignored -- it's + there for compatibility with the importer protocol. + + Deprecated since Python 3.10. Use find_spec() instead. + """ + + @deprecated("Deprecated since Python 3.10; removed in Python 3.12. Use `find_spec()` instead.") + def find_module(self, fullname: str, path: str | None = None) -> zipimporter | None: + """find_module(fullname, path=None) -> self or None. + + Search for a module specified by 'fullname'. 'fullname' must be the + fully qualified (dotted) module name. It returns the zipimporter + instance itself if the module was found, or None if it wasn't. + The optional 'path' argument is ignored -- it's there for compatibility + with the importer protocol. + + Deprecated since Python 3.10. Use find_spec() instead. + """ + else: + def find_loader(self, fullname: str, path: str | None = None) -> tuple[zipimporter | None, list[str]]: + """find_loader(fullname, path=None) -> self, str or None. + + Search for a module specified by 'fullname'. 'fullname' must be the + fully qualified (dotted) module name. It returns the zipimporter + instance itself if the module was found, a string containing the + full path name if it's possibly a portion of a namespace package, + or None otherwise. The optional 'path' argument is ignored -- it's + there for compatibility with the importer protocol. + """ + + def find_module(self, fullname: str, path: str | None = None) -> zipimporter | None: + """find_module(fullname, path=None) -> self or None. + + Search for a module specified by 'fullname'. 'fullname' must be the + fully qualified (dotted) module name. It returns the zipimporter + instance itself if the module was found, or None if it wasn't. + The optional 'path' argument is ignored -- it's there for compatibility + with the importer protocol. + """ def get_code(self, fullname: str) -> CodeType: """get_code(fullname) -> code object. @@ -126,18 +150,18 @@ class zipimporter(_LoaderBasics): Return True if the module specified by fullname is a package. Raise ZipImportError if the module couldn't be found. """ + if sys.version_info >= (3, 10): + @deprecated("Deprecated since Python 3.10; removed in Python 3.15. Use `exec_module()` instead.") + def load_module(self, fullname: str) -> ModuleType: + """load_module(fullname) -> module. - @deprecated("Deprecated since 3.10; use exec_module() instead") - def load_module(self, fullname: str) -> ModuleType: - """load_module(fullname) -> module. + Load the module specified by 'fullname'. 'fullname' must be the + fully qualified (dotted) module name. It returns the imported + module, or raises ZipImportError if it could not be imported. - Load the module specified by 'fullname'. 'fullname' must be the - fully qualified (dotted) module name. It returns the imported - module, or raises ZipImportError if it could not be imported. + Deprecated since Python 3.10. Use exec_module() instead. + """ - Deprecated since Python 3.10. Use exec_module() instead. - """ - if sys.version_info >= (3, 10): def exec_module(self, module: ModuleType) -> None: """Execute the module.""" @@ -152,3 +176,11 @@ class zipimporter(_LoaderBasics): def invalidate_caches(self) -> None: """Invalidates the cache of file data of the archive path.""" + else: + def load_module(self, fullname: str) -> ModuleType: + """load_module(fullname) -> module. + + Load the module specified by 'fullname'. 'fullname' must be the + fully qualified (dotted) module name. It returns the imported + module, or raises ZipImportError if it wasn't found. + """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/zlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/zlib.pyi index 93e1ac5c1e77f..97d70804a36fe 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/zlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/zlib.pyi @@ -19,11 +19,11 @@ from typing import Any, Final, final, type_check_only from typing_extensions import Self DEFLATED: Final = 8 -DEF_MEM_LEVEL: int # can change +DEF_MEM_LEVEL: Final[int] DEF_BUF_SIZE: Final = 16384 -MAX_WBITS: int -ZLIB_VERSION: str # can change -ZLIB_RUNTIME_VERSION: str # can change +MAX_WBITS: Final[int] +ZLIB_VERSION: Final[str] +ZLIB_RUNTIME_VERSION: Final[str] Z_NO_COMPRESSION: Final = 0 Z_PARTIAL_FLUSH: Final = 1 Z_BEST_COMPRESSION: Final = 9 @@ -41,6 +41,10 @@ Z_RLE: Final = 3 Z_SYNC_FLUSH: Final = 2 Z_TREES: Final = 6 +if sys.version_info >= (3, 14) and sys.platform == "win32": + # Available when zlib was built with zlib-ng, usually only on Windows + ZLIBNG_VERSION: Final[str] + class error(Exception): ... # This class is not exposed at runtime. It calls itself zlib.Compress. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/_common.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/_common.pyi index b527aab5669f5..69ddef03f693a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/_common.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/_common.pyi @@ -1,6 +1,7 @@ import io -from typing import Any, Protocol +from typing import Any, Protocol, type_check_only +@type_check_only class _IOBytes(Protocol): def read(self, size: int, /) -> bytes: ... def seek(self, size: int, whence: int = ..., /) -> Any: ... From 6de84ed56eac4f1f3efe9d8a9d47c9b30a445707 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 15 Aug 2025 14:52:30 +0100 Subject: [PATCH 008/160] Add `else`-branch narrowing for `if type(a) is A` when `A` is `@final` (#19925) --- .../resources/mdtest/narrow/type.md | 44 ++++++++++++++++++- crates/ty_python_semantic/src/types/narrow.rs | 9 ++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/type.md b/crates/ty_python_semantic/resources/mdtest/narrow/type.md index 004d53be3fa97..0376ca8d0466c 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/type.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/type.md @@ -3,10 +3,15 @@ ## `type(x) is C` ```py +from typing import final + class A: ... class B: ... -def _(x: A | B): +@final +class C: ... + +def _(x: A | B, y: A | C): if type(x) is A: reveal_type(x) # revealed: A else: @@ -14,20 +19,55 @@ def _(x: A | B): # of `x` could be a subclass of `A`, so we need # to infer the full union type: reveal_type(x) # revealed: A | B + + if type(y) is C: + reveal_type(y) # revealed: C + else: + # here, however, inferring `A` is fine, + # because `C` is `@final`: no subclass of `A` + # and `C` could exist + reveal_type(y) # revealed: A + + if type(y) is A: + reveal_type(y) # revealed: A + else: + # but here, `type(y)` could be a subclass of `A`, + # in which case the `type(y) is A` call would evaluate + # to `False` even if `y` was an instance of `A`, + # so narrowing cannot occur + reveal_type(y) # revealed: A | C ``` ## `type(x) is not C` ```py +from typing import final + class A: ... class B: ... -def _(x: A | B): +@final +class C: ... + +def _(x: A | B, y: A | C): if type(x) is not A: # Same reasoning as above: no narrowing should occur here. reveal_type(x) # revealed: A | B else: reveal_type(x) # revealed: A + + if type(y) is not C: + # same reasoning as above: narrowing *can* occur here because `C` is `@final` + reveal_type(y) # revealed: A + else: + reveal_type(y) # revealed: C + + if type(y) is not A: + # same reasoning as above: narrowing *cannot* occur here + # because `A` is not `@final` + reveal_type(y) # revealed: A | C + else: + reveal_type(y) # revealed: A ``` ## `type(x) == C`, `type(x) != C` diff --git a/crates/ty_python_semantic/src/types/narrow.rs b/crates/ty_python_semantic/src/types/narrow.rs index 2693570e1c228..39c2ba402dfef 100644 --- a/crates/ty_python_semantic/src/types/narrow.rs +++ b/crates/ty_python_semantic/src/types/narrow.rs @@ -772,13 +772,15 @@ impl<'db, 'ast> NarrowingConstraintsBuilder<'db, 'ast> { _ => continue, }; - let is_valid_constraint = if is_positive { + let is_positive = if is_positive { op == &ast::CmpOp::Is } else { op == &ast::CmpOp::IsNot }; - if !is_valid_constraint { + // `else`-branch narrowing for `if type(x) is Y` can only be done + // if `Y` is a final class + if !rhs_class.is_final(self.db) && !is_positive { continue; } @@ -791,7 +793,8 @@ impl<'db, 'ast> NarrowingConstraintsBuilder<'db, 'ast> { let place = self.expect_place(&target); constraints.insert( place, - Type::instance(self.db, rhs_class.unknown_specialization(self.db)), + Type::instance(self.db, rhs_class.unknown_specialization(self.db)) + .negate_if(self.db, !is_positive), ); } } From f344dda82c0478b8ea3cc2d510b21e7933f4c89c Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 15 Aug 2025 17:55:38 +0200 Subject: [PATCH 009/160] Bump Rust MSRV to 1.87 (#19924) --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index bed513fe3de47..ce3061284af48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ resolver = "2" [workspace.package] # Please update rustfmt.toml when bumping the Rust edition edition = "2024" -rust-version = "1.86" +rust-version = "1.87" homepage = "https://docs.astral.sh/ruff" documentation = "https://docs.astral.sh/ruff" repository = "https://github.com/astral-sh/ruff" From 9ced219ffcc698c2fa99c0580d09ee79889a8cf6 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 15 Aug 2025 17:52:14 +0100 Subject: [PATCH 010/160] [ty] Remove incorrect type narrowing for `if type(x) is C[int]` (#19926) --- .../resources/mdtest/narrow/type.md | 50 +++++++++++++++++++ crates/ty_python_semantic/src/types/narrow.rs | 8 +-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/type.md b/crates/ty_python_semantic/resources/mdtest/narrow/type.md index 0376ca8d0466c..ef754d021ae7e 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/type.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/type.md @@ -70,6 +70,56 @@ def _(x: A | B, y: A | C): reveal_type(y) # revealed: A ``` +## No narrowing for `type(x) is C[int]` + +At runtime, `type(x)` will never return a generic alias object (only ever a class-literal object), +so no narrowing can occur if `type(x)` is compared with a generic alias object. + +```toml +[environment] +python-version = "3.12" +``` + +```py +class A[T]: ... +class B: ... + +def f(x: A[int] | B): + if type(x) is A[int]: + # this branch is actually unreachable -- we *could* reveal `Never` here! + reveal_type(x) # revealed: A[int] | B + else: + reveal_type(x) # revealed: A[int] | B + + if type(x) is A: + # TODO: this should be `A[int]`, but `A[int] | B` would be better than `Never` + reveal_type(x) # revealed: Never + else: + reveal_type(x) # revealed: A[int] | B + + if type(x) is B: + reveal_type(x) # revealed: B + else: + reveal_type(x) # revealed: A[int] | B + + if type(x) is not A[int]: + reveal_type(x) # revealed: A[int] | B + else: + # this branch is actually unreachable -- we *could* reveal `Never` here! + reveal_type(x) # revealed: A[int] | B + + if type(x) is not A: + reveal_type(x) # revealed: A[int] | B + else: + # TODO: this should be `A[int]`, but `A[int] | B` would be better than `Never` + reveal_type(x) # revealed: Never + + if type(x) is not B: + reveal_type(x) # revealed: A[int] | B + else: + reveal_type(x) # revealed: B +``` + ## `type(x) == C`, `type(x) != C` No narrowing can occur for equality comparisons, since there might be a custom `__eq__` diff --git a/crates/ty_python_semantic/src/types/narrow.rs b/crates/ty_python_semantic/src/types/narrow.rs index 39c2ba402dfef..8569c961d5d8d 100644 --- a/crates/ty_python_semantic/src/types/narrow.rs +++ b/crates/ty_python_semantic/src/types/narrow.rs @@ -756,12 +756,8 @@ impl<'db, 'ast> NarrowingConstraintsBuilder<'db, 'ast> { node_index: _, }, }) if keywords.is_empty() => { - let rhs_class = match rhs_ty { - Type::ClassLiteral(class) => class, - Type::GenericAlias(alias) => alias.origin(self.db), - _ => { - continue; - } + let Type::ClassLiteral(rhs_class) = rhs_ty else { + continue; }; let target = match &**args { From 26d6c3831f237a511507c9cf5498e89f6f1d72d4 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 15 Aug 2025 18:20:14 +0100 Subject: [PATCH 011/160] [ty] Represent `NamedTuple` as an opaque special form, not a class (#19915) --- .../resources/mdtest/named_tuple.md | 82 +++++++++++++++++++ crates/ty_python_semantic/src/types.rs | 21 ++++- crates/ty_python_semantic/src/types/class.rs | 32 ++++---- .../src/types/class_base.rs | 26 +++--- crates/ty_python_semantic/src/types/infer.rs | 34 +++++--- .../src/types/special_form.rs | 10 +++ .../ty_extensions/ty_extensions.pyi | 25 +++++- 7 files changed, 182 insertions(+), 48 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/named_tuple.md b/crates/ty_python_semantic/resources/mdtest/named_tuple.md index e642b25b2eb8d..94070455c9d68 100644 --- a/crates/ty_python_semantic/resources/mdtest/named_tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/named_tuple.md @@ -268,6 +268,88 @@ alice = Person(1, "Alice", 42) bob = Person(2, "Bob") ``` +## The symbol `NamedTuple` itself + +At runtime, `NamedTuple` is a function, and we understand this: + +```py +import types +import typing + +def expects_functiontype(x: types.FunctionType): ... + +expects_functiontype(typing.NamedTuple) +``` + +This means we also understand that all attributes on function objects are available on the symbol +`typing.NamedTuple`: + +```py +reveal_type(typing.NamedTuple.__name__) # revealed: str +reveal_type(typing.NamedTuple.__qualname__) # revealed: str +reveal_type(typing.NamedTuple.__kwdefaults__) # revealed: dict[str, Any] | None + +# TODO: this should cause us to emit a diagnostic and reveal `Unknown` (function objects don't have an `__mro__` attribute), +# but the fact that we don't isn't actually a `NamedTuple` bug (https://github.com/astral-sh/ty/issues/986) +reveal_type(typing.NamedTuple.__mro__) # revealed: tuple[, ] +``` + +By the normal rules, `NamedTuple` and `type[NamedTuple]` should not be valid in type expressions -- +there is no object at runtime that is an "instance of `NamedTuple`", nor is there any class at +runtime that is a "subclass of `NamedTuple`" -- these are both impossible, since `NamedTuple` is a +function and not a class. However, for compatibility with other type checkers, we allow `NamedTuple` +in type expressions and understand it as describing an interface that all `NamedTuple` classes would +satisfy: + +```py +def expects_named_tuple(x: typing.NamedTuple): + reveal_type(x) # revealed: tuple[object, ...] & NamedTupleLike + reveal_type(x._make) # revealed: bound method type[NamedTupleLike]._make(iterable: Iterable[Any]) -> Self@_make + reveal_type(x._replace) # revealed: bound method NamedTupleLike._replace(**kwargs) -> Self@_replace + # revealed: Overload[(value: tuple[object, ...], /) -> tuple[object, ...], (value: tuple[_T@__add__, ...], /) -> tuple[object, ...]] + reveal_type(x.__add__) + reveal_type(x.__iter__) # revealed: bound method tuple[object, ...].__iter__() -> Iterator[object] + +def _(y: type[typing.NamedTuple]): + reveal_type(y) # revealed: @Todo(unsupported type[X] special form) +``` + +Any instance of a `NamedTuple` class can therefore be passed for a function parameter that is +annotated with `NamedTuple`: + +```py +from typing import NamedTuple, Protocol, Iterable, Any +from ty_extensions import static_assert, is_assignable_to + +class Point(NamedTuple): + x: int + y: int + +reveal_type(Point._make) # revealed: bound method ._make(iterable: Iterable[Any]) -> Self@_make +reveal_type(Point._asdict) # revealed: def _asdict(self) -> dict[str, Any] +reveal_type(Point._replace) # revealed: def _replace(self, **kwargs: Any) -> Self@_replace + +static_assert(is_assignable_to(Point, NamedTuple)) + +expects_named_tuple(Point(x=42, y=56)) # fine + +# error: [invalid-argument-type] "Argument to function `expects_named_tuple` is incorrect: Expected `tuple[object, ...] & NamedTupleLike`, found `tuple[Literal[1], Literal[2]]`" +expects_named_tuple((1, 2)) +``` + +The type described by `NamedTuple` in type expressions is understood as being assignable to +`tuple[object, ...]` and `tuple[Any, ...]`: + +```py +static_assert(is_assignable_to(NamedTuple, tuple)) +static_assert(is_assignable_to(NamedTuple, tuple[object, ...])) +static_assert(is_assignable_to(NamedTuple, tuple[Any, ...])) + +def expects_tuple(x: tuple[object, ...]): ... +def _(x: NamedTuple): + expects_tuple(x) # fine +``` + ## NamedTuple with custom `__getattr__` This is a regression test for . Make sure that the diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 89b66a6b343a3..ad7a4c0ade918 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -4264,10 +4264,6 @@ impl<'db> Type<'db> { .into() } - Some(KnownClass::NamedTuple) => { - Binding::single(self, Signature::todo("functional `NamedTuple` syntax")).into() - } - Some(KnownClass::Object) => { // ```py // class object: @@ -4583,6 +4579,10 @@ impl<'db> Type<'db> { .into() } + Type::SpecialForm(SpecialFormType::NamedTuple) => { + Binding::single(self, Signature::todo("functional `NamedTuple` syntax")).into() + } + Type::GenericAlias(_) => { // TODO annotated return type on `__new__` or metaclass `__call__` // TODO check call vs signatures of `__new__` and/or `__init__` @@ -5471,6 +5471,19 @@ impl<'db> Type<'db> { // TODO: Use an opt-in rule for a bare `Callable` SpecialFormType::Callable => Ok(CallableType::unknown(db)), + // Special case: `NamedTuple` in a type expression is understood to describe the type + // `tuple[object, ...] & `. + // This isn't very principled (since at runtime, `NamedTuple` is just a function), + // but it appears to be what users often expect, and it improves compatibility with + // other type checkers such as mypy. + // See conversation in https://github.com/astral-sh/ruff/pull/19915. + SpecialFormType::NamedTuple => Ok(IntersectionBuilder::new(db) + .positive_elements([ + Type::homogeneous_tuple(db, Type::object(db)), + KnownClass::NamedTupleLike.to_instance(db), + ]) + .build()), + SpecialFormType::TypingSelf => { let module = parsed_module(db, scope_id.file(db)).load(db); let index = semantic_index(db, scope_id.file(db)); diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 60cf7c491e417..cd749f8444060 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -197,10 +197,7 @@ impl CodeGeneratorKind { Some(CodeGeneratorKind::DataclassLike) } else if class .explicit_bases(db) - .iter() - .copied() - .filter_map(Type::into_class_literal) - .any(|class| class.is_known(db, KnownClass::NamedTuple)) + .contains(&Type::SpecialForm(SpecialFormType::NamedTuple)) { Some(CodeGeneratorKind::NamedTuple) } else if class.is_typed_dict(db) { @@ -3137,7 +3134,6 @@ pub enum KnownClass { TypeVarTuple, TypeAliasType, NoDefaultType, - NamedTuple, NewType, SupportsIndex, Iterable, @@ -3160,6 +3156,7 @@ pub enum KnownClass { InitVar, // _typeshed._type_checker_internals NamedTupleFallback, + NamedTupleLike, TypedDictFallback, } @@ -3245,8 +3242,6 @@ impl KnownClass { | Self::ABCMeta | Self::Iterable | Self::Iterator - // Empty tuples are AlwaysFalse; non-empty tuples are AlwaysTrue - | Self::NamedTuple // Evaluating `NotImplementedType` in a boolean context was deprecated in Python 3.9 // and raises a `TypeError` in Python >=3.14 // (see https://docs.python.org/3/library/constants.html#NotImplemented) @@ -3260,6 +3255,7 @@ impl KnownClass { | Self::KwOnly | Self::InitVar | Self::NamedTupleFallback + | Self::NamedTupleLike | Self::TypedDictFallback => Some(Truthiness::Ambiguous), Self::Tuple => None, @@ -3342,8 +3338,8 @@ impl KnownClass { | Self::ExceptionGroup | Self::Field | Self::SupportsIndex - | Self::NamedTuple | Self::NamedTupleFallback + | Self::NamedTupleLike | Self::TypedDictFallback | Self::Counter | Self::DefaultDict @@ -3412,7 +3408,6 @@ impl KnownClass { | KnownClass::TypeVarTuple | KnownClass::TypeAliasType | KnownClass::NoDefaultType - | KnownClass::NamedTuple | KnownClass::NewType | KnownClass::SupportsIndex | KnownClass::Iterable @@ -3429,6 +3424,7 @@ impl KnownClass { | KnownClass::KwOnly | KnownClass::InitVar | KnownClass::NamedTupleFallback + | KnownClass::NamedTupleLike | KnownClass::TypedDictFallback => false, } } @@ -3489,7 +3485,6 @@ impl KnownClass { | KnownClass::TypeVarTuple | KnownClass::TypeAliasType | KnownClass::NoDefaultType - | KnownClass::NamedTuple | KnownClass::NewType | KnownClass::SupportsIndex | KnownClass::Iterable @@ -3506,6 +3501,7 @@ impl KnownClass { | KnownClass::KwOnly | KnownClass::InitVar | KnownClass::NamedTupleFallback + | KnownClass::NamedTupleLike | KnownClass::TypedDictFallback => false, } } @@ -3566,7 +3562,6 @@ impl KnownClass { | KnownClass::TypeVarTuple | KnownClass::TypeAliasType | KnownClass::NoDefaultType - | KnownClass::NamedTuple | KnownClass::NewType | KnownClass::SupportsIndex | KnownClass::Iterable @@ -3582,6 +3577,7 @@ impl KnownClass { | KnownClass::KwOnly | KnownClass::InitVar | KnownClass::TypedDictFallback + | KnownClass::NamedTupleLike | KnownClass::NamedTupleFallback => false, } } @@ -3604,6 +3600,7 @@ impl KnownClass { | Self::Iterable | Self::Iterator | Self::Awaitable + | Self::NamedTupleLike | Self::Generator => true, Self::Any @@ -3648,7 +3645,6 @@ impl KnownClass { | Self::TypeVarTuple | Self::TypeAliasType | Self::NoDefaultType - | Self::NamedTuple | Self::NewType | Self::ChainMap | Self::Counter @@ -3713,7 +3709,6 @@ impl KnownClass { Self::GeneratorType => "GeneratorType", Self::AsyncGeneratorType => "AsyncGeneratorType", Self::CoroutineType => "CoroutineType", - Self::NamedTuple => "NamedTuple", Self::NoneType => "NoneType", Self::SpecialForm => "_SpecialForm", Self::TypeVar => "TypeVar", @@ -3767,6 +3762,7 @@ impl KnownClass { Self::KwOnly => "KW_ONLY", Self::InitVar => "InitVar", Self::NamedTupleFallback => "NamedTupleFallback", + Self::NamedTupleLike => "NamedTupleLike", Self::TypedDictFallback => "TypedDictFallback", } } @@ -3984,7 +3980,6 @@ impl KnownClass { | Self::Generator | Self::SpecialForm | Self::TypeVar - | Self::NamedTuple | Self::StdlibAlias | Self::Iterable | Self::Iterator @@ -4025,6 +4020,7 @@ impl KnownClass { | Self::OrderedDict => KnownModule::Collections, Self::Field | Self::KwOnly | Self::InitVar => KnownModule::Dataclasses, Self::NamedTupleFallback | Self::TypedDictFallback => KnownModule::TypeCheckerInternals, + Self::NamedTupleLike => KnownModule::TyExtensions, } } @@ -4095,7 +4091,6 @@ impl KnownClass { | Self::Nonmember | Self::ABCMeta | Self::Super - | Self::NamedTuple | Self::NewType | Self::Field | Self::KwOnly @@ -4103,6 +4098,7 @@ impl KnownClass { | Self::Iterable | Self::Iterator | Self::NamedTupleFallback + | Self::NamedTupleLike | Self::TypedDictFallback => Some(false), Self::Tuple => None, @@ -4177,7 +4173,6 @@ impl KnownClass { | Self::ABCMeta | Self::Super | Self::UnionType - | Self::NamedTuple | Self::NewType | Self::Field | Self::KwOnly @@ -4185,6 +4180,7 @@ impl KnownClass { | Self::Iterable | Self::Iterator | Self::NamedTupleFallback + | Self::NamedTupleLike | Self::TypedDictFallback => false, } } @@ -4234,7 +4230,6 @@ impl KnownClass { "UnionType" => Self::UnionType, "MethodWrapperType" => Self::MethodWrapperType, "WrapperDescriptorType" => Self::WrapperDescriptorType, - "NamedTuple" => Self::NamedTuple, "NewType" => Self::NewType, "TypeAliasType" => Self::TypeAliasType, "TypeVar" => Self::TypeVar, @@ -4275,6 +4270,7 @@ impl KnownClass { "KW_ONLY" => Self::KwOnly, "InitVar" => Self::InitVar, "NamedTupleFallback" => Self::NamedTupleFallback, + "NamedTupleLike" => Self::NamedTupleLike, "TypedDictFallback" => Self::TypedDictFallback, _ => return None, }; @@ -4341,6 +4337,7 @@ impl KnownClass { | Self::InitVar | Self::NamedTupleFallback | Self::TypedDictFallback + | Self::NamedTupleLike | Self::Awaitable | Self::Generator => module == self.canonical_module(db), Self::NoneType => matches!(module, KnownModule::Typeshed | KnownModule::Types), @@ -4353,7 +4350,6 @@ impl KnownClass { | Self::ParamSpecArgs | Self::ParamSpecKwargs | Self::TypeVarTuple - | Self::NamedTuple | Self::Iterable | Self::Iterator | Self::NewType => matches!(module, KnownModule::Typing | KnownModule::TypingExtensions), diff --git a/crates/ty_python_semantic/src/types/class_base.rs b/crates/ty_python_semantic/src/types/class_base.rs index c74dc815f3363..aff7e833ce19b 100644 --- a/crates/ty_python_semantic/src/types/class_base.rs +++ b/crates/ty_python_semantic/src/types/class_base.rs @@ -80,18 +80,6 @@ impl<'db> ClassBase<'db> { Type::ClassLiteral(literal) => { if literal.is_known(db, KnownClass::Any) { Some(Self::Dynamic(DynamicType::Any)) - } else if literal.is_known(db, KnownClass::NamedTuple) { - let fields = subclass.own_fields(db, None); - Self::try_from_type( - db, - TupleType::heterogeneous( - db, - fields.values().map(|field| field.declared_ty), - )? - .to_class_type(db) - .into(), - subclass, - ) } else { Some(Self::Class(literal.default_specialization(db))) } @@ -215,6 +203,20 @@ impl<'db> ClassBase<'db> { SpecialFormType::Protocol => Some(Self::Protocol), SpecialFormType::Generic => Some(Self::Generic), + SpecialFormType::NamedTuple => { + let fields = subclass.own_fields(db, None); + Self::try_from_type( + db, + TupleType::heterogeneous( + db, + fields.values().map(|field| field.declared_ty), + )? + .to_class_type(db) + .into(), + subclass, + ) + } + // TODO: Classes inheriting from `typing.Type` et al. also have `Generic` in their MRO SpecialFormType::Dict => { Self::try_from_type(db, KnownClass::Dict.to_class_literal(db), subclass) diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 3f8ade1195f34..acd7fbb0baf7d 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -64,7 +64,7 @@ use super::string_annotation::{ use super::subclass_of::SubclassOfInner; use super::{ClassBase, add_inferred_python_version_hint_to_diagnostic}; use crate::module_name::{ModuleName, ModuleNameResolutionError}; -use crate::module_resolver::resolve_module; +use crate::module_resolver::{KnownModule, file_to_module, resolve_module}; use crate::node_key::NodeKey; use crate::place::{ Boundness, ConsideredDefinitions, LookupError, Place, PlaceAndQualifiers, @@ -3034,20 +3034,29 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let maybe_known_class = KnownClass::try_from_file_and_name(self.db(), self.file(), name); - let class_ty = Type::from(ClassLiteral::new( - self.db(), - name.id.clone(), - body_scope, - maybe_known_class, - deprecated, - dataclass_params, - dataclass_transformer_params, - )); + let ty = if maybe_known_class.is_none() + && &name.id == "NamedTuple" + && matches!( + file_to_module(self.db(), self.file()).and_then(|module| module.known(self.db())), + Some(KnownModule::Typing | KnownModule::TypingExtensions) + ) { + Type::SpecialForm(SpecialFormType::NamedTuple) + } else { + Type::from(ClassLiteral::new( + self.db(), + name.id.clone(), + body_scope, + maybe_known_class, + deprecated, + dataclass_params, + dataclass_transformer_params, + )) + }; self.add_declaration_with_binding( class_node.into(), definition, - &DeclaredAndInferredType::are_the_same_type(class_ty), + &DeclaredAndInferredType::are_the_same_type(ty), ); // if there are type parameters, then the keywords and bases are within that scope @@ -6206,7 +6215,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | KnownClass::Property | KnownClass::Super | KnownClass::TypeVar - | KnownClass::NamedTuple | KnownClass::TypeAliasType | KnownClass::Deprecated ) @@ -10800,7 +10808,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { SpecialFormType::Tuple => { Type::tuple(self.infer_tuple_type_expression(arguments_slice)) } - SpecialFormType::Generic | SpecialFormType::Protocol => { + SpecialFormType::Generic | SpecialFormType::Protocol | SpecialFormType::NamedTuple => { self.infer_expression(arguments_slice); if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) { builder.into_diagnostic(format_args!( diff --git a/crates/ty_python_semantic/src/types/special_form.rs b/crates/ty_python_semantic/src/types/special_form.rs index a502a6864d42c..f0dd81b150cdf 100644 --- a/crates/ty_python_semantic/src/types/special_form.rs +++ b/crates/ty_python_semantic/src/types/special_form.rs @@ -117,6 +117,11 @@ pub enum SpecialFormType { /// Note that instances of subscripted `typing.Generic` are not represented by this type; /// see also [`super::KnownInstanceType::SubscriptedGeneric`]. Generic, + + /// The symbol `typing.NamedTuple` (which can also be found as `typing_extensions.NamedTuple`). + /// Typeshed defines this symbol as a class, but this isn't accurate: it's actually a factory function + /// at runtime. We therefore represent it as a special form internally. + NamedTuple, } impl SpecialFormType { @@ -163,6 +168,8 @@ impl SpecialFormType { | Self::OrderedDict => KnownClass::StdlibAlias, Self::Unknown | Self::AlwaysTruthy | Self::AlwaysFalsy => KnownClass::Object, + + Self::NamedTuple => KnownClass::FunctionType, } } @@ -230,6 +237,7 @@ impl SpecialFormType { | Self::TypeIs | Self::TypingSelf | Self::Protocol + | Self::NamedTuple | Self::ReadOnly => { matches!(module, KnownModule::Typing | KnownModule::TypingExtensions) } @@ -261,6 +269,7 @@ impl SpecialFormType { | Self::Counter | Self::DefaultDict | Self::Deque + | Self::NamedTuple | Self::OrderedDict => true, // All other special forms are not callable @@ -344,6 +353,7 @@ impl SpecialFormType { SpecialFormType::CallableTypeOf => "ty_extensions.CallableTypeOf", SpecialFormType::Protocol => "typing.Protocol", SpecialFormType::Generic => "typing.Generic", + SpecialFormType::NamedTuple => "typing.NamedTuple", } } } diff --git a/crates/ty_vendored/ty_extensions/ty_extensions.pyi b/crates/ty_vendored/ty_extensions/ty_extensions.pyi index 4dd041762fa41..6968bcb75a89d 100644 --- a/crates/ty_vendored/ty_extensions/ty_extensions.pyi +++ b/crates/ty_vendored/ty_extensions/ty_extensions.pyi @@ -1,5 +1,15 @@ +import sys +from collections.abc import Iterable from enum import Enum -from typing import Any, LiteralString, _SpecialForm +from typing import ( + Any, + ClassVar, + LiteralString, + Protocol, + _SpecialForm, +) + +from typing_extensions import Self # noqa: UP035 # Special operations def static_assert(condition: object, msg: LiteralString | None = None) -> None: ... @@ -69,3 +79,16 @@ def has_member(obj: Any, name: str) -> bool: ... # diagnostic describing the protocol's interface. Passing a non-protocol type # will cause ty to emit an error diagnostic. def reveal_protocol_interface(protocol: type) -> None: ... + +# A protocol describing an interface that should be satisfied by all named tuples +# created using `typing.NamedTuple` or `collections.namedtuple`. +class NamedTupleLike(Protocol): + # from typing.NamedTuple stub + _field_defaults: ClassVar[dict[str, Any]] + _fields: ClassVar[tuple[str, ...]] + @classmethod + def _make(self: Self, iterable: Iterable[Any]) -> Self: ... + def _asdict(self, /) -> dict[str, Any]: ... + def _replace(self: Self, /, **kwargs) -> Self: ... + if sys.version_info >= (3, 13): + def __replace__(self: Self, **kwargs) -> Self: ... From 2dc2f68b0f48a18ff038d9aadeb07ca8ca73a085 Mon Sep 17 00:00:00 2001 From: Dan Parizher <105245560+danparizher@users.noreply.github.com> Date: Fri, 15 Aug 2025 15:09:55 -0400 Subject: [PATCH 012/160] [`pycodestyle`] Make `E731` fix unsafe instead of display-only for class assignments (#19700) ## Summary Fixes #19650 --------- Co-authored-by: Brent Westbrook --- .../pycodestyle/rules/lambda_assignment.rs | 35 ++++++++----------- ...les__pycodestyle__tests__E731_E731.py.snap | 12 +++---- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs index c8cbc21ce6aa7..24c47e1c7c035 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -10,7 +10,7 @@ use ruff_source_file::UniversalNewlines; use ruff_text_size::{Ranged, TextRange}; use crate::checkers::ast::Checker; -use crate::{Edit, Fix, FixAvailability, Violation}; +use crate::{Applicability, Edit, Fix, FixAvailability, Violation}; /// ## What it does /// Checks for lambda expressions which are assigned to a variable. @@ -105,29 +105,24 @@ pub(crate) fn lambda_assignment( } } - // Otherwise, if the assignment is in a class body, flag it, but use a display-only fix. - // Rewriting safely would require making this a static method. - // - // Similarly, if the lambda is shadowing a variable in the current scope, + // If the lambda is shadowing a variable in the current scope, // rewriting it as a function declaration may break type-checking. // See: https://github.com/astral-sh/ruff/issues/5421 - if checker.semantic().current_scope().kind.is_class() - || checker - .semantic() - .current_scope() - .get_all(id) - .any(|binding_id| checker.semantic().binding(binding_id).kind.is_annotation()) + let applicability = if checker + .semantic() + .current_scope() + .get_all(id) + .any(|binding_id| checker.semantic().binding(binding_id).kind.is_annotation()) { - diagnostic.set_fix(Fix::display_only_edit(Edit::range_replacement( - indented, - stmt.range(), - ))); + Applicability::DisplayOnly } else { - diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( - indented, - stmt.range(), - ))); - } + Applicability::Unsafe + }; + + diagnostic.set_fix(Fix::applicable_edit( + Edit::range_replacement(indented, stmt.range()), + applicability, + )); } } diff --git a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E731_E731.py.snap b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E731_E731.py.snap index 9b7e9c54c8d45..f3054605a493f 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E731_E731.py.snap +++ b/crates/ruff_linter/src/rules/pycodestyle/snapshots/ruff_linter__rules__pycodestyle__tests__E731_E731.py.snap @@ -105,7 +105,7 @@ help: Rewrite `f` as a `def` 26 27 | 27 28 | def scope(): -E731 Do not assign a `lambda` expression, use a `def` +E731 [*] Do not assign a `lambda` expression, use a `def` --> E731.py:57:5 | 55 | class Scope: @@ -115,7 +115,7 @@ E731 Do not assign a `lambda` expression, use a `def` | help: Rewrite `f` as a `def` -ℹ Display-only fix +ℹ Unsafe fix 54 54 | 55 55 | class Scope: 56 56 | # E731 @@ -318,7 +318,7 @@ help: Rewrite `f` as a `def` 137 138 | 138 139 | class TemperatureScales(Enum): -E731 Do not assign a `lambda` expression, use a `def` +E731 [*] Do not assign a `lambda` expression, use a `def` --> E731.py:139:5 | 138 | class TemperatureScales(Enum): @@ -328,7 +328,7 @@ E731 Do not assign a `lambda` expression, use a `def` | help: Rewrite `CELSIUS` as a `def` -ℹ Display-only fix +ℹ Unsafe fix 136 136 | 137 137 | 138 138 | class TemperatureScales(Enum): @@ -339,7 +339,7 @@ help: Rewrite `CELSIUS` as a `def` 141 142 | 142 143 | -E731 Do not assign a `lambda` expression, use a `def` +E731 [*] Do not assign a `lambda` expression, use a `def` --> E731.py:140:5 | 138 | class TemperatureScales(Enum): @@ -349,7 +349,7 @@ E731 Do not assign a `lambda` expression, use a `def` | help: Rewrite `FAHRENHEIT` as a `def` -ℹ Display-only fix +ℹ Unsafe fix 137 137 | 138 138 | class TemperatureScales(Enum): 139 139 | CELSIUS = (lambda deg_c: deg_c) From 2e1d6623cd5ba3e8ddbffee4df76e3ff0359b903 Mon Sep 17 00:00:00 2001 From: Frazer McLean Date: Fri, 15 Aug 2025 21:18:06 +0200 Subject: [PATCH 013/160] [`flake8-simplify`] Implement fix for `maxsplit` without separator (`SIM905`) (#19851) **Stacked on top of #19849; diff will include that PR until it is merged.** --- ## Summary As part of #19849, I noticed this fix could be implemented. ## Test Plan Tests added based on CPython behaviour. --- .../test/fixtures/flake8_simplify/SIM905.py | 4 + crates/ruff_linter/src/preview.rs | 5 + .../src/rules/flake8_simplify/mod.rs | 1 + .../rules/split_static_string.rs | 38 +- ...ke8_simplify__tests__SIM905_SIM905.py.snap | 28 + ...ify__tests__preview__SIM905_SIM905.py.snap | 1580 +++++++++++++++++ 6 files changed, 1650 insertions(+), 6 deletions(-) create mode 100644 crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM905_SIM905.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM905.py b/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM905.py index 1981b422ad981..6b954b530b4de 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM905.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_simplify/SIM905.py @@ -166,3 +166,7 @@ print("S\x1cP\x1dL\x1eI\x1fT".split()) print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) + +# leading/trailing whitespace should not count towards maxsplit +" a b c d ".split(maxsplit=2) # ["a", "b", "c d "] +" a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] diff --git a/crates/ruff_linter/src/preview.rs b/crates/ruff_linter/src/preview.rs index 3bcc8721fb9cb..73edcbf71dfdc 100644 --- a/crates/ruff_linter/src/preview.rs +++ b/crates/ruff_linter/src/preview.rs @@ -230,3 +230,8 @@ pub(crate) const fn is_add_future_annotations_imports_enabled(settings: &LinterS pub(crate) const fn is_trailing_comma_type_params_enabled(settings: &LinterSettings) -> bool { settings.preview.is_enabled() } + +// https://github.com/astral-sh/ruff/pull/19851 +pub(crate) const fn is_maxsplit_without_separator_fix_enabled(settings: &LinterSettings) -> bool { + settings.preview.is_enabled() +} diff --git a/crates/ruff_linter/src/rules/flake8_simplify/mod.rs b/crates/ruff_linter/src/rules/flake8_simplify/mod.rs index 1fd42b3450245..d3ac85a8fb1e2 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/mod.rs @@ -60,6 +60,7 @@ mod tests { } #[test_case(Rule::MultipleWithStatements, Path::new("SIM117.py"))] + #[test_case(Rule::SplitStaticString, Path::new("SIM905.py"))] fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( "preview__{}_{}", diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs index 367f2b5b34e26..c8a6f46e03e00 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs @@ -9,6 +9,8 @@ use ruff_python_ast::{ use ruff_text_size::{Ranged, TextRange}; use crate::checkers::ast::Checker; +use crate::preview::is_maxsplit_without_separator_fix_enabled; +use crate::settings::LinterSettings; use crate::{Applicability, Edit, Fix, FixAvailability, Violation}; /// ## What it does @@ -84,7 +86,9 @@ pub(crate) fn split_static_string( let sep_arg = arguments.find_argument_value("sep", 0); let split_replacement = if let Some(sep) = sep_arg { match sep { - Expr::NoneLiteral(_) => split_default(str_value, maxsplit_value, direction), + Expr::NoneLiteral(_) => { + split_default(str_value, maxsplit_value, direction, checker.settings()) + } Expr::StringLiteral(sep_value) => { let sep_value_str = sep_value.value.to_str(); Some(split_sep( @@ -100,7 +104,7 @@ pub(crate) fn split_static_string( } } } else { - split_default(str_value, maxsplit_value, direction) + split_default(str_value, maxsplit_value, direction, checker.settings()) }; let mut diagnostic = checker.report_diagnostic(SplitStaticString, call.range()); @@ -174,6 +178,7 @@ fn split_default( str_value: &StringLiteralValue, max_split: i32, direction: Direction, + settings: &LinterSettings, ) -> Option { // From the Python documentation: // > If sep is not specified or is None, a different splitting algorithm is applied: runs of @@ -185,10 +190,31 @@ fn split_default( let string_val = str_value.to_str(); match max_split.cmp(&0) { Ordering::Greater => { - // Autofix for `maxsplit` without separator not yet implemented, as - // `split_whitespace().remainder()` is not stable: - // https://doc.rust-lang.org/std/str/struct.SplitWhitespace.html#method.remainder - None + if !is_maxsplit_without_separator_fix_enabled(settings) { + return None; + } + let Ok(max_split) = usize::try_from(max_split) else { + return None; + }; + let list_items: Vec<&str> = if direction == Direction::Left { + string_val + .trim_start_matches(py_unicode_is_whitespace) + .splitn(max_split + 1, py_unicode_is_whitespace) + .filter(|s| !s.is_empty()) + .collect() + } else { + let mut items: Vec<&str> = string_val + .trim_end_matches(py_unicode_is_whitespace) + .rsplitn(max_split + 1, py_unicode_is_whitespace) + .filter(|s| !s.is_empty()) + .collect(); + items.reverse(); + items + }; + Some(construct_replacement( + &list_items, + str_value.first_literal_flags(), + )) } Ordering::Equal => { // Behavior for maxsplit = 0 when sep is None: diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM905_SIM905.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM905_SIM905.py.snap index 84feb52b7d457..bda8037b7f790 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM905_SIM905.py.snap +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__SIM905_SIM905.py.snap @@ -1439,6 +1439,7 @@ help: Replace with list literal 166 |+print(["S", "P", "L", "I", "T"]) 167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) +169 169 | SIM905 [*] Consider using a list literal instead of `str.split` --> SIM905.py:167:7 @@ -1458,6 +1459,8 @@ help: Replace with list literal 167 |-print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 167 |+print([">"]) 168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) +169 169 | +170 170 | # leading/trailing whitespace should not count towards maxsplit SIM905 [*] Consider using a list literal instead of `str.split` --> SIM905.py:168:7 @@ -1466,6 +1469,8 @@ SIM905 [*] Consider using a list literal instead of `str.split` 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +169 | +170 | # leading/trailing whitespace should not count towards maxsplit | help: Replace with list literal @@ -1475,3 +1480,26 @@ help: Replace with list literal 167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) 168 |-print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) 168 |+print(["<"]) +169 169 | +170 170 | # leading/trailing whitespace should not count towards maxsplit +171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] + +SIM905 Consider using a list literal instead of `str.split` + --> SIM905.py:171:1 + | +170 | # leading/trailing whitespace should not count towards maxsplit +171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] + | +help: Replace with list literal + +SIM905 Consider using a list literal instead of `str.split` + --> SIM905.py:172:1 + | +170 | # leading/trailing whitespace should not count towards maxsplit +171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] +172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Replace with list literal diff --git a/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM905_SIM905.py.snap b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM905_SIM905.py.snap new file mode 100644 index 0000000000000..e45eabb21c132 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_simplify/snapshots/ruff_linter__rules__flake8_simplify__tests__preview__SIM905_SIM905.py.snap @@ -0,0 +1,1580 @@ +--- +source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs +--- +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:6:1 + | + 5 | # positives + 6 | / """ + 7 | | itemA + 8 | | itemB + 9 | | itemC +10 | | """.split() + | |___________^ +11 | +12 | "a,b,c,d".split(",") + | +help: Replace with list literal + +ℹ Safe fix +3 3 | no_sep = None +4 4 | +5 5 | # positives +6 |-""" +7 |- itemA +8 |- itemB +9 |- itemC +10 |-""".split() + 6 |+["itemA", "itemB", "itemC"] +11 7 | +12 8 | "a,b,c,d".split(",") +13 9 | "a,b,c,d".split(None) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:12:1 + | +10 | """.split() +11 | +12 | "a,b,c,d".split(",") + | ^^^^^^^^^^^^^^^^^^^^ +13 | "a,b,c,d".split(None) +14 | "a,b,c,d".split(",", 1) + | +help: Replace with list literal + +ℹ Safe fix +9 9 | itemC +10 10 | """.split() +11 11 | +12 |-"a,b,c,d".split(",") + 12 |+["a", "b", "c", "d"] +13 13 | "a,b,c,d".split(None) +14 14 | "a,b,c,d".split(",", 1) +15 15 | "a,b,c,d".split(None, 1) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:13:1 + | +12 | "a,b,c,d".split(",") +13 | "a,b,c,d".split(None) + | ^^^^^^^^^^^^^^^^^^^^^ +14 | "a,b,c,d".split(",", 1) +15 | "a,b,c,d".split(None, 1) + | +help: Replace with list literal + +ℹ Safe fix +10 10 | """.split() +11 11 | +12 12 | "a,b,c,d".split(",") +13 |-"a,b,c,d".split(None) + 13 |+["a,b,c,d"] +14 14 | "a,b,c,d".split(",", 1) +15 15 | "a,b,c,d".split(None, 1) +16 16 | "a,b,c,d".split(sep=",") + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:14:1 + | +12 | "a,b,c,d".split(",") +13 | "a,b,c,d".split(None) +14 | "a,b,c,d".split(",", 1) + | ^^^^^^^^^^^^^^^^^^^^^^^ +15 | "a,b,c,d".split(None, 1) +16 | "a,b,c,d".split(sep=",") + | +help: Replace with list literal + +ℹ Safe fix +11 11 | +12 12 | "a,b,c,d".split(",") +13 13 | "a,b,c,d".split(None) +14 |-"a,b,c,d".split(",", 1) + 14 |+["a", "b,c,d"] +15 15 | "a,b,c,d".split(None, 1) +16 16 | "a,b,c,d".split(sep=",") +17 17 | "a,b,c,d".split(sep=None) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:15:1 + | +13 | "a,b,c,d".split(None) +14 | "a,b,c,d".split(",", 1) +15 | "a,b,c,d".split(None, 1) + | ^^^^^^^^^^^^^^^^^^^^^^^^ +16 | "a,b,c,d".split(sep=",") +17 | "a,b,c,d".split(sep=None) + | +help: Replace with list literal + +ℹ Safe fix +12 12 | "a,b,c,d".split(",") +13 13 | "a,b,c,d".split(None) +14 14 | "a,b,c,d".split(",", 1) +15 |-"a,b,c,d".split(None, 1) + 15 |+["a,b,c,d"] +16 16 | "a,b,c,d".split(sep=",") +17 17 | "a,b,c,d".split(sep=None) +18 18 | "a,b,c,d".split(sep=",", maxsplit=1) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:16:1 + | +14 | "a,b,c,d".split(",", 1) +15 | "a,b,c,d".split(None, 1) +16 | "a,b,c,d".split(sep=",") + | ^^^^^^^^^^^^^^^^^^^^^^^^ +17 | "a,b,c,d".split(sep=None) +18 | "a,b,c,d".split(sep=",", maxsplit=1) + | +help: Replace with list literal + +ℹ Safe fix +13 13 | "a,b,c,d".split(None) +14 14 | "a,b,c,d".split(",", 1) +15 15 | "a,b,c,d".split(None, 1) +16 |-"a,b,c,d".split(sep=",") + 16 |+["a", "b", "c", "d"] +17 17 | "a,b,c,d".split(sep=None) +18 18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 19 | "a,b,c,d".split(sep=None, maxsplit=1) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:17:1 + | +15 | "a,b,c,d".split(None, 1) +16 | "a,b,c,d".split(sep=",") +17 | "a,b,c,d".split(sep=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 | "a,b,c,d".split(sep=None, maxsplit=1) + | +help: Replace with list literal + +ℹ Safe fix +14 14 | "a,b,c,d".split(",", 1) +15 15 | "a,b,c,d".split(None, 1) +16 16 | "a,b,c,d".split(sep=",") +17 |-"a,b,c,d".split(sep=None) + 17 |+["a,b,c,d"] +18 18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 20 | "a,b,c,d".split(maxsplit=1, sep=",") + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:18:1 + | +16 | "a,b,c,d".split(sep=",") +17 | "a,b,c,d".split(sep=None) +18 | "a,b,c,d".split(sep=",", maxsplit=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 | "a,b,c,d".split(maxsplit=1, sep=",") + | +help: Replace with list literal + +ℹ Safe fix +15 15 | "a,b,c,d".split(None, 1) +16 16 | "a,b,c,d".split(sep=",") +17 17 | "a,b,c,d".split(sep=None) +18 |-"a,b,c,d".split(sep=",", maxsplit=1) + 18 |+["a", "b,c,d"] +19 19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 21 | "a,b,c,d".split(maxsplit=1, sep=None) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:19:1 + | +17 | "a,b,c,d".split(sep=None) +18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 | "a,b,c,d".split(sep=None, maxsplit=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 | "a,b,c,d".split(maxsplit=1, sep=None) + | +help: Replace with list literal + +ℹ Safe fix +16 16 | "a,b,c,d".split(sep=",") +17 17 | "a,b,c,d".split(sep=None) +18 18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 |-"a,b,c,d".split(sep=None, maxsplit=1) + 19 |+["a,b,c,d"] +20 20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 22 | "a,b,c,d".split(",", maxsplit=1) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:20:1 + | +18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 | "a,b,c,d".split(maxsplit=1, sep=",") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 | "a,b,c,d".split(",", maxsplit=1) + | +help: Replace with list literal + +ℹ Safe fix +17 17 | "a,b,c,d".split(sep=None) +18 18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 |-"a,b,c,d".split(maxsplit=1, sep=",") + 20 |+["a", "b,c,d"] +21 21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 22 | "a,b,c,d".split(",", maxsplit=1) +23 23 | "a,b,c,d".split(None, maxsplit=1) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:21:1 + | +19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 | "a,b,c,d".split(maxsplit=1, sep=None) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +22 | "a,b,c,d".split(",", maxsplit=1) +23 | "a,b,c,d".split(None, maxsplit=1) + | +help: Replace with list literal + +ℹ Safe fix +18 18 | "a,b,c,d".split(sep=",", maxsplit=1) +19 19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 |-"a,b,c,d".split(maxsplit=1, sep=None) + 21 |+["a,b,c,d"] +22 22 | "a,b,c,d".split(",", maxsplit=1) +23 23 | "a,b,c,d".split(None, maxsplit=1) +24 24 | "a,b,c,d".split(maxsplit=1) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:22:1 + | +20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 | "a,b,c,d".split(",", maxsplit=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +23 | "a,b,c,d".split(None, maxsplit=1) +24 | "a,b,c,d".split(maxsplit=1) + | +help: Replace with list literal + +ℹ Safe fix +19 19 | "a,b,c,d".split(sep=None, maxsplit=1) +20 20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 |-"a,b,c,d".split(",", maxsplit=1) + 22 |+["a", "b,c,d"] +23 23 | "a,b,c,d".split(None, maxsplit=1) +24 24 | "a,b,c,d".split(maxsplit=1) +25 25 | "a,b,c,d".split(maxsplit=1.0) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:23:1 + | +21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 | "a,b,c,d".split(",", maxsplit=1) +23 | "a,b,c,d".split(None, maxsplit=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +24 | "a,b,c,d".split(maxsplit=1) +25 | "a,b,c,d".split(maxsplit=1.0) + | +help: Replace with list literal + +ℹ Safe fix +20 20 | "a,b,c,d".split(maxsplit=1, sep=",") +21 21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 22 | "a,b,c,d".split(",", maxsplit=1) +23 |-"a,b,c,d".split(None, maxsplit=1) + 23 |+["a,b,c,d"] +24 24 | "a,b,c,d".split(maxsplit=1) +25 25 | "a,b,c,d".split(maxsplit=1.0) +26 26 | "a,b,c,d".split(maxsplit=1) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:24:1 + | +22 | "a,b,c,d".split(",", maxsplit=1) +23 | "a,b,c,d".split(None, maxsplit=1) +24 | "a,b,c,d".split(maxsplit=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +25 | "a,b,c,d".split(maxsplit=1.0) +26 | "a,b,c,d".split(maxsplit=1) + | +help: Replace with list literal + +ℹ Safe fix +21 21 | "a,b,c,d".split(maxsplit=1, sep=None) +22 22 | "a,b,c,d".split(",", maxsplit=1) +23 23 | "a,b,c,d".split(None, maxsplit=1) +24 |-"a,b,c,d".split(maxsplit=1) + 24 |+["a,b,c,d"] +25 25 | "a,b,c,d".split(maxsplit=1.0) +26 26 | "a,b,c,d".split(maxsplit=1) +27 27 | "a,b,c,d".split(maxsplit=0) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:26:1 + | +24 | "a,b,c,d".split(maxsplit=1) +25 | "a,b,c,d".split(maxsplit=1.0) +26 | "a,b,c,d".split(maxsplit=1) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +27 | "a,b,c,d".split(maxsplit=0) +28 | "VERB AUX PRON ADP DET".split(" ") + | +help: Replace with list literal + +ℹ Safe fix +23 23 | "a,b,c,d".split(None, maxsplit=1) +24 24 | "a,b,c,d".split(maxsplit=1) +25 25 | "a,b,c,d".split(maxsplit=1.0) +26 |-"a,b,c,d".split(maxsplit=1) + 26 |+["a,b,c,d"] +27 27 | "a,b,c,d".split(maxsplit=0) +28 28 | "VERB AUX PRON ADP DET".split(" ") +29 29 | ' 1 2 3 '.split() + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:27:1 + | +25 | "a,b,c,d".split(maxsplit=1.0) +26 | "a,b,c,d".split(maxsplit=1) +27 | "a,b,c,d".split(maxsplit=0) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ +28 | "VERB AUX PRON ADP DET".split(" ") +29 | ' 1 2 3 '.split() + | +help: Replace with list literal + +ℹ Safe fix +24 24 | "a,b,c,d".split(maxsplit=1) +25 25 | "a,b,c,d".split(maxsplit=1.0) +26 26 | "a,b,c,d".split(maxsplit=1) +27 |-"a,b,c,d".split(maxsplit=0) + 27 |+["a,b,c,d"] +28 28 | "VERB AUX PRON ADP DET".split(" ") +29 29 | ' 1 2 3 '.split() +30 30 | '1<>2<>3<4'.split('<>') + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:28:1 + | +26 | "a,b,c,d".split(maxsplit=1) +27 | "a,b,c,d".split(maxsplit=0) +28 | "VERB AUX PRON ADP DET".split(" ") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +29 | ' 1 2 3 '.split() +30 | '1<>2<>3<4'.split('<>') + | +help: Replace with list literal + +ℹ Safe fix +25 25 | "a,b,c,d".split(maxsplit=1.0) +26 26 | "a,b,c,d".split(maxsplit=1) +27 27 | "a,b,c,d".split(maxsplit=0) +28 |-"VERB AUX PRON ADP DET".split(" ") + 28 |+["VERB", "AUX", "PRON", "ADP", "DET"] +29 29 | ' 1 2 3 '.split() +30 30 | '1<>2<>3<4'.split('<>') +31 31 | + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:29:1 + | +27 | "a,b,c,d".split(maxsplit=0) +28 | "VERB AUX PRON ADP DET".split(" ") +29 | ' 1 2 3 '.split() + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +30 | '1<>2<>3<4'.split('<>') + | +help: Replace with list literal + +ℹ Safe fix +26 26 | "a,b,c,d".split(maxsplit=1) +27 27 | "a,b,c,d".split(maxsplit=0) +28 28 | "VERB AUX PRON ADP DET".split(" ") +29 |-' 1 2 3 '.split() + 29 |+['1', '2', '3'] +30 30 | '1<>2<>3<4'.split('<>') +31 31 | +32 32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:30:1 + | +28 | "VERB AUX PRON ADP DET".split(" ") +29 | ' 1 2 3 '.split() +30 | '1<>2<>3<4'.split('<>') + | ^^^^^^^^^^^^^^^^^^^^^^^ +31 | +32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] + | +help: Replace with list literal + +ℹ Safe fix +27 27 | "a,b,c,d".split(maxsplit=0) +28 28 | "VERB AUX PRON ADP DET".split(" ") +29 29 | ' 1 2 3 '.split() +30 |-'1<>2<>3<4'.split('<>') + 30 |+['1', '2', '3<4'] +31 31 | +32 32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] +33 33 | "".split() # [] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:32:1 + | +30 | '1<>2<>3<4'.split('<>') +31 | +32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +33 | "".split() # [] +34 | """ + | +help: Replace with list literal + +ℹ Safe fix +29 29 | ' 1 2 3 '.split() +30 30 | '1<>2<>3<4'.split('<>') +31 31 | +32 |-" a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] + 32 |+[" a", "a a", "a a "] # [" a", "a a", "a a "] +33 33 | "".split() # [] +34 34 | """ +35 35 | """.split() # [] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:33:1 + | +32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] +33 | "".split() # [] + | ^^^^^^^^^^ +34 | """ +35 | """.split() # [] + | +help: Replace with list literal + +ℹ Safe fix +30 30 | '1<>2<>3<4'.split('<>') +31 31 | +32 32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] +33 |-"".split() # [] + 33 |+[] # [] +34 34 | """ +35 35 | """.split() # [] +36 36 | " ".split() # [] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:34:1 + | +32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] +33 | "".split() # [] +34 | / """ +35 | | """.split() # [] + | |___________^ +36 | " ".split() # [] +37 | "/abc/".split() # ["/abc/"] + | +help: Replace with list literal + +ℹ Safe fix +31 31 | +32 32 | " a*a a*a a ".split("*", -1) # [" a", "a a", "a a "] +33 33 | "".split() # [] +34 |-""" +35 |-""".split() # [] + 34 |+[] # [] +36 35 | " ".split() # [] +37 36 | "/abc/".split() # ["/abc/"] +38 37 | ("a,b,c" + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:36:1 + | +34 | """ +35 | """.split() # [] +36 | " ".split() # [] + | ^^^^^^^^^^^^^^^^^ +37 | "/abc/".split() # ["/abc/"] +38 | ("a,b,c" + | +help: Replace with list literal + +ℹ Safe fix +33 33 | "".split() # [] +34 34 | """ +35 35 | """.split() # [] +36 |-" ".split() # [] + 36 |+[] # [] +37 37 | "/abc/".split() # ["/abc/"] +38 38 | ("a,b,c" +39 39 | # comment + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:37:1 + | +35 | """.split() # [] +36 | " ".split() # [] +37 | "/abc/".split() # ["/abc/"] + | ^^^^^^^^^^^^^^^ +38 | ("a,b,c" +39 | # comment + | +help: Replace with list literal + +ℹ Safe fix +34 34 | """ +35 35 | """.split() # [] +36 36 | " ".split() # [] +37 |-"/abc/".split() # ["/abc/"] + 37 |+["/abc/"] # ["/abc/"] +38 38 | ("a,b,c" +39 39 | # comment +40 40 | .split() + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:38:2 + | +36 | " ".split() # [] +37 | "/abc/".split() # ["/abc/"] +38 | ("a,b,c" + | __^ +39 | | # comment +40 | | .split() + | |________^ +41 | ) # ["a,b,c"] +42 | ("a,b,c" + | +help: Replace with list literal + +ℹ Unsafe fix +35 35 | """.split() # [] +36 36 | " ".split() # [] +37 37 | "/abc/".split() # ["/abc/"] +38 |-("a,b,c" +39 |-# comment +40 |-.split() + 38 |+(["a,b,c"] +41 39 | ) # ["a,b,c"] +42 40 | ("a,b,c" +43 41 | # comment1 + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:42:2 + | +40 | .split() +41 | ) # ["a,b,c"] +42 | ("a,b,c" + | __^ +43 | | # comment1 +44 | | .split(",") + | |___________^ +45 | ) # ["a", "b", "c"] +46 | ("a," + | +help: Replace with list literal + +ℹ Unsafe fix +39 39 | # comment +40 40 | .split() +41 41 | ) # ["a,b,c"] +42 |-("a,b,c" +43 |-# comment1 +44 |-.split(",") + 42 |+(["a", "b", "c"] +45 43 | ) # ["a", "b", "c"] +46 44 | ("a," +47 45 | # comment + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:46:2 + | +44 | .split(",") +45 | ) # ["a", "b", "c"] +46 | ("a," + | __^ +47 | | # comment +48 | | "b," +49 | | "c" +50 | | .split(",") + | |___________^ +51 | ) # ["a", "b", "c"] + | +help: Replace with list literal + +ℹ Unsafe fix +43 43 | # comment1 +44 44 | .split(",") +45 45 | ) # ["a", "b", "c"] +46 |-("a," +47 |-# comment +48 |-"b," +49 |-"c" +50 |-.split(",") + 46 |+(["a", "b", "c"] +51 47 | ) # ["a", "b", "c"] +52 48 | +53 49 | "hello "\ + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:53:1 + | +51 | ) # ["a", "b", "c"] +52 | +53 | / "hello "\ +54 | | "world".split() + | |___________________^ +55 | # ["hello", "world"] + | +help: Replace with list literal + +ℹ Safe fix +50 50 | .split(",") +51 51 | ) # ["a", "b", "c"] +52 52 | +53 |-"hello "\ +54 |- "world".split() + 53 |+["hello", "world"] +55 54 | # ["hello", "world"] +56 55 | +57 56 | # prefixes and isc + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:58:1 + | +57 | # prefixes and isc +58 | u"a b".split() # [u"a", u"b"] + | ^^^^^^^^^^^^^^ +59 | r"a \n b".split() # [r"a", r"\n", r"b"] +60 | ("a " "b").split() # ["a", "b"] + | +help: Replace with list literal + +ℹ Safe fix +55 55 | # ["hello", "world"] +56 56 | +57 57 | # prefixes and isc +58 |-u"a b".split() # [u"a", u"b"] + 58 |+[u"a", u"b"] # [u"a", u"b"] +59 59 | r"a \n b".split() # [r"a", r"\n", r"b"] +60 60 | ("a " "b").split() # ["a", "b"] +61 61 | "a " "b".split() # ["a", "b"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:59:1 + | +57 | # prefixes and isc +58 | u"a b".split() # [u"a", u"b"] +59 | r"a \n b".split() # [r"a", r"\n", r"b"] + | ^^^^^^^^^^^^^^^^^ +60 | ("a " "b").split() # ["a", "b"] +61 | "a " "b".split() # ["a", "b"] + | +help: Replace with list literal + +ℹ Safe fix +56 56 | +57 57 | # prefixes and isc +58 58 | u"a b".split() # [u"a", u"b"] +59 |-r"a \n b".split() # [r"a", r"\n", r"b"] + 59 |+[r"a", r"\n", r"b"] # [r"a", r"\n", r"b"] +60 60 | ("a " "b").split() # ["a", "b"] +61 61 | "a " "b".split() # ["a", "b"] +62 62 | u"a " "b".split() # [u"a", u"b"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:60:1 + | +58 | u"a b".split() # [u"a", u"b"] +59 | r"a \n b".split() # [r"a", r"\n", r"b"] +60 | ("a " "b").split() # ["a", "b"] + | ^^^^^^^^^^^^^^^^^^ +61 | "a " "b".split() # ["a", "b"] +62 | u"a " "b".split() # [u"a", u"b"] + | +help: Replace with list literal + +ℹ Safe fix +57 57 | # prefixes and isc +58 58 | u"a b".split() # [u"a", u"b"] +59 59 | r"a \n b".split() # [r"a", r"\n", r"b"] +60 |-("a " "b").split() # ["a", "b"] + 60 |+["a", "b"] # ["a", "b"] +61 61 | "a " "b".split() # ["a", "b"] +62 62 | u"a " "b".split() # [u"a", u"b"] +63 63 | "a " u"b".split() # ["a", "b"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:61:1 + | +59 | r"a \n b".split() # [r"a", r"\n", r"b"] +60 | ("a " "b").split() # ["a", "b"] +61 | "a " "b".split() # ["a", "b"] + | ^^^^^^^^^^^^^^^^ +62 | u"a " "b".split() # [u"a", u"b"] +63 | "a " u"b".split() # ["a", "b"] + | +help: Replace with list literal + +ℹ Safe fix +58 58 | u"a b".split() # [u"a", u"b"] +59 59 | r"a \n b".split() # [r"a", r"\n", r"b"] +60 60 | ("a " "b").split() # ["a", "b"] +61 |-"a " "b".split() # ["a", "b"] + 61 |+["a", "b"] # ["a", "b"] +62 62 | u"a " "b".split() # [u"a", u"b"] +63 63 | "a " u"b".split() # ["a", "b"] +64 64 | u"a " r"\n".split() # [u"a", u"\\n"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:62:1 + | +60 | ("a " "b").split() # ["a", "b"] +61 | "a " "b".split() # ["a", "b"] +62 | u"a " "b".split() # [u"a", u"b"] + | ^^^^^^^^^^^^^^^^^ +63 | "a " u"b".split() # ["a", "b"] +64 | u"a " r"\n".split() # [u"a", u"\\n"] + | +help: Replace with list literal + +ℹ Safe fix +59 59 | r"a \n b".split() # [r"a", r"\n", r"b"] +60 60 | ("a " "b").split() # ["a", "b"] +61 61 | "a " "b".split() # ["a", "b"] +62 |-u"a " "b".split() # [u"a", u"b"] + 62 |+[u"a", u"b"] # [u"a", u"b"] +63 63 | "a " u"b".split() # ["a", "b"] +64 64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 65 | r"\n " u"\n".split() # [r"\n"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:63:1 + | +61 | "a " "b".split() # ["a", "b"] +62 | u"a " "b".split() # [u"a", u"b"] +63 | "a " u"b".split() # ["a", "b"] + | ^^^^^^^^^^^^^^^^^ +64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 | r"\n " u"\n".split() # [r"\n"] + | +help: Replace with list literal + +ℹ Safe fix +60 60 | ("a " "b").split() # ["a", "b"] +61 61 | "a " "b".split() # ["a", "b"] +62 62 | u"a " "b".split() # [u"a", u"b"] +63 |-"a " u"b".split() # ["a", "b"] + 63 |+["a", "b"] # ["a", "b"] +64 64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 65 | r"\n " u"\n".split() # [r"\n"] +66 66 | r"\n " "\n".split() # [r"\n"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:64:1 + | +62 | u"a " "b".split() # [u"a", u"b"] +63 | "a " u"b".split() # ["a", "b"] +64 | u"a " r"\n".split() # [u"a", u"\\n"] + | ^^^^^^^^^^^^^^^^^^^ +65 | r"\n " u"\n".split() # [r"\n"] +66 | r"\n " "\n".split() # [r"\n"] + | +help: Replace with list literal + +ℹ Safe fix +61 61 | "a " "b".split() # ["a", "b"] +62 62 | u"a " "b".split() # [u"a", u"b"] +63 63 | "a " u"b".split() # ["a", "b"] +64 |-u"a " r"\n".split() # [u"a", u"\\n"] + 64 |+[u"a", u"\\n"] # [u"a", u"\\n"] +65 65 | r"\n " u"\n".split() # [r"\n"] +66 66 | r"\n " "\n".split() # [r"\n"] +67 67 | "a " r"\n".split() # ["a", "\\n"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:65:1 + | +63 | "a " u"b".split() # ["a", "b"] +64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 | r"\n " u"\n".split() # [r"\n"] + | ^^^^^^^^^^^^^^^^^^^^ +66 | r"\n " "\n".split() # [r"\n"] +67 | "a " r"\n".split() # ["a", "\\n"] + | +help: Replace with list literal + +ℹ Safe fix +62 62 | u"a " "b".split() # [u"a", u"b"] +63 63 | "a " u"b".split() # ["a", "b"] +64 64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 |-r"\n " u"\n".split() # [r"\n"] + 65 |+[r"\n"] # [r"\n"] +66 66 | r"\n " "\n".split() # [r"\n"] +67 67 | "a " r"\n".split() # ["a", "\\n"] +68 68 | + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:66:1 + | +64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 | r"\n " u"\n".split() # [r"\n"] +66 | r"\n " "\n".split() # [r"\n"] + | ^^^^^^^^^^^^^^^^^^^ +67 | "a " r"\n".split() # ["a", "\\n"] + | +help: Replace with list literal + +ℹ Safe fix +63 63 | "a " u"b".split() # ["a", "b"] +64 64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 65 | r"\n " u"\n".split() # [r"\n"] +66 |-r"\n " "\n".split() # [r"\n"] + 66 |+[r"\n"] # [r"\n"] +67 67 | "a " r"\n".split() # ["a", "\\n"] +68 68 | +69 69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:67:1 + | +65 | r"\n " u"\n".split() # [r"\n"] +66 | r"\n " "\n".split() # [r"\n"] +67 | "a " r"\n".split() # ["a", "\\n"] + | ^^^^^^^^^^^^^^^^^^ +68 | +69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] + | +help: Replace with list literal + +ℹ Safe fix +64 64 | u"a " r"\n".split() # [u"a", u"\\n"] +65 65 | r"\n " u"\n".split() # [r"\n"] +66 66 | r"\n " "\n".split() # [r"\n"] +67 |-"a " r"\n".split() # ["a", "\\n"] + 67 |+["a", "\\n"] # ["a", "\\n"] +68 68 | +69 69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] +70 70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:69:1 + | +67 | "a " r"\n".split() # ["a", "\\n"] +68 | +69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] +71 | "a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] + | +help: Replace with list literal + +ℹ Safe fix +66 66 | r"\n " "\n".split() # [r"\n"] +67 67 | "a " r"\n".split() # ["a", "\\n"] +68 68 | +69 |-"a,b,c".split(',', maxsplit=0) # ["a,b,c"] + 69 |+["a,b,c"] # ["a,b,c"] +70 70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] +71 71 | "a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] +72 72 | "a,b,c".split(',', maxsplit=-0) # ["a,b,c"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:70:1 + | +69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] +70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +71 | "a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] +72 | "a,b,c".split(',', maxsplit=-0) # ["a,b,c"] + | +help: Replace with list literal + +ℹ Safe fix +67 67 | "a " r"\n".split() # ["a", "\\n"] +68 68 | +69 69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] +70 |-"a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] + 70 |+["a", "b", "c"] # ["a", "b", "c"] +71 71 | "a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] +72 72 | "a,b,c".split(',', maxsplit=-0) # ["a,b,c"] +73 73 | + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:71:1 + | +69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] +70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] +71 | "a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +72 | "a,b,c".split(',', maxsplit=-0) # ["a,b,c"] + | +help: Replace with list literal + +ℹ Safe fix +68 68 | +69 69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] +70 70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] +71 |-"a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] + 71 |+["a", "b", "c"] # ["a", "b", "c"] +72 72 | "a,b,c".split(',', maxsplit=-0) # ["a,b,c"] +73 73 | +74 74 | # negatives + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:72:1 + | +70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] +71 | "a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] +72 | "a,b,c".split(',', maxsplit=-0) # ["a,b,c"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +73 | +74 | # negatives + | +help: Replace with list literal + +ℹ Safe fix +69 69 | "a,b,c".split(',', maxsplit=0) # ["a,b,c"] +70 70 | "a,b,c".split(',', maxsplit=-1) # ["a", "b", "c"] +71 71 | "a,b,c".split(',', maxsplit=-2) # ["a", "b", "c"] +72 |-"a,b,c".split(',', maxsplit=-0) # ["a,b,c"] + 72 |+["a,b,c"] # ["a,b,c"] +73 73 | +74 74 | # negatives +75 75 | + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:103:1 + | +102 | # another positive demonstrating quote preservation +103 | / """ +104 | | "itemA" +105 | | 'itemB' +106 | | '''itemC''' +107 | | "'itemD'" +108 | | """.split() + | |___________^ +109 | +110 | # https://github.com/astral-sh/ruff/issues/18042 + | +help: Replace with list literal + +ℹ Safe fix +100 100 | +101 101 | +102 102 | # another positive demonstrating quote preservation +103 |-""" +104 |-"itemA" +105 |-'itemB' +106 |-'''itemC''' +107 |-"'itemD'" +108 |-""".split() + 103 |+['"itemA"', "'itemB'", "'''itemC'''", "\"'itemD'\""] +109 104 | +110 105 | # https://github.com/astral-sh/ruff/issues/18042 +111 106 | print("a,b".rsplit(",")) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:111:7 + | +110 | # https://github.com/astral-sh/ruff/issues/18042 +111 | print("a,b".rsplit(",")) + | ^^^^^^^^^^^^^^^^^ +112 | print("a,b,c".rsplit(",", 1)) + | +help: Replace with list literal + +ℹ Safe fix +108 108 | """.split() +109 109 | +110 110 | # https://github.com/astral-sh/ruff/issues/18042 +111 |-print("a,b".rsplit(",")) + 111 |+print(["a", "b"]) +112 112 | print("a,b,c".rsplit(",", 1)) +113 113 | +114 114 | # https://github.com/astral-sh/ruff/issues/18069 + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:112:7 + | +110 | # https://github.com/astral-sh/ruff/issues/18042 +111 | print("a,b".rsplit(",")) +112 | print("a,b,c".rsplit(",", 1)) + | ^^^^^^^^^^^^^^^^^^^^^^ +113 | +114 | # https://github.com/astral-sh/ruff/issues/18069 + | +help: Replace with list literal + +ℹ Safe fix +109 109 | +110 110 | # https://github.com/astral-sh/ruff/issues/18042 +111 111 | print("a,b".rsplit(",")) +112 |-print("a,b,c".rsplit(",", 1)) + 112 |+print(["a,b", "c"]) +113 113 | +114 114 | # https://github.com/astral-sh/ruff/issues/18069 +115 115 | + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:116:7 + | +114 | # https://github.com/astral-sh/ruff/issues/18069 +115 | +116 | print("".split(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^ +117 | print("".split(sep=None, maxsplit=0)) +118 | print(" ".split(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +113 113 | +114 114 | # https://github.com/astral-sh/ruff/issues/18069 +115 115 | +116 |-print("".split(maxsplit=0)) + 116 |+print([]) +117 117 | print("".split(sep=None, maxsplit=0)) +118 118 | print(" ".split(maxsplit=0)) +119 119 | print(" ".split(sep=None, maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:117:7 + | +116 | print("".split(maxsplit=0)) +117 | print("".split(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +118 | print(" ".split(maxsplit=0)) +119 | print(" ".split(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +114 114 | # https://github.com/astral-sh/ruff/issues/18069 +115 115 | +116 116 | print("".split(maxsplit=0)) +117 |-print("".split(sep=None, maxsplit=0)) + 117 |+print([]) +118 118 | print(" ".split(maxsplit=0)) +119 119 | print(" ".split(sep=None, maxsplit=0)) +120 120 | print(" x ".split(maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:118:7 + | +116 | print("".split(maxsplit=0)) +117 | print("".split(sep=None, maxsplit=0)) +118 | print(" ".split(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^ +119 | print(" ".split(sep=None, maxsplit=0)) +120 | print(" x ".split(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +115 115 | +116 116 | print("".split(maxsplit=0)) +117 117 | print("".split(sep=None, maxsplit=0)) +118 |-print(" ".split(maxsplit=0)) + 118 |+print([]) +119 119 | print(" ".split(sep=None, maxsplit=0)) +120 120 | print(" x ".split(maxsplit=0)) +121 121 | print(" x ".split(sep=None, maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:119:7 + | +117 | print("".split(sep=None, maxsplit=0)) +118 | print(" ".split(maxsplit=0)) +119 | print(" ".split(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +120 | print(" x ".split(maxsplit=0)) +121 | print(" x ".split(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +116 116 | print("".split(maxsplit=0)) +117 117 | print("".split(sep=None, maxsplit=0)) +118 118 | print(" ".split(maxsplit=0)) +119 |-print(" ".split(sep=None, maxsplit=0)) + 119 |+print([]) +120 120 | print(" x ".split(maxsplit=0)) +121 121 | print(" x ".split(sep=None, maxsplit=0)) +122 122 | print(" x ".split(maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:120:7 + | +118 | print(" ".split(maxsplit=0)) +119 | print(" ".split(sep=None, maxsplit=0)) +120 | print(" x ".split(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^ +121 | print(" x ".split(sep=None, maxsplit=0)) +122 | print(" x ".split(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +117 117 | print("".split(sep=None, maxsplit=0)) +118 118 | print(" ".split(maxsplit=0)) +119 119 | print(" ".split(sep=None, maxsplit=0)) +120 |-print(" x ".split(maxsplit=0)) + 120 |+print(["x "]) +121 121 | print(" x ".split(sep=None, maxsplit=0)) +122 122 | print(" x ".split(maxsplit=0)) +123 123 | print(" x ".split(sep=None, maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:121:7 + | +119 | print(" ".split(sep=None, maxsplit=0)) +120 | print(" x ".split(maxsplit=0)) +121 | print(" x ".split(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +122 | print(" x ".split(maxsplit=0)) +123 | print(" x ".split(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +118 118 | print(" ".split(maxsplit=0)) +119 119 | print(" ".split(sep=None, maxsplit=0)) +120 120 | print(" x ".split(maxsplit=0)) +121 |-print(" x ".split(sep=None, maxsplit=0)) + 121 |+print(["x "]) +122 122 | print(" x ".split(maxsplit=0)) +123 123 | print(" x ".split(sep=None, maxsplit=0)) +124 124 | print("".rsplit(maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:122:7 + | +120 | print(" x ".split(maxsplit=0)) +121 | print(" x ".split(sep=None, maxsplit=0)) +122 | print(" x ".split(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +123 | print(" x ".split(sep=None, maxsplit=0)) +124 | print("".rsplit(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +119 119 | print(" ".split(sep=None, maxsplit=0)) +120 120 | print(" x ".split(maxsplit=0)) +121 121 | print(" x ".split(sep=None, maxsplit=0)) +122 |-print(" x ".split(maxsplit=0)) + 122 |+print(["x "]) +123 123 | print(" x ".split(sep=None, maxsplit=0)) +124 124 | print("".rsplit(maxsplit=0)) +125 125 | print("".rsplit(sep=None, maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:123:7 + | +121 | print(" x ".split(sep=None, maxsplit=0)) +122 | print(" x ".split(maxsplit=0)) +123 | print(" x ".split(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +124 | print("".rsplit(maxsplit=0)) +125 | print("".rsplit(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +120 120 | print(" x ".split(maxsplit=0)) +121 121 | print(" x ".split(sep=None, maxsplit=0)) +122 122 | print(" x ".split(maxsplit=0)) +123 |-print(" x ".split(sep=None, maxsplit=0)) + 123 |+print(["x "]) +124 124 | print("".rsplit(maxsplit=0)) +125 125 | print("".rsplit(sep=None, maxsplit=0)) +126 126 | print(" ".rsplit(maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:124:7 + | +122 | print(" x ".split(maxsplit=0)) +123 | print(" x ".split(sep=None, maxsplit=0)) +124 | print("".rsplit(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^ +125 | print("".rsplit(sep=None, maxsplit=0)) +126 | print(" ".rsplit(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +121 121 | print(" x ".split(sep=None, maxsplit=0)) +122 122 | print(" x ".split(maxsplit=0)) +123 123 | print(" x ".split(sep=None, maxsplit=0)) +124 |-print("".rsplit(maxsplit=0)) + 124 |+print([]) +125 125 | print("".rsplit(sep=None, maxsplit=0)) +126 126 | print(" ".rsplit(maxsplit=0)) +127 127 | print(" ".rsplit(sep=None, maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:125:7 + | +123 | print(" x ".split(sep=None, maxsplit=0)) +124 | print("".rsplit(maxsplit=0)) +125 | print("".rsplit(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +126 | print(" ".rsplit(maxsplit=0)) +127 | print(" ".rsplit(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +122 122 | print(" x ".split(maxsplit=0)) +123 123 | print(" x ".split(sep=None, maxsplit=0)) +124 124 | print("".rsplit(maxsplit=0)) +125 |-print("".rsplit(sep=None, maxsplit=0)) + 125 |+print([]) +126 126 | print(" ".rsplit(maxsplit=0)) +127 127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 128 | print(" x ".rsplit(maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:126:7 + | +124 | print("".rsplit(maxsplit=0)) +125 | print("".rsplit(sep=None, maxsplit=0)) +126 | print(" ".rsplit(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^ +127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 | print(" x ".rsplit(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +123 123 | print(" x ".split(sep=None, maxsplit=0)) +124 124 | print("".rsplit(maxsplit=0)) +125 125 | print("".rsplit(sep=None, maxsplit=0)) +126 |-print(" ".rsplit(maxsplit=0)) + 126 |+print([]) +127 127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 128 | print(" x ".rsplit(maxsplit=0)) +129 129 | print(" x ".rsplit(maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:127:7 + | +125 | print("".rsplit(sep=None, maxsplit=0)) +126 | print(" ".rsplit(maxsplit=0)) +127 | print(" ".rsplit(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +128 | print(" x ".rsplit(maxsplit=0)) +129 | print(" x ".rsplit(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +124 124 | print("".rsplit(maxsplit=0)) +125 125 | print("".rsplit(sep=None, maxsplit=0)) +126 126 | print(" ".rsplit(maxsplit=0)) +127 |-print(" ".rsplit(sep=None, maxsplit=0)) + 127 |+print([]) +128 128 | print(" x ".rsplit(maxsplit=0)) +129 129 | print(" x ".rsplit(maxsplit=0)) +130 130 | print(" x ".rsplit(sep=None, maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:128:7 + | +126 | print(" ".rsplit(maxsplit=0)) +127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 | print(" x ".rsplit(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^ +129 | print(" x ".rsplit(maxsplit=0)) +130 | print(" x ".rsplit(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +125 125 | print("".rsplit(sep=None, maxsplit=0)) +126 126 | print(" ".rsplit(maxsplit=0)) +127 127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 |-print(" x ".rsplit(maxsplit=0)) + 128 |+print([" x"]) +129 129 | print(" x ".rsplit(maxsplit=0)) +130 130 | print(" x ".rsplit(sep=None, maxsplit=0)) +131 131 | print(" x ".rsplit(maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:129:7 + | +127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 | print(" x ".rsplit(maxsplit=0)) +129 | print(" x ".rsplit(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^ +130 | print(" x ".rsplit(sep=None, maxsplit=0)) +131 | print(" x ".rsplit(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +126 126 | print(" ".rsplit(maxsplit=0)) +127 127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 128 | print(" x ".rsplit(maxsplit=0)) +129 |-print(" x ".rsplit(maxsplit=0)) + 129 |+print([" x"]) +130 130 | print(" x ".rsplit(sep=None, maxsplit=0)) +131 131 | print(" x ".rsplit(maxsplit=0)) +132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:130:7 + | +128 | print(" x ".rsplit(maxsplit=0)) +129 | print(" x ".rsplit(maxsplit=0)) +130 | print(" x ".rsplit(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +131 | print(" x ".rsplit(maxsplit=0)) +132 | print(" x ".rsplit(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +127 127 | print(" ".rsplit(sep=None, maxsplit=0)) +128 128 | print(" x ".rsplit(maxsplit=0)) +129 129 | print(" x ".rsplit(maxsplit=0)) +130 |-print(" x ".rsplit(sep=None, maxsplit=0)) + 130 |+print([" x"]) +131 131 | print(" x ".rsplit(maxsplit=0)) +132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) +133 133 | + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:131:7 + | +129 | print(" x ".rsplit(maxsplit=0)) +130 | print(" x ".rsplit(sep=None, maxsplit=0)) +131 | print(" x ".rsplit(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ +132 | print(" x ".rsplit(sep=None, maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +128 128 | print(" x ".rsplit(maxsplit=0)) +129 129 | print(" x ".rsplit(maxsplit=0)) +130 130 | print(" x ".rsplit(sep=None, maxsplit=0)) +131 |-print(" x ".rsplit(maxsplit=0)) + 131 |+print([" x"]) +132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) +133 133 | +134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:132:7 + | +130 | print(" x ".rsplit(sep=None, maxsplit=0)) +131 | print(" x ".rsplit(maxsplit=0)) +132 | print(" x ".rsplit(sep=None, maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +133 | +134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings + | +help: Replace with list literal + +ℹ Safe fix +129 129 | print(" x ".rsplit(maxsplit=0)) +130 130 | print(" x ".rsplit(sep=None, maxsplit=0)) +131 131 | print(" x ".rsplit(maxsplit=0)) +132 |-print(" x ".rsplit(sep=None, maxsplit=0)) + 132 |+print([" x"]) +133 133 | +134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings +135 135 | r"""simple@example.com + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:135:1 + | +134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings +135 | / r"""simple@example.com +136 | | very.common@example.com +137 | | FirstName.LastName@EasierReading.org +138 | | x@example.com +139 | | long.email-address-with-hyphens@and.subdomains.example.com +140 | | user.name+tag+sorting@example.com +141 | | name/surname@example.com +142 | | xample@s.example +143 | | " "@example.org +144 | | "john..doe"@example.org +145 | | mailhost!username@example.org +146 | | "very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com +147 | | user%example.com@example.org +148 | | user-@example.org +149 | | I❤️CHOCOLATE@example.com +150 | | this\ still\"not\\allowed@example.com +151 | | stellyamburrr985@example.com +152 | | Abc.123@example.com +153 | | user+mailbox/department=shipping@example.com +154 | | !#$%&'*+-/=?^_`.{|}~@example.com +155 | | "Abc@def"@example.com +156 | | "Fred\ Bloggs"@example.com +157 | | "Joe.\\Blow"@example.com""".split("\n") + | |_______________________________________^ + | +help: Replace with list literal + +ℹ Safe fix +132 132 | print(" x ".rsplit(sep=None, maxsplit=0)) +133 133 | +134 134 | # https://github.com/astral-sh/ruff/issues/19581 - embedded quotes in raw strings +135 |-r"""simple@example.com +136 |-very.common@example.com +137 |-FirstName.LastName@EasierReading.org +138 |-x@example.com +139 |-long.email-address-with-hyphens@and.subdomains.example.com +140 |-user.name+tag+sorting@example.com +141 |-name/surname@example.com +142 |-xample@s.example +143 |-" "@example.org +144 |-"john..doe"@example.org +145 |-mailhost!username@example.org +146 |-"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com +147 |-user%example.com@example.org +148 |-user-@example.org +149 |-I❤️CHOCOLATE@example.com +150 |-this\ still\"not\\allowed@example.com +151 |-stellyamburrr985@example.com +152 |-Abc.123@example.com +153 |-user+mailbox/department=shipping@example.com +154 |-!#$%&'*+-/=?^_`.{|}~@example.com +155 |-"Abc@def"@example.com +156 |-"Fred\ Bloggs"@example.com +157 |-"Joe.\\Blow"@example.com""".split("\n") + 135 |+[r"simple@example.com", r"very.common@example.com", r"FirstName.LastName@EasierReading.org", r"x@example.com", r"long.email-address-with-hyphens@and.subdomains.example.com", r"user.name+tag+sorting@example.com", r"name/surname@example.com", r"xample@s.example", r'" "@example.org', r'"john..doe"@example.org', r"mailhost!username@example.org", r'"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com', r"user%example.com@example.org", r"user-@example.org", r"I❤️CHOCOLATE@example.com", r'this\ still\"not\\allowed@example.com', r"stellyamburrr985@example.com", r"Abc.123@example.com", r"user+mailbox/department=shipping@example.com", r"!#$%&'*+-/=?^_`.{|}~@example.com", r'"Abc@def"@example.com', r'"Fred\ Bloggs"@example.com', r'"Joe.\\Blow"@example.com'] +158 136 | +159 137 | +160 138 | r"""first + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:160:1 + | +160 | / r"""first +161 | | 'no need' to escape +162 | | "swap" quote style +163 | | "use' ugly triple quotes""".split("\n") + | |_______________________________________^ +164 | +165 | # https://github.com/astral-sh/ruff/issues/19845 + | +help: Replace with list literal + +ℹ Safe fix +157 157 | "Joe.\\Blow"@example.com""".split("\n") +158 158 | +159 159 | +160 |-r"""first +161 |-'no need' to escape +162 |-"swap" quote style +163 |-"use' ugly triple quotes""".split("\n") + 160 |+[r"first", r"'no need' to escape", r'"swap" quote style', r""""use' ugly triple quotes"""] +164 161 | +165 162 | # https://github.com/astral-sh/ruff/issues/19845 +166 163 | print("S\x1cP\x1dL\x1eI\x1fT".split()) + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:166:7 + | +165 | # https://github.com/astral-sh/ruff/issues/19845 +166 | print("S\x1cP\x1dL\x1eI\x1fT".split()) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) +168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +163 163 | "use' ugly triple quotes""".split("\n") +164 164 | +165 165 | # https://github.com/astral-sh/ruff/issues/19845 +166 |-print("S\x1cP\x1dL\x1eI\x1fT".split()) + 166 |+print(["S", "P", "L", "I", "T"]) +167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) +168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) +169 169 | + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:167:7 + | +165 | # https://github.com/astral-sh/ruff/issues/19845 +166 | print("S\x1cP\x1dL\x1eI\x1fT".split()) +167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) + | +help: Replace with list literal + +ℹ Safe fix +164 164 | +165 165 | # https://github.com/astral-sh/ruff/issues/19845 +166 166 | print("S\x1cP\x1dL\x1eI\x1fT".split()) +167 |-print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) + 167 |+print([">"]) +168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) +169 169 | +170 170 | # leading/trailing whitespace should not count towards maxsplit + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:168:7 + | +166 | print("S\x1cP\x1dL\x1eI\x1fT".split()) +167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) +168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +169 | +170 | # leading/trailing whitespace should not count towards maxsplit + | +help: Replace with list literal + +ℹ Safe fix +165 165 | # https://github.com/astral-sh/ruff/issues/19845 +166 166 | print("S\x1cP\x1dL\x1eI\x1fT".split()) +167 167 | print("\x1c\x1d\x1e\x1f>".split(maxsplit=0)) +168 |-print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) + 168 |+print(["<"]) +169 169 | +170 170 | # leading/trailing whitespace should not count towards maxsplit +171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:171:1 + | +170 | # leading/trailing whitespace should not count towards maxsplit +171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] + | +help: Replace with list literal + +ℹ Safe fix +168 168 | print("<\x1c\x1d\x1e\x1f".rsplit(maxsplit=0)) +169 169 | +170 170 | # leading/trailing whitespace should not count towards maxsplit +171 |-" a b c d ".split(maxsplit=2) # ["a", "b", "c d "] + 171 |+["a", "b", "c d "] # ["a", "b", "c d "] +172 172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] + +SIM905 [*] Consider using a list literal instead of `str.split` + --> SIM905.py:172:1 + | +170 | # leading/trailing whitespace should not count towards maxsplit +171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] +172 | " a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Replace with list literal + +ℹ Safe fix +169 169 | +170 170 | # leading/trailing whitespace should not count towards maxsplit +171 171 | " a b c d ".split(maxsplit=2) # ["a", "b", "c d "] +172 |-" a b c d ".rsplit(maxsplit=2) # [" a b", "c", "d"] + 172 |+[" a b", "c", "d"] # [" a b", "c", "d"] From f0e9c1d8f9d73c911a6d2109e31c9dd6ff6ab44c Mon Sep 17 00:00:00 2001 From: Dan Parizher <105245560+danparizher@users.noreply.github.com> Date: Fri, 15 Aug 2025 17:17:50 -0400 Subject: [PATCH 014/160] [`isort`] Handle multiple continuation lines after module docstring (`I002`) (#19818) ## Summary Fixes #19815 --------- Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com> --- .../docstring_with_multiple_continuations.py | 4 ++++ crates/ruff_linter/src/importer/insertion.rs | 17 ++++++++++++++--- crates/ruff_linter/src/rules/isort/mod.rs | 2 ++ ...ocstring_with_multiple_continuations.py.snap | 13 +++++++++++++ ...ocstring_with_multiple_continuations.py.snap | 13 +++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 crates/ruff_linter/resources/test/fixtures/isort/required_imports/docstring_with_multiple_continuations.py create mode 100644 crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_docstring_with_multiple_continuations.py.snap create mode 100644 crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_with_alias_docstring_with_multiple_continuations.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/isort/required_imports/docstring_with_multiple_continuations.py b/crates/ruff_linter/resources/test/fixtures/isort/required_imports/docstring_with_multiple_continuations.py new file mode 100644 index 0000000000000..d98a63c3be376 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/isort/required_imports/docstring_with_multiple_continuations.py @@ -0,0 +1,4 @@ +"""Hello, world!"""\ +\ + +x = 1; y = 2 diff --git a/crates/ruff_linter/src/importer/insertion.rs b/crates/ruff_linter/src/importer/insertion.rs index fbef92894e410..69c9afbe6c61e 100644 --- a/crates/ruff_linter/src/importer/insertion.rs +++ b/crates/ruff_linter/src/importer/insertion.rs @@ -63,9 +63,9 @@ impl<'a> Insertion<'a> { return Insertion::inline(" ", location.add(offset).add(TextSize::of(';')), ";"); } - // If the first token after the docstring is a continuation character (i.e. "\"), advance - // an additional row to prevent inserting in the same logical line. - if match_continuation(locator.after(location)).is_some() { + // While the first token after the docstring is a continuation character (i.e. "\"), advance + // additional rows to prevent inserting in the same logical line. + while match_continuation(locator.after(location)).is_some() { location = locator.full_line_end(location); } @@ -379,6 +379,17 @@ mod tests { Insertion::own_line("", TextSize::from(22), "\n") ); + let contents = r#" +"""Hello, world!"""\ +\ + +"# + .trim_start(); + assert_eq!( + insert(contents)?, + Insertion::own_line("", TextSize::from(24), "\n") + ); + let contents = r" x = 1 " diff --git a/crates/ruff_linter/src/rules/isort/mod.rs b/crates/ruff_linter/src/rules/isort/mod.rs index 0ad92d763bacc..6f18ce05b817d 100644 --- a/crates/ruff_linter/src/rules/isort/mod.rs +++ b/crates/ruff_linter/src/rules/isort/mod.rs @@ -797,6 +797,7 @@ mod tests { #[test_case(Path::new("docstring_followed_by_continuation.py"))] #[test_case(Path::new("docstring_only.py"))] #[test_case(Path::new("docstring_with_continuation.py"))] + #[test_case(Path::new("docstring_with_multiple_continuations.py"))] #[test_case(Path::new("docstring_with_semicolon.py"))] #[test_case(Path::new("empty.py"))] #[test_case(Path::new("existing_import.py"))] @@ -832,6 +833,7 @@ mod tests { #[test_case(Path::new("docstring_followed_by_continuation.py"))] #[test_case(Path::new("docstring_only.py"))] #[test_case(Path::new("docstring_with_continuation.py"))] + #[test_case(Path::new("docstring_with_multiple_continuations.py"))] #[test_case(Path::new("docstring_with_semicolon.py"))] #[test_case(Path::new("empty.py"))] #[test_case(Path::new("existing_import.py"))] diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_docstring_with_multiple_continuations.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_docstring_with_multiple_continuations.py.snap new file mode 100644 index 0000000000000..3c438a2ed8204 --- /dev/null +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_docstring_with_multiple_continuations.py.snap @@ -0,0 +1,13 @@ +--- +source: crates/ruff_linter/src/rules/isort/mod.rs +--- +I002 [*] Missing required import: `from __future__ import annotations` +--> docstring_with_multiple_continuations.py:1:1 +help: Insert required import: `from __future__ import annotations` + +ℹ Safe fix +1 1 | """Hello, world!"""\ +2 2 | \ +3 3 | + 4 |+from __future__ import annotations +4 5 | x = 1; y = 2 diff --git a/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_with_alias_docstring_with_multiple_continuations.py.snap b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_with_alias_docstring_with_multiple_continuations.py.snap new file mode 100644 index 0000000000000..ce1f0d64bac87 --- /dev/null +++ b/crates/ruff_linter/src/rules/isort/snapshots/ruff_linter__rules__isort__tests__required_import_with_alias_docstring_with_multiple_continuations.py.snap @@ -0,0 +1,13 @@ +--- +source: crates/ruff_linter/src/rules/isort/mod.rs +--- +I002 [*] Missing required import: `from __future__ import annotations as _annotations` +--> docstring_with_multiple_continuations.py:1:1 +help: Insert required import: `from __future__ import annotations as _annotations` + +ℹ Safe fix +1 1 | """Hello, world!"""\ +2 2 | \ +3 3 | + 4 |+from __future__ import annotations as _annotations +4 5 | x = 1; y = 2 From 527a690a732ebec0ee2c5e43f6aebe0238a7e789 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Sat, 16 Aug 2025 16:37:28 +0200 Subject: [PATCH 015/160] [ty] Fix example in environment docs (#19937) --- crates/ty/docs/configuration.md | 2 +- crates/ty_project/src/metadata/options.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ty/docs/configuration.md b/crates/ty/docs/configuration.md index f2a39837fa717..946c814a5d852 100644 --- a/crates/ty/docs/configuration.md +++ b/crates/ty/docs/configuration.md @@ -44,7 +44,7 @@ or pyright's `stubPath` configuration setting. ```toml [tool.ty.environment] -extra-paths = ["~/shared/my-search-path"] +extra-paths = ["./shared/my-search-path"] ``` --- diff --git a/crates/ty_project/src/metadata/options.rs b/crates/ty_project/src/metadata/options.rs index cc008bbd091e9..5d21320049181 100644 --- a/crates/ty_project/src/metadata/options.rs +++ b/crates/ty_project/src/metadata/options.rs @@ -498,7 +498,7 @@ pub struct EnvironmentOptions { default = r#"[]"#, value_type = "list[str]", example = r#" - extra-paths = ["~/shared/my-search-path"] + extra-paths = ["./shared/my-search-path"] "# )] pub extra_paths: Option>, From f4d8826428cc8638f17f04cf514410f0753d9893 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 16 Aug 2025 18:45:15 +0100 Subject: [PATCH 016/160] [ty] Fix error message for invalidly providing type arguments to `NamedTuple` when it occurs in a type expression (#19940) --- crates/ty_python_semantic/resources/mdtest/named_tuple.md | 3 +++ crates/ty_python_semantic/src/types/infer.rs | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/named_tuple.md b/crates/ty_python_semantic/resources/mdtest/named_tuple.md index 94070455c9d68..3d20c984923f3 100644 --- a/crates/ty_python_semantic/resources/mdtest/named_tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/named_tuple.md @@ -312,6 +312,9 @@ def expects_named_tuple(x: typing.NamedTuple): def _(y: type[typing.NamedTuple]): reveal_type(y) # revealed: @Todo(unsupported type[X] special form) + +# error: [invalid-type-form] "Special form `typing.NamedTuple` expected no type parameter" +def _(z: typing.NamedTuple[int]): ... ``` Any instance of a `NamedTuple` class can therefore be passed for a function parameter that is diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index acd7fbb0baf7d..018eccd71ccd3 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -10783,7 +10783,8 @@ impl<'db> TypeInferenceBuilder<'db, '_> { SpecialFormType::TypingSelf | SpecialFormType::TypeAlias | SpecialFormType::TypedDict - | SpecialFormType::Unknown => { + | SpecialFormType::Unknown + | SpecialFormType::NamedTuple => { self.infer_type_expression(arguments_slice); if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) { @@ -10808,7 +10809,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { SpecialFormType::Tuple => { Type::tuple(self.infer_tuple_type_expression(arguments_slice)) } - SpecialFormType::Generic | SpecialFormType::Protocol | SpecialFormType::NamedTuple => { + SpecialFormType::Generic | SpecialFormType::Protocol => { self.infer_expression(arguments_slice); if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) { builder.into_diagnostic(format_args!( From 9ac39cee98d568c712f3849cc816265488119989 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sat, 16 Aug 2025 19:38:43 +0100 Subject: [PATCH 017/160] [ty] Ban protocols from inheriting from non-protocol generic classes (#19941) --- .../resources/mdtest/protocols.md | 8 ++++++++ crates/ty_python_semantic/src/types/infer.rs | 17 +++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/protocols.md b/crates/ty_python_semantic/resources/mdtest/protocols.md index e68cc538ee8f1..5c7899c7a4248 100644 --- a/crates/ty_python_semantic/resources/mdtest/protocols.md +++ b/crates/ty_python_semantic/resources/mdtest/protocols.md @@ -150,6 +150,14 @@ class AlsoInvalid(MyProtocol, OtherProtocol, NotAProtocol, Protocol): ... # revealed: tuple[, , , , typing.Protocol, typing.Generic, ] reveal_type(AlsoInvalid.__mro__) + +class NotAGenericProtocol[T]: ... + +# error: [invalid-protocol] "Protocol class `StillInvalid` cannot inherit from non-protocol class `NotAGenericProtocol`" +class StillInvalid(NotAGenericProtocol[int], Protocol): ... + +# revealed: tuple[, , typing.Protocol, typing.Generic, ] +reveal_type(StillInvalid.__mro__) ``` But two exceptions to this rule are `object` and `Generic`: diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 018eccd71ccd3..2a6ebc63ae863 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -1117,13 +1117,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { // - Check for inheritance from a `@final` classes // - If the class is a protocol class: check for inheritance from a non-protocol class for (i, base_class) in class.explicit_bases(self.db()).iter().enumerate() { - if let Some((class, solid_base)) = base_class - .to_class_type(self.db()) - .and_then(|class| Some((class, class.nearest_solid_base(self.db())?))) - { - solid_bases.insert(solid_base, i, class.class_literal(self.db()).0); - } - let base_class = match base_class { Type::SpecialForm(SpecialFormType::Generic) => { if let Some(builder) = self @@ -1155,13 +1148,17 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); continue; } - Type::ClassLiteral(class) => class, - // dynamic/unknown bases are never `@final` + Type::ClassLiteral(class) => ClassType::NonGeneric(*class), + Type::GenericAlias(class) => ClassType::Generic(*class), _ => continue, }; + if let Some(solid_base) = base_class.nearest_solid_base(self.db()) { + solid_bases.insert(solid_base, i, base_class.class_literal(self.db()).0); + } + if is_protocol - && !(base_class.is_protocol(self.db()) + && !(base_class.class_literal(self.db()).0.is_protocol(self.db()) || base_class.is_known(self.db(), KnownClass::Object)) { if let Some(builder) = self From b892e4548e9b71949b1a6cb52d10ccb0c61e50d3 Mon Sep 17 00:00:00 2001 From: Douglas Creager Date: Sat, 16 Aug 2025 18:25:03 -0400 Subject: [PATCH 018/160] [ty] Track when type variables are inferable or not (#19786) `Type::TypeVar` now distinguishes whether the typevar in question is inferable or not. A typevar is _not inferable_ inside the body of the generic class or function that binds it: ```py def f[T](t: T) -> T: return t ``` The infered type of `t` in the function body is `TypeVar(T, NotInferable)`. This represents how e.g. assignability checks need to be valid for all possible specializations of the typevar. Most of the existing assignability/etc logic only applies to non-inferable typevars. Outside of the function body, the typevar is _inferable_: ```py f(4) ``` Here, the parameter type of `f` is `TypeVar(T, Inferable)`. This represents how e.g. assignability doesn't need to hold for _all_ specializations; instead, we need to find the constraints under which this specific assignability check holds. This is in support of starting to perform specialization inference _as part of_ performing the assignability check at the call site. In the [[POPL2015][]] paper, this concept is called _monomorphic_ / _polymorphic_, but I thought _non-inferable_ / _inferable_ would be clearer for us. Depends on #19784 [POPL2015]: https://doi.org/10.1145/2676726.2676991 --------- Co-authored-by: Carl Meyer --- crates/ty_ide/src/completion.rs | 4 +- crates/ty_ide/src/semantic_tokens.rs | 4 +- .../resources/mdtest/annotations/self.md | 64 ++-- .../mdtest/generics/legacy/classes.md | 18 ++ .../mdtest/generics/pep695/classes.md | 13 + .../resources/mdtest/named_tuple.md | 8 +- .../ty_python_semantic/src/semantic_model.rs | 2 +- crates/ty_python_semantic/src/types.rs | 291 +++++++++++++----- .../ty_python_semantic/src/types/builder.rs | 3 +- crates/ty_python_semantic/src/types/class.rs | 7 +- .../src/types/class_base.rs | 1 + .../ty_python_semantic/src/types/display.rs | 18 +- .../ty_python_semantic/src/types/function.rs | 1 + .../ty_python_semantic/src/types/generics.rs | 38 ++- .../src/types/ide_support.rs | 1 + crates/ty_python_semantic/src/types/infer.rs | 9 +- crates/ty_python_semantic/src/types/narrow.rs | 3 +- .../src/types/signatures.rs | 43 ++- .../src/types/subclass_of.rs | 2 +- .../src/types/type_ordering.rs | 4 + .../ty_python_semantic/src/types/visitor.rs | 7 + 21 files changed, 383 insertions(+), 158 deletions(-) diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index c452ff75ffcb5..72d4a29756fc0 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -1247,7 +1247,7 @@ quux. __init_subclass__ :: bound method Quux.__init_subclass__() -> None __module__ :: str __ne__ :: bound method Quux.__ne__(value: object, /) -> bool - __new__ :: bound method Quux.__new__() -> Self@__new__ + __new__ :: bound method Quux.__new__() -> Quux __reduce__ :: bound method Quux.__reduce__() -> str | tuple[Any, ...] __reduce_ex__ :: bound method Quux.__reduce_ex__(protocol: SupportsIndex, /) -> str | tuple[Any, ...] __repr__ :: bound method Quux.__repr__() -> str @@ -1292,7 +1292,7 @@ quux.b __init_subclass__ :: bound method Quux.__init_subclass__() -> None __module__ :: str __ne__ :: bound method Quux.__ne__(value: object, /) -> bool - __new__ :: bound method Quux.__new__() -> Self@__new__ + __new__ :: bound method Quux.__new__() -> Quux __reduce__ :: bound method Quux.__reduce__() -> str | tuple[Any, ...] __reduce_ex__ :: bound method Quux.__reduce_ex__(protocol: SupportsIndex, /) -> str | tuple[Any, ...] __repr__ :: bound method Quux.__repr__() -> str diff --git a/crates/ty_ide/src/semantic_tokens.rs b/crates/ty_ide/src/semantic_tokens.rs index f8f6955bc53a1..749671ad1813c 100644 --- a/crates/ty_ide/src/semantic_tokens.rs +++ b/crates/ty_ide/src/semantic_tokens.rs @@ -337,7 +337,9 @@ impl<'db> SemanticTokenVisitor<'db> { match ty { Type::ClassLiteral(_) => (SemanticTokenType::Class, modifiers), - Type::TypeVar(_) => (SemanticTokenType::TypeParameter, modifiers), + Type::NonInferableTypeVar(_) | Type::TypeVar(_) => { + (SemanticTokenType::TypeParameter, modifiers) + } Type::FunctionLiteral(_) => { // Check if this is a method based on current scope if self.in_class_scope { diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/self.md b/crates/ty_python_semantic/resources/mdtest/annotations/self.md index d03dd21c02ae1..e476e03a75c46 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/self.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/self.md @@ -1,16 +1,16 @@ # Self +```toml +[environment] +python-version = "3.11" +``` + `Self` is treated as if it were a `TypeVar` bound to the class it's being used on. `typing.Self` is only available in Python 3.11 and later. ## Methods -```toml -[environment] -python-version = "3.11" -``` - ```py from typing import Self @@ -74,11 +74,6 @@ reveal_type(C().method()) # revealed: C ## Class Methods -```toml -[environment] -python-version = "3.11" -``` - ```py from typing import Self, TypeVar @@ -101,11 +96,6 @@ reveal_type(Shape.bar()) # revealed: Unknown ## Attributes -```toml -[environment] -python-version = "3.11" -``` - TODO: The use of `Self` to annotate the `next_node` attribute should be [modeled as a property][self attribute], using `Self` in its parameter and return type. @@ -127,11 +117,6 @@ reveal_type(LinkedList().next()) # revealed: LinkedList ## Generic Classes -```toml -[environment] -python-version = "3.11" -``` - ```py from typing import Self, Generic, TypeVar @@ -153,11 +138,6 @@ TODO: ## Annotations -```toml -[environment] -python-version = "3.11" -``` - ```py from typing import Self @@ -171,11 +151,6 @@ class Shape: `Self` cannot be used in the signature of a function or variable. -```toml -[environment] -python-version = "3.11" -``` - ```py from typing import Self, Generic, TypeVar @@ -218,4 +193,33 @@ class MyMetaclass(type): return super().__new__(cls) ``` +## Binding a method fixes `Self` + +When a method is bound, any instances of `Self` in its signature are "fixed", since we now know the +specific type of the bound parameter. + +```py +from typing import Self + +class C: + def instance_method(self, other: Self) -> Self: + return self + + @classmethod + def class_method(cls) -> Self: + return cls() + +# revealed: bound method C.instance_method(other: C) -> C +reveal_type(C().instance_method) +# revealed: bound method .class_method() -> C +reveal_type(C.class_method) + +class D(C): ... + +# revealed: bound method D.instance_method(other: D) -> D +reveal_type(D().instance_method) +# revealed: bound method .class_method() -> D +reveal_type(D.class_method) +``` + [self attribute]: https://typing.python.org/en/latest/spec/generics.html#use-in-attribute-annotations diff --git a/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md b/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md index 0a60e08d85f68..234de56a8cb73 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/legacy/classes.md @@ -491,6 +491,24 @@ class A(Generic[T]): reveal_type(A(x=1)) # revealed: A[int] ``` +### Class typevar has another typevar as a default + +```py +from typing import Generic, TypeVar + +T = TypeVar("T") +U = TypeVar("U", default=T) + +class C(Generic[T, U]): ... + +reveal_type(C()) # revealed: C[Unknown, Unknown] + +class D(Generic[T, U]): + def __init__(self) -> None: ... + +reveal_type(D()) # revealed: D[Unknown, Unknown] +``` + ## Generic subclass When a generic subclass fills its superclass's type parameter with one of its own, the actual types diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md index 261c3d370d975..56cdbc426bf9a 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md @@ -438,6 +438,19 @@ class A[T]: reveal_type(A(x=1)) # revealed: A[int] ``` +### Class typevar has another typevar as a default + +```py +class C[T, U = T]: ... + +reveal_type(C()) # revealed: C[Unknown, Unknown] + +class D[T, U = T]: + def __init__(self) -> None: ... + +reveal_type(D()) # revealed: D[Unknown, Unknown] +``` + ## Generic subclass When a generic subclass fills its superclass's type parameter with one of its own, the actual types diff --git a/crates/ty_python_semantic/resources/mdtest/named_tuple.md b/crates/ty_python_semantic/resources/mdtest/named_tuple.md index 3d20c984923f3..b89d0a457e942 100644 --- a/crates/ty_python_semantic/resources/mdtest/named_tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/named_tuple.md @@ -243,7 +243,7 @@ class Person(NamedTuple): reveal_type(Person._field_defaults) # revealed: dict[str, Any] reveal_type(Person._fields) # revealed: tuple[str, ...] -reveal_type(Person._make) # revealed: bound method ._make(iterable: Iterable[Any]) -> Self@_make +reveal_type(Person._make) # revealed: bound method ._make(iterable: Iterable[Any]) -> Person reveal_type(Person._asdict) # revealed: def _asdict(self) -> dict[str, Any] reveal_type(Person._replace) # revealed: def _replace(self, **kwargs: Any) -> Self@_replace @@ -304,8 +304,8 @@ satisfy: ```py def expects_named_tuple(x: typing.NamedTuple): reveal_type(x) # revealed: tuple[object, ...] & NamedTupleLike - reveal_type(x._make) # revealed: bound method type[NamedTupleLike]._make(iterable: Iterable[Any]) -> Self@_make - reveal_type(x._replace) # revealed: bound method NamedTupleLike._replace(**kwargs) -> Self@_replace + reveal_type(x._make) # revealed: bound method type[NamedTupleLike]._make(iterable: Iterable[Any]) -> NamedTupleLike + reveal_type(x._replace) # revealed: bound method NamedTupleLike._replace(**kwargs) -> NamedTupleLike # revealed: Overload[(value: tuple[object, ...], /) -> tuple[object, ...], (value: tuple[_T@__add__, ...], /) -> tuple[object, ...]] reveal_type(x.__add__) reveal_type(x.__iter__) # revealed: bound method tuple[object, ...].__iter__() -> Iterator[object] @@ -328,7 +328,7 @@ class Point(NamedTuple): x: int y: int -reveal_type(Point._make) # revealed: bound method ._make(iterable: Iterable[Any]) -> Self@_make +reveal_type(Point._make) # revealed: bound method ._make(iterable: Iterable[Any]) -> Point reveal_type(Point._asdict) # revealed: def _asdict(self) -> dict[str, Any] reveal_type(Point._replace) # revealed: def _replace(self, **kwargs: Any) -> Self@_replace diff --git a/crates/ty_python_semantic/src/semantic_model.rs b/crates/ty_python_semantic/src/semantic_model.rs index 52587fe60f713..1aeeb36db7778 100644 --- a/crates/ty_python_semantic/src/semantic_model.rs +++ b/crates/ty_python_semantic/src/semantic_model.rs @@ -232,7 +232,7 @@ impl<'db> Completion<'db> { | Type::BytesLiteral(_) => CompletionKind::Value, Type::EnumLiteral(_) => CompletionKind::Enum, Type::ProtocolInstance(_) => CompletionKind::Interface, - Type::TypeVar(_) => CompletionKind::TypeParameter, + Type::NonInferableTypeVar(_) | Type::TypeVar(_) => CompletionKind::TypeParameter, Type::Union(union) => union.elements(db).iter().find_map(|&ty| imp(db, ty))?, Type::Intersection(intersection) => { intersection.iter_positive(db).find_map(|ty| imp(db, ty))? diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index ad7a4c0ade918..2636acfd899fd 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -44,7 +44,7 @@ use crate::types::context::{LintDiagnosticGuard, LintDiagnosticGuardBuilder}; use crate::types::diagnostic::{INVALID_AWAIT, INVALID_TYPE_FORM, UNSUPPORTED_BOOL_CONVERSION}; use crate::types::enums::{enum_metadata, is_single_member_enum}; use crate::types::function::{ - DataclassTransformerParams, FunctionSpans, FunctionType, KnownFunction, + DataclassTransformerParams, FunctionDecorators, FunctionSpans, FunctionType, KnownFunction, }; use crate::types::generics::{ GenericContext, PartialSpecialization, Specialization, bind_typevar, walk_generic_context, @@ -612,9 +612,15 @@ pub enum Type<'db> { LiteralString, /// A bytes literal BytesLiteral(BytesLiteralType<'db>), - /// An instance of a typevar in a generic class or function. When the generic class or function - /// is specialized, we will replace this typevar with its specialization. + /// An instance of a typevar in a context where we can infer a specialization for it. (This is + /// typically the signature of a generic function, or of a constructor of a generic class.) + /// When the generic class or function binding this typevar is specialized, we will replace the + /// typevar with its specialization. TypeVar(BoundTypeVarInstance<'db>), + /// An instance of a typevar where we cannot infer a specialization for it. (This is typically + /// the body of the generic function or class that binds the typevar.) In these positions, + /// properties like assignability must hold for all possible specializations. + NonInferableTypeVar(BoundTypeVarInstance<'db>), /// A bound super object like `super()` or `super(A, A())` /// This type doesn't handle an unbound super object like `super(A)`; for that we just use /// a `Type::NominalInstance` of `builtins.super`. @@ -823,6 +829,9 @@ impl<'db> Type<'db> { ) .build(), Type::TypeVar(bound_typevar) => Type::TypeVar(bound_typevar.materialize(db, variance)), + Type::NonInferableTypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar.materialize(db, variance)) + } Type::TypeIs(type_is) => { type_is.with_type(db, type_is.return_type(db).materialize(db, variance)) } @@ -1127,6 +1136,9 @@ impl<'db> Type<'db> { Type::TypeVar(bound_typevar) => visitor.visit(self, || { Type::TypeVar(bound_typevar.normalized_impl(db, visitor)) }), + Type::NonInferableTypeVar(bound_typevar) => visitor.visit(self, || { + Type::NonInferableTypeVar(bound_typevar.normalized_impl(db, visitor)) + }), Type::KnownInstance(known_instance) => visitor.visit(self, || { Type::KnownInstance(known_instance.normalized_impl(db, visitor)) }), @@ -1203,6 +1215,7 @@ impl<'db> Type<'db> { | Type::Union(_) | Type::Intersection(_) | Type::Callable(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::BoundSuper(_) | Type::TypeIs(_) @@ -1283,6 +1296,7 @@ impl<'db> Type<'db> { | Type::KnownInstance(_) | Type::PropertyInstance(_) | Type::Intersection(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::BoundSuper(_) => None, } @@ -1399,13 +1413,17 @@ impl<'db> Type<'db> { // However, there is one exception to this general rule: for any given typevar `T`, // `T` will always be a subtype of any union containing `T`. // A similar rule applies in reverse to intersection types. - (Type::TypeVar(_), Type::Union(union)) if union.elements(db).contains(&self) => true, - (Type::Intersection(intersection), Type::TypeVar(_)) + (Type::NonInferableTypeVar(_), Type::Union(union)) + if union.elements(db).contains(&self) => + { + true + } + (Type::Intersection(intersection), Type::NonInferableTypeVar(_)) if intersection.positive(db).contains(&target) => { true } - (Type::Intersection(intersection), Type::TypeVar(_)) + (Type::Intersection(intersection), Type::NonInferableTypeVar(_)) if intersection.negative(db).contains(&target) => { false @@ -1416,16 +1434,15 @@ impl<'db> Type<'db> { // // Note that this is not handled by the early return at the beginning of this method, // since subtyping between a TypeVar and an arbitrary other type cannot be guaranteed to be reflexive. - (Type::TypeVar(lhs_bound_typevar), Type::TypeVar(rhs_bound_typevar)) - if lhs_bound_typevar == rhs_bound_typevar => - { - true - } + ( + Type::NonInferableTypeVar(lhs_bound_typevar), + Type::NonInferableTypeVar(rhs_bound_typevar), + ) if lhs_bound_typevar == rhs_bound_typevar => true, // A fully static typevar is a subtype of its upper bound, and to something similar to // the union of its constraints. An unbound, unconstrained, fully static typevar has an // implicit upper bound of `object` (which is handled above). - (Type::TypeVar(bound_typevar), _) + (Type::NonInferableTypeVar(bound_typevar), _) if bound_typevar.typevar(db).bound_or_constraints(db).is_some() => { match bound_typevar.typevar(db).bound_or_constraints(db) { @@ -1444,7 +1461,7 @@ impl<'db> Type<'db> { // If the typevar is constrained, there must be multiple constraints, and the typevar // might be specialized to any one of them. However, the constraints do not have to be // disjoint, which means an lhs type might be a subtype of all of the constraints. - (_, Type::TypeVar(bound_typevar)) + (_, Type::NonInferableTypeVar(bound_typevar)) if bound_typevar .typevar(db) .constraints(db) @@ -1496,7 +1513,10 @@ impl<'db> Type<'db> { // (If the typevar is bounded, it might be specialized to a smaller type than the // bound. This is true even if the bound is a final class, since the typevar can still // be specialized to `Never`.) - (_, Type::TypeVar(_)) => false, + (_, Type::NonInferableTypeVar(_)) => false, + + // TODO: Infer specializations here + (Type::TypeVar(_), _) | (_, Type::TypeVar(_)) => false, // Note that the definition of `Type::AlwaysFalsy` depends on the return value of `__bool__`. // If `__bool__` always returns True or False, it can be treated as a subtype of `AlwaysTruthy` or `AlwaysFalsy`, respectively. @@ -1756,7 +1776,7 @@ impl<'db> Type<'db> { // Other than the special cases enumerated above, `Instance` types and typevars are // never subtypes of any other variants - (Type::NominalInstance(_) | Type::TypeVar(_), _) => false, + (Type::NominalInstance(_) | Type::NonInferableTypeVar(_), _) => false, } } @@ -1913,14 +1933,14 @@ impl<'db> Type<'db> { // be specialized to the same type. (This is an important difference between typevars // and `Any`!) Different typevars might be disjoint, depending on their bounds and // constraints, which are handled below. - (Type::TypeVar(self_bound_typevar), Type::TypeVar(other_bound_typevar)) + (Type::NonInferableTypeVar(self_bound_typevar), Type::NonInferableTypeVar(other_bound_typevar)) if self_bound_typevar == other_bound_typevar => { false } - (tvar @ Type::TypeVar(_), Type::Intersection(intersection)) - | (Type::Intersection(intersection), tvar @ Type::TypeVar(_)) + (tvar @ Type::NonInferableTypeVar(_), Type::Intersection(intersection)) + | (Type::Intersection(intersection), tvar @ Type::NonInferableTypeVar(_)) if intersection.negative(db).contains(&tvar) => { true @@ -1930,7 +1950,7 @@ impl<'db> Type<'db> { // specialized to any type. A bounded typevar is not disjoint from its bound, and is // only disjoint from other types if its bound is. A constrained typevar is disjoint // from a type if all of its constraints are. - (Type::TypeVar(bound_typevar), other) | (other, Type::TypeVar(bound_typevar)) => { + (Type::NonInferableTypeVar(bound_typevar), other) | (other, Type::NonInferableTypeVar(bound_typevar)) => { match bound_typevar.typevar(db).bound_or_constraints(db) { None => false, Some(TypeVarBoundOrConstraints::UpperBound(bound)) => { @@ -1943,6 +1963,10 @@ impl<'db> Type<'db> { } } + // TODO: Infer specializations here + (Type::TypeVar(_), _) + | (_, Type::TypeVar(_)) => false, + (Type::Union(union), other) | (other, Type::Union(union)) => union .elements(db) .iter() @@ -2383,7 +2407,7 @@ impl<'db> Type<'db> { // the bound is a final singleton class, since it can still be specialized to `Never`. // A constrained typevar is a singleton if all of its constraints are singletons. (Note // that you cannot specialize a constrained typevar to a subtype of a constraint.) - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) => { match bound_typevar.typevar(db).bound_or_constraints(db) { None => false, Some(TypeVarBoundOrConstraints::UpperBound(_)) => false, @@ -2394,6 +2418,8 @@ impl<'db> Type<'db> { } } + Type::TypeVar(_) => false, + // We eagerly transform `SubclassOf` to `ClassLiteral` for final types, so `SubclassOf` is never a singleton. Type::SubclassOf(..) => false, Type::BoundSuper(..) => false, @@ -2513,7 +2539,7 @@ impl<'db> Type<'db> { // `Never`. A constrained typevar is single-valued if all of its constraints are // single-valued. (Note that you cannot specialize a constrained typevar to a subtype // of a constraint.) - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) => { match bound_typevar.typevar(db).bound_or_constraints(db) { None => false, Some(TypeVarBoundOrConstraints::UpperBound(_)) => false, @@ -2524,6 +2550,8 @@ impl<'db> Type<'db> { } } + Type::TypeVar(_) => false, + Type::SubclassOf(..) => { // TODO: Same comment as above for `is_singleton` false @@ -2680,6 +2708,7 @@ impl<'db> Type<'db> { | Type::LiteralString | Type::BytesLiteral(_) | Type::EnumLiteral(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::NominalInstance(_) | Type::ProtocolInstance(_) @@ -2790,7 +2819,7 @@ impl<'db> Type<'db> { Type::object(db).instance_member(db, name) } - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) => { match bound_typevar.typevar(db).bound_or_constraints(db) { None => Type::object(db).instance_member(db, name), Some(TypeVarBoundOrConstraints::UpperBound(bound)) => { @@ -2803,6 +2832,16 @@ impl<'db> Type<'db> { } } + Type::TypeVar(_) => { + debug_assert!( + false, + "should not be able to access instance member `{name}` \ + of type variable {} in inferable position", + self.display(db) + ); + Place::Unbound.into() + } + Type::IntLiteral(_) => KnownClass::Int.to_instance(db).instance_member(db, name), Type::BooleanLiteral(_) | Type::TypeIs(_) => { KnownClass::Bool.to_instance(db).instance_member(db, name) @@ -3329,6 +3368,7 @@ impl<'db> Type<'db> { | Type::BytesLiteral(..) | Type::EnumLiteral(..) | Type::LiteralString + | Type::NonInferableTypeVar(..) | Type::TypeVar(..) | Type::SpecialForm(..) | Type::KnownInstance(..) @@ -3664,7 +3704,7 @@ impl<'db> Type<'db> { } }, - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) => { match bound_typevar.typevar(db).bound_or_constraints(db) { None => Truthiness::Ambiguous, Some(TypeVarBoundOrConstraints::UpperBound(bound)) => { @@ -3675,6 +3715,7 @@ impl<'db> Type<'db> { } } } + Type::TypeVar(_) => Truthiness::Ambiguous, Type::NominalInstance(instance) => instance .class(db) @@ -3767,7 +3808,7 @@ impl<'db> Type<'db> { .into() } - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) => { match bound_typevar.typevar(db).bound_or_constraints(db) { None => CallableBinding::not_callable(self).into(), Some(TypeVarBoundOrConstraints::UpperBound(bound)) => bound.bindings(db), @@ -3780,6 +3821,15 @@ impl<'db> Type<'db> { } } + Type::TypeVar(_) => { + debug_assert!( + false, + "should not be able to call type variable {} in inferable position", + self.display(db) + ); + CallableBinding::not_callable(self).into() + } + Type::BoundMethod(bound_method) => { let signature = bound_method.function(db).signature(db); CallableBinding::from_overloads(self, signature.overloads.iter().cloned()) @@ -5111,20 +5161,22 @@ impl<'db> Type<'db> { // have the class's typevars still in the method signature when we attempt to call it. To // do this, we instead use the _identity_ specialization, which maps each of the class's // generic typevars to itself. - let (generic_origin, generic_context, self_type) = - match self { - Type::ClassLiteral(class) => match class.generic_context(db) { - Some(generic_context) => ( - Some(class), - Some(generic_context), - Type::from(class.apply_specialization(db, |_| { - generic_context.identity_specialization(db) - })), - ), - _ => (None, None, self), - }, + let (generic_origin, generic_context, self_type) = match self { + Type::ClassLiteral(class) => match class.generic_context(db) { + Some(generic_context) => ( + Some(class), + Some(generic_context), + Type::from(class.apply_specialization(db, |_| { + // It is important that identity_specialization specializes the class with + // _inferable_ typevars, so that our specialization inference logic will + // try to find a specialization for them. + generic_context.identity_specialization(db) + })), + ), _ => (None, None, self), - }; + }, + _ => (None, None, self), + }; // As of now we do not model custom `__call__` on meta-classes, so the code below // only deals with interplay between `__new__` and `__init__` methods. @@ -5281,32 +5333,10 @@ impl<'db> Type<'db> { // If there is no bound or constraints on a typevar `T`, `T: object` implicitly, which // has no instance type. Otherwise, synthesize a typevar with bound or constraints // mapped through `to_instance`. - Type::TypeVar(bound_typevar) => { - let typevar = bound_typevar.typevar(db); - let bound_or_constraints = match typevar.bound_or_constraints(db)? { - TypeVarBoundOrConstraints::UpperBound(upper_bound) => { - TypeVarBoundOrConstraints::UpperBound(upper_bound.to_instance(db)?) - } - TypeVarBoundOrConstraints::Constraints(constraints) => { - TypeVarBoundOrConstraints::Constraints( - constraints.to_instance(db)?.into_union()?, - ) - } - }; - Some(Type::TypeVar(BoundTypeVarInstance::new( - db, - TypeVarInstance::new( - db, - Name::new(format!("{}'instance", typevar.name(db))), - None, - Some(bound_or_constraints.into()), - typevar.variance(db), - None, - typevar.kind(db), - ), - bound_typevar.binding_context(db), - ))) + Type::NonInferableTypeVar(bound_typevar) => { + Some(Type::NonInferableTypeVar(bound_typevar.to_instance(db)?)) } + Type::TypeVar(bound_typevar) => Some(Type::TypeVar(bound_typevar.to_instance(db)?)), Type::TypeAlias(alias) => alias.value_type(db).to_instance(db), Type::Intersection(_) => Some(todo_type!("Type::Intersection.to_instance")), Type::BooleanLiteral(_) @@ -5390,6 +5420,7 @@ impl<'db> Type<'db> { | Type::LiteralString | Type::ModuleLiteral(_) | Type::StringLiteral(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::Callable(_) | Type::BoundMethod(_) @@ -5423,7 +5454,7 @@ impl<'db> Type<'db> { typevar_binding_context, *typevar, ) - .map(Type::TypeVar) + .map(Type::NonInferableTypeVar) .unwrap_or(*self)) } KnownInstanceType::Deprecated(_) => Err(InvalidTypeExpressionError { @@ -5506,7 +5537,7 @@ impl<'db> Type<'db> { Some(TypeVarBoundOrConstraints::UpperBound(instance).into()), TypeVarVariance::Invariant, None, - TypeVarKind::Implicit, + TypeVarKind::TypingSelf, ); Ok(bind_typevar( db, @@ -5516,7 +5547,7 @@ impl<'db> Type<'db> { typevar_binding_context, typevar, ) - .map(Type::TypeVar) + .map(Type::NonInferableTypeVar) .unwrap_or(*self)) } SpecialFormType::TypeAlias => Ok(Type::Dynamic(DynamicType::TodoTypeAlias)), @@ -5685,7 +5716,7 @@ impl<'db> Type<'db> { } Type::Callable(_) | Type::DataclassTransformer(_) => KnownClass::Type.to_instance(db), Type::ModuleLiteral(_) => KnownClass::ModuleType.to_class_literal(db), - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) => { match bound_typevar.typevar(db).bound_or_constraints(db) { None => KnownClass::Type.to_instance(db), Some(TypeVarBoundOrConstraints::UpperBound(bound)) => bound.to_meta_type(db), @@ -5696,6 +5727,7 @@ impl<'db> Type<'db> { } } } + Type::TypeVar(_) => KnownClass::Type.to_instance(db), Type::ClassLiteral(class) => class.metaclass(db), Type::GenericAlias(alias) => ClassType::from(*alias).metaclass(db), @@ -5792,16 +5824,46 @@ impl<'db> Type<'db> { TypeMapping::PartialSpecialization(partial) => { partial.get(db, bound_typevar).unwrap_or(self) } - TypeMapping::PromoteLiterals | TypeMapping::BindLegacyTypevars(_) => self, + TypeMapping::BindSelf(self_type) => { + if bound_typevar.typevar(db).is_self(db) { + *self_type + } else { + self + } + } + TypeMapping::PromoteLiterals | TypeMapping::BindLegacyTypevars(_) | + TypeMapping::MarkTypeVarsInferable(_) => self, + } + + Type::NonInferableTypeVar(bound_typevar) => match type_mapping { + TypeMapping::Specialization(specialization) => { + specialization.get(db, bound_typevar).unwrap_or(self) + } + TypeMapping::PartialSpecialization(partial) => { + partial.get(db, bound_typevar).unwrap_or(self) + } + TypeMapping::MarkTypeVarsInferable(binding_context) => { + if bound_typevar.binding_context(db) == *binding_context { + Type::TypeVar(bound_typevar) + } else { + self + } + } + TypeMapping::PromoteLiterals | + TypeMapping::BindLegacyTypevars(_) | + TypeMapping::BindSelf(_) + => self, } Type::KnownInstance(KnownInstanceType::TypeVar(typevar)) => match type_mapping { - TypeMapping::Specialization(_) | - TypeMapping::PartialSpecialization(_) | - TypeMapping::PromoteLiterals => self, TypeMapping::BindLegacyTypevars(binding_context) => { Type::TypeVar(BoundTypeVarInstance::new(db, typevar, *binding_context)) } + TypeMapping::Specialization(_) | + TypeMapping::PartialSpecialization(_) | + TypeMapping::PromoteLiterals | + TypeMapping::BindSelf(_) | + TypeMapping::MarkTypeVarsInferable(_) => self, } Type::FunctionLiteral(function) => { @@ -5896,7 +5958,9 @@ impl<'db> Type<'db> { | Type::EnumLiteral(_) => match type_mapping { TypeMapping::Specialization(_) | TypeMapping::PartialSpecialization(_) | - TypeMapping::BindLegacyTypevars(_) => self, + TypeMapping::BindLegacyTypevars(_) | + TypeMapping::BindSelf(_) | + TypeMapping::MarkTypeVarsInferable(_) => self, TypeMapping::PromoteLiterals => self.literal_fallback_instance(db) .expect("literal type should have fallback instance type"), } @@ -5929,10 +5993,10 @@ impl<'db> Type<'db> { typevars: &mut FxOrderSet>, ) { match self { - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) | Type::TypeVar(bound_typevar) => { if matches!( bound_typevar.typevar(db).kind(db), - TypeVarKind::Legacy | TypeVarKind::Implicit + TypeVarKind::Legacy | TypeVarKind::TypingSelf ) && binding_context.is_none_or(|binding_context| { bound_typevar.binding_context(db) == BindingContext::Definition(binding_context) }) { @@ -6145,6 +6209,7 @@ impl<'db> Type<'db> { | Self::PropertyInstance(_) | Self::BoundSuper(_) => self.to_meta_type(db).definition(db), + Self::NonInferableTypeVar(bound_typevar) | Self::TypeVar(bound_typevar) => Some(TypeDefinition::TypeVar(bound_typevar.typevar(db).definition(db)?)), Self::ProtocolInstance(protocol) => match protocol.inner { @@ -6270,6 +6335,10 @@ pub enum TypeMapping<'a, 'db> { /// Binds a legacy typevar with the generic context (class, function, type alias) that it is /// being used in. BindLegacyTypevars(BindingContext<'db>), + /// Binds any `typing.Self` typevar with a particular `self` class. + BindSelf(Type<'db>), + /// Marks the typevars that are bound by a generic class or function as inferable. + MarkTypeVarsInferable(BindingContext<'db>), } fn walk_type_mapping<'db, V: visitor::TypeVisitor<'db> + ?Sized>( @@ -6284,7 +6353,12 @@ fn walk_type_mapping<'db, V: visitor::TypeVisitor<'db> + ?Sized>( TypeMapping::PartialSpecialization(specialization) => { walk_partial_specialization(db, specialization, visitor); } - TypeMapping::PromoteLiterals | TypeMapping::BindLegacyTypevars(_) => {} + TypeMapping::BindSelf(self_type) => { + visitor.visit_type(db, *self_type); + } + TypeMapping::PromoteLiterals + | TypeMapping::BindLegacyTypevars(_) + | TypeMapping::MarkTypeVarsInferable(_) => {} } } @@ -6301,6 +6375,10 @@ impl<'db> TypeMapping<'_, 'db> { TypeMapping::BindLegacyTypevars(binding_context) => { TypeMapping::BindLegacyTypevars(*binding_context) } + TypeMapping::BindSelf(self_type) => TypeMapping::BindSelf(*self_type), + TypeMapping::MarkTypeVarsInferable(binding_context) => { + TypeMapping::MarkTypeVarsInferable(*binding_context) + } } } @@ -6316,6 +6394,12 @@ impl<'db> TypeMapping<'_, 'db> { TypeMapping::BindLegacyTypevars(binding_context) => { TypeMapping::BindLegacyTypevars(*binding_context) } + TypeMapping::BindSelf(self_type) => { + TypeMapping::BindSelf(self_type.normalized_impl(db, visitor)) + } + TypeMapping::MarkTypeVarsInferable(binding_context) => { + TypeMapping::MarkTypeVarsInferable(*binding_context) + } } } } @@ -6836,7 +6920,7 @@ pub enum TypeVarKind { /// `def foo[T](x: T) -> T: ...` Pep695, /// `typing.Self` - Implicit, + TypingSelf, } /// A type variable that has not been bound to a generic context yet. @@ -6926,8 +7010,8 @@ impl<'db> TypeVarInstance<'db> { BoundTypeVarInstance::new(db, self, BindingContext::Definition(binding_context)) } - pub(crate) fn is_implicit(self, db: &'db dyn Db) -> bool { - matches!(self.kind(db), TypeVarKind::Implicit) + pub(crate) fn is_self(self, db: &'db dyn Db) -> bool { + matches!(self.kind(db), TypeVarKind::TypingSelf) } pub(crate) fn upper_bound(self, db: &'db dyn Db) -> Option> { @@ -7022,6 +7106,26 @@ impl<'db> TypeVarInstance<'db> { ) } + fn to_instance(self, db: &'db dyn Db) -> Option { + let bound_or_constraints = match self.bound_or_constraints(db)? { + TypeVarBoundOrConstraints::UpperBound(upper_bound) => { + TypeVarBoundOrConstraints::UpperBound(upper_bound.to_instance(db)?) + } + TypeVarBoundOrConstraints::Constraints(constraints) => { + TypeVarBoundOrConstraints::Constraints(constraints.to_instance(db)?.into_union()?) + } + }; + Some(Self::new( + db, + Name::new(format!("{}'instance", self.name(db))), + None, + Some(bound_or_constraints.into()), + self.variance(db), + None, + self.kind(db), + )) + } + #[salsa::tracked] fn lazy_bound(self, db: &'db dyn Db) -> Option> { let definition = self.definition(db)?; @@ -7138,6 +7242,14 @@ impl<'db> BoundTypeVarInstance<'db> { self.binding_context(db), ) } + + fn to_instance(self, db: &'db dyn Db) -> Option { + Some(Self::new( + db, + self.typevar(db).to_instance(db)?, + self.binding_context(db), + )) + } } #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, salsa::Update, get_size2::GetSize)] @@ -8328,16 +8440,35 @@ fn walk_bound_method_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( visitor.visit_type(db, method.self_instance(db)); } +#[salsa::tracked] impl<'db> BoundMethodType<'db> { + /// Returns the type that replaces any `typing.Self` annotations in the bound method signature. + /// This is normally the bound-instance type (the type of `self` or `cls`), but if the bound method is + /// a `@classmethod`, then it should be an instance of that bound-instance type. + pub(crate) fn typing_self_type(self, db: &'db dyn Db) -> Type<'db> { + let mut self_instance = self.self_instance(db); + if self + .function(db) + .has_known_decorator(db, FunctionDecorators::CLASSMETHOD) + { + self_instance = self_instance.to_instance(db).unwrap_or_else(Type::unknown); + } + self_instance + } + + #[salsa::tracked(heap_size=ruff_memory_usage::heap_size)] pub(crate) fn into_callable_type(self, db: &'db dyn Db) -> CallableType<'db> { + let function = self.function(db); + let self_instance = self.typing_self_type(db); + CallableType::new( db, CallableSignature::from_overloads( - self.function(db) + function .signature(db) .overloads .iter() - .map(signatures::Signature::bind_self), + .map(|signature| signature.bind_self(db, Some(self_instance))), ), false, ) @@ -8435,7 +8566,7 @@ impl<'db> CallableType<'db> { pub(crate) fn bind_self(self, db: &'db dyn Db) -> Type<'db> { Type::Callable(CallableType::new( db, - self.signatures(db).bind_self(), + self.signatures(db).bind_self(db, None), false, )) } diff --git a/crates/ty_python_semantic/src/types/builder.rs b/crates/ty_python_semantic/src/types/builder.rs index 8e529e4fcafd5..0f6ba1782d3e5 100644 --- a/crates/ty_python_semantic/src/types/builder.rs +++ b/crates/ty_python_semantic/src/types/builder.rs @@ -983,7 +983,8 @@ impl<'db> InnerIntersectionBuilder<'db> { let mut positive_to_remove = SmallVec::<[usize; 1]>::new(); for (typevar_index, ty) in self.positive.iter().enumerate() { - let Type::TypeVar(bound_typevar) = ty else { + let (Type::NonInferableTypeVar(bound_typevar) | Type::TypeVar(bound_typevar)) = ty + else { continue; }; let Some(TypeVarBoundOrConstraints::Constraints(constraints)) = diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index cd749f8444060..beac62e3618d0 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -966,6 +966,7 @@ impl<'db> ClassType<'db> { /// Return a callable type (or union of callable types) that represents the callable /// constructor signature of this class. + #[salsa::tracked(heap_size=ruff_memory_usage::heap_size)] pub(super) fn into_callable(self, db: &'db dyn Db) -> Type<'db> { let self_ty = Type::from(self); let metaclass_dunder_call_function_symbol = self_ty @@ -1017,9 +1018,10 @@ impl<'db> ClassType<'db> { }) }); + let instance_ty = Type::instance(db, self); let dunder_new_bound_method = Type::Callable(CallableType::new( db, - dunder_new_signature.bind_self(), + dunder_new_signature.bind_self(db, Some(instance_ty)), true, )); @@ -1057,9 +1059,10 @@ impl<'db> ClassType<'db> { if let Some(signature) = signature { let synthesized_signature = |signature: &Signature<'db>| { + let instance_ty = Type::instance(db, self); Signature::new(signature.parameters().clone(), Some(correct_return_type)) .with_definition(signature.definition()) - .bind_self() + .bind_self(db, Some(instance_ty)) }; let synthesized_dunder_init_signature = CallableSignature::from_overloads( diff --git a/crates/ty_python_semantic/src/types/class_base.rs b/crates/ty_python_semantic/src/types/class_base.rs index aff7e833ce19b..e8a5fd1e41e8f 100644 --- a/crates/ty_python_semantic/src/types/class_base.rs +++ b/crates/ty_python_semantic/src/types/class_base.rs @@ -155,6 +155,7 @@ impl<'db> ClassBase<'db> { | Type::StringLiteral(_) | Type::LiteralString | Type::ModuleLiteral(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::BoundSuper(_) | Type::ProtocolInstance(_) diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index b50ca3d996b10..3d23a8393d25a 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -130,6 +130,8 @@ impl Display for DisplayRepresentation<'_> { Type::Callable(callable) => callable.display(self.db).fmt(f), Type::BoundMethod(bound_method) => { let function = bound_method.function(self.db); + let self_ty = bound_method.self_instance(self.db); + let typing_self_ty = bound_method.typing_self_type(self.db); match function.signature(self.db).overloads.as_slice() { [signature] => { @@ -142,9 +144,11 @@ impl Display for DisplayRepresentation<'_> { f, "bound method {instance}.{method}{type_parameters}{signature}", method = function.name(self.db), - instance = bound_method.self_instance(self.db).display(self.db), + instance = self_ty.display(self.db), type_parameters = type_parameters, - signature = signature.bind_self().display(self.db) + signature = signature + .bind_self(self.db, Some(typing_self_ty)) + .display(self.db) ) } signatures => { @@ -152,7 +156,11 @@ impl Display for DisplayRepresentation<'_> { f.write_str("Overload[")?; let mut join = f.join(", "); for signature in signatures { - join.entry(&signature.bind_self().display(self.db)); + join.entry( + &signature + .bind_self(self.db, Some(typing_self_ty)) + .display(self.db), + ); } f.write_str("]") } @@ -214,7 +222,7 @@ impl Display for DisplayRepresentation<'_> { name = enum_literal.name(self.db), ) } - Type::TypeVar(bound_typevar) => { + Type::NonInferableTypeVar(bound_typevar) | Type::TypeVar(bound_typevar) => { f.write_str(bound_typevar.typevar(self.db).name(self.db))?; if let Some(binding_context) = bound_typevar.binding_context(self.db).name(self.db) { @@ -455,7 +463,7 @@ impl Display for DisplayGenericContext<'_> { let non_implicit_variables: Vec<_> = variables .iter() - .filter(|bound_typevar| !bound_typevar.typevar(self.db).is_implicit(self.db)) + .filter(|bound_typevar| !bound_typevar.typevar(self.db).is_self(self.db)) .collect(); if non_implicit_variables.is_empty() { diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 632425f16c3be..b482e23e7439f 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -1014,6 +1014,7 @@ fn is_instance_truthiness<'db>( | Type::PropertyInstance(..) | Type::AlwaysTruthy | Type::AlwaysFalsy + | Type::NonInferableTypeVar(..) | Type::TypeVar(..) | Type::BoundSuper(..) | Type::TypeIs(..) diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index 00089be337e41..8b628fd375528 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -236,7 +236,8 @@ impl<'db> GenericContext<'db> { db: &'db dyn Db, known_class: Option, ) -> Specialization<'db> { - let partial = self.specialize_partial(db, &vec![None; self.variables(db).len()]); + let partial = + self.specialize_partial(db, std::iter::repeat_n(None, self.variables(db).len())); if known_class == Some(KnownClass::Tuple) { Specialization::new( db, @@ -249,6 +250,10 @@ impl<'db> GenericContext<'db> { } } + /// Returns a specialization of this generic context where each typevar is mapped to itself. + /// (And in particular, to an _inferable_ version of itself, since this will be used in our + /// class constructor invocation machinery to infer a specialization for the class from the + /// arguments passed to its constructor.) pub(crate) fn identity_specialization(self, db: &'db dyn Db) -> Specialization<'db> { let types = self .variables(db) @@ -314,11 +319,12 @@ impl<'db> GenericContext<'db> { /// Creates a specialization of this generic context. Panics if the length of `types` does not /// match the number of typevars in the generic context. If any provided type is `None`, we /// will use the corresponding typevar's default type. - pub(crate) fn specialize_partial( - self, - db: &'db dyn Db, - types: &[Option>], - ) -> Specialization<'db> { + pub(crate) fn specialize_partial(self, db: &'db dyn Db, types: I) -> Specialization<'db> + where + I: IntoIterator>>, + I::IntoIter: ExactSizeIterator, + { + let types = types.into_iter(); let variables = self.variables(db); assert!(variables.len() == types.len()); @@ -331,9 +337,9 @@ impl<'db> GenericContext<'db> { // If there is a mapping for `T`, we want to map `U` to that type, not to `T`. To handle // this, we repeatedly apply the specialization to itself, until we reach a fixed point. let mut expanded = vec![Type::unknown(); types.len()]; - for (idx, (ty, typevar)) in types.iter().zip(variables).enumerate() { + for (idx, (ty, typevar)) in types.zip(variables).enumerate() { if let Some(ty) = ty { - expanded[idx] = *ty; + expanded[idx] = ty; continue; } @@ -749,18 +755,12 @@ impl<'db> SpecializationBuilder<'db> { } pub(crate) fn build(&mut self, generic_context: GenericContext<'db>) -> Specialization<'db> { - let types: Box<[_]> = generic_context + let types = generic_context .variables(self.db) .iter() - .map(|variable| { - self.types - .get(variable) - .copied() - .unwrap_or(variable.default_type(self.db).unwrap_or(Type::unknown())) - }) - .collect(); + .map(|variable| self.types.get(variable).copied()); // TODO Infer the tuple spec for a tuple type - Specialization::new(self.db, generic_context, types, None) + generic_context.specialize_partial(self.db, types) } fn add_type_mapping(&mut self, bound_typevar: BoundTypeVarInstance<'db>, ty: Type<'db>) { @@ -777,6 +777,10 @@ impl<'db> SpecializationBuilder<'db> { formal: Type<'db>, actual: Type<'db>, ) -> Result<(), SpecializationError<'db>> { + if formal == actual { + return Ok(()); + } + // If the actual type is a subtype of the formal type, then return without adding any new // type mappings. (Note that if the formal type contains any typevars, this check will // fail, since no non-typevar types are assignable to a typevar. Also note that we are diff --git a/crates/ty_python_semantic/src/types/ide_support.rs b/crates/ty_python_semantic/src/types/ide_support.rs index 12f3a07bd08ec..36a139145c301 100644 --- a/crates/ty_python_semantic/src/types/ide_support.rs +++ b/crates/ty_python_semantic/src/types/ide_support.rs @@ -151,6 +151,7 @@ impl<'db> AllMembers<'db> { | Type::ProtocolInstance(_) | Type::SpecialForm(_) | Type::KnownInstance(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::BoundSuper(_) | Type::TypeIs(_) => match ty.to_meta_type(db) { diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 2a6ebc63ae863..c819d1d3486e9 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -4025,6 +4025,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | Type::WrapperDescriptor(_) | Type::DataclassDecorator(_) | Type::DataclassTransformer(_) + | Type::NonInferableTypeVar(..) | Type::TypeVar(..) | Type::AlwaysTruthy | Type::AlwaysFalsy @@ -7231,6 +7232,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | Type::BytesLiteral(_) | Type::EnumLiteral(_) | Type::BoundSuper(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::TypeIs(_) | Type::TypedDict(_), @@ -7572,6 +7574,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | Type::BytesLiteral(_) | Type::EnumLiteral(_) | Type::BoundSuper(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::TypeIs(_) | Type::TypedDict(_), @@ -7601,6 +7604,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { | Type::BytesLiteral(_) | Type::EnumLiteral(_) | Type::BoundSuper(_) + | Type::NonInferableTypeVar(_) | Type::TypeVar(_) | Type::TypeIs(_) | Type::TypedDict(_), @@ -8652,7 +8656,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { .next() .expect("valid bindings should have matching overload"); Type::from(generic_class.apply_specialization(self.db(), |_| { - generic_context.specialize_partial(self.db(), overload.parameter_types()) + generic_context + .specialize_partial(self.db(), overload.parameter_types().iter().copied()) })) } @@ -10604,7 +10609,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let mut signature_iter = callable_binding.into_iter().map(|binding| { if argument_type.is_bound_method() { - binding.signature.bind_self() + binding.signature.bind_self(self.db(), Some(argument_type)) } else { binding.signature.clone() } diff --git a/crates/ty_python_semantic/src/types/narrow.rs b/crates/ty_python_semantic/src/types/narrow.rs index 8569c961d5d8d..d1df76dee6fa2 100644 --- a/crates/ty_python_semantic/src/types/narrow.rs +++ b/crates/ty_python_semantic/src/types/narrow.rs @@ -215,7 +215,7 @@ impl ClassInfoConstraintFunction { Type::Union(union) => { union.try_map(db, |element| self.generate_constraint(db, *element)) } - Type::TypeVar(bound_typevar) => match bound_typevar + Type::NonInferableTypeVar(bound_typevar) => match bound_typevar .typevar(db) .bound_or_constraints(db)? { @@ -259,6 +259,7 @@ impl ClassInfoConstraintFunction { | Type::IntLiteral(_) | Type::KnownInstance(_) | Type::TypeIs(_) + | Type::TypeVar(_) | Type::WrapperDescriptor(_) | Type::DataclassTransformer(_) | Type::TypedDict(_) => None, diff --git a/crates/ty_python_semantic/src/types/signatures.rs b/crates/ty_python_semantic/src/types/signatures.rs index 11ca44bb8fa7e..8d1492adc6970 100644 --- a/crates/ty_python_semantic/src/types/signatures.rs +++ b/crates/ty_python_semantic/src/types/signatures.rs @@ -19,7 +19,8 @@ use super::{DynamicType, Type, TypeVarVariance, definition_expression_type}; use crate::semantic_index::definition::Definition; use crate::types::generics::{GenericContext, walk_generic_context}; use crate::types::{ - BoundTypeVarInstance, KnownClass, NormalizedVisitor, TypeMapping, TypeRelation, todo_type, + BindingContext, BoundTypeVarInstance, KnownClass, NormalizedVisitor, TypeMapping, TypeRelation, + todo_type, }; use crate::{Db, FxOrderSet}; use ruff_python_ast::{self as ast, name::Name}; @@ -98,9 +99,16 @@ impl<'db> CallableSignature<'db> { } } - pub(crate) fn bind_self(&self) -> Self { + /// Binds the first (presumably `self`) parameter of this signature. If a `self_type` is + /// provided, we will replace any occurrences of `typing.Self` in the parameter and return + /// annotations with that type. + pub(crate) fn bind_self(&self, db: &'db dyn Db, self_type: Option>) -> Self { Self { - overloads: self.overloads.iter().map(Signature::bind_self).collect(), + overloads: self + .overloads + .iter() + .map(|signature| signature.bind_self(db, self_type)) + .collect(), } } @@ -328,8 +336,11 @@ impl<'db> Signature<'db> { let parameters = Parameters::from_parameters(db, definition, function_node.parameters.as_ref()); let return_ty = function_node.returns.as_ref().map(|returns| { - let plain_return_ty = definition_expression_type(db, definition, returns.as_ref()); - + let plain_return_ty = definition_expression_type(db, definition, returns.as_ref()) + .apply_type_mapping( + db, + &TypeMapping::MarkTypeVarsInferable(BindingContext::Definition(definition)), + ); if function_node.is_async && !is_generator { KnownClass::CoroutineType .to_specialized_instance(db, [Type::any(), Type::any(), plain_return_ty]) @@ -457,13 +468,20 @@ impl<'db> Signature<'db> { self.definition } - pub(crate) fn bind_self(&self) -> Self { + pub(crate) fn bind_self(&self, db: &'db dyn Db, self_type: Option>) -> Self { + let mut parameters = Parameters::new(self.parameters().iter().skip(1).cloned()); + let mut return_ty = self.return_ty; + if let Some(self_type) = self_type { + parameters = parameters.apply_type_mapping(db, &TypeMapping::BindSelf(self_type)); + return_ty = + return_ty.map(|ty| ty.apply_type_mapping(db, &TypeMapping::BindSelf(self_type))); + } Self { generic_context: self.generic_context, inherited_generic_context: self.inherited_generic_context, definition: self.definition, - parameters: Parameters::new(self.parameters().iter().skip(1).cloned()), - return_ty: self.return_ty, + parameters, + return_ty, } } @@ -1432,9 +1450,12 @@ impl<'db> Parameter<'db> { kind: ParameterKind<'db>, ) -> Self { Self { - annotated_type: parameter - .annotation() - .map(|annotation| definition_expression_type(db, definition, annotation)), + annotated_type: parameter.annotation().map(|annotation| { + definition_expression_type(db, definition, annotation).apply_type_mapping( + db, + &TypeMapping::MarkTypeVarsInferable(BindingContext::Definition(definition)), + ) + }), kind, form: ParameterForm::Value, } diff --git a/crates/ty_python_semantic/src/types/subclass_of.rs b/crates/ty_python_semantic/src/types/subclass_of.rs index 1a67759432b3d..c27e92018e1e4 100644 --- a/crates/ty_python_semantic/src/types/subclass_of.rs +++ b/crates/ty_python_semantic/src/types/subclass_of.rs @@ -91,7 +91,7 @@ impl<'db> SubclassOfType<'db> { TypeVarVariance::Invariant => { // We need to materialize this to `type[T]` but that isn't representable so // we instead use a type variable with an upper bound of `type`. - Type::TypeVar(BoundTypeVarInstance::new( + Type::NonInferableTypeVar(BoundTypeVarInstance::new( db, TypeVarInstance::new( db, diff --git a/crates/ty_python_semantic/src/types/type_ordering.rs b/crates/ty_python_semantic/src/types/type_ordering.rs index 0747fc8d176d6..21612c36148ac 100644 --- a/crates/ty_python_semantic/src/types/type_ordering.rs +++ b/crates/ty_python_semantic/src/types/type_ordering.rs @@ -142,6 +142,10 @@ pub(super) fn union_or_intersection_elements_ordering<'db>( (Type::ProtocolInstance(_), _) => Ordering::Less, (_, Type::ProtocolInstance(_)) => Ordering::Greater, + (Type::NonInferableTypeVar(left), Type::NonInferableTypeVar(right)) => left.cmp(right), + (Type::NonInferableTypeVar(_), _) => Ordering::Less, + (_, Type::NonInferableTypeVar(_)) => Ordering::Greater, + (Type::TypeVar(left), Type::TypeVar(right)) => left.cmp(right), (Type::TypeVar(_), _) => Ordering::Less, (_, Type::TypeVar(_)) => Ordering::Greater, diff --git a/crates/ty_python_semantic/src/types/visitor.rs b/crates/ty_python_semantic/src/types/visitor.rs index deb68eab7427c..4b58f20bf5071 100644 --- a/crates/ty_python_semantic/src/types/visitor.rs +++ b/crates/ty_python_semantic/src/types/visitor.rs @@ -114,6 +114,7 @@ enum NonAtomicType<'db> { NominalInstance(NominalInstanceType<'db>), PropertyInstance(PropertyInstanceType<'db>), TypeIs(TypeIsType<'db>), + NonInferableTypeVar(BoundTypeVarInstance<'db>), TypeVar(BoundTypeVarInstance<'db>), ProtocolInstance(ProtocolInstanceType<'db>), TypedDict(TypedDictType<'db>), @@ -177,6 +178,9 @@ impl<'db> From> for TypeKind<'db> { Type::PropertyInstance(property) => { TypeKind::NonAtomic(NonAtomicType::PropertyInstance(property)) } + Type::NonInferableTypeVar(bound_typevar) => { + TypeKind::NonAtomic(NonAtomicType::NonInferableTypeVar(bound_typevar)) + } Type::TypeVar(bound_typevar) => { TypeKind::NonAtomic(NonAtomicType::TypeVar(bound_typevar)) } @@ -216,6 +220,9 @@ fn walk_non_atomic_type<'db, V: TypeVisitor<'db> + ?Sized>( visitor.visit_property_instance_type(db, property); } NonAtomicType::TypeIs(type_is) => visitor.visit_typeis_type(db, type_is), + NonAtomicType::NonInferableTypeVar(bound_typevar) => { + visitor.visit_bound_type_var_type(db, bound_typevar); + } NonAtomicType::TypeVar(bound_typevar) => { visitor.visit_bound_type_var_type(db, bound_typevar); } From ec3163781c645b2e72414e8b0c5686e815d34e0d Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 17 Aug 2025 18:54:24 +0100 Subject: [PATCH 019/160] [ty] Remove unused code (#19949) --- crates/ty_ide/src/lib.rs | 3 +- crates/ty_python_semantic/src/types.rs | 206 +++++++----------- .../src/types/call/arguments.rs | 2 +- .../ty_python_semantic/src/types/generics.rs | 13 +- 4 files changed, 83 insertions(+), 141 deletions(-) diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index 45d5c897f0615..55e4a920f84a1 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -235,7 +235,8 @@ impl HasNavigationTargets for Type<'_> { fn navigation_targets(&self, db: &dyn Db) -> NavigationTargets { match self { Type::Union(union) => union - .iter(db) + .elements(db) + .iter() .flat_map(|target| target.navigation_targets(db)) .collect(), diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 2636acfd899fd..3440ee58b0590 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -3,7 +3,6 @@ use itertools::{Either, Itertools}; use ruff_db::parsed::parsed_module; use std::borrow::Cow; -use std::slice::Iter; use bitflags::bitflags; use call::{CallDunderError, CallError, CallErrorKind}; @@ -635,15 +634,15 @@ pub enum Type<'db> { #[salsa::tracked] impl<'db> Type<'db> { - pub const fn any() -> Self { + pub(crate) const fn any() -> Self { Self::Dynamic(DynamicType::Any) } - pub const fn unknown() -> Self { + pub(crate) const fn unknown() -> Self { Self::Dynamic(DynamicType::Unknown) } - pub fn object(db: &'db dyn Db) -> Self { + pub(crate) fn object(db: &'db dyn Db) -> Self { KnownClass::Object.to_instance(db) } @@ -651,12 +650,12 @@ impl<'db> Type<'db> { matches!(self, Type::Dynamic(DynamicType::Unknown)) } - pub const fn is_never(&self) -> bool { + pub(crate) const fn is_never(&self) -> bool { matches!(self, Type::Never) } /// Returns `true` if `self` is [`Type::Callable`]. - pub const fn is_callable_type(&self) -> bool { + pub(crate) const fn is_callable_type(&self) -> bool { matches!(self, Type::Callable(..)) } @@ -670,7 +669,7 @@ impl<'db> Type<'db> { .is_some_and(|instance| instance.class(db).is_known(db, KnownClass::Bool)) } - pub fn is_notimplemented(&self, db: &'db dyn Db) -> bool { + pub(crate) fn is_notimplemented(&self, db: &'db dyn Db) -> bool { self.into_nominal_instance().is_some_and(|instance| { instance .class(db) @@ -678,16 +677,16 @@ impl<'db> Type<'db> { }) } - pub fn is_object(&self, db: &'db dyn Db) -> bool { + pub(crate) fn is_object(&self, db: &'db dyn Db) -> bool { self.into_nominal_instance() .is_some_and(|instance| instance.is_object(db)) } - pub const fn is_todo(&self) -> bool { + pub(crate) const fn is_todo(&self) -> bool { matches!(self, Type::Dynamic(DynamicType::Todo(_))) } - pub const fn is_generic_alias(&self) -> bool { + pub(crate) const fn is_generic_alias(&self) -> bool { matches!(self, Type::GenericAlias(_)) } @@ -843,43 +842,38 @@ impl<'db> Type<'db> { } } - pub const fn into_class_literal(self) -> Option> { + pub(crate) const fn into_class_literal(self) -> Option> { match self { Type::ClassLiteral(class_type) => Some(class_type), _ => None, } } - pub const fn into_subclass_of(self) -> Option> { - match self { - Type::SubclassOf(subclass_of) => Some(subclass_of), - _ => None, - } - } - #[track_caller] - pub fn expect_class_literal(self) -> ClassLiteral<'db> { + pub(crate) fn expect_class_literal(self) -> ClassLiteral<'db> { self.into_class_literal() .expect("Expected a Type::ClassLiteral variant") } - pub const fn is_subclass_of(&self) -> bool { + pub(crate) const fn is_subclass_of(&self) -> bool { matches!(self, Type::SubclassOf(..)) } - pub const fn is_class_literal(&self) -> bool { + #[cfg(test)] + pub(crate) const fn is_class_literal(&self) -> bool { matches!(self, Type::ClassLiteral(..)) } - pub fn into_enum_literal(self) -> Option> { + pub(crate) fn into_enum_literal(self) -> Option> { match self { Type::EnumLiteral(enum_literal) => Some(enum_literal), _ => None, } } + #[cfg(test)] #[track_caller] - pub fn expect_enum_literal(self) -> EnumLiteralType<'db> { + pub(crate) fn expect_enum_literal(self) -> EnumLiteralType<'db> { self.into_enum_literal() .expect("Expected a Type::EnumLiteral variant") } @@ -898,7 +892,7 @@ impl<'db> Type<'db> { /// Turn a class literal (`Type::ClassLiteral` or `Type::GenericAlias`) into a `ClassType`. /// Since a `ClassType` must be specialized, apply the default specialization to any /// unspecialized generic class literal. - pub fn to_class_type(self, db: &'db dyn Db) -> Option> { + pub(crate) fn to_class_type(self, db: &'db dyn Db) -> Option> { match self { Type::ClassLiteral(class_literal) => Some(class_literal.default_specialization(db)), Type::GenericAlias(alias) => Some(ClassType::Generic(alias)), @@ -906,25 +900,15 @@ impl<'db> Type<'db> { } } - #[track_caller] - pub fn expect_class_type(self, db: &'db dyn Db) -> ClassType<'db> { - self.to_class_type(db) - .expect("Expected a Type::GenericAlias or Type::ClassLiteral variant") - } - - pub fn is_class_type(&self, db: &'db dyn Db) -> bool { - match self { - Type::ClassLiteral(class) if class.generic_context(db).is_none() => true, - Type::GenericAlias(_) => true, - _ => false, - } - } - pub const fn is_property_instance(&self) -> bool { matches!(self, Type::PropertyInstance(..)) } - pub fn module_literal(db: &'db dyn Db, importing_file: File, submodule: Module<'db>) -> Self { + pub(crate) fn module_literal( + db: &'db dyn Db, + importing_file: File, + submodule: Module<'db>, + ) -> Self { Self::ModuleLiteral(ModuleLiteralType::new( db, submodule, @@ -932,70 +916,50 @@ impl<'db> Type<'db> { )) } - pub const fn into_module_literal(self) -> Option> { + pub(crate) const fn into_module_literal(self) -> Option> { match self { Type::ModuleLiteral(module) => Some(module), _ => None, } } - #[track_caller] - pub fn expect_module_literal(self) -> ModuleLiteralType<'db> { - self.into_module_literal() - .expect("Expected a Type::ModuleLiteral variant") - } - - pub const fn into_union(self) -> Option> { + pub(crate) const fn into_union(self) -> Option> { match self { Type::Union(union_type) => Some(union_type), _ => None, } } + #[cfg(test)] #[track_caller] - pub fn expect_union(self) -> UnionType<'db> { + pub(crate) fn expect_union(self) -> UnionType<'db> { self.into_union().expect("Expected a Type::Union variant") } - pub const fn is_union(&self) -> bool { - matches!(self, Type::Union(..)) - } - - pub const fn into_intersection(self) -> Option> { - match self { - Type::Intersection(intersection_type) => Some(intersection_type), - _ => None, - } - } - - #[track_caller] - pub fn expect_intersection(self) -> IntersectionType<'db> { - self.into_intersection() - .expect("Expected a Type::Intersection variant") - } - - pub const fn into_function_literal(self) -> Option> { + pub(crate) const fn into_function_literal(self) -> Option> { match self { Type::FunctionLiteral(function_type) => Some(function_type), _ => None, } } + #[cfg(test)] #[track_caller] - pub fn expect_function_literal(self) -> FunctionType<'db> { + pub(crate) fn expect_function_literal(self) -> FunctionType<'db> { self.into_function_literal() .expect("Expected a Type::FunctionLiteral variant") } - pub const fn is_function_literal(&self) -> bool { + #[cfg(test)] + pub(crate) const fn is_function_literal(&self) -> bool { matches!(self, Type::FunctionLiteral(..)) } - pub const fn is_bound_method(&self) -> bool { + pub(crate) const fn is_bound_method(&self) -> bool { matches!(self, Type::BoundMethod(..)) } - pub fn is_union_of_single_valued(&self, db: &'db dyn Db) -> bool { + pub(crate) fn is_union_of_single_valued(&self, db: &'db dyn Db) -> bool { self.into_union().is_some_and(|union| { union .elements(db) @@ -1005,43 +969,22 @@ impl<'db> Type<'db> { || self.is_literal_string() } - pub const fn into_int_literal(self) -> Option { - match self { - Type::IntLiteral(value) => Some(value), - _ => None, - } - } - - pub fn into_string_literal(self) -> Option> { + pub(crate) fn into_string_literal(self) -> Option> { match self { Type::StringLiteral(string_literal) => Some(string_literal), _ => None, } } - pub fn is_string_literal(&self) -> bool { - matches!(self, Type::StringLiteral(..)) - } - - #[track_caller] - pub fn expect_int_literal(self) -> i64 { - self.into_int_literal() - .expect("Expected a Type::IntLiteral variant") - } - - pub const fn is_boolean_literal(&self) -> bool { - matches!(self, Type::BooleanLiteral(..)) - } - - pub const fn is_literal_string(&self) -> bool { + pub(crate) const fn is_literal_string(&self) -> bool { matches!(self, Type::LiteralString) } - pub fn string_literal(db: &'db dyn Db, string: &str) -> Self { + pub(crate) fn string_literal(db: &'db dyn Db, string: &str) -> Self { Self::StringLiteral(StringLiteralType::new(db, string)) } - pub fn bytes_literal(db: &'db dyn Db, bytes: &[u8]) -> Self { + pub(crate) fn bytes_literal(db: &'db dyn Db, bytes: &[u8]) -> Self { Self::BytesLiteral(BytesLiteralType::new(db, bytes)) } @@ -1052,18 +995,18 @@ impl<'db> Type<'db> { } #[must_use] - pub fn negate(&self, db: &'db dyn Db) -> Type<'db> { + pub(crate) fn negate(&self, db: &'db dyn Db) -> Type<'db> { IntersectionBuilder::new(db).add_negative(*self).build() } #[must_use] - pub fn negate_if(&self, db: &'db dyn Db, yes: bool) -> Type<'db> { + pub(crate) fn negate_if(&self, db: &'db dyn Db, yes: bool) -> Type<'db> { if yes { self.negate(db) } else { *self } } /// Returns the fallback instance type that a literal is an instance of, or `None` if the type /// is not a literal. - pub fn literal_fallback_instance(self, db: &'db dyn Db) -> Option> { + pub(crate) fn literal_fallback_instance(self, db: &'db dyn Db) -> Option> { // There are other literal types that could conceivable be included here: class literals // falling back to `type[X]`, for instance. For now, there is not much rigorous thought put // into what's included vs not; this is just an empirical choice that makes our ecosystem @@ -1090,7 +1033,7 @@ impl<'db> Type<'db> { /// *has* or *does not have* a default value is relevant to whether two `Callable` types are equivalent. /// - Converts class-based protocols into synthesized protocols #[must_use] - pub fn normalized(self, db: &'db dyn Db) -> Self { + pub(crate) fn normalized(self, db: &'db dyn Db) -> Self { self.normalized_impl(db, &TypeTransformer::default()) } @@ -5323,11 +5266,11 @@ impl<'db> Type<'db> { } #[must_use] - pub fn to_instance(&self, db: &'db dyn Db) -> Option> { + pub(crate) fn to_instance(self, db: &'db dyn Db) -> Option> { match self { - Type::Dynamic(_) | Type::Never => Some(*self), + Type::Dynamic(_) | Type::Never => Some(self), Type::ClassLiteral(class) => Some(Type::instance(db, class.default_specialization(db))), - Type::GenericAlias(alias) => Some(Type::instance(db, ClassType::from(*alias))), + Type::GenericAlias(alias) => Some(Type::instance(db, ClassType::from(alias))), Type::SubclassOf(subclass_of_ty) => Some(subclass_of_ty.to_instance(db)), Type::Union(union) => union.to_instance(db), // If there is no bound or constraints on a typevar `T`, `T: object` implicitly, which @@ -5684,7 +5627,7 @@ impl<'db> Type<'db> { } /// The type `NoneType` / `None` - pub fn none(db: &'db dyn Db) -> Type<'db> { + pub(crate) fn none(db: &'db dyn Db) -> Type<'db> { KnownClass::NoneType.to_instance(db) } @@ -5694,7 +5637,7 @@ impl<'db> Type<'db> { /// Note: the return type of `type(obj)` is subtly different from this. /// See `Self::dunder_class` for more details. #[must_use] - pub fn to_meta_type(&self, db: &'db dyn Db) -> Type<'db> { + pub(crate) fn to_meta_type(self, db: &'db dyn Db) -> Type<'db> { match self { Type::Never => Type::Never, Type::NominalInstance(instance) => instance.to_meta_type(db), @@ -5730,9 +5673,9 @@ impl<'db> Type<'db> { Type::TypeVar(_) => KnownClass::Type.to_instance(db), Type::ClassLiteral(class) => class.metaclass(db), - Type::GenericAlias(alias) => ClassType::from(*alias).metaclass(db), + Type::GenericAlias(alias) => ClassType::from(alias).metaclass(db), Type::SubclassOf(subclass_of_ty) => match subclass_of_ty.subclass_of() { - SubclassOfInner::Dynamic(_) => *self, + SubclassOfInner::Dynamic(_) => self, SubclassOfInner::Class(class) => SubclassOfType::from( db, SubclassOfInner::try_from_type(db, class.metaclass(db)) @@ -5741,7 +5684,7 @@ impl<'db> Type<'db> { }, Type::StringLiteral(_) | Type::LiteralString => KnownClass::Str.to_class_literal(db), - Type::Dynamic(dynamic) => SubclassOfType::from(db, SubclassOfInner::Dynamic(*dynamic)), + Type::Dynamic(dynamic) => SubclassOfType::from(db, SubclassOfInner::Dynamic(dynamic)), // TODO intersections Type::Intersection(_) => SubclassOfType::from( db, @@ -5762,7 +5705,7 @@ impl<'db> Type<'db> { /// this returns `type[dict[str, object]]` instead, because inhabitants of a `TypedDict` are /// instances of `dict` at runtime. #[must_use] - pub fn dunder_class(self, db: &'db dyn Db) -> Type<'db> { + pub(crate) fn dunder_class(self, db: &'db dyn Db) -> Type<'db> { if self.is_typed_dict() { return KnownClass::Dict .to_specialized_class_type(db, [KnownClass::Str.to_instance(db), Type::object(db)]) @@ -5775,7 +5718,7 @@ impl<'db> Type<'db> { } #[must_use] - pub fn apply_optional_specialization( + pub(crate) fn apply_optional_specialization( self, db: &'db dyn Db, specialization: Option>, @@ -5794,7 +5737,7 @@ impl<'db> Type<'db> { /// different operation that is performed explicitly (via a subscript operation), or implicitly /// via a call to the generic object. #[salsa::tracked(heap_size=ruff_memory_usage::heap_size)] - pub fn apply_specialization( + pub(crate) fn apply_specialization( self, db: &'db dyn Db, specialization: Specialization<'db>, @@ -6040,7 +5983,7 @@ impl<'db> Type<'db> { } Type::Union(union) => { - for element in union.iter(db) { + for element in union.elements(db) { element.find_legacy_typevars(db, binding_context, typevars); } } @@ -6110,7 +6053,7 @@ impl<'db> Type<'db> { /// When not available, this should fall back to the value of `[Type::repr]`. /// Note: this method is used in the builtins `format`, `print`, `str.format` and `f-strings`. #[must_use] - pub fn str(&self, db: &'db dyn Db) -> Type<'db> { + pub(crate) fn str(&self, db: &'db dyn Db) -> Type<'db> { match self { Type::IntLiteral(_) | Type::BooleanLiteral(_) => self.repr(db), Type::StringLiteral(_) | Type::LiteralString => *self, @@ -6135,7 +6078,7 @@ impl<'db> Type<'db> { /// Return the string representation of this type as it would be provided by the `__repr__` /// method at runtime. #[must_use] - pub fn repr(&self, db: &'db dyn Db) -> Type<'db> { + pub(crate) fn repr(&self, db: &'db dyn Db) -> Type<'db> { match self { Type::IntLiteral(number) => Type::string_literal(db, &number.to_string()), Type::BooleanLiteral(true) => Type::string_literal(db, "True"), @@ -9112,8 +9055,8 @@ impl<'db> UnionType<'db> { /// Apply a transformation function to all elements of the union, /// and create a new union from the resulting set of types. - pub fn map( - &self, + pub(crate) fn map( + self, db: &'db dyn Db, transform_fn: impl FnMut(&Type<'db>) -> Type<'db>, ) -> Type<'db> { @@ -9147,10 +9090,6 @@ impl<'db> UnionType<'db> { Self::from_elements(db, self.elements(db).iter().filter(filter_fn)) } - pub fn iter(&self, db: &'db dyn Db) -> Iter<'_, Type<'db>> { - self.elements(db).iter() - } - pub(crate) fn map_with_boundness( self, db: &'db dyn Db, @@ -9373,7 +9312,7 @@ impl<'db> IntersectionType<'db> { /// Returns an iterator over the positive elements of the intersection. If /// there are no positive elements, returns a single `object` type. - fn positive_elements_or_object(&self, db: &'db dyn Db) -> impl Iterator> { + fn positive_elements_or_object(self, db: &'db dyn Db) -> impl Iterator> { if self.positive(db).is_empty() { Either::Left(std::iter::once(Type::object(db))) } else { @@ -9466,11 +9405,11 @@ impl<'db> IntersectionType<'db> { } } - pub fn iter_positive(&self, db: &'db dyn Db) -> impl Iterator> { + pub fn iter_positive(self, db: &'db dyn Db) -> impl Iterator> { self.positive(db).iter().copied() } - pub fn has_one_element(&self, db: &'db dyn Db) -> bool { + pub(crate) fn has_one_element(self, db: &'db dyn Db) -> bool { (self.positive(db).len() + self.negative(db).len()) == 1 } @@ -9550,7 +9489,7 @@ pub struct EnumLiteralType<'db> { impl get_size2::GetSize for EnumLiteralType<'_> {} impl<'db> EnumLiteralType<'db> { - pub fn enum_class_instance(self, db: &'db dyn Db) -> Type<'db> { + pub(crate) fn enum_class_instance(self, db: &'db dyn Db) -> Type<'db> { self.enum_class(db).to_non_generic_instance(db) } } @@ -9956,18 +9895,18 @@ fn walk_typeis_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( impl get_size2::GetSize for TypeIsType<'_> {} impl<'db> TypeIsType<'db> { - pub fn place_name(self, db: &'db dyn Db) -> Option { + pub(crate) fn place_name(self, db: &'db dyn Db) -> Option { let (scope, place) = self.place_info(db)?; let table = place_table(db, scope); Some(format!("{}", table.place(place))) } - pub fn unbound(db: &'db dyn Db, ty: Type<'db>) -> Type<'db> { + pub(crate) fn unbound(db: &'db dyn Db, ty: Type<'db>) -> Type<'db> { Type::TypeIs(Self::new(db, ty, None)) } - pub fn bound( + pub(crate) fn bound( db: &'db dyn Db, return_type: Type<'db>, scope: ScopeId<'db>, @@ -9977,22 +9916,23 @@ impl<'db> TypeIsType<'db> { } #[must_use] - pub fn bind(self, db: &'db dyn Db, scope: ScopeId<'db>, place: ScopedPlaceId) -> Type<'db> { + pub(crate) fn bind( + self, + db: &'db dyn Db, + scope: ScopeId<'db>, + place: ScopedPlaceId, + ) -> Type<'db> { Self::bound(db, self.return_type(db), scope, place) } #[must_use] - pub fn with_type(self, db: &'db dyn Db, ty: Type<'db>) -> Type<'db> { + pub(crate) fn with_type(self, db: &'db dyn Db, ty: Type<'db>) -> Type<'db> { Type::TypeIs(Self::new(db, ty, self.place_info(db))) } - pub fn is_bound(&self, db: &'db dyn Db) -> bool { + pub(crate) fn is_bound(self, db: &'db dyn Db) -> bool { self.place_info(db).is_some() } - - pub fn is_unbound(&self, db: &'db dyn Db) -> bool { - self.place_info(db).is_none() - } } // Make sure that the `Type` enum does not grow unexpectedly. diff --git a/crates/ty_python_semantic/src/types/call/arguments.rs b/crates/ty_python_semantic/src/types/call/arguments.rs index 0da96bcf4874c..b200f3fc8af14 100644 --- a/crates/ty_python_semantic/src/types/call/arguments.rs +++ b/crates/ty_python_semantic/src/types/call/arguments.rs @@ -257,7 +257,7 @@ fn expand_type<'db>(db: &'db dyn Db, ty: Type<'db>) -> Option>> { None } - Type::Union(union) => Some(union.iter(db).copied().collect()), + Type::Union(union) => Some(union.elements(db).to_vec()), // We don't handle `type[A | B]` here because it's already stored in the expanded form // i.e., `type[A] | type[B]` which is handled by the `Type::Union` case. _ => None, diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index 8b628fd375528..e0619e8343698 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -221,7 +221,7 @@ impl<'db> GenericContext<'db> { // TODO: This should be a new type variant where only these exact types are // assignable, and not subclasses of them, nor a union of them. parameter = parameter - .with_annotated_type(UnionType::from_elements(db, constraints.iter(db))); + .with_annotated_type(UnionType::from_elements(db, constraints.elements(db))); } None => {} } @@ -816,10 +816,11 @@ impl<'db> SpecializationBuilder<'db> { // and add a mapping between that typevar and the actual type. (Note that we've // already handled above the case where the actual is assignable to a _non-typevar_ // union element.) - let mut bound_typevars = formal.iter(self.db).filter_map(|ty| match ty { - Type::TypeVar(bound_typevar) => Some(*bound_typevar), - _ => None, - }); + let mut bound_typevars = + formal.elements(self.db).iter().filter_map(|ty| match ty { + Type::TypeVar(bound_typevar) => Some(*bound_typevar), + _ => None, + }); let bound_typevar = bound_typevars.next(); let additional_bound_typevars = bound_typevars.next(); if let (Some(bound_typevar), None) = (bound_typevar, additional_bound_typevars) { @@ -849,7 +850,7 @@ impl<'db> SpecializationBuilder<'db> { self.add_type_mapping(bound_typevar, ty); } Some(TypeVarBoundOrConstraints::Constraints(constraints)) => { - for constraint in constraints.iter(self.db) { + for constraint in constraints.elements(self.db) { if ty.is_assignable_to(self.db, *constraint) { self.add_type_mapping(bound_typevar, *constraint); return Ok(()); From 47d44e5f7b158e6f9d1c438b50635d190fcb044c Mon Sep 17 00:00:00 2001 From: gkowzan Date: Mon, 18 Aug 2025 01:35:37 +0200 Subject: [PATCH 020/160] Fix description of global config file discovery strategy (#19143) (#19188) Contrary to docs, ruff uses etcetera's base strategy rather than the native strategy. --- docs/configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index 533c04c71dcd8..0b79a20de9437 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -270,7 +270,7 @@ There are a few exceptions to these rules: 1. If no config file is found in the filesystem hierarchy, Ruff will fall back to using a default configuration. If a user-specific configuration file exists at `${config_dir}/ruff/pyproject.toml`, that file will be used instead of the default - configuration, with `${config_dir}` being determined via [`etcetera`'s native strategy](https://docs.rs/etcetera/latest/etcetera/#native-strategy), + configuration, with `${config_dir}` being determined via [`etcetera`'s base strategy](https://docs.rs/etcetera/latest/etcetera/#native-strategy), and all relative paths being again resolved relative to the _current working directory_. 1. Any config-file-supported settings that are provided on the command-line (e.g., via `--select`) will override the settings in _every_ resolved configuration file. From 510a07dee2a10510d89342988e0cd5d091892e66 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:44:00 +0200 Subject: [PATCH 021/160] Update PyO3/maturin-action action to v1.49.4 (#19955) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/build-binaries.yml | 16 ++++++++-------- .github/workflows/ci.yaml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 8b8d9d128e447..573513079994e 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -49,7 +49,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build sdist" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: command: sdist args: --out dist @@ -79,7 +79,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels - x86_64" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: target: x86_64 args: --release --locked --out dist @@ -121,7 +121,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels - aarch64" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: target: aarch64 args: --release --locked --out dist @@ -177,7 +177,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: target: ${{ matrix.platform.target }} args: --release --locked --out dist @@ -230,7 +230,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: target: ${{ matrix.target }} manylinux: auto @@ -306,7 +306,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: target: ${{ matrix.platform.target }} manylinux: auto @@ -372,7 +372,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: target: ${{ matrix.target }} manylinux: musllinux_1_2 @@ -437,7 +437,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: target: ${{ matrix.platform.target }} manylinux: musllinux_1_2 diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index aa6e5646b1852..9ac4c7b62b59e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -715,7 +715,7 @@ jobs: - name: "Prep README.md" run: python scripts/transform_readme.py --target pypi - name: "Build wheels" - uses: PyO3/maturin-action@e10f6c464b90acceb5f640d31beda6d586ba7b4a # v1.49.3 + uses: PyO3/maturin-action@86b9d133d34bc1b40018696f782949dac11bd380 # v1.49.4 with: args: --out dist - name: "Test wheel" From 48772c04d7186ffbbf4b4a1989d476f596c5ee57 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:53:10 +0200 Subject: [PATCH 022/160] Update Rust crate anyhow to v1.0.99 (#19956) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9ae86d5acf69b..fd12c083cf402 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -128,9 +128,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.98" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100" [[package]] name = "approx" From a5339a52c3d308ae72335861c5b7839a29ade37e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:53:31 +0200 Subject: [PATCH 023/160] Update Rust crate libc to v0.2.175 (#19960) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd12c083cf402..dfe07fe717e03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1764,9 +1764,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.174" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libcst" From c8d155b2b91cd5cdb5610dd139f1ce589f65a63c Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:53:51 +0200 Subject: [PATCH 024/160] Update Rust crate clap to v4.5.45 (#19958) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dfe07fe717e03..504a42c17337a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -408,9 +408,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.43" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50fd97c9dc2399518aa331917ac6f274280ec5eb34e555dd291899745c48ec6f" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", "clap_derive", @@ -418,9 +418,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.43" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35b5830294e1fa0462034af85cc95225a4cb07092c088c55bda3147cfcd8f65" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstream", "anstyle", @@ -461,9 +461,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.41" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" +checksum = "14cb31bb0a7d536caef2639baa7fad459e15c3144efefa6dbd1c84562c4739f6" dependencies = [ "heck", "proc-macro2", From d423191d94d2c73faad7ab6a87eb62a2829f94a9 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:54:09 +0200 Subject: [PATCH 025/160] Update Rust crate bitflags to v2.9.2 (#19957) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 504a42c17337a..e310958413383 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,9 +257,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29" [[package]] name = "bitvec" @@ -1241,7 +1241,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "ignore", "walkdir", ] @@ -1521,7 +1521,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "inotify-sys", "libc", ] @@ -1809,7 +1809,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "libc", "redox_syscall", ] @@ -2014,7 +2014,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "cfg-if", "cfg_aliases", "libc", @@ -2026,7 +2026,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "cfg-if", "cfg_aliases", "libc", @@ -2054,7 +2054,7 @@ version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "fsevent-sys", "inotify", "kqueue", @@ -2666,7 +2666,7 @@ version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", ] [[package]] @@ -2749,7 +2749,7 @@ dependencies = [ "argfile", "assert_fs", "bincode 2.0.1", - "bitflags 2.9.1", + "bitflags 2.9.2", "cachedir", "clap", "clap_complete_command", @@ -3000,7 +3000,7 @@ version = "0.12.9" dependencies = [ "aho-corasick", "anyhow", - "bitflags 2.9.1", + "bitflags 2.9.2", "clap", "colored 3.0.0", "fern", @@ -3106,7 +3106,7 @@ name = "ruff_python_ast" version = "0.0.0" dependencies = [ "aho-corasick", - "bitflags 2.9.1", + "bitflags 2.9.2", "compact_str", "get-size2", "is-macro", @@ -3194,7 +3194,7 @@ dependencies = [ name = "ruff_python_literal" version = "0.0.0" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "itertools 0.14.0", "ruff_python_ast", "unic-ucd-category", @@ -3205,7 +3205,7 @@ name = "ruff_python_parser" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.1", + "bitflags 2.9.2", "bstr", "compact_str", "get-size2", @@ -3230,7 +3230,7 @@ dependencies = [ name = "ruff_python_semantic" version = "0.0.0" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "insta", "is-macro", "ruff_cache", @@ -3251,7 +3251,7 @@ dependencies = [ name = "ruff_python_stdlib" version = "0.0.0" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "unicode-ident", ] @@ -3428,7 +3428,7 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "errno", "libc", "linux-raw-sys", @@ -4238,7 +4238,7 @@ dependencies = [ name = "ty_ide" version = "0.0.0" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", "insta", "itertools 0.14.0", "regex", @@ -4297,7 +4297,7 @@ name = "ty_python_semantic" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.1", + "bitflags 2.9.2", "bitvec", "camino", "colored 3.0.0", @@ -4350,7 +4350,7 @@ name = "ty_server" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.1", + "bitflags 2.9.2", "crossbeam", "dunce", "insta", @@ -4393,7 +4393,7 @@ name = "ty_test" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.1", + "bitflags 2.9.2", "camino", "colored 3.0.0", "insta", @@ -5143,7 +5143,7 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.2", ] [[package]] From 76c933d10ea1ae01d9d21444d585d87872307fbe Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 08:54:23 +0200 Subject: [PATCH 026/160] Update dependency ruff to v0.12.9 (#19954) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- docs/requirements-insiders.txt | 2 +- docs/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/requirements-insiders.txt b/docs/requirements-insiders.txt index e0c9c0272a2f1..3da4b69557420 100644 --- a/docs/requirements-insiders.txt +++ b/docs/requirements-insiders.txt @@ -1,5 +1,5 @@ PyYAML==6.0.2 -ruff==0.12.8 +ruff==0.12.9 mkdocs==1.6.1 mkdocs-material @ git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@39da7a5e761410349e9a1b8abf593b0cdd5453ff mkdocs-redirects==1.2.2 diff --git a/docs/requirements.txt b/docs/requirements.txt index 88c24df27949e..baf3c32b4fe48 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ PyYAML==6.0.2 -ruff==0.12.8 +ruff==0.12.9 mkdocs==1.6.1 mkdocs-material==9.5.38 mkdocs-redirects==1.2.2 From 7d8f7c20da394cf9590953c9311d3c5e03743956 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 18 Aug 2025 09:16:53 +0200 Subject: [PATCH 027/160] [ty] Log server version at info level (#19961) --- crates/ty_server/src/server.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/ty_server/src/server.rs b/crates/ty_server/src/server.rs index 5819789fe517c..46ee9c210d4db 100644 --- a/crates/ty_server/src/server.rs +++ b/crates/ty_server/src/server.rs @@ -80,7 +80,7 @@ impl Server { ); let version = ruff_db::program_version().unwrap_or("Unknown"); - tracing::debug!("Version: {version}"); + tracing::info!("Version: {version}"); connection.initialize_finish( id, From c7af595fc13c99e1f68ed18f4d0fd0647cf953cc Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 18 Aug 2025 09:20:49 +0200 Subject: [PATCH 028/160] [ty] Use debug builds for conformance tests and run them single threaded (#19938) --- .github/workflows/typing_conformance.yaml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/typing_conformance.yaml b/.github/workflows/typing_conformance.yaml index 8f76462173d03..660163fea738e 100644 --- a/.github/workflows/typing_conformance.yaml +++ b/.github/workflows/typing_conformance.yaml @@ -54,6 +54,9 @@ jobs: - name: Compute diagnostic diff shell: bash + env: + # TODO: Remove this once we fixed the remaining panics in the conformance suite. + TY_MAX_PARALLELISM: 1 run: | RUFF_DIR="$GITHUB_WORKSPACE/ruff" @@ -63,15 +66,15 @@ jobs: echo "new commit" git rev-list --format=%s --max-count=1 "$GITHUB_SHA" - cargo build --release --bin ty - mv target/release/ty ty-new + cargo build --bin ty + mv target/debug/ty ty-new MERGE_BASE="$(git merge-base "$GITHUB_SHA" "origin/$GITHUB_BASE_REF")" git checkout -b old_commit "$MERGE_BASE" echo "old commit (merge base)" git rev-list --format=%s --max-count=1 old_commit - cargo build --release --bin ty - mv target/release/ty ty-old + cargo build --bin ty + mv target/debug/ty ty-old ) ( From 083bb85d9dc3cd13a2d1dd8bff0cc2c1df6be315 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 07:31:07 +0000 Subject: [PATCH 029/160] Update actions/checkout to v5.0.0 (#19952) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Micha Reiser --- .github/workflows/release.yml | 8 ++++---- dist-workspace.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1ae4d8fb71d77..218f07b9a8d19 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 with: persist-credentials: false submodules: recursive @@ -124,7 +124,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json steps: - - uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 with: persist-credentials: false submodules: recursive @@ -175,7 +175,7 @@ jobs: outputs: val: ${{ steps.host.outputs.manifest }} steps: - - uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 with: persist-credentials: false submodules: recursive @@ -251,7 +251,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@09d2acae674a48949e3602304ab46fd20ae0c42f + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 with: persist-credentials: false submodules: recursive diff --git a/dist-workspace.toml b/dist-workspace.toml index 499bbd0766e52..ebbf36ab20626 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -70,7 +70,7 @@ install-path = ["$XDG_BIN_HOME/", "$XDG_DATA_HOME/../bin", "~/.local/bin"] global = "depot-ubuntu-latest-4" [dist.github-action-commits] -"actions/checkout" = "09d2acae674a48949e3602304ab46fd20ae0c42f" # v4 +"actions/checkout" = "08c6903cd8c0fde910a37f88322edcfb5dd907a8" # v5.0.0 "actions/upload-artifact" = "6027e3dd177782cd8ab9af838c04fd81a07f1d47" # v4.6.2 "actions/download-artifact" = "634f93cb2916e3fdff6788551b99b062d0335ce0" # v5.0.0 "actions/attest-build-provenance" = "c074443f1aee8d4aeeae555aebba3282517141b2" #v2.2.3 From 4ac2b2c22283c9f8eb7f7fd945ab1c5f08098ab4 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 18 Aug 2025 11:30:52 +0100 Subject: [PATCH 030/160] [ty] Have `SemanticIndex::place_table()` and `SemanticIndex::use_def_map` return references (#19944) --- .../ty_python_semantic/src/semantic_index.rs | 56 +++++++++---------- .../src/types/ide_support.rs | 15 ++--- crates/ty_python_semantic/src/types/infer.rs | 39 ++++++------- 3 files changed, 52 insertions(+), 58 deletions(-) diff --git a/crates/ty_python_semantic/src/semantic_index.rs b/crates/ty_python_semantic/src/semantic_index.rs index 71ab64f736a5a..2c770ee0a67b2 100644 --- a/crates/ty_python_semantic/src/semantic_index.rs +++ b/crates/ty_python_semantic/src/semantic_index.rs @@ -70,8 +70,7 @@ pub(crate) fn place_table<'db>(db: &'db dyn Db, scope: ScopeId<'db>) -> Arc(db: &'db dyn Db, scope: ScopeId<'db>) -> Arc SemanticIndex<'db> { /// Use the Salsa cached [`place_table()`] query if you only need the /// place table for a single scope. #[track_caller] - pub(super) fn place_table(&self, scope_id: FileScopeId) -> Arc { - self.place_tables[scope_id].clone() + pub(super) fn place_table(&self, scope_id: FileScopeId) -> &PlaceTable { + &self.place_tables[scope_id] } /// Returns the use-def map for a specific scope. @@ -261,8 +259,8 @@ impl<'db> SemanticIndex<'db> { /// Use the Salsa cached [`use_def_map()`] query if you only need the /// use-def map for a single scope. #[track_caller] - pub(super) fn use_def_map(&self, scope_id: FileScopeId) -> Arc> { - self.use_def_maps[scope_id].clone() + pub(super) fn use_def_map(&self, scope_id: FileScopeId) -> &UseDefMap<'db> { + &self.use_def_maps[scope_id] } #[track_caller] @@ -907,7 +905,7 @@ y = 2 ); let class_table = index.place_table(class_scope_id); - assert_eq!(names(&class_table), vec!["x"]); + assert_eq!(names(class_table), vec!["x"]); let use_def = index.use_def_map(class_scope_id); let binding = use_def @@ -929,7 +927,7 @@ y = 2 let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["func", "y"]); + assert_eq!(names(global_table), vec!["func", "y"]); let [(function_scope_id, function_scope)] = index .child_scopes(FileScopeId::global()) @@ -944,7 +942,7 @@ y = 2 ); let function_table = index.place_table(function_scope_id); - assert_eq!(names(&function_table), vec!["x"]); + assert_eq!(names(function_table), vec!["x"]); let use_def = index.use_def_map(function_scope_id); let binding = use_def @@ -976,7 +974,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs): let function_table = index.place_table(function_scope_id); assert_eq!( - names(&function_table), + names(function_table), vec!["a", "b", "c", "d", "args", "kwargs"], ); @@ -1021,7 +1019,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs): let lambda_table = index.place_table(lambda_scope_id); assert_eq!( - names(&lambda_table), + names(lambda_table), vec!["a", "b", "c", "d", "args", "kwargs"], ); @@ -1062,7 +1060,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs): let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["iter1"]); + assert_eq!(names(global_table), vec!["iter1"]); let [(comprehension_scope_id, comprehension_scope)] = index .child_scopes(FileScopeId::global()) @@ -1081,7 +1079,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs): let comprehension_symbol_table = index.place_table(comprehension_scope_id); - assert_eq!(names(&comprehension_symbol_table), vec!["x", "y"]); + assert_eq!(names(comprehension_symbol_table), vec!["x", "y"]); let use_def = index.use_def_map(comprehension_scope_id); for name in ["x", "y"] { @@ -1159,7 +1157,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs): let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["iter1"]); + assert_eq!(names(global_table), vec!["iter1"]); let [(comprehension_scope_id, comprehension_scope)] = index .child_scopes(FileScopeId::global()) @@ -1178,7 +1176,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs): let comprehension_symbol_table = index.place_table(comprehension_scope_id); - assert_eq!(names(&comprehension_symbol_table), vec!["y", "iter2"]); + assert_eq!(names(comprehension_symbol_table), vec!["y", "iter2"]); let [(inner_comprehension_scope_id, inner_comprehension_scope)] = index .child_scopes(comprehension_scope_id) @@ -1197,7 +1195,7 @@ def f(a: str, /, b: str, c: int = 1, *args, d: int = 2, **kwargs): let inner_comprehension_symbol_table = index.place_table(inner_comprehension_scope_id); - assert_eq!(names(&inner_comprehension_symbol_table), vec!["x"]); + assert_eq!(names(inner_comprehension_symbol_table), vec!["x"]); } #[test] @@ -1212,7 +1210,7 @@ with item1 as x, item2 as y: let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["item1", "x", "item2", "y"]); + assert_eq!(names(global_table), vec!["item1", "x", "item2", "y"]); let use_def = index.use_def_map(FileScopeId::global()); for name in ["x", "y"] { @@ -1235,7 +1233,7 @@ with context() as (x, y): let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["context", "x", "y"]); + assert_eq!(names(global_table), vec!["context", "x", "y"]); let use_def = index.use_def_map(FileScopeId::global()); for name in ["x", "y"] { @@ -1260,7 +1258,7 @@ def func(): let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["func"]); + assert_eq!(names(global_table), vec!["func"]); let [ (func_scope1_id, func_scope_1), (func_scope2_id, func_scope_2), @@ -1285,8 +1283,8 @@ def func(): let func1_table = index.place_table(func_scope1_id); let func2_table = index.place_table(func_scope2_id); - assert_eq!(names(&func1_table), vec!["x"]); - assert_eq!(names(&func2_table), vec!["y"]); + assert_eq!(names(func1_table), vec!["x"]); + assert_eq!(names(func2_table), vec!["y"]); let use_def = index.use_def_map(FileScopeId::global()); let binding = use_def @@ -1308,7 +1306,7 @@ def func[T](): let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["func"]); + assert_eq!(names(global_table), vec!["func"]); let [(ann_scope_id, ann_scope)] = index .child_scopes(FileScopeId::global()) @@ -1323,7 +1321,7 @@ def func[T](): "func" ); let ann_table = index.place_table(ann_scope_id); - assert_eq!(names(&ann_table), vec!["T"]); + assert_eq!(names(ann_table), vec!["T"]); let [(func_scope_id, func_scope)] = index.child_scopes(ann_scope_id).collect::>()[..] @@ -1336,7 +1334,7 @@ def func[T](): "func" ); let func_table = index.place_table(func_scope_id); - assert_eq!(names(&func_table), vec!["x"]); + assert_eq!(names(func_table), vec!["x"]); } #[test] @@ -1352,7 +1350,7 @@ class C[T]: let index = semantic_index(&db, file); let global_table = index.place_table(FileScopeId::global()); - assert_eq!(names(&global_table), vec!["C"]); + assert_eq!(names(global_table), vec!["C"]); let [(ann_scope_id, ann_scope)] = index .child_scopes(FileScopeId::global()) @@ -1364,7 +1362,7 @@ class C[T]: assert_eq!(ann_scope.kind(), ScopeKind::TypeParams); assert_eq!(ann_scope_id.to_scope_id(&db, file).name(&db, &module), "C"); let ann_table = index.place_table(ann_scope_id); - assert_eq!(names(&ann_table), vec!["T"]); + assert_eq!(names(ann_table), vec!["T"]); assert!( ann_table .symbol_by_name("T") @@ -1383,7 +1381,7 @@ class C[T]: class_scope_id.to_scope_id(&db, file).name(&db, &module), "C" ); - assert_eq!(names(&index.place_table(class_scope_id)), vec!["x"]); + assert_eq!(names(index.place_table(class_scope_id)), vec!["x"]); } #[test] diff --git a/crates/ty_python_semantic/src/types/ide_support.rs b/crates/ty_python_semantic/src/types/ide_support.rs index 36a139145c301..f96401bd2f862 100644 --- a/crates/ty_python_semantic/src/types/ide_support.rs +++ b/crates/ty_python_semantic/src/types/ide_support.rs @@ -307,8 +307,7 @@ impl<'db> AllMembers<'db> { let file = class_body_scope.file(db); let index = semantic_index(db, file); for function_scope_id in attribute_scopes(db, class_body_scope) { - let place_table = index.place_table(function_scope_id); - for place_expr in place_table.members() { + for place_expr in index.place_table(function_scope_id).members() { let Some(name) = place_expr.as_instance_attribute() else { continue; }; @@ -411,8 +410,9 @@ pub fn definition_kind_for_name<'db>( let symbol_id = place_table.symbol_id(name_str)?; // Get the use-def map and look up definitions for this place - let use_def_map = index.use_def_map(file_scope); - let declarations = use_def_map.all_reachable_symbol_declarations(symbol_id); + let declarations = index + .use_def_map(file_scope) + .all_reachable_symbol_declarations(symbol_id); // Find the first valid definition and return its kind for declaration in declarations { @@ -662,9 +662,10 @@ pub fn definitions_for_attribute<'db>( let index = semantic_index(db, file); for function_scope_id in attribute_scopes(db, class_scope) { - let place_table = index.place_table(function_scope_id); - - if let Some(place_id) = place_table.member_id_by_instance_attribute_name(name_str) { + if let Some(place_id) = index + .place_table(function_scope_id) + .member_id_by_instance_attribute_name(name_str) + { let use_def = index.use_def_map(function_scope_id); // Check declarations first diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index c819d1d3486e9..83c7212d25b14 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -1848,7 +1848,6 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let mut bound_ty = ty; let global_use_def_map = self.index.use_def_map(FileScopeId::global()); - let nonlocal_use_def_map; let place_id = binding.place(self.db()); let place = place_table.place(place_id); @@ -1908,9 +1907,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } // We found the closest definition. Note that (as in `infer_place_load`) this does // *not* need to be a binding. It could be just a declaration, e.g. `x: int`. - nonlocal_use_def_map = self.index.use_def_map(enclosing_scope_file_id); - declarations = - nonlocal_use_def_map.end_of_scope_symbol_declarations(enclosing_symbol_id); + declarations = self + .index + .use_def_map(enclosing_scope_file_id) + .end_of_scope_symbol_declarations(enclosing_symbol_id); is_local = false; break; } @@ -2107,8 +2107,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { .or_fall_back_to(self.db(), || { // Fallback to bindings declared on `types.ModuleType` if it's a global symbol let scope = self.scope().file_scope_id(self.db()); - let place_table = self.index.place_table(scope); - let place = place_table.place(declaration.place(self.db())); + let place = self + .index + .place_table(scope) + .place(declaration.place(self.db())); if let PlaceExprRef::Symbol(symbol) = &place { if scope.is_global() { module_type_implicit_global_symbol(self.db(), symbol.name()) @@ -2501,8 +2503,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { invalid.ty, ); } - let use_def = self.index.use_def_map(scope_id); - if use_def.can_implicitly_return_none(self.db()) + if self + .index + .use_def_map(scope_id) + .can_implicitly_return_none(self.db()) && !Type::none(self.db()).is_assignable_to(self.db(), expected_ty) { let no_return = self.return_types_and_ranges.is_empty(); @@ -5169,20 +5173,11 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let module_ty = Type::module_literal(self.db(), self.file(), module); - // The indirection of having `star_import_info` as a separate variable - // is required in order to make the borrow checker happy. - let star_import_info = definition - .kind(self.db()) - .as_star_import() - .map(|star_import| { - let place_table = self - .index - .place_table(self.scope().file_scope_id(self.db())); - (star_import, place_table) - }); - - let name = if let Some((star_import, symbol_table)) = star_import_info.as_ref() { - symbol_table.symbol(star_import.symbol_id()).name() + let name = if let Some(star_import) = definition.kind(self.db()).as_star_import() { + self.index + .place_table(self.scope().file_scope_id(self.db())) + .symbol(star_import.symbol_id()) + .name() } else { &alias.name.id }; From 67529edad6452c1f6eb646c8e5f6fb88caf012ae Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 18 Aug 2025 12:35:40 +0200 Subject: [PATCH 031/160] [ty] Short-circuit inlayhints request if disabled in settings (#19963) --- crates/ty_ide/src/inlay_hints.rs | 7 +++++++ crates/ty_server/src/server/api/requests/inlay_hints.rs | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/ty_ide/src/inlay_hints.rs b/crates/ty_ide/src/inlay_hints.rs index f9f109aa1dd53..1004f5b4d58aa 100644 --- a/crates/ty_ide/src/inlay_hints.rs +++ b/crates/ty_ide/src/inlay_hints.rs @@ -85,6 +85,13 @@ pub struct InlayHintSettings { /// foo("x="1) /// ``` pub call_argument_names: bool, + // Add any new setting that enables additional inlays to `any_enabled`. +} + +impl InlayHintSettings { + pub fn any_enabled(&self) -> bool { + self.variable_types || self.call_argument_names + } } impl Default for InlayHintSettings { diff --git a/crates/ty_server/src/server/api/requests/inlay_hints.rs b/crates/ty_server/src/server/api/requests/inlay_hints.rs index 2d903d1a88fee..3c5e44d2644f2 100644 --- a/crates/ty_server/src/server/api/requests/inlay_hints.rs +++ b/crates/ty_server/src/server/api/requests/inlay_hints.rs @@ -29,9 +29,9 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler { _client: &Client, params: InlayHintParams, ) -> crate::server::Result>> { - if snapshot - .workspace_settings() - .is_language_services_disabled() + let workspace_settings = snapshot.workspace_settings(); + if workspace_settings.is_language_services_disabled() + || !workspace_settings.inlay_hints().any_enabled() { return Ok(None); } @@ -47,7 +47,7 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler { .range .to_text_range(&source, &index, snapshot.encoding()); - let inlay_hints = inlay_hints(db, file, range, snapshot.workspace_settings().inlay_hints()); + let inlay_hints = inlay_hints(db, file, range, workspace_settings.inlay_hints()); let inlay_hints = inlay_hints .into_iter() From 5e4fa9e4421be6692129b0c04cee3681555d5933 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Mon, 18 Aug 2025 12:56:06 +0200 Subject: [PATCH 032/160] [ty] Speedup tracing checks (#19965) --- crates/ty_server/src/logging.rs | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/crates/ty_server/src/logging.rs b/crates/ty_server/src/logging.rs index 467455cdbb6fa..65c45864774b3 100644 --- a/crates/ty_server/src/logging.rs +++ b/crates/ty_server/src/logging.rs @@ -8,7 +8,9 @@ use std::sync::Arc; use ruff_db::system::{SystemPath, SystemPathBuf}; use serde::Deserialize; +use tracing::Metadata; use tracing::level_filters::LevelFilter; +use tracing::subscriber::Interest; use tracing_subscriber::Layer; use tracing_subscriber::fmt::time::ChronoLocal; use tracing_subscriber::fmt::writer::BoxMakeWriter; @@ -92,12 +94,8 @@ struct LogLevelFilter { filter: LogLevel, } -impl tracing_subscriber::layer::Filter for LogLevelFilter { - fn enabled( - &self, - meta: &tracing::Metadata<'_>, - _: &tracing_subscriber::layer::Context<'_, S>, - ) -> bool { +impl LogLevelFilter { + fn is_enabled(&self, meta: &Metadata<'_>) -> bool { let filter = if meta.target().starts_with("ty") || meta.target().starts_with("ruff") || meta.target().starts_with("e2e") @@ -109,6 +107,27 @@ impl tracing_subscriber::layer::Filter for LogLevelFilter { meta.level() <= &filter } +} + +impl tracing_subscriber::layer::Filter for LogLevelFilter { + fn enabled( + &self, + meta: &tracing::Metadata<'_>, + _: &tracing_subscriber::layer::Context<'_, S>, + ) -> bool { + self.is_enabled(meta) + } + + fn callsite_enabled(&self, meta: &'static Metadata<'static>) -> Interest { + // The result of `self.enabled(metadata, ...)` will always be + // the same for any given `Metadata`, so we can convert it into + // an `Interest`: + if self.is_enabled(meta) { + Interest::always() + } else { + Interest::never() + } + } fn max_level_hint(&self) -> Option { Some(LevelFilter::from_level(self.filter.trace_level())) From fbf24be8ae07621465cfe052d685e89bee91552e Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 18 Aug 2025 13:03:01 +0100 Subject: [PATCH 033/160] [ty] Detect illegal multiple inheritance with `NamedTuple` (#19943) --- crates/ty/docs/rules.md | 152 +++++++++++------- .../resources/mdtest/named_tuple.md | 21 ++- ...ltiple_Inheritance_(82ed33d1b3b433d8).snap | 73 +++++++++ crates/ty_python_semantic/src/types/class.rs | 2 +- .../src/types/diagnostic.rs | 27 ++++ crates/ty_python_semantic/src/types/infer.rs | 41 +++-- ty.schema.json | 10 ++ 7 files changed, 250 insertions(+), 76 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Multiple_Inheritance_(82ed33d1b3b433d8).snap diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index 9aadce2eca419..c122710031e29 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -36,7 +36,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-non-callable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L102) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L103) **What it does** @@ -58,7 +58,7 @@ Calling a non-callable object will raise a `TypeError` at runtime. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-argument-forms) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L146) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L147) **What it does** @@ -88,7 +88,7 @@ f(int) # error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-declarations) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L172) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L173) **What it does** @@ -117,7 +117,7 @@ a = 1 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L197) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L198) **What it does** @@ -147,7 +147,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20cyclic-class-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L223) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L224) **What it does** @@ -177,7 +177,7 @@ class B(A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L288) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L289) **What it does** @@ -202,7 +202,7 @@ class B(A, A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-kw-only) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L309) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L310) **What it does** @@ -306,7 +306,7 @@ def test(): -> "Literal[5]": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20inconsistent-mro) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L451) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L478) **What it does** @@ -334,7 +334,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20index-out-of-bounds) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L475) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L502) **What it does** @@ -358,7 +358,7 @@ t[3] # IndexError: tuple index out of range Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20instance-layout-conflict) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L341) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L342) **What it does** @@ -445,7 +445,7 @@ an atypical memory layout. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-argument-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L520) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L547) **What it does** @@ -470,7 +470,7 @@ func("foo") # error: [invalid-argument-type] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-assignment) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L560) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L587) **What it does** @@ -496,7 +496,7 @@ a: int = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-attribute-access) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1594) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1621) **What it does** @@ -528,7 +528,7 @@ C.instance_var = 3 # error: Cannot assign to instance variable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-await) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L582) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L609) **What it does** @@ -562,7 +562,7 @@ asyncio.run(main()) Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L612) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L639) **What it does** @@ -584,7 +584,7 @@ class A(42): ... # error: [invalid-base] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-context-manager) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L663) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L690) **What it does** @@ -609,7 +609,7 @@ with 1: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-declaration) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L684) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L711) **What it does** @@ -636,7 +636,7 @@ a: str Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-exception-caught) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L707) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L734) **What it does** @@ -678,7 +678,7 @@ except ZeroDivisionError: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-generic-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L743) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L770) **What it does** @@ -709,7 +709,7 @@ class C[U](Generic[T]): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-key) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L495) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L522) **What it does** @@ -738,7 +738,7 @@ alice["height"] # KeyError: 'height' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-legacy-type-variable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L769) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L796) **What it does** @@ -771,7 +771,7 @@ def f(t: TypeVar("U")): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L818) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L845) **What it does** @@ -798,12 +798,42 @@ class B(metaclass=f): ... - [Python documentation: Metaclasses](https://docs.python.org/3/reference/datamodel.html#metaclasses) +## `invalid-named-tuple` + + +Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · +[Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-named-tuple) · +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L452) + + +**What it does** + +Checks for invalidly defined `NamedTuple` classes. + +**Why is this bad?** + +An invalidly defined `NamedTuple` class may lead to the type checker +drawing incorrect conclusions. It may also lead to `TypeError`s at runtime. + +**Examples** + +A class definition cannot combine `NamedTuple` with other base classes +in multiple inheritance; doing so raises a `TypeError` at runtime. The sole +exception to this rule is `Generic[]`, which can be used alongside `NamedTuple` +in a class's bases list. + +```pycon +>>> from typing import NamedTuple +>>> class Foo(NamedTuple, object): ... +TypeError: can only inherit from a NamedTuple type and Generic +``` + ## `invalid-overload` Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L845) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L872) **What it does** @@ -851,7 +881,7 @@ def foo(x: int) -> int: ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-parameter-default) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L888) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L915) **What it does** @@ -875,7 +905,7 @@ def f(a: int = ''): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-protocol) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L423) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L424) **What it does** @@ -907,7 +937,7 @@ TypeError: Protocols can only inherit from other protocols, got Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-raise) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L908) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L935) Checks for `raise` statements that raise non-exceptions or use invalid @@ -954,7 +984,7 @@ def g(): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-return-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L541) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L568) **What it does** @@ -977,7 +1007,7 @@ def func() -> int: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-super-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L951) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L978) **What it does** @@ -1031,7 +1061,7 @@ TODO #14889 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-alias-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L797) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L824) **What it does** @@ -1056,7 +1086,7 @@ NewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name mus Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-checking-constant) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L990) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1017) **What it does** @@ -1084,7 +1114,7 @@ TYPE_CHECKING = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-form) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1014) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1041) **What it does** @@ -1112,7 +1142,7 @@ b: Annotated[int] # `Annotated` expects at least two arguments Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1066) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1093) **What it does** @@ -1144,7 +1174,7 @@ f(10) # Error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1038) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1065) **What it does** @@ -1176,7 +1206,7 @@ class C: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-variable-constraints) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1094) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1121) **What it does** @@ -1209,7 +1239,7 @@ T = TypeVar('T', bound=str) # valid bound TypeVar Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1123) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1150) **What it does** @@ -1232,7 +1262,7 @@ func() # TypeError: func() missing 1 required positional argument: 'x' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20no-matching-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1142) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1169) **What it does** @@ -1259,7 +1289,7 @@ func("string") # error: [no-matching-overload] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20non-subscriptable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1165) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1192) **What it does** @@ -1281,7 +1311,7 @@ Subscripting an object that does not support it will raise a `TypeError` at runt Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20not-iterable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1183) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1210) **What it does** @@ -1305,7 +1335,7 @@ for i in 34: # TypeError: 'int' object is not iterable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20parameter-already-assigned) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1234) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1261) **What it does** @@ -1359,7 +1389,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20static-assert-error) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1570) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1597) **What it does** @@ -1387,7 +1417,7 @@ static_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known tr Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20subclass-of-final-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1325) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1352) **What it does** @@ -1414,7 +1444,7 @@ class B(A): ... # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20too-many-positional-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1370) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1397) **What it does** @@ -1439,7 +1469,7 @@ f("foo") # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20type-assertion-failure) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1348) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1375) **What it does** @@ -1465,7 +1495,7 @@ def _(x: int): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unavailable-implicit-super-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1391) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1418) **What it does** @@ -1509,7 +1539,7 @@ class A: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unknown-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1448) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1475) **What it does** @@ -1534,7 +1564,7 @@ f(x=1, y=2) # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1469) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1496) **What it does** @@ -1560,7 +1590,7 @@ A().foo # AttributeError: 'A' object has no attribute 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1491) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1518) **What it does** @@ -1583,7 +1613,7 @@ import foo # ModuleNotFoundError: No module named 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1510) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1537) **What it does** @@ -1606,7 +1636,7 @@ print(x) # NameError: name 'x' is not defined Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-bool-conversion) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1203) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1230) **What it does** @@ -1641,7 +1671,7 @@ b1 < b2 < b1 # exception raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-operator) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1529) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1556) **What it does** @@ -1667,7 +1697,7 @@ A() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20zero-stepsize-in-slice) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1551) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1578) **What it does** @@ -1690,7 +1720,7 @@ l[1:10:0] # ValueError: slice step cannot be zero Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20deprecated) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L267) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L268) **What it does** @@ -1743,7 +1773,7 @@ a = 20 / 0 # type: ignore Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1255) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1282) **What it does** @@ -1769,7 +1799,7 @@ A.c # AttributeError: type object 'A' has no attribute 'c' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-implicit-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L120) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L121) **What it does** @@ -1799,7 +1829,7 @@ A()[0] # TypeError: 'A' object is not subscriptable Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1277) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1304) **What it does** @@ -1829,7 +1859,7 @@ from module import a # ImportError: cannot import name 'a' from 'module' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20redundant-cast) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1622) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1649) **What it does** @@ -1854,7 +1884,7 @@ cast(int, f()) # Redundant Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20undefined-reveal) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1430) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1457) **What it does** @@ -1905,7 +1935,7 @@ a = 20 / 0 # ty: ignore[division-by-zero] Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-global) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1643) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1670) **What it does** @@ -1959,7 +1989,7 @@ def g(): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L630) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L657) **What it does** @@ -1996,7 +2026,7 @@ class D(C): ... # error: [unsupported-base] Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20division-by-zero) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L249) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L250) **What it does** @@ -2018,7 +2048,7 @@ Dividing by zero raises a `ZeroDivisionError` at runtime. Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1303) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1330) **What it does** diff --git a/crates/ty_python_semantic/resources/mdtest/named_tuple.md b/crates/ty_python_semantic/resources/mdtest/named_tuple.md index b89d0a457e942..49d957240ee45 100644 --- a/crates/ty_python_semantic/resources/mdtest/named_tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/named_tuple.md @@ -115,15 +115,28 @@ class Location(NamedTuple): ### Multiple Inheritance -Multiple inheritance is not supported for `NamedTuple` classes: + + +Multiple inheritance is not supported for `NamedTuple` classes except with `Generic`: ```py -from typing import NamedTuple +from typing import NamedTuple, Protocol -# This should ideally emit a diagnostic +# error: [invalid-named-tuple] "NamedTuple class `C` cannot use multiple inheritance except with `Generic[]`" class C(NamedTuple, object): id: int - name: str + +# fmt: off + +class D( + int, # error: [invalid-named-tuple] + NamedTuple +): ... + +# fmt: on + +# error: [invalid-named-tuple] +class E(NamedTuple, Protocol): ... ``` ### Inheriting from a `NamedTuple` diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Multiple_Inheritance_(82ed33d1b3b433d8).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Multiple_Inheritance_(82ed33d1b3b433d8).snap new file mode 100644 index 0000000000000..b2cc9d918e0ec --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Multiple_Inheritance_(82ed33d1b3b433d8).snap @@ -0,0 +1,73 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: named_tuple.md - `NamedTuple` - `typing.NamedTuple` - Multiple Inheritance +mdtest path: crates/ty_python_semantic/resources/mdtest/named_tuple.md +--- + +# Python source files + +## mdtest_snippet.py + +``` + 1 | from typing import NamedTuple, Protocol + 2 | + 3 | # error: [invalid-named-tuple] "NamedTuple class `C` cannot use multiple inheritance except with `Generic[]`" + 4 | class C(NamedTuple, object): + 5 | id: int + 6 | + 7 | # fmt: off + 8 | + 9 | class D( +10 | int, # error: [invalid-named-tuple] +11 | NamedTuple +12 | ): ... +13 | +14 | # fmt: on +15 | +16 | # error: [invalid-named-tuple] +17 | class E(NamedTuple, Protocol): ... +``` + +# Diagnostics + +``` +error[invalid-named-tuple]: NamedTuple class `C` cannot use multiple inheritance except with `Generic[]` + --> src/mdtest_snippet.py:4:21 + | +3 | # error: [invalid-named-tuple] "NamedTuple class `C` cannot use multiple inheritance except with `Generic[]`" +4 | class C(NamedTuple, object): + | ^^^^^^ +5 | id: int + | +info: rule `invalid-named-tuple` is enabled by default + +``` + +``` +error[invalid-named-tuple]: NamedTuple class `D` cannot use multiple inheritance except with `Generic[]` + --> src/mdtest_snippet.py:10:5 + | + 9 | class D( +10 | int, # error: [invalid-named-tuple] + | ^^^ +11 | NamedTuple +12 | ): ... + | +info: rule `invalid-named-tuple` is enabled by default + +``` + +``` +error[invalid-named-tuple]: NamedTuple class `E` cannot use multiple inheritance except with `Generic[]` + --> src/mdtest_snippet.py:17:21 + | +16 | # error: [invalid-named-tuple] +17 | class E(NamedTuple, Protocol): ... + | ^^^^^^^^ + | +info: rule `invalid-named-tuple` is enabled by default + +``` diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index beac62e3618d0..2dcb979fcd229 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -227,7 +227,7 @@ impl CodeGeneratorKind { code_generator_of_class(db, class) } - fn matches(self, db: &dyn Db, class: ClassLiteral<'_>) -> bool { + pub(super) fn matches(self, db: &dyn Db, class: ClassLiteral<'_>) -> bool { CodeGeneratorKind::from_class(db, class) == Some(self) } } diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index 113d0fa508a7b..730ab1627d8ff 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -57,6 +57,7 @@ pub(crate) fn register_lints(registry: &mut LintRegistryBuilder) { registry.register_lint(&INVALID_OVERLOAD); registry.register_lint(&INVALID_PARAMETER_DEFAULT); registry.register_lint(&INVALID_PROTOCOL); + registry.register_lint(&INVALID_NAMED_TUPLE); registry.register_lint(&INVALID_RAISE); registry.register_lint(&INVALID_SUPER_ARGUMENT); registry.register_lint(&INVALID_TYPE_CHECKING_CONSTANT); @@ -448,6 +449,32 @@ declare_lint! { } } +declare_lint! { + /// ## What it does + /// Checks for invalidly defined `NamedTuple` classes. + /// + /// ## Why is this bad? + /// An invalidly defined `NamedTuple` class may lead to the type checker + /// drawing incorrect conclusions. It may also lead to `TypeError`s at runtime. + /// + /// ## Examples + /// A class definition cannot combine `NamedTuple` with other base classes + /// in multiple inheritance; doing so raises a `TypeError` at runtime. The sole + /// exception to this rule is `Generic[]`, which can be used alongside `NamedTuple` + /// in a class's bases list. + /// + /// ```pycon + /// >>> from typing import NamedTuple + /// >>> class Foo(NamedTuple, object): ... + /// TypeError: can only inherit from a NamedTuple type and Generic + /// ``` + pub(crate) static INVALID_NAMED_TUPLE = { + summary: "detects invalid `NamedTuple` class definitions", + status: LintStatus::preview("1.0.0"), + default_level: Level::Error, + } +} + declare_lint! { /// ## What it does /// Checks for classes with an inconsistent [method resolution order] (MRO). diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 83c7212d25b14..a1a3cb2e7b937 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -95,16 +95,17 @@ use crate::types::diagnostic::{ self, CALL_NON_CALLABLE, CONFLICTING_DECLARATIONS, CONFLICTING_METACLASS, CYCLIC_CLASS_DEFINITION, DIVISION_BY_ZERO, DUPLICATE_KW_ONLY, INCONSISTENT_MRO, INVALID_ARGUMENT_TYPE, INVALID_ASSIGNMENT, INVALID_ATTRIBUTE_ACCESS, INVALID_BASE, - INVALID_DECLARATION, INVALID_GENERIC_CLASS, INVALID_KEY, INVALID_PARAMETER_DEFAULT, - INVALID_TYPE_FORM, INVALID_TYPE_GUARD_CALL, INVALID_TYPE_VARIABLE_CONSTRAINTS, - IncompatibleBases, POSSIBLY_UNBOUND_IMPLICIT_CALL, POSSIBLY_UNBOUND_IMPORT, - TypeCheckDiagnostics, UNDEFINED_REVEAL, UNRESOLVED_ATTRIBUTE, UNRESOLVED_GLOBAL, - UNRESOLVED_IMPORT, UNRESOLVED_REFERENCE, UNSUPPORTED_OPERATOR, report_implicit_return_type, - report_instance_layout_conflict, report_invalid_argument_number_to_special_form, - report_invalid_arguments_to_annotated, report_invalid_arguments_to_callable, - report_invalid_assignment, report_invalid_attribute_assignment, - report_invalid_generator_function_return_type, report_invalid_key_on_typed_dict, - report_invalid_return_type, report_possibly_unbound_attribute, + INVALID_DECLARATION, INVALID_GENERIC_CLASS, INVALID_KEY, INVALID_NAMED_TUPLE, + INVALID_PARAMETER_DEFAULT, INVALID_TYPE_FORM, INVALID_TYPE_GUARD_CALL, + INVALID_TYPE_VARIABLE_CONSTRAINTS, IncompatibleBases, POSSIBLY_UNBOUND_IMPLICIT_CALL, + POSSIBLY_UNBOUND_IMPORT, TypeCheckDiagnostics, UNDEFINED_REVEAL, UNRESOLVED_ATTRIBUTE, + UNRESOLVED_GLOBAL, UNRESOLVED_IMPORT, UNRESOLVED_REFERENCE, UNSUPPORTED_OPERATOR, + report_implicit_return_type, report_instance_layout_conflict, + report_invalid_argument_number_to_special_form, report_invalid_arguments_to_annotated, + report_invalid_arguments_to_callable, report_invalid_assignment, + report_invalid_attribute_assignment, report_invalid_generator_function_return_type, + report_invalid_key_on_typed_dict, report_invalid_return_type, + report_possibly_unbound_attribute, }; use crate::types::enums::is_enum_class; use crate::types::function::{ @@ -1110,13 +1111,33 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } let is_protocol = class.is_protocol(self.db()); + let is_named_tuple = CodeGeneratorKind::NamedTuple.matches(self.db(), class); let mut solid_bases = IncompatibleBases::default(); // (2) Iterate through the class's explicit bases to check for various possible errors: // - Check for inheritance from plain `Generic`, // - Check for inheritance from a `@final` classes // - If the class is a protocol class: check for inheritance from a non-protocol class + // - If the class is a NamedTuple class: check for multiple inheritance that isn't `Generic[]` for (i, base_class) in class.explicit_bases(self.db()).iter().enumerate() { + if is_named_tuple + && !matches!( + base_class, + Type::SpecialForm(SpecialFormType::NamedTuple) + | Type::KnownInstance(KnownInstanceType::SubscriptedGeneric(_)) + ) + { + if let Some(builder) = self + .context + .report_lint(&INVALID_NAMED_TUPLE, &class_node.bases()[i]) + { + builder.into_diagnostic(format_args!( + "NamedTuple class `{}` cannot use multiple inheritance except with `Generic[]`", + class.name(self.db()), + )); + } + } + let base_class = match base_class { Type::SpecialForm(SpecialFormType::Generic) => { if let Some(builder) = self diff --git a/ty.schema.json b/ty.schema.json index d94057ef9e1b3..f6043e2d8f706 100644 --- a/ty.schema.json +++ b/ty.schema.json @@ -561,6 +561,16 @@ } ] }, + "invalid-named-tuple": { + "title": "detects invalid `NamedTuple` class definitions", + "description": "## What it does\nChecks for invalidly defined `NamedTuple` classes.\n\n## Why is this bad?\nAn invalidly defined `NamedTuple` class may lead to the type checker\ndrawing incorrect conclusions. It may also lead to `TypeError`s at runtime.\n\n## Examples\nA class definition cannot combine `NamedTuple` with other base classes\nin multiple inheritance; doing so raises a `TypeError` at runtime. The sole\nexception to this rule is `Generic[]`, which can be used alongside `NamedTuple`\nin a class's bases list.\n\n```pycon\n>>> from typing import NamedTuple\n>>> class Foo(NamedTuple, object): ...\nTypeError: can only inherit from a NamedTuple type and Generic\n```", + "default": "error", + "oneOf": [ + { + "$ref": "#/definitions/Level" + } + ] + }, "invalid-overload": { "title": "detects invalid `@overload` usages", "description": "## What it does\nChecks for various invalid `@overload` usages.\n\n## Why is this bad?\nThe `@overload` decorator is used to define functions and methods that accepts different\ncombinations of arguments and return different types based on the arguments passed. This is\nmainly beneficial for type checkers. But, if the `@overload` usage is invalid, the type\nchecker may not be able to provide correct type information.\n\n## Example\n\nDefining only one overload:\n\n```py\nfrom typing import overload\n\n@overload\ndef foo(x: int) -> int: ...\ndef foo(x: int | None) -> int | None:\n return x\n```\n\nOr, not providing an implementation for the overloaded definition:\n\n```py\nfrom typing import overload\n\n@overload\ndef foo() -> None: ...\n@overload\ndef foo(x: int) -> int: ...\n```\n\n## References\n- [Python documentation: `@overload`](https://docs.python.org/3/library/typing.html#typing.overload)", From e4f1b587cc2a5764e3fd6bda4e48ffedd111f30d Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 18 Aug 2025 13:27:54 +0100 Subject: [PATCH 034/160] Upgrade mypy_primer pin (#19967) --- .github/workflows/mypy_primer.yaml | 1 + scripts/mypy_primer.sh | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/mypy_primer.yaml b/.github/workflows/mypy_primer.yaml index 1a35bb75777d9..3d91decb11623 100644 --- a/.github/workflows/mypy_primer.yaml +++ b/.github/workflows/mypy_primer.yaml @@ -11,6 +11,7 @@ on: - "crates/ruff_python_parser" - ".github/workflows/mypy_primer.yaml" - ".github/workflows/mypy_primer_comment.yaml" + - "scripts/mypy_primer.sh" - "Cargo.lock" - "!**.md" diff --git a/scripts/mypy_primer.sh b/scripts/mypy_primer.sh index f4268eff5602c..05b9bc5ac7f09 100755 --- a/scripts/mypy_primer.sh +++ b/scripts/mypy_primer.sh @@ -20,7 +20,7 @@ cd .. echo "Project selector: ${PRIMER_SELECTOR}" # Allow the exit code to be 0 or 1, only fail for actual mypy_primer crashes/bugs uvx \ - --from="git+https://github.com/hauntsaninja/mypy_primer@59509d48de6da6aaa4e3a2f5e338769bc471f2d7" \ + --from="git+https://github.com/hauntsaninja/mypy_primer@a3798a3d7b8470603e650179b0f82deb2154364d" \ mypy_primer \ --repo ruff \ --type-checker ty \ From f6491cacd19110f4386d3ac10189cb7f678df02a Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Mon, 18 Aug 2025 11:46:16 -0400 Subject: [PATCH 035/160] Add `full` output format changes to the changelog (#19968) Summary -- I thought this might warrant a small blog-style writeup, especially since we already got a question about it (#19966), but I'm happy to switch back to a one-liner under `### Other changes` if preferred. I'll copy whatever we add here to the release notes too. Do we need a note at the top about the late addition? --- CHANGELOG.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 323ef6667a4fa..d9952e0f66bd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,8 +24,31 @@ ### Other changes - Build `riscv64` binaries for release ([#19819](https://github.com/astral-sh/ruff/pull/19819)) + - Add rule code to error description in GitLab output ([#19896](https://github.com/astral-sh/ruff/pull/19896)) +- Improve rendering of the `full` output format ([#19415](https://github.com/astral-sh/ruff/pull/19415)) + + Below is an example diff for [`F401`](https://docs.astral.sh/ruff/rules/unused-import/): + + ```diff + -unused.py:8:19: F401 [*] `pathlib` imported but unused + +F401 [*] `pathlib` imported but unused + + --> unused.py:8:19 + | + 7 | # Unused, _not_ marked as required (due to the alias). + 8 | import pathlib as non_alias + - | ^^^^^^^^^ F401 + + | ^^^^^^^^^ + 9 | + 10 | # Unused, marked as required. + | + - = help: Remove unused import: `pathlib` + +help: Remove unused import: `pathlib` + ``` + + For now, the primary difference is the movement of the filename, line number, and column information to a second line in the header. This new representation will allow us to make further additions to Ruff's diagnostics, such as adding sub-diagnostics and multiple annotations to the same snippet. + ## 0.12.8 ### Preview features From 0cb1abc1fc940148b9c253895e6c08cccf9219b0 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Mon, 18 Aug 2025 13:14:13 -0400 Subject: [PATCH 036/160] [ty] Implement partial stubs (#19931) Fixes https://github.com/astral-sh/ty/issues/184 --- .../mdtest/import/partial_stub_packages.md | 425 ++++++++++++++++++ .../src/module_resolver/path.rs | 27 +- .../src/module_resolver/resolver.rs | 86 +++- 3 files changed, 519 insertions(+), 19 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md diff --git a/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md new file mode 100644 index 0000000000000..3d01aa3ab4de2 --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md @@ -0,0 +1,425 @@ +# Partial stub packages + +Partial stub packages are stubs that are allowed to be missing modules. See the +[specification](https://peps.python.org/pep-0561/#partial-stub-packages). Partial stubs are also +called "incomplete" packages, and non-partial stubs are called "complete" packages. + +Normally a stub package is expected to define a copy of every module the real implementation +defines. Module resolution is consequently required to report a module doesn't exist if it finds +`mypackage-stubs` and fails to find `mypackage.mymodule` *even if* `mypackage` does define +`mymodule`. + +If a stub package declares that it's partial, we instead are expected to fall through to the +implementation package and try to discover `mymodule` there. This is described as follows: + +> Type checkers should merge the stub package and runtime package or typeshed directories. This can +> be thought of as the functional equivalent of copying the stub package into the same directory as +> the corresponding runtime package or typeshed folder and type checking the combined directory +> structure. Thus type checkers MUST maintain the normal resolution order of checking `*.pyi` before +> `*.py` files. + +Namespace stub packages are always considered partial by necessity. Regular stub packages are only +considered partial if they define a `py.typed` file containing the string `partial\n` (due to real +stubs in the wild, we relax this and look case-insensitively for `partial`). + +The `py.typed` file was originally specified as an empty marker for "this package supports types", +as a way to opt into having typecheckers run on a package. However ty and pyright choose to largely +ignore this and just type check every package. + +In its original specification it was specified that subpackages inherit any `py.typed` declared in a +parent package. However the precise interaction with `partial\n` was never specified. We currently +implement a simple inheritance scheme where a subpackage can always declare its own `py.typed` and +override whether it's partial or not. + +## Partial stub with missing module + +A stub package that includes a partial `py.typed` file. + +Here "both" is found in the stub, while "impl" is found in the implementation. "fake" is found in +neither. + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/foo-stubs/py.typed`: + +```text +partial +``` + +`/packages/foo-stubs/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/both.py`: + +```py +class Both: + both: str + other: int +``` + +`/packages/foo/__init__.py`: + +```py +``` + +`/packages/foo/both.py`: + +```py +class Both: ... +``` + +`/packages/foo/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from foo.both import Both +from foo.impl import Impl +from foo.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: str +reveal_type(Fake().fake) # revealed: Unknown +``` + +## Non-partial stub with missing module + +Omitting the partial `py.typed`, we see "impl" now cannot be found. + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/foo-stubs/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/both.py`: + +```py +class Both: + both: str + other: int +``` + +`/packages/foo/__init__.py`: + +```py +``` + +`/packages/foo/both.py`: + +```py +class Both: ... +``` + +`/packages/foo/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from foo.both import Both +from foo.impl import Impl # error: "Cannot resolve" +from foo.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: Unknown +reveal_type(Fake().fake) # revealed: Unknown +``` + +## Full-typed stub with missing module + +Including a blank py.typed we still don't conclude it's partial. + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/foo-stubs/py.typed`: + +```text +``` + +`/packages/foo-stubs/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/both.py`: + +```py +class Both: + both: str + other: int +``` + +`/packages/foo/__init__.py`: + +```py +``` + +`/packages/foo/both.py`: + +```py +class Both: ... +``` + +`/packages/foo/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from foo.both import Both +from foo.impl import Impl # error: "Cannot resolve" +from foo.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: Unknown +reveal_type(Fake().fake) # revealed: Unknown +``` + +## Inheriting a partial `py.typed` + +`foo-stubs` defines a partial py.typed which is used by `foo-stubs/bar` + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/foo-stubs/py.typed`: + +```text +# Also testing permissive parsing +# PARTIAL\n +``` + +`/packages/foo-stubs/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/bar/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/bar/both.py`: + +```py +class Both: + both: str + other: int +``` + +`/packages/foo/__init__.py`: + +```py +``` + +`/packages/foo/bar/__init__.py`: + +```py +``` + +`/packages/foo/bar/both.py`: + +```py +class Both: ... +``` + +`/packages/foo/bar/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from foo.bar.both import Both +from foo.bar.impl import Impl +from foo.bar.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: str +reveal_type(Fake().fake) # revealed: Unknown +``` + +## Overloading a full `py.typed` + +`foo-stubs` defines a full py.typed which is overloaded to partial by `foo-stubs/bar` + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/foo-stubs/py.typed`: + +```text +``` + +`/packages/foo-stubs/bar/py.typed`: + +```text +# Also testing permissive parsing +partial/n +``` + +`/packages/foo-stubs/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/bar/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/bar/both.py`: + +```py +class Both: + both: str + other: int +``` + +`/packages/foo/__init__.py`: + +```py +``` + +`/packages/foo/bar/__init__.py`: + +```py +``` + +`/packages/foo/bar/both.py`: + +```py +class Both: ... +``` + +`/packages/foo/bar/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from foo.bar.both import Both +from foo.bar.impl import Impl +from foo.bar.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: str +reveal_type(Fake().fake) # revealed: Unknown +``` + +## Overloading a partial `py.typed` + +`foo-stubs` defines a partial py.typed which is overloaded to full by `foo-stubs/bar` + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/foo-stubs/py.typed`: + +```text +# Also testing permissive parsing +pArTiAl\n +``` + +`/packages/foo-stubs/bar/py.typed`: + +```text +``` + +`/packages/foo-stubs/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/bar/__init__.pyi`: + +```pyi +``` + +`/packages/foo-stubs/bar/both.py`: + +```py +class Both: + both: str + other: int +``` + +`/packages/foo/__init__.py`: + +```py +``` + +`/packages/foo/bar/__init__.py`: + +```py +``` + +`/packages/foo/bar/both.py`: + +```py +class Both: ... +``` + +`/packages/foo/bar/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from foo.bar.both import Both +from foo.bar.impl import Impl # error: "Cannot resolve" +from foo.bar.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: Unknown +reveal_type(Fake().fake) # revealed: Unknown +``` diff --git a/crates/ty_python_semantic/src/module_resolver/path.rs b/crates/ty_python_semantic/src/module_resolver/path.rs index ff07b0a7c4735..77b0219afe35c 100644 --- a/crates/ty_python_semantic/src/module_resolver/path.rs +++ b/crates/ty_python_semantic/src/module_resolver/path.rs @@ -11,7 +11,7 @@ use ruff_db::vendored::{VendoredPath, VendoredPathBuf}; use super::typeshed::{TypeshedVersionsParseError, TypeshedVersionsQueryResult, typeshed_versions}; use crate::Db; use crate::module_name::ModuleName; -use crate::module_resolver::resolver::ResolverContext; +use crate::module_resolver::resolver::{PyTyped, ResolverContext}; use crate::site_packages::SitePackagesDiscoveryError; /// A path that points to a Python module. @@ -148,6 +148,31 @@ impl ModulePath { } } + /// Get the `py.typed` info for this package (not considering parent packages) + pub(super) fn py_typed(&self, resolver: &ResolverContext) -> PyTyped { + let Some(py_typed_contents) = self.to_system_path().and_then(|path| { + let py_typed_path = path.join("py.typed"); + let py_typed_file = system_path_to_file(resolver.db, py_typed_path).ok()?; + // If we fail to read it let's say that's like it doesn't exist + // (right now the difference between Untyped and Full is academic) + py_typed_file.read_to_string(resolver.db).ok() + }) else { + return PyTyped::Untyped; + }; + // The python typing spec says to look for "partial\n" but in the wild we've seen: + // + // * PARTIAL\n + // * partial\\n (as in they typed "\n") + // * partial/n + // + // since the py.typed file never really grew any other contents, let's be permissive + if py_typed_contents.to_ascii_lowercase().contains("partial") { + PyTyped::Partial + } else { + PyTyped::Full + } + } + pub(super) fn to_system_path(&self) -> Option { let ModulePath { search_path, diff --git a/crates/ty_python_semantic/src/module_resolver/resolver.rs b/crates/ty_python_semantic/src/module_resolver/resolver.rs index 52335901ac91b..783bc4dfe3ea4 100644 --- a/crates/ty_python_semantic/src/module_resolver/resolver.rs +++ b/crates/ty_python_semantic/src/module_resolver/resolver.rs @@ -684,7 +684,7 @@ fn resolve_name(db: &dyn Db, name: &ModuleName, mode: ModuleResolveMode) -> Opti if !search_path.is_standard_library() && resolver_state.mode.stubs_allowed() { match resolve_name_in_search_path(&resolver_state, &stub_name, search_path) { - Ok((package_kind, ResolvedName::FileModule(module))) => { + Ok((package_kind, _, ResolvedName::FileModule(module))) => { if package_kind.is_root() && module.kind.is_module() { tracing::trace!( "Search path `{search_path}` contains a module \ @@ -694,23 +694,30 @@ fn resolve_name(db: &dyn Db, name: &ModuleName, mode: ModuleResolveMode) -> Opti return Some(ResolvedName::FileModule(module)); } } - Ok((_, ResolvedName::NamespacePackage)) => { + Ok((_, _, ResolvedName::NamespacePackage)) => { is_namespace_package = true; } - Err(PackageKind::Root) => { + Err((PackageKind::Root, _)) => { tracing::trace!( "Search path `{search_path}` contains no stub package named `{stub_name}`." ); } - Err(PackageKind::Regular) => { + Err((PackageKind::Regular, PyTyped::Partial)) => { + tracing::trace!( + "Stub-package in `{search_path}` doesn't contain module: \ + `{name}` but it is a partial package, keep going." + ); + // stub exists, but the module doesn't. But this is a partial package, + // fall through to looking for a non-stub package + } + Err((PackageKind::Regular, _)) => { tracing::trace!( "Stub-package in `{search_path}` doesn't contain module: `{name}`" ); // stub exists, but the module doesn't. - // TODO: Support partial packages. return None; } - Err(PackageKind::Namespace) => { + Err((PackageKind::Namespace, _)) => { tracing::trace!( "Stub-package in `{search_path}` doesn't contain module: \ `{name}` but it is a namespace package, keep going." @@ -723,25 +730,31 @@ fn resolve_name(db: &dyn Db, name: &ModuleName, mode: ModuleResolveMode) -> Opti } match resolve_name_in_search_path(&resolver_state, &name, search_path) { - Ok((_, ResolvedName::FileModule(module))) => { + Ok((_, _, ResolvedName::FileModule(module))) => { return Some(ResolvedName::FileModule(module)); } - Ok((_, ResolvedName::NamespacePackage)) => { + Ok((_, _, ResolvedName::NamespacePackage)) => { is_namespace_package = true; } Err(kind) => match kind { - PackageKind::Root => { + (PackageKind::Root, _) => { tracing::trace!( "Search path `{search_path}` contains no package named `{name}`." ); } - PackageKind::Regular => { + (PackageKind::Regular, PyTyped::Partial) => { + tracing::trace!( + "Package in `{search_path}` doesn't contain module: \ + `{name}` but it is a partial package, keep going." + ); + } + (PackageKind::Regular, _) => { // For regular packages, don't search the next search path. All files of that // package must be in the same location tracing::trace!("Package in `{search_path}` doesn't contain module: `{name}`"); return None; } - PackageKind::Namespace => { + (PackageKind::Namespace, _) => { tracing::trace!( "Package in `{search_path}` doesn't contain module: \ `{name}` but it is a namespace package, keep going." @@ -796,7 +809,7 @@ fn resolve_name_in_search_path( context: &ResolverContext, name: &RelaxedModuleName, search_path: &SearchPath, -) -> Result<(PackageKind, ResolvedName), PackageKind> { +) -> Result<(PackageKind, PyTyped, ResolvedName), (PackageKind, PyTyped)> { let mut components = name.components(); let module_name = components.next_back().unwrap(); @@ -811,6 +824,7 @@ fn resolve_name_in_search_path( if let Some(regular_package) = resolve_file_module(&package_path, context) { return Ok(( resolved_package.kind, + resolved_package.typed, ResolvedName::FileModule(ResolvedFileModule { search_path: search_path.clone(), kind: ModuleKind::Package, @@ -825,6 +839,7 @@ fn resolve_name_in_search_path( if let Some(file_module) = resolve_file_module(&package_path, context) { return Ok(( resolved_package.kind, + resolved_package.typed, ResolvedName::FileModule(ResolvedFileModule { file: file_module, kind: ModuleKind::Module, @@ -859,12 +874,16 @@ fn resolve_name_in_search_path( package_path.search_path().as_system_path().unwrap(), ) { - return Ok((resolved_package.kind, ResolvedName::NamespacePackage)); + return Ok(( + resolved_package.kind, + resolved_package.typed, + ResolvedName::NamespacePackage, + )); } } } - Err(resolved_package.kind) + Err((resolved_package.kind, resolved_package.typed)) } /// If `module` exists on disk with either a `.pyi` or `.py` extension, @@ -919,7 +938,7 @@ fn resolve_package<'a, 'db, I>( module_search_path: &SearchPath, components: I, resolver_state: &ResolverContext<'db>, -) -> Result +) -> Result where I: Iterator, { @@ -933,9 +952,12 @@ where // `true` if resolving a sub-package. For example, `true` when resolving `bar` of `foo.bar`. let mut in_sub_package = false; + let mut typed = package_path.py_typed(resolver_state); + // For `foo.bar.baz`, test that `foo` and `bar` both contain a `__init__.py`. for folder in components { package_path.push(folder); + typed = package_path.py_typed(resolver_state).inherit_parent(typed); let is_regular_package = package_path.is_regular_package(resolver_state); @@ -950,13 +972,13 @@ where in_namespace_package = true; } else if in_namespace_package { // Package not found but it is part of a namespace package. - return Err(PackageKind::Namespace); + return Err((PackageKind::Namespace, typed)); } else if in_sub_package { // A regular sub package wasn't found. - return Err(PackageKind::Regular); + return Err((PackageKind::Regular, typed)); } else { // We couldn't find `foo` for `foo.bar.baz`, search the next search path. - return Err(PackageKind::Root); + return Err((PackageKind::Root, typed)); } in_sub_package = true; @@ -973,6 +995,7 @@ where Ok(ResolvedPackage { kind, path: package_path, + typed, }) } @@ -980,6 +1003,7 @@ where struct ResolvedPackage { path: ModulePath, kind: PackageKind, + typed: PyTyped, } #[derive(Copy, Clone, Eq, PartialEq, Debug)] @@ -1006,6 +1030,32 @@ impl PackageKind { } } +/// Info about the `py.typed` file for this package +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub(crate) enum PyTyped { + /// No `py.typed` was found + Untyped, + /// A `py.typed` was found containing "partial" + Partial, + /// A `py.typed` was found (not partial) + Full, +} + +impl PyTyped { + /// Inherit py.typed info from the parent package + /// + /// > This marker applies recursively: if a top-level package includes it, + /// > all its sub-packages MUST support type checking as well. + /// + /// This implementation implies that once a `py.typed` is specified + /// all child packages inherit it, so they can never become Untyped. + /// However they can override whether that's Full or Partial by + /// redeclaring a `py.typed` file of their own. + fn inherit_parent(self, parent: Self) -> Self { + if self == Self::Untyped { parent } else { self } + } +} + pub(super) struct ResolverContext<'db> { pub(super) db: &'db dyn Db, pub(super) python_version: PythonVersion, From 3314cf90ed718ef11fa83a1500f537c8026028a3 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 18 Aug 2025 18:30:05 +0100 Subject: [PATCH 037/160] [ty] Add more regression tests for `tuple` (#19974) --- .../mdtest/generics/pep695/classes.md | 29 +++++++++++++++++++ .../resources/mdtest/narrow/type.md | 11 +++++++ 2 files changed, 40 insertions(+) diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md index 56cdbc426bf9a..92840bcf1abec 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md @@ -630,5 +630,34 @@ class C[T](C): ... class D[T](D[int]): ... ``` +## Tuple as a PEP-695 generic class + +Our special handling for `tuple` does not break if `tuple` is defined as a PEP-695 generic class in +typeshed: + +```toml +[environment] +python-version = "3.12" +typeshed = "/typeshed" +``` + +`/typeshed/stdlib/builtins.pyi`: + +```pyi +class tuple[T]: ... +``` + +`/typeshed/stdlib/typing_extensions.pyi`: + +```pyi +def reveal_type(obj, /): ... +``` + +`main.py`: + +```py +reveal_type((1, 2, 3)) # revealed: tuple[Literal[1], Literal[2], Literal[3]] +``` + [crtp]: https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern [f-bound]: https://en.wikipedia.org/wiki/Bounded_quantification#F-bounded_quantification diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/type.md b/crates/ty_python_semantic/resources/mdtest/narrow/type.md index ef754d021ae7e..fccd6e54faa0f 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/type.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/type.md @@ -223,6 +223,17 @@ def _[T](x: A | B): reveal_type(x) # revealed: A[int] | B ``` +## Narrowing for tuple + +An early version of caused us to crash on this: + +```py +def _(val): + if type(val) is tuple: + # TODO: better would be `Unknown & tuple[object, ...]` + reveal_type(val) # revealed: Unknown & tuple[Unknown, ...] +``` + ## Limitations ```py From 24f6d2dc13abb41652157f21dccc4405c0305426 Mon Sep 17 00:00:00 2001 From: Matthew Mckee Date: Mon, 18 Aug 2025 18:45:44 +0100 Subject: [PATCH 038/160] [ty] Infer the correct type of Enum `__eq__` and `__ne__` comparisions (#19666) ## Summary Resolves https://github.com/astral-sh/ty/issues/920 ## Test Plan Update `enums.md` --------- Co-authored-by: David Peter --- .../resources/mdtest/enums.md | 45 ++++++++ crates/ty_python_semantic/src/types/infer.rs | 104 +++++++++++------- 2 files changed, 110 insertions(+), 39 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/enums.md b/crates/ty_python_semantic/resources/mdtest/enums.md index d1265225cf51d..a70a92d4303b1 100644 --- a/crates/ty_python_semantic/resources/mdtest/enums.md +++ b/crates/ty_python_semantic/resources/mdtest/enums.md @@ -749,6 +749,51 @@ def singleton_check(value: Singleton) -> str: assert_never(value) ``` +## `__eq__` and `__ne__` + +### No `__eq__` or `__ne__` overrides + +```py +from enum import Enum + +class Color(Enum): + RED = 1 + GREEN = 2 + +reveal_type(Color.RED == Color.RED) # revealed: Literal[True] +reveal_type(Color.RED != Color.RED) # revealed: Literal[False] +``` + +### Overridden `__eq__` + +```py +from enum import Enum + +class Color(Enum): + RED = 1 + GREEN = 2 + + def __eq__(self, other: object) -> bool: + return False + +reveal_type(Color.RED == Color.RED) # revealed: bool +``` + +### Overridden `__ne__` + +```py +from enum import Enum + +class Color(Enum): + RED = 1 + GREEN = 2 + + def __ne__(self, other: object) -> bool: + return False + +reveal_type(Color.RED != Color.RED) # revealed: bool +``` + ## References - Typing spec: diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index a1a3cb2e7b937..201dcd750078a 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -8019,6 +8019,48 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { // language spec. // - `[ast::CompOp::Is]`: return `false` if unequal, `bool` if equal // - `[ast::CompOp::IsNot]`: return `true` if unequal, `bool` if equal + let db = self.db(); + let try_dunder = |inference: &mut TypeInferenceBuilder<'db, '_>, + policy: MemberLookupPolicy| { + let rich_comparison = |op| inference.infer_rich_comparison(left, right, op, policy); + let membership_test_comparison = |op, range: TextRange| { + inference.infer_membership_test_comparison(left, right, op, range) + }; + + match op { + ast::CmpOp::Eq => rich_comparison(RichCompareOperator::Eq), + ast::CmpOp::NotEq => rich_comparison(RichCompareOperator::Ne), + ast::CmpOp::Lt => rich_comparison(RichCompareOperator::Lt), + ast::CmpOp::LtE => rich_comparison(RichCompareOperator::Le), + ast::CmpOp::Gt => rich_comparison(RichCompareOperator::Gt), + ast::CmpOp::GtE => rich_comparison(RichCompareOperator::Ge), + ast::CmpOp::In => { + membership_test_comparison(MembershipTestCompareOperator::In, range) + } + ast::CmpOp::NotIn => { + membership_test_comparison(MembershipTestCompareOperator::NotIn, range) + } + ast::CmpOp::Is => { + if left.is_disjoint_from(db, right) { + Ok(Type::BooleanLiteral(false)) + } else if left.is_singleton(db) && left.is_equivalent_to(db, right) { + Ok(Type::BooleanLiteral(true)) + } else { + Ok(KnownClass::Bool.to_instance(db)) + } + } + ast::CmpOp::IsNot => { + if left.is_disjoint_from(db, right) { + Ok(Type::BooleanLiteral(true)) + } else if left.is_singleton(db) && left.is_equivalent_to(db, right) { + Ok(Type::BooleanLiteral(false)) + } else { + Ok(KnownClass::Bool.to_instance(db)) + } + } + } + }; + let comparison_result = match (left, right) { (Type::Union(union), other) => { let mut builder = UnionBuilder::new(self.db()); @@ -8233,12 +8275,18 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { (Type::EnumLiteral(literal_1), Type::EnumLiteral(literal_2)) if op == ast::CmpOp::Eq => { - Some(Ok(Type::BooleanLiteral(literal_1 == literal_2))) + Some(Ok(match try_dunder(self, MemberLookupPolicy::MRO_NO_OBJECT_FALLBACK) { + Ok(ty) => ty, + Err(_) => Type::BooleanLiteral(literal_1 == literal_2), + })) } (Type::EnumLiteral(literal_1), Type::EnumLiteral(literal_2)) if op == ast::CmpOp::NotEq => { - Some(Ok(Type::BooleanLiteral(literal_1 != literal_2))) + Some(Ok(match try_dunder(self, MemberLookupPolicy::MRO_NO_OBJECT_FALLBACK) { + Ok(ty) => ty, + Err(_) => Type::BooleanLiteral(literal_1 != literal_2), + })) } ( @@ -8320,39 +8368,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } // Final generalized fallback: lookup the rich comparison `__dunder__` methods - let rich_comparison = |op| self.infer_rich_comparison(left, right, op); - let membership_test_comparison = - |op, range: TextRange| self.infer_membership_test_comparison(left, right, op, range); - match op { - ast::CmpOp::Eq => rich_comparison(RichCompareOperator::Eq), - ast::CmpOp::NotEq => rich_comparison(RichCompareOperator::Ne), - ast::CmpOp::Lt => rich_comparison(RichCompareOperator::Lt), - ast::CmpOp::LtE => rich_comparison(RichCompareOperator::Le), - ast::CmpOp::Gt => rich_comparison(RichCompareOperator::Gt), - ast::CmpOp::GtE => rich_comparison(RichCompareOperator::Ge), - ast::CmpOp::In => membership_test_comparison(MembershipTestCompareOperator::In, range), - ast::CmpOp::NotIn => { - membership_test_comparison(MembershipTestCompareOperator::NotIn, range) - } - ast::CmpOp::Is => { - if left.is_disjoint_from(self.db(), right) { - Ok(Type::BooleanLiteral(false)) - } else if left.is_singleton(self.db()) && left.is_equivalent_to(self.db(), right) { - Ok(Type::BooleanLiteral(true)) - } else { - Ok(KnownClass::Bool.to_instance(self.db())) - } - } - ast::CmpOp::IsNot => { - if left.is_disjoint_from(self.db(), right) { - Ok(Type::BooleanLiteral(true)) - } else if left.is_singleton(self.db()) && left.is_equivalent_to(self.db(), right) { - Ok(Type::BooleanLiteral(false)) - } else { - Ok(KnownClass::Bool.to_instance(self.db())) - } - } - } + try_dunder(self, MemberLookupPolicy::default()) } /// Rich comparison in Python are the operators `==`, `!=`, `<`, `<=`, `>`, and `>=`. Their @@ -8364,14 +8380,20 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { left: Type<'db>, right: Type<'db>, op: RichCompareOperator, + policy: MemberLookupPolicy, ) -> Result, CompareUnsupportedError<'db>> { let db = self.db(); // The following resource has details about the rich comparison algorithm: // https://snarky.ca/unravelling-rich-comparison-operators/ let call_dunder = |op: RichCompareOperator, left: Type<'db>, right: Type<'db>| { - left.try_call_dunder(db, op.dunder(), CallArguments::positional([right])) - .map(|outcome| outcome.return_type(db)) - .ok() + left.try_call_dunder_with_policy( + db, + op.dunder(), + &mut CallArguments::positional([right]), + policy, + ) + .map(|outcome| outcome.return_type(db)) + .ok() }; // The reflected dunder has priority if the right-hand side is a strict subclass of the left-hand side. @@ -8384,7 +8406,11 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { // When no appropriate method returns any value other than NotImplemented, // the `==` and `!=` operators will fall back to `is` and `is not`, respectively. // refer to `` - if matches!(op, RichCompareOperator::Eq | RichCompareOperator::Ne) { + if matches!(op, RichCompareOperator::Eq | RichCompareOperator::Ne) + // This branch implements specific behavior of the `__eq__` and `__ne__` methods + // on `object`, so it does not apply if we skip looking up attributes on `object`. + && !policy.mro_no_object_fallback() + { Some(KnownClass::Bool.to_instance(db)) } else { None From e6dcdd29f20eb2ab8e4e34ff164015f4ba212248 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 18 Aug 2025 21:38:19 +0100 Subject: [PATCH 039/160] [ty] Add a Todo-type branch for `type[P]` where `P` is a protocol class (#19947) --- .../resources/mdtest/protocols.md | 62 ++++++++++++++++++- ...ol_cl\342\200\246_(288988036f34ddcf).snap" | 18 ++---- crates/ty_python_semantic/src/types.rs | 12 ++++ crates/ty_python_semantic/src/types/infer.rs | 5 ++ .../src/types/subclass_of.rs | 6 ++ 5 files changed, 87 insertions(+), 16 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/protocols.md b/crates/ty_python_semantic/resources/mdtest/protocols.md index 5c7899c7a4248..28fd2c9362d0e 100644 --- a/crates/ty_python_semantic/resources/mdtest/protocols.md +++ b/crates/ty_python_semantic/resources/mdtest/protocols.md @@ -355,7 +355,9 @@ And as a corollary, `type[MyProtocol]` can also be called: ```py def f(x: type[MyProtocol]): - reveal_type(x()) # revealed: MyProtocol + # TODO: add a `reveal_type` call here once it's no longer a `Todo` type + # (which doesn't work well with snapshots) + x() ``` ## Members of a protocol @@ -1931,7 +1933,7 @@ def _(r: Recursive): reveal_type(r.t) # revealed: tuple[int, tuple[str, Recursive]] reveal_type(r.callable1) # revealed: (int, /) -> Recursive reveal_type(r.callable2) # revealed: (Recursive, /) -> int - reveal_type(r.subtype_of) # revealed: type[Recursive] + reveal_type(r.subtype_of) # revealed: @Todo(type[T] for protocols) reveal_type(r.generic) # revealed: GenericC[Recursive] reveal_type(r.method(r)) # revealed: Recursive reveal_type(r.nested) # revealed: Recursive | ((Recursive, tuple[Recursive, Recursive], /) -> Recursive) @@ -2069,6 +2071,62 @@ def f(value: Iterator): cast(Iterator, value) # error: [redundant-cast] ``` +## Meta-protocols + +Where `P` is a protocol type, a class object `N` can be said to inhabit the type `type[P]` if: + +- All `ClassVar` members on `P` exist on the class object `N` +- All method members on `P` exist on the class object `N` +- Instantiating `N` creates an object that would satisfy the protocol `P` + +Currently meta-protocols are not fully supported by ty, but we try to keep false positives to a +minimum in the meantime. + +```py +from typing import Protocol, ClassVar +from ty_extensions import static_assert, is_assignable_to, TypeOf, is_subtype_of + +class Foo(Protocol): + x: int + y: ClassVar[str] + def method(self) -> bytes: ... + +def _(f: type[Foo]): + reveal_type(f) # revealed: type[@Todo(type[T] for protocols)] + + # TODO: we should emit `unresolved-attribute` here: although we would accept this for a + # nominal class, we would see any class `N` as inhabiting `Foo` if it had an implicit + # instance attribute `x`, and implicit instance attributes are rarely bound on the class + # object. + reveal_type(f.x) # revealed: @Todo(type[T] for protocols) + + # TODO: should be `str` + reveal_type(f.y) # revealed: @Todo(type[T] for protocols) + f.y = "foo" # fine + + # TODO: should be `Callable[[Foo], bytes]` + reveal_type(f.method) # revealed: @Todo(type[T] for protocols) + +class Bar: ... + +# TODO: these should pass +static_assert(not is_assignable_to(type[Bar], type[Foo])) # error: [static-assert-error] +static_assert(not is_assignable_to(TypeOf[Bar], type[Foo])) # error: [static-assert-error] + +class Baz: + x: int + y: ClassVar[str] = "foo" + def method(self) -> bytes: + return b"foo" + +static_assert(is_assignable_to(type[Baz], type[Foo])) +static_assert(is_assignable_to(TypeOf[Baz], type[Foo])) + +# TODO: these should pass +static_assert(is_subtype_of(type[Baz], type[Foo])) # error: [static-assert-error] +static_assert(is_subtype_of(TypeOf[Baz], type[Foo])) # error: [static-assert-error] +``` + ## TODO Add tests for: diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl\342\200\246_(288988036f34ddcf).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl\342\200\246_(288988036f34ddcf).snap" index 3553f119c2242..923dac0803424 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl\342\200\246_(288988036f34ddcf).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Calls_to_protocol_cl\342\200\246_(288988036f34ddcf).snap" @@ -36,7 +36,9 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/protocols.md 22 | 23 | reveal_type(SubclassOfGenericProtocol[int]()) # revealed: SubclassOfGenericProtocol[int] 24 | def f(x: type[MyProtocol]): -25 | reveal_type(x()) # revealed: MyProtocol +25 | # TODO: add a `reveal_type` call here once it's no longer a `Todo` type +26 | # (which doesn't work well with snapshots) +27 | x() ``` # Diagnostics @@ -161,19 +163,7 @@ info[revealed-type]: Revealed type 23 | reveal_type(SubclassOfGenericProtocol[int]()) # revealed: SubclassOfGenericProtocol[int] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `SubclassOfGenericProtocol[int]` 24 | def f(x: type[MyProtocol]): -25 | reveal_type(x()) # revealed: MyProtocol - | - -``` - -``` -info[revealed-type]: Revealed type - --> src/mdtest_snippet.py:25:17 - | -23 | reveal_type(SubclassOfGenericProtocol[int]()) # revealed: SubclassOfGenericProtocol[int] -24 | def f(x: type[MyProtocol]): -25 | reveal_type(x()) # revealed: MyProtocol - | ^^^ `MyProtocol` +25 | # TODO: add a `reveal_type` call here once it's no longer a `Todo` type | ``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 3440ee58b0590..ac5124a4bc143 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -849,6 +849,18 @@ impl<'db> Type<'db> { } } + pub(crate) const fn into_dynamic(self) -> Option { + match self { + Type::Dynamic(dynamic_type) => Some(dynamic_type), + _ => None, + } + } + + pub(crate) const fn expect_dynamic(self) -> DynamicType { + self.into_dynamic() + .expect("Expected a Type::Dynamic variant") + } + #[track_caller] pub(crate) fn expect_class_literal(self) -> ClassLiteral<'db> { self.into_class_literal() diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 201dcd750078a..9d46d16965397 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -10198,6 +10198,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { Type::ClassLiteral(class_literal) => { if class_literal.is_known(self.db(), KnownClass::Any) { SubclassOfType::subclass_of_any() + } else if class_literal.is_protocol(self.db()) { + SubclassOfType::from( + self.db(), + todo_type!("type[T] for protocols").expect_dynamic(), + ) } else { SubclassOfType::from( self.db(), diff --git a/crates/ty_python_semantic/src/types/subclass_of.rs b/crates/ty_python_semantic/src/types/subclass_of.rs index c27e92018e1e4..02cb7bbebc3c1 100644 --- a/crates/ty_python_semantic/src/types/subclass_of.rs +++ b/crates/ty_python_semantic/src/types/subclass_of.rs @@ -285,6 +285,12 @@ impl<'db> From> for SubclassOfInner<'db> { } } +impl From for SubclassOfInner<'_> { + fn from(value: DynamicType) -> Self { + SubclassOfInner::Dynamic(value) + } +} + impl<'db> From> for Type<'db> { fn from(value: SubclassOfInner<'db>) -> Self { match value { From a04375173cf5e6378aeeeb69e3032b05cefb7a5c Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Mon, 18 Aug 2025 17:54:05 -0700 Subject: [PATCH 040/160] [ty] fix unpacking a type alias with detailed tuple spec (#19981) ## Summary Fixes https://github.com/astral-sh/ty/issues/1046 We special-case iteration of certain types because they may have a more detailed tuple-spec. Now that type aliases are a distinct type variant, we need to handle them as well. I don't love that `Type::TypeAlias` means we have to remember to add a case for it basically anywhere we are special-casing a certain kind of type, but at the moment I don't have a better plan. It's another argument for avoiding fallback cases in `Type` matches, which we usually prefer; I've updated this match statement to be comprehensive. ## Test Plan Added mdtest. --- .../resources/mdtest/pep695_type_aliases.md | 11 ++++++ crates/ty_python_semantic/src/types.rs | 34 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md b/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md index ee5bffcb19f3e..904f08099a76a 100644 --- a/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md +++ b/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md @@ -64,6 +64,17 @@ x: MyIntOrStr = 1 y: MyIntOrStr = None ``` +## Unpacking from a type alias + +```py +type T = tuple[int, str] + +def f(x: T): + a, b = x + reveal_type(a) # revealed: int + reveal_type(b) # revealed: str +``` + ## Generic type aliases ```py diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index ac5124a4bc143..30e01fdc97edc 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -4866,7 +4866,39 @@ impl<'db> Type<'db> { // diagnostic in unreachable code. return Ok(Cow::Owned(TupleSpec::homogeneous(Type::unknown()))); } - _ => {} + Type::TypeAlias(alias) => { + return alias.value_type(db).try_iterate_with_mode(db, mode); + } + Type::Dynamic(_) + | Type::FunctionLiteral(_) + | Type::GenericAlias(_) + | Type::BoundMethod(_) + | Type::MethodWrapper(_) + | Type::WrapperDescriptor(_) + | Type::DataclassDecorator(_) + | Type::DataclassTransformer(_) + | Type::Callable(_) + | Type::ModuleLiteral(_) + | Type::ClassLiteral(_) + | Type::SubclassOf(_) + | Type::ProtocolInstance(_) + | Type::SpecialForm(_) + | Type::KnownInstance(_) + | Type::PropertyInstance(_) + | Type::Union(_) + | Type::Intersection(_) + | Type::AlwaysTruthy + | Type::AlwaysFalsy + | Type::IntLiteral(_) + | Type::BooleanLiteral(_) + | Type::EnumLiteral(_) + | Type::LiteralString + | Type::BytesLiteral(_) + | Type::TypeVar(_) + | Type::NonInferableTypeVar(_) + | Type::BoundSuper(_) + | Type::TypeIs(_) + | Type::TypedDict(_) => {} } let try_call_dunder_getitem = || { From c20d906503ad35898898000819aab6735ac90bdb Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Mon, 18 Aug 2025 21:42:53 -0400 Subject: [PATCH 041/160] [ty] improve goto/hover for definitions (#19976) By computing the actual Definition for, well, definitions, we unlock a bunch of richer machinery in the goto/hover subsystems for free. Fixes https://github.com/astral-sh/ty/issues/1001 Fixes https://github.com/astral-sh/ty/issues/1004 --- crates/ty_ide/src/goto.rs | 49 ++---- crates/ty_ide/src/goto_definition.rs | 90 +++++++++++ crates/ty_ide/src/goto_references.rs | 36 ++++- crates/ty_ide/src/hover.rs | 150 ++++++++++++++++++ crates/ty_python_semantic/src/lib.rs | 4 +- .../ty_python_semantic/src/semantic_model.rs | 32 +++- 6 files changed, 316 insertions(+), 45 deletions(-) diff --git a/crates/ty_ide/src/goto.rs b/crates/ty_ide/src/goto.rs index 17f38b3417584..2047dce35ee34 100644 --- a/crates/ty_ide/src/goto.rs +++ b/crates/ty_ide/src/goto.rs @@ -11,6 +11,7 @@ use ruff_db::parsed::ParsedModuleRef; use ruff_python_ast::{self as ast, AnyNodeRef}; use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextRange, TextSize}; +use ty_python_semantic::HasDefinition; use ty_python_semantic::ImportAliasResolution; use ty_python_semantic::ResolvedDefinition; use ty_python_semantic::types::Type; @@ -285,36 +286,24 @@ impl GotoTarget<'_> { // For already-defined symbols, they are their own definitions GotoTarget::FunctionDef(function) => { - let range = function.name.range; - Some(DefinitionsOrTargets::Targets( - crate::NavigationTargets::single(NavigationTarget { - file, - focus_range: range, - full_range: function.range(), - }), - )) + let model = SemanticModel::new(db, file); + Some(DefinitionsOrTargets::Definitions(vec![ + ResolvedDefinition::Definition(function.definition(&model)), + ])) } GotoTarget::ClassDef(class) => { - let range = class.name.range; - Some(DefinitionsOrTargets::Targets( - crate::NavigationTargets::single(NavigationTarget { - file, - focus_range: range, - full_range: class.range(), - }), - )) + let model = SemanticModel::new(db, file); + Some(DefinitionsOrTargets::Definitions(vec![ + ResolvedDefinition::Definition(class.definition(&model)), + ])) } GotoTarget::Parameter(parameter) => { - let range = parameter.name.range; - Some(DefinitionsOrTargets::Targets( - crate::NavigationTargets::single(NavigationTarget { - file, - focus_range: range, - full_range: parameter.range(), - }), - )) + let model = SemanticModel::new(db, file); + Some(DefinitionsOrTargets::Definitions(vec![ + ResolvedDefinition::Definition(parameter.definition(&model)), + ])) } // For import aliases (offset within 'y' or 'z' in "from x import y as z") @@ -376,14 +365,10 @@ impl GotoTarget<'_> { // For exception variables, they are their own definitions (like parameters) GotoTarget::ExceptVariable(except_handler) => { - if let Some(name) = &except_handler.name { - let range = name.range; - Some(DefinitionsOrTargets::Targets( - crate::NavigationTargets::single(NavigationTarget::new(file, range)), - )) - } else { - None - } + let model = SemanticModel::new(db, file); + Some(DefinitionsOrTargets::Definitions(vec![ + ResolvedDefinition::Definition(except_handler.definition(&model)), + ])) } // For pattern match rest variables, they are their own definitions diff --git a/crates/ty_ide/src/goto_definition.rs b/crates/ty_ide/src/goto_definition.rs index a2aaee4b16927..aaa02cd2a231f 100644 --- a/crates/ty_ide/src/goto_definition.rs +++ b/crates/ty_ide/src/goto_definition.rs @@ -181,6 +181,49 @@ def other_function(): ... "#); } + /// goto-definition on a function definition in a .pyi should go to the .py + #[test] + fn goto_definition_stub_map_function_def() { + let test = CursorTest::builder() + .source( + "mymodule.py", + r#" +def my_function(): + return "hello" + +def other_function(): + return "other" +"#, + ) + .source( + "mymodule.pyi", + r#" +def my_function(): ... + +def other_function(): ... +"#, + ) + .build(); + + assert_snapshot!(test.goto_definition(), @r#" + info[goto-definition]: Definition + --> mymodule.py:2:5 + | + 2 | def my_function(): + | ^^^^^^^^^^^ + 3 | return "hello" + | + info: Source + --> mymodule.pyi:2:5 + | + 2 | def my_function(): ... + | ^^^^^^^^^^^ + 3 | + 4 | def other_function(): ... + | + "#); + } + /// goto-definition on a function that's redefined many times in the impl .py /// /// Currently this yields all instances. There's an argument for only yielding @@ -328,6 +371,53 @@ class MyOtherClass: "); } + /// goto-definition on a class def in a .pyi should go to the .py + #[test] + fn goto_definition_stub_map_class_def() { + let test = CursorTest::builder() + .source( + "mymodule.py", + r#" +class MyClass: + def __init__(self, val): + self.val = val + +class MyOtherClass: + def __init__(self, val): + self.val = val + 1 +"#, + ) + .source( + "mymodule.pyi", + r#" +class MyClass: + def __init__(self, val: bool): ... + +class MyOtherClass: + def __init__(self, val: bool): ... +"#, + ) + .build(); + + assert_snapshot!(test.goto_definition(), @r" + info[goto-definition]: Definition + --> mymodule.py:2:7 + | + 2 | class MyClass: + | ^^^^^^^ + 3 | def __init__(self, val): + 4 | self.val = val + | + info: Source + --> mymodule.pyi:2:7 + | + 2 | class MyClass: + | ^^^^^^^ + 3 | def __init__(self, val: bool): ... + | + "); + } + /// goto-definition on a class init should go to the .py not the .pyi #[test] fn goto_definition_stub_map_class_init() { diff --git a/crates/ty_ide/src/goto_references.rs b/crates/ty_ide/src/goto_references.rs index cacf8cf4122c6..7860cfb169548 100644 --- a/crates/ty_ide/src/goto_references.rs +++ b/crates/ty_ide/src/goto_references.rs @@ -405,9 +405,7 @@ except ValueError as err: ", ); - // Note: Currently only finds the declaration, not the usages - // This is because semantic analysis for except handler variables isn't fully implemented - assert_snapshot!(test.references(), @r###" + assert_snapshot!(test.references(), @r" info[references]: Reference 1 --> main.py:4:29 | @@ -418,7 +416,37 @@ except ValueError as err: 5 | print(f'Error: {err}') 6 | return err | - "###); + + info[references]: Reference 2 + --> main.py:5:21 + | + 3 | x = 1 / 0 + 4 | except ZeroDivisionError as err: + 5 | print(f'Error: {err}') + | ^^^ + 6 | return err + | + + info[references]: Reference 3 + --> main.py:6:12 + | + 4 | except ZeroDivisionError as err: + 5 | print(f'Error: {err}') + 6 | return err + | ^^^ + 7 | + 8 | try: + | + + info[references]: Reference 4 + --> main.py:11:31 + | + 9 | y = 2 / 0 + 10 | except ValueError as err: + 11 | print(f'Different error: {err}') + | ^^^ + | + "); } #[test] diff --git a/crates/ty_ide/src/hover.rs b/crates/ty_ide/src/hover.rs index 0918d86a4ded8..0ede0fc2f76b0 100644 --- a/crates/ty_ide/src/hover.rs +++ b/crates/ty_ide/src/hover.rs @@ -237,6 +237,57 @@ mod tests { "); } + #[test] + fn hover_function_def() { + let test = cursor_test( + r#" + def my_func(a, b): + '''This is such a great func!! + + Args: + a: first for a reason + b: coming for `a`'s title + ''' + return 0 + "#, + ); + + assert_snapshot!(test.hover(), @r" + def my_func(a, b) -> Unknown + --------------------------------------------- + This is such a great func!! + + Args: + a: first for a reason + b: coming for `a`'s title + + --------------------------------------------- + ```python + def my_func(a, b) -> Unknown + ``` + --- + ```text + This is such a great func!! + + Args: + a: first for a reason + b: coming for `a`'s title + + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:2:13 + | + 2 | def my_func(a, b): + | ^^^^^-^ + | | | + | | Cursor offset + | source + 3 | '''This is such a great func!! + | + "); + } + #[test] fn hover_class() { let test = cursor_test( @@ -304,6 +355,71 @@ mod tests { "); } + #[test] + fn hover_class_def() { + let test = cursor_test( + r#" + class MyClass: + ''' + This is such a great class!! + + Don't you know? + + Everyone loves my class!! + + ''' + def __init__(self, val): + """initializes MyClass (perfectly)""" + self.val = val + + def my_method(self, a, b): + '''This is such a great func!! + + Args: + a: first for a reason + b: coming for `a`'s title + ''' + return 0 + "#, + ); + + assert_snapshot!(test.hover(), @r" + + --------------------------------------------- + This is such a great class!! + + Don't you know? + + Everyone loves my class!! + + --------------------------------------------- + ```python + + ``` + --- + ```text + This is such a great class!! + + Don't you know? + + Everyone loves my class!! + + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:2:15 + | + 2 | class MyClass: + | ^^^^^-^ + | | | + | | Cursor offset + | source + 3 | ''' + 4 | This is such a great class!! + | + "); + } + #[test] fn hover_class_init() { let test = cursor_test( @@ -571,6 +687,40 @@ mod tests { "); } + #[test] + fn hover_keyword_parameter_def() { + let test = cursor_test( + r#" + def test(ab: int): + """my cool test + + Args: + ab: a nice little integer + """ + return 0 + "#, + ); + + assert_snapshot!(test.hover(), @r#" + int + --------------------------------------------- + ```python + int + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:2:22 + | + 2 | def test(ab: int): + | ^- + | || + | |Cursor offset + | source + 3 | """my cool test + | + "#); + } + #[test] fn hover_union() { let test = cursor_test( diff --git a/crates/ty_python_semantic/src/lib.rs b/crates/ty_python_semantic/src/lib.rs index 321d7b99a772a..ba4075ef2aefd 100644 --- a/crates/ty_python_semantic/src/lib.rs +++ b/crates/ty_python_semantic/src/lib.rs @@ -15,7 +15,9 @@ pub use program::{ PythonVersionWithSource, SearchPathSettings, }; pub use python_platform::PythonPlatform; -pub use semantic_model::{Completion, CompletionKind, HasType, NameKind, SemanticModel}; +pub use semantic_model::{ + Completion, CompletionKind, HasDefinition, HasType, NameKind, SemanticModel, +}; pub use site_packages::{PythonEnvironment, SitePackagesPaths, SysPrefixPathOrigin}; pub use types::ide_support::{ ImportAliasResolution, ResolvedDefinition, definitions_for_attribute, diff --git a/crates/ty_python_semantic/src/semantic_model.rs b/crates/ty_python_semantic/src/semantic_model.rs index 1aeeb36db7778..f038111c5f1fa 100644 --- a/crates/ty_python_semantic/src/semantic_model.rs +++ b/crates/ty_python_semantic/src/semantic_model.rs @@ -7,6 +7,7 @@ use ruff_source_file::LineIndex; use crate::Db; use crate::module_name::ModuleName; use crate::module_resolver::{KnownModule, Module, resolve_module}; +use crate::semantic_index::definition::Definition; use crate::semantic_index::scope::FileScopeId; use crate::semantic_index::semantic_index; use crate::types::ide_support::all_declarations_and_bindings; @@ -296,6 +297,14 @@ pub trait HasType { fn inferred_type<'db>(&self, model: &SemanticModel<'db>) -> Type<'db>; } +pub trait HasDefinition { + /// Returns the inferred type of `self`. + /// + /// ## Panics + /// May panic if `self` is from another file than `model`. + fn definition<'db>(&self, model: &SemanticModel<'db>) -> Definition<'db>; +} + impl HasType for ast::ExprRef<'_> { fn inferred_type<'db>(&self, model: &SemanticModel<'db>) -> Type<'db> { let index = semantic_index(model.db, model.file); @@ -392,24 +401,31 @@ impl HasType for ast::Expr { } } -macro_rules! impl_binding_has_ty { +macro_rules! impl_binding_has_ty_def { ($ty: ty) => { + impl HasDefinition for $ty { + #[inline] + fn definition<'db>(&self, model: &SemanticModel<'db>) -> Definition<'db> { + let index = semantic_index(model.db, model.file); + index.expect_single_definition(self) + } + } + impl HasType for $ty { #[inline] fn inferred_type<'db>(&self, model: &SemanticModel<'db>) -> Type<'db> { - let index = semantic_index(model.db, model.file); - let binding = index.expect_single_definition(self); + let binding = HasDefinition::definition(self, model); binding_type(model.db, binding) } } }; } -impl_binding_has_ty!(ast::StmtFunctionDef); -impl_binding_has_ty!(ast::StmtClassDef); -impl_binding_has_ty!(ast::Parameter); -impl_binding_has_ty!(ast::ParameterWithDefault); -impl_binding_has_ty!(ast::ExceptHandlerExceptHandler); +impl_binding_has_ty_def!(ast::StmtFunctionDef); +impl_binding_has_ty_def!(ast::StmtClassDef); +impl_binding_has_ty_def!(ast::Parameter); +impl_binding_has_ty_def!(ast::ParameterWithDefault); +impl_binding_has_ty_def!(ast::ExceptHandlerExceptHandler); impl HasType for ast::Alias { fn inferred_type<'db>(&self, model: &SemanticModel<'db>) -> Type<'db> { From 4242905b36f1f64de6fcc311a412a1dbf55e119b Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Aug 2025 09:56:08 +0100 Subject: [PATCH 042/160] [ty] Detect `NamedTuple` classes where fields without default values follow fields with default values (#19945) --- crates/ty/docs/rules.md | 124 ++++++++-------- .../resources/mdtest/named_tuple.md | 22 ++- ...uple`_-_Definition_(bbf79630502e65e9).snap | 140 ++++++++++++++++++ crates/ty_python_semantic/src/types/class.rs | 53 ++++++- .../src/types/diagnostic.rs | 55 +++++++ crates/ty_python_semantic/src/types/infer.rs | 34 ++++- 6 files changed, 358 insertions(+), 70 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Definition_(bbf79630502e65e9).snap diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index c122710031e29..1e190e7dd6f89 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -36,7 +36,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-non-callable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L103) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L104) **What it does** @@ -58,7 +58,7 @@ Calling a non-callable object will raise a `TypeError` at runtime. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-argument-forms) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L147) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L148) **What it does** @@ -88,7 +88,7 @@ f(int) # error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-declarations) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L173) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L174) **What it does** @@ -117,7 +117,7 @@ a = 1 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L198) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L199) **What it does** @@ -147,7 +147,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20cyclic-class-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L224) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L225) **What it does** @@ -177,7 +177,7 @@ class B(A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L289) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L290) **What it does** @@ -202,7 +202,7 @@ class B(A, A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-kw-only) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L310) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L311) **What it does** @@ -306,7 +306,7 @@ def test(): -> "Literal[5]": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20inconsistent-mro) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L478) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L479) **What it does** @@ -334,7 +334,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20index-out-of-bounds) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L502) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L503) **What it does** @@ -358,7 +358,7 @@ t[3] # IndexError: tuple index out of range Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20instance-layout-conflict) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L342) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L343) **What it does** @@ -445,7 +445,7 @@ an atypical memory layout. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-argument-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L547) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L548) **What it does** @@ -470,7 +470,7 @@ func("foo") # error: [invalid-argument-type] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-assignment) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L587) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L588) **What it does** @@ -496,7 +496,7 @@ a: int = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-attribute-access) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1621) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1622) **What it does** @@ -528,7 +528,7 @@ C.instance_var = 3 # error: Cannot assign to instance variable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-await) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L609) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L610) **What it does** @@ -562,7 +562,7 @@ asyncio.run(main()) Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L639) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L640) **What it does** @@ -584,7 +584,7 @@ class A(42): ... # error: [invalid-base] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-context-manager) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L690) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L691) **What it does** @@ -609,7 +609,7 @@ with 1: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-declaration) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L711) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L712) **What it does** @@ -636,7 +636,7 @@ a: str Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-exception-caught) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L734) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L735) **What it does** @@ -678,7 +678,7 @@ except ZeroDivisionError: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-generic-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L770) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L771) **What it does** @@ -709,7 +709,7 @@ class C[U](Generic[T]): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-key) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L522) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L523) **What it does** @@ -738,7 +738,7 @@ alice["height"] # KeyError: 'height' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-legacy-type-variable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L796) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L797) **What it does** @@ -771,7 +771,7 @@ def f(t: TypeVar("U")): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L845) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L846) **What it does** @@ -803,7 +803,7 @@ class B(metaclass=f): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-named-tuple) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L452) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L453) **What it does** @@ -833,7 +833,7 @@ TypeError: can only inherit from a NamedTuple type and Generic Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L872) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L873) **What it does** @@ -881,7 +881,7 @@ def foo(x: int) -> int: ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-parameter-default) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L915) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L916) **What it does** @@ -905,7 +905,7 @@ def f(a: int = ''): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-protocol) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L424) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L425) **What it does** @@ -937,7 +937,7 @@ TypeError: Protocols can only inherit from other protocols, got Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-raise) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L935) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L936) Checks for `raise` statements that raise non-exceptions or use invalid @@ -984,7 +984,7 @@ def g(): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-return-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L568) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L569) **What it does** @@ -1007,7 +1007,7 @@ def func() -> int: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-super-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L978) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L979) **What it does** @@ -1061,7 +1061,7 @@ TODO #14889 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-alias-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L824) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L825) **What it does** @@ -1086,7 +1086,7 @@ NewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name mus Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-checking-constant) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1017) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1018) **What it does** @@ -1114,7 +1114,7 @@ TYPE_CHECKING = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-form) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1041) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1042) **What it does** @@ -1142,7 +1142,7 @@ b: Annotated[int] # `Annotated` expects at least two arguments Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1093) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1094) **What it does** @@ -1174,7 +1174,7 @@ f(10) # Error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1065) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1066) **What it does** @@ -1206,7 +1206,7 @@ class C: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-variable-constraints) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1121) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1122) **What it does** @@ -1239,7 +1239,7 @@ T = TypeVar('T', bound=str) # valid bound TypeVar Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1150) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1151) **What it does** @@ -1262,7 +1262,7 @@ func() # TypeError: func() missing 1 required positional argument: 'x' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20no-matching-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1169) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1170) **What it does** @@ -1289,7 +1289,7 @@ func("string") # error: [no-matching-overload] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20non-subscriptable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1192) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1193) **What it does** @@ -1311,7 +1311,7 @@ Subscripting an object that does not support it will raise a `TypeError` at runt Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20not-iterable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1210) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1211) **What it does** @@ -1335,7 +1335,7 @@ for i in 34: # TypeError: 'int' object is not iterable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20parameter-already-assigned) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1261) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1262) **What it does** @@ -1389,7 +1389,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20static-assert-error) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1597) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1598) **What it does** @@ -1417,7 +1417,7 @@ static_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known tr Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20subclass-of-final-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1352) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1353) **What it does** @@ -1444,7 +1444,7 @@ class B(A): ... # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20too-many-positional-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1397) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1398) **What it does** @@ -1469,7 +1469,7 @@ f("foo") # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20type-assertion-failure) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1375) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1376) **What it does** @@ -1495,7 +1495,7 @@ def _(x: int): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unavailable-implicit-super-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1418) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1419) **What it does** @@ -1539,7 +1539,7 @@ class A: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unknown-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1475) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1476) **What it does** @@ -1564,7 +1564,7 @@ f(x=1, y=2) # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1496) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1497) **What it does** @@ -1590,7 +1590,7 @@ A().foo # AttributeError: 'A' object has no attribute 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1518) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1519) **What it does** @@ -1613,7 +1613,7 @@ import foo # ModuleNotFoundError: No module named 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1537) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1538) **What it does** @@ -1636,7 +1636,7 @@ print(x) # NameError: name 'x' is not defined Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-bool-conversion) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1230) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1231) **What it does** @@ -1671,7 +1671,7 @@ b1 < b2 < b1 # exception raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-operator) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1556) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1557) **What it does** @@ -1697,7 +1697,7 @@ A() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20zero-stepsize-in-slice) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1578) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1579) **What it does** @@ -1720,7 +1720,7 @@ l[1:10:0] # ValueError: slice step cannot be zero Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20deprecated) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L268) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L269) **What it does** @@ -1773,7 +1773,7 @@ a = 20 / 0 # type: ignore Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1282) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1283) **What it does** @@ -1799,7 +1799,7 @@ A.c # AttributeError: type object 'A' has no attribute 'c' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-implicit-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L121) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L122) **What it does** @@ -1829,7 +1829,7 @@ A()[0] # TypeError: 'A' object is not subscriptable Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1304) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1305) **What it does** @@ -1859,7 +1859,7 @@ from module import a # ImportError: cannot import name 'a' from 'module' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20redundant-cast) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1649) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1650) **What it does** @@ -1884,7 +1884,7 @@ cast(int, f()) # Redundant Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20undefined-reveal) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1457) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1458) **What it does** @@ -1935,7 +1935,7 @@ a = 20 / 0 # ty: ignore[division-by-zero] Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-global) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1670) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1671) **What it does** @@ -1989,7 +1989,7 @@ def g(): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L657) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L658) **What it does** @@ -2026,7 +2026,7 @@ class D(C): ... # error: [unsupported-base] Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20division-by-zero) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L250) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L251) **What it does** @@ -2048,7 +2048,7 @@ Dividing by zero raises a `ZeroDivisionError` at runtime. Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1330) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1331) **What it does** diff --git a/crates/ty_python_semantic/resources/mdtest/named_tuple.md b/crates/ty_python_semantic/resources/mdtest/named_tuple.md index 49d957240ee45..29b17542a82c1 100644 --- a/crates/ty_python_semantic/resources/mdtest/named_tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/named_tuple.md @@ -102,15 +102,33 @@ reveal_type(alice2.name) # revealed: @Todo(functional `NamedTuple` syntax) ### Definition -TODO: Fields without default values should come before fields with. + + +Fields without default values must come before fields with. ```py from typing import NamedTuple class Location(NamedTuple): altitude: float = 0.0 - latitude: float # this should be an error + # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `latitude` defined here without a default value" + latitude: float + # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longitude` defined here without a default value" longitude: float + +class StrangeLocation(NamedTuple): + altitude: float + altitude: float = 0.0 + altitude: float + altitude: float = 0.0 + latitude: float # error: [invalid-named-tuple] + longitude: float # error: [invalid-named-tuple] + +class VeryStrangeLocation(NamedTuple): + altitude: float = 0.0 + latitude: float # error: [invalid-named-tuple] + longitude: float # error: [invalid-named-tuple] + altitude: float = 0.0 ``` ### Multiple Inheritance diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Definition_(bbf79630502e65e9).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Definition_(bbf79630502e65e9).snap new file mode 100644 index 0000000000000..666d2bc2c50f9 --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/named_tuple.md_-_`NamedTuple`_-_`typing.NamedTuple`_-_Definition_(bbf79630502e65e9).snap @@ -0,0 +1,140 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: named_tuple.md - `NamedTuple` - `typing.NamedTuple` - Definition +mdtest path: crates/ty_python_semantic/resources/mdtest/named_tuple.md +--- + +# Python source files + +## mdtest_snippet.py + +``` + 1 | from typing import NamedTuple + 2 | + 3 | class Location(NamedTuple): + 4 | altitude: float = 0.0 + 5 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `latitude` defined here without a default value" + 6 | latitude: float + 7 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longitude` defined here without a default value" + 8 | longitude: float + 9 | +10 | class StrangeLocation(NamedTuple): +11 | altitude: float +12 | altitude: float = 0.0 +13 | altitude: float +14 | altitude: float = 0.0 +15 | latitude: float # error: [invalid-named-tuple] +16 | longitude: float # error: [invalid-named-tuple] +17 | +18 | class VeryStrangeLocation(NamedTuple): +19 | altitude: float = 0.0 +20 | latitude: float # error: [invalid-named-tuple] +21 | longitude: float # error: [invalid-named-tuple] +22 | altitude: float = 0.0 +``` + +# Diagnostics + +``` +error[invalid-named-tuple]: NamedTuple field without default value cannot follow field(s) with default value(s) + --> src/mdtest_snippet.py:4:5 + | +3 | class Location(NamedTuple): +4 | altitude: float = 0.0 + | --------------------- Earlier field `altitude` defined here with a default value +5 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `latitud… +6 | latitude: float + | ^^^^^^^^ Field `latitude` defined here without a default value +7 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longitu… +8 | longitude: float + | +info: rule `invalid-named-tuple` is enabled by default + +``` + +``` +error[invalid-named-tuple]: NamedTuple field without default value cannot follow field(s) with default value(s) + --> src/mdtest_snippet.py:4:5 + | + 3 | class Location(NamedTuple): + 4 | altitude: float = 0.0 + | --------------------- Earlier field `altitude` defined here with a default value + 5 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `latitu… + 6 | latitude: float + 7 | # error: [invalid-named-tuple] "NamedTuple field without default value cannot follow field(s) with default value(s): Field `longit… + 8 | longitude: float + | ^^^^^^^^^ Field `longitude` defined here without a default value + 9 | +10 | class StrangeLocation(NamedTuple): + | +info: rule `invalid-named-tuple` is enabled by default + +``` + +``` +error[invalid-named-tuple]: NamedTuple field without default value cannot follow field(s) with default value(s) + --> src/mdtest_snippet.py:14:5 + | +12 | altitude: float = 0.0 +13 | altitude: float +14 | altitude: float = 0.0 + | --------------------- Earlier field `altitude` defined here with a default value +15 | latitude: float # error: [invalid-named-tuple] + | ^^^^^^^^ Field `latitude` defined here without a default value +16 | longitude: float # error: [invalid-named-tuple] + | +info: rule `invalid-named-tuple` is enabled by default + +``` + +``` +error[invalid-named-tuple]: NamedTuple field without default value cannot follow field(s) with default value(s) + --> src/mdtest_snippet.py:14:5 + | +12 | altitude: float = 0.0 +13 | altitude: float +14 | altitude: float = 0.0 + | --------------------- Earlier field `altitude` defined here with a default value +15 | latitude: float # error: [invalid-named-tuple] +16 | longitude: float # error: [invalid-named-tuple] + | ^^^^^^^^^ Field `longitude` defined here without a default value +17 | +18 | class VeryStrangeLocation(NamedTuple): + | +info: rule `invalid-named-tuple` is enabled by default + +``` + +``` +error[invalid-named-tuple]: NamedTuple field without default value cannot follow field(s) with default value(s) + --> src/mdtest_snippet.py:20:5 + | +18 | class VeryStrangeLocation(NamedTuple): +19 | altitude: float = 0.0 +20 | latitude: float # error: [invalid-named-tuple] + | ^^^^^^^^ Field `latitude` defined here without a default value +21 | longitude: float # error: [invalid-named-tuple] +22 | altitude: float = 0.0 + | +info: Earlier field `altitude` was defined with a default value +info: rule `invalid-named-tuple` is enabled by default + +``` + +``` +error[invalid-named-tuple]: NamedTuple field without default value cannot follow field(s) with default value(s) + --> src/mdtest_snippet.py:21:5 + | +19 | altitude: float = 0.0 +20 | latitude: float # error: [invalid-named-tuple] +21 | longitude: float # error: [invalid-named-tuple] + | ^^^^^^^^^ Field `longitude` defined here without a default value +22 | altitude: float = 0.0 + | +info: Earlier field `altitude` was defined with a default value +info: rule `invalid-named-tuple` is enabled by default + +``` diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 2dcb979fcd229..97f3862819efa 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -11,8 +11,11 @@ use super::{ use crate::FxOrderMap; use crate::module_resolver::KnownModule; use crate::semantic_index::definition::{Definition, DefinitionState}; +use crate::semantic_index::place::ScopedPlaceId; use crate::semantic_index::scope::NodeWithScopeKind; -use crate::semantic_index::{DeclarationWithConstraint, SemanticIndex, attribute_declarations}; +use crate::semantic_index::{ + BindingWithConstraints, DeclarationWithConstraint, SemanticIndex, attribute_declarations, +}; use crate::types::context::InferContext; use crate::types::diagnostic::{INVALID_LEGACY_TYPE_VARIABLE, INVALID_TYPE_ALIAS_TYPE}; use crate::types::enums::enum_metadata; @@ -2982,6 +2985,54 @@ impl<'db> ClassLiteral<'db> { .unwrap_or_else(|| class_name.end()), ) } + + pub(super) fn declarations_of_name( + self, + db: &'db dyn Db, + name: &str, + index: &'db SemanticIndex<'db>, + ) -> Option>> { + let class_body_scope = self.body_scope(db).file_scope_id(db); + let symbol_id = index.place_table(class_body_scope).symbol_id(name)?; + let use_def = index.use_def_map(class_body_scope); + Some(use_def.end_of_scope_declarations(ScopedPlaceId::Symbol(symbol_id))) + } + + pub(super) fn first_declaration_of_name( + self, + db: &'db dyn Db, + name: &str, + index: &'db SemanticIndex<'db>, + ) -> Option> { + self.declarations_of_name(db, name, index) + .into_iter() + .flatten() + .next() + } + + pub(super) fn bindings_of_name( + self, + db: &'db dyn Db, + name: &str, + index: &'db SemanticIndex<'db>, + ) -> Option>> { + let class_body_scope = self.body_scope(db).file_scope_id(db); + let symbol_id = index.place_table(class_body_scope).symbol_id(name)?; + let use_def = index.use_def_map(class_body_scope); + Some(use_def.end_of_scope_bindings(ScopedPlaceId::Symbol(symbol_id))) + } + + pub(super) fn first_binding_of_name( + self, + db: &'db dyn Db, + name: &str, + index: &'db SemanticIndex<'db>, + ) -> Option> { + self.bindings_of_name(db, name, index) + .into_iter() + .flatten() + .next() + } } impl<'db> From> for Type<'db> { diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index 730ab1627d8ff..bbbeff5044131 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -6,6 +6,7 @@ use super::{ add_inferred_python_version_hint_to_diagnostic, }; use crate::lint::{Level, LintRegistryBuilder, LintStatus}; +use crate::semantic_index::SemanticIndex; use crate::suppression::FileSuppressionId; use crate::types::LintDiagnosticGuard; use crate::types::class::{Field, SolidBase, SolidBaseKind}; @@ -2676,6 +2677,60 @@ pub(crate) fn report_invalid_key_on_typed_dict<'db>( } } +pub(super) fn report_namedtuple_field_without_default_after_field_with_default<'db>( + context: &InferContext<'db, '_>, + class: ClassLiteral<'db>, + index: &'db SemanticIndex<'db>, + field_name: &str, + field_with_default: &str, +) { + let db = context.db(); + let module = context.module(); + + let diagnostic_range = class + .first_declaration_of_name(db, field_name, index) + .and_then(|definition| definition.declaration.definition()) + .map(|definition| definition.kind(db).full_range(module)) + .unwrap_or_else(|| class.header_range(db)); + + let Some(builder) = context.report_lint(&INVALID_NAMED_TUPLE, diagnostic_range) else { + return; + }; + let mut diagnostic = builder.into_diagnostic(format_args!( + "NamedTuple field without default value cannot follow field(s) with default value(s)", + )); + + diagnostic.set_primary_message(format_args!( + "Field `{field_name}` defined here without a default value" + )); + + let Some(field_with_default_range) = class + .first_binding_of_name(db, field_with_default, index) + .and_then(|definition| definition.binding.definition()) + .map(|definition| definition.kind(db).full_range(module)) + else { + return; + }; + + // If the end-of-scope definition in the class scope of the field-with-a-default-value + // occurs after the range of the field-without-a-default-value, + // avoid adding a subdiagnostic that points to the definition of the + // field-with-a-default-value. It's confusing to talk about a field "before" the + // field without the default value but then point to a definition that actually + // occurs after the field without-a-default-value. + if field_with_default_range.end() < diagnostic_range.start() { + diagnostic.annotate( + Annotation::secondary(context.span(field_with_default_range)).message(format_args!( + "Earlier field `{field_with_default}` defined here with a default value", + )), + ); + } else { + diagnostic.info(format_args!( + "Earlier field `{field_with_default}` was defined with a default value" + )); + } +} + /// This function receives an unresolved `from foo import bar` import, /// where `foo` can be resolved to a module but that module does not /// have a `bar` member or submodule. diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 9d46d16965397..ff5799770791b 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -105,6 +105,7 @@ use crate::types::diagnostic::{ report_invalid_arguments_to_callable, report_invalid_assignment, report_invalid_attribute_assignment, report_invalid_generator_function_return_type, report_invalid_key_on_typed_dict, report_invalid_return_type, + report_namedtuple_field_without_default_after_field_with_default, report_possibly_unbound_attribute, }; use crate::types::enums::is_enum_class; @@ -1110,11 +1111,34 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { continue; } - let is_protocol = class.is_protocol(self.db()); let is_named_tuple = CodeGeneratorKind::NamedTuple.matches(self.db(), class); + + // (2) If it's a `NamedTuple` class, check that no field without a default value + // appears after a field with a default value. + if is_named_tuple { + let mut field_with_default_encountered = None; + + for (field_name, field) in class.own_fields(self.db(), None) { + if field.default_ty.is_some() { + field_with_default_encountered = Some(field_name); + } else if let Some(field_with_default) = field_with_default_encountered.as_ref() + { + report_namedtuple_field_without_default_after_field_with_default( + &self.context, + class, + self.index, + &field_name, + field_with_default, + ); + } + } + } + + let is_protocol = class.is_protocol(self.db()); + let mut solid_bases = IncompatibleBases::default(); - // (2) Iterate through the class's explicit bases to check for various possible errors: + // (3) Iterate through the class's explicit bases to check for various possible errors: // - Check for inheritance from plain `Generic`, // - Check for inheritance from a `@final` classes // - If the class is a protocol class: check for inheritance from a non-protocol class @@ -1208,7 +1232,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } - // (3) Check that the class's MRO is resolvable + // (4) Check that the class's MRO is resolvable match class.try_mro(self.db(), None) { Err(mro_error) => match mro_error.reason() { MroErrorKind::DuplicateBases(duplicates) => { @@ -1279,7 +1303,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } - // (4) Check that the class's metaclass can be determined without error. + // (5) Check that the class's metaclass can be determined without error. if let Err(metaclass_error) = class.try_metaclass(self.db()) { match metaclass_error.reason() { MetaclassErrorKind::Cycle => { @@ -1376,7 +1400,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } - // (5) Check that a dataclass does not have more than one `KW_ONLY`. + // (6) Check that a dataclass does not have more than one `KW_ONLY`. if let Some(field_policy @ CodeGeneratorKind::DataclassLike) = CodeGeneratorKind::from_class(self.db(), class) { From 10301f6190994467ef7165523f2e14fecc040a44 Mon Sep 17 00:00:00 2001 From: David Peter Date: Tue, 19 Aug 2025 11:13:03 +0200 Subject: [PATCH 043/160] [ty] Enable virtual terminal on Windows (#19984) ## Summary Should hopefully fix https://github.com/astral-sh/ty/issues/1045 --- crates/ty/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crates/ty/src/lib.rs b/crates/ty/src/lib.rs index f16192bcd54fc..3e11a3bedfa4c 100644 --- a/crates/ty/src/lib.rs +++ b/crates/ty/src/lib.rs @@ -62,6 +62,10 @@ pub(crate) fn version() -> Result<()> { } fn run_check(args: CheckCommand) -> anyhow::Result { + // Enabled ANSI colors on Windows 10. + #[cfg(windows)] + assert!(colored::control::set_virtual_terminal(true).is_ok()); + set_colored_override(args.color); let verbosity = args.verbosity.level(); From e5c091b850a95601c86d7db718953a91de1e1b48 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Aug 2025 11:31:11 +0100 Subject: [PATCH 044/160] [ty] Fix protocol interface inference for stub protocols and subprotocols (#19950) --- .../resources/mdtest/protocols.md | 80 +++++++++- .../src/types/protocol_class.rs | 138 ++++++++++-------- 2 files changed, 148 insertions(+), 70 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/protocols.md b/crates/ty_python_semantic/resources/mdtest/protocols.md index 28fd2c9362d0e..ae8dc65d9ddde 100644 --- a/crates/ty_python_semantic/resources/mdtest/protocols.md +++ b/crates/ty_python_semantic/resources/mdtest/protocols.md @@ -397,7 +397,7 @@ To see the kinds and types of the protocol members, you can use the debugging ai ```py from ty_extensions import reveal_protocol_interface -from typing import SupportsIndex, SupportsAbs +from typing import SupportsIndex, SupportsAbs, ClassVar # error: [revealed-type] "Revealed protocol interface: `{"method_member": MethodMember(`(self) -> bytes`), "x": AttributeMember(`int`), "y": PropertyMember { getter: `def y(self) -> str` }, "z": PropertyMember { getter: `def z(self) -> int`, setter: `def z(self, z: int) -> None` }}`" reveal_protocol_interface(Foo) @@ -415,6 +415,33 @@ reveal_protocol_interface("foo") # # error: [invalid-argument-type] "Invalid argument to `reveal_protocol_interface`: Only protocol classes can be passed to `reveal_protocol_interface`" reveal_protocol_interface(SupportsAbs[int]) + +class BaseProto(Protocol): + def member(self) -> int: ... + +class SubProto(BaseProto, Protocol): + def member(self) -> bool: ... + +# error: [revealed-type] "Revealed protocol interface: `{"member": MethodMember(`(self) -> int`)}`" +reveal_protocol_interface(BaseProto) + +# error: [revealed-type] "Revealed protocol interface: `{"member": MethodMember(`(self) -> bool`)}`" +reveal_protocol_interface(SubProto) + +class ProtoWithClassVar(Protocol): + x: ClassVar[int] + +# error: [revealed-type] "Revealed protocol interface: `{"x": AttributeMember(`int`; ClassVar)}`" +reveal_protocol_interface(ProtoWithClassVar) + +class ProtocolWithDefault(Protocol): + x: int = 0 + +# We used to incorrectly report this as having an `x: Literal[0]` member; +# declared types should take priority over inferred types for protocol interfaces! +# +# error: [revealed-type] "Revealed protocol interface: `{"x": AttributeMember(`int`)}`" +reveal_protocol_interface(ProtocolWithDefault) ``` Certain special attributes and methods are not considered protocol members at runtime, and should @@ -623,13 +650,26 @@ class HasXWithDefault(Protocol): class FooWithZero: x: int = 0 -# TODO: these should pass -static_assert(is_subtype_of(FooWithZero, HasXWithDefault)) # error: [static-assert-error] -static_assert(is_assignable_to(FooWithZero, HasXWithDefault)) # error: [static-assert-error] -static_assert(not is_subtype_of(Foo, HasXWithDefault)) -static_assert(not is_assignable_to(Foo, HasXWithDefault)) -static_assert(not is_subtype_of(Qux, HasXWithDefault)) -static_assert(not is_assignable_to(Qux, HasXWithDefault)) +static_assert(is_subtype_of(FooWithZero, HasXWithDefault)) +static_assert(is_assignable_to(FooWithZero, HasXWithDefault)) + +# TODO: whether or not any of these four assertions should pass is not clearly specified. +# +# A test in the typing conformance suite implies that they all should: +# that a nominal class with an instance attribute `x` +# (*without* a default value on the class body) +# should be understood as satisfying a protocol that has an attribute member `x` +# even if the protocol's `x` member has a default value on the class body. +# +# See . +# +# The implications of this for meta-protocols are not clearly spelled out, however, +# and the fact that attribute members on protocols can have defaults is only mentioned +# in a throwaway comment in the spec's prose. +static_assert(is_subtype_of(Foo, HasXWithDefault)) +static_assert(is_assignable_to(Foo, HasXWithDefault)) +static_assert(is_subtype_of(Qux, HasXWithDefault)) +static_assert(is_assignable_to(Qux, HasXWithDefault)) class HasClassVarX(Protocol): x: ClassVar[int] @@ -2127,6 +2167,30 @@ static_assert(is_subtype_of(type[Baz], type[Foo])) # error: [static-assert-erro static_assert(is_subtype_of(TypeOf[Baz], type[Foo])) # error: [static-assert-error] ``` +## Regression test for `ClassVar` members in stubs + +In an early version of our protocol implementation, we didn't retain the `ClassVar` qualifier for +protocols defined in stub files. + +`stub.pyi`: + +```pyi +from typing import ClassVar, Protocol + +class Foo(Protocol): + x: ClassVar[int] +``` + +`main.py`: + +```py +from stub import Foo +from ty_extensions import reveal_protocol_interface + +# error: [revealed-type] "Revealed protocol interface: `{"x": AttributeMember(`int`; ClassVar)}`" +reveal_protocol_interface(Foo) +``` + ## TODO Add tests for: diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index 77c5607c00562..2d5c996a8f086 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -4,6 +4,7 @@ use std::{collections::BTreeMap, ops::Deref}; use itertools::Itertools; use ruff_python_ast::name::Name; +use rustc_hash::FxHashMap; use super::TypeVarVariance; use crate::semantic_index::place_table; @@ -286,6 +287,7 @@ impl<'db> ProtocolMemberData<'db> { struct ProtocolMemberDataDisplay<'db> { db: &'db dyn Db, data: ProtocolMemberKind<'db>, + qualifiers: TypeQualifiers, } impl std::fmt::Display for ProtocolMemberDataDisplay<'_> { @@ -305,7 +307,12 @@ impl<'db> ProtocolMemberData<'db> { d.finish() } ProtocolMemberKind::Other(ty) => { - write!(f, "AttributeMember(`{}`)", ty.display(self.db)) + f.write_str("AttributeMember(")?; + write!(f, "`{}`", ty.display(self.db))?; + if self.qualifiers.contains(TypeQualifiers::CLASS_VAR) { + f.write_str("; ClassVar")?; + } + f.write_char(')') } } } @@ -314,6 +321,7 @@ impl<'db> ProtocolMemberData<'db> { ProtocolMemberDataDisplay { db, data: self.kind, + qualifiers: self.qualifiers, } } } @@ -517,6 +525,12 @@ enum BoundOnClass { No, } +impl BoundOnClass { + const fn is_yes(self) -> bool { + matches!(self, BoundOnClass::Yes) + } +} + /// Inner Salsa query for [`ProtocolClassLiteral::interface`]. #[salsa::tracked(cycle_fn=proto_interface_cycle_recover, cycle_initial=proto_interface_cycle_initial, heap_size=ruff_memory_usage::heap_size)] fn cached_protocol_interface<'db>( @@ -533,69 +547,69 @@ fn cached_protocol_interface<'db>( let parent_scope = parent_protocol.body_scope(db); let use_def_map = use_def_map(db, parent_scope); let place_table = place_table(db, parent_scope); + let mut direct_members = FxHashMap::default(); + + // Bindings in the class body that are not declared in the class body + // are not valid protocol members, and we plan to emit diagnostics for them + // elsewhere. Invalid or not, however, it's important that we still consider + // them to be protocol members. The implementation of `issubclass()` and + // `isinstance()` for runtime-checkable protocols considers them to be protocol + // members at runtime, and it's important that we accurately understand + // type narrowing that uses `isinstance()` or `issubclass()` with + // runtime-checkable protocols. + for (symbol_id, bindings) in use_def_map.all_end_of_scope_symbol_bindings() { + let Some(ty) = place_from_bindings(db, bindings).ignore_possibly_unbound() else { + continue; + }; + direct_members.insert( + symbol_id, + (ty, TypeQualifiers::default(), BoundOnClass::Yes), + ); + } - members.extend( - use_def_map - .all_end_of_scope_symbol_declarations() - .map(|(symbol_id, declarations)| { - ( - symbol_id, - place_from_declarations(db, declarations).ignore_conflicting_declarations(), - ) - }) - .filter_map(|(symbol_id, place)| { - place - .place - .ignore_possibly_unbound() - .map(|ty| (symbol_id, ty, place.qualifiers, BoundOnClass::No)) - }) - // Bindings in the class body that are not declared in the class body - // are not valid protocol members, and we plan to emit diagnostics for them - // elsewhere. Invalid or not, however, it's important that we still consider - // them to be protocol members. The implementation of `issubclass()` and - // `isinstance()` for runtime-checkable protocols considers them to be protocol - // members at runtime, and it's important that we accurately understand - // type narrowing that uses `isinstance()` or `issubclass()` with - // runtime-checkable protocols. - .chain(use_def_map.all_end_of_scope_symbol_bindings().filter_map( - |(symbol_id, bindings)| { - place_from_bindings(db, bindings) - .ignore_possibly_unbound() - .map(|ty| (symbol_id, ty, TypeQualifiers::default(), BoundOnClass::Yes)) - }, - )) - .map(|(symbol_id, member, qualifiers, bound_on_class)| { - ( - place_table.symbol(symbol_id).name(), - member, - qualifiers, - bound_on_class, - ) - }) - .filter(|(name, _, _, _)| !excluded_from_proto_members(name)) - .map(|(name, ty, qualifiers, bound_on_class)| { - let kind = match (ty, bound_on_class) { - // TODO: if the getter or setter is a function literal, we should - // upcast it to a `CallableType` so that two protocols with identical property - // members are recognized as equivalent. - (Type::PropertyInstance(property), _) => { - ProtocolMemberKind::Property(property) - } - (Type::Callable(callable), BoundOnClass::Yes) - if callable.is_function_like(db) => - { - ProtocolMemberKind::Method(callable) - } - (Type::FunctionLiteral(function), BoundOnClass::Yes) => { - ProtocolMemberKind::Method(function.into_callable_type(db)) - } - _ => ProtocolMemberKind::Other(ty), - }; + for (symbol_id, declarations) in use_def_map.all_end_of_scope_symbol_declarations() { + let place = place_from_declarations(db, declarations).ignore_conflicting_declarations(); + if let Some(new_type) = place.place.ignore_possibly_unbound() { + direct_members + .entry(symbol_id) + .and_modify(|(ty, quals, _)| { + *ty = new_type; + *quals = place.qualifiers; + }) + .or_insert((new_type, place.qualifiers, BoundOnClass::No)); + } + } - let member = ProtocolMemberData { kind, qualifiers }; - (name.clone(), member) - }), - ); + for (symbol_id, (ty, qualifiers, bound_on_class)) in direct_members { + let name = place_table.symbol(symbol_id).name(); + if excluded_from_proto_members(name) { + continue; + } + if members.contains_key(name) { + continue; + } + + let member = match ty { + Type::PropertyInstance(property) => ProtocolMemberKind::Property(property), + Type::Callable(callable) + if bound_on_class.is_yes() && callable.is_function_like(db) => + { + ProtocolMemberKind::Method(callable) + } + Type::FunctionLiteral(function) if bound_on_class.is_yes() => { + ProtocolMemberKind::Method(function.into_callable_type(db)) + } + _ => ProtocolMemberKind::Other(ty), + }; + + members.insert( + name.clone(), + ProtocolMemberData { + kind: member, + qualifiers, + }, + ); + } } ProtocolInterface::new(db, members) From 600245478caf0efbf7e946e17b5e03543d070f4f Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Aug 2025 12:53:06 +0100 Subject: [PATCH 045/160] [ty] Look for `site-packages` directories in `/lib64/` as well as `/lib/` on non-Windows systems (#19978) --- crates/ty/tests/cli/python_environment.rs | 49 +++- .../ty_python_semantic/src/site_packages.rs | 262 +++++++++++------- 2 files changed, 215 insertions(+), 96 deletions(-) diff --git a/crates/ty/tests/cli/python_environment.rs b/crates/ty/tests/cli/python_environment.rs index a84269d666cb6..a3362b3875eff 100644 --- a/crates/ty/tests/cli/python_environment.rs +++ b/crates/ty/tests/cli/python_environment.rs @@ -345,6 +345,51 @@ import bar", Ok(()) } +/// On Unix systems, a virtual environment can come with multiple `site-packages` directories: +/// one at `/lib/pythonX.Y/site-packages` and one at +/// `/lib64/pythonX.Y/site-packages`. According to [the stdlib docs], the `lib64` +/// is not *meant* to have any Python files in it (only C extensions and similar). Empirically, +/// however, it sometimes does indeed have Python files in it: popular tools such as poetry +/// appear to sometimes install Python packages into the `lib64` site-packages directory even +/// though they probably shouldn't. We therefore check for both a `lib64` and a `lib` directory, +/// and add them both as search paths if they both exist. +/// +/// See: +/// - +/// - . +/// +/// [the stdlib docs]: https://docs.python.org/3/library/sys.html#sys.platlibdir +#[cfg(unix)] +#[test] +fn lib64_site_packages_directory_on_unix() -> anyhow::Result<()> { + let case = CliTest::with_files([ + (".venv/lib/python3.13/site-packages/foo.py", ""), + (".venv/lib64/python3.13/site-packages/bar.py", ""), + ("test.py", "import foo, bar, baz"), + ])?; + + assert_cmd_snapshot!(case.command().arg("--python").arg(".venv"), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Cannot resolve imported module `baz` + --> test.py:1:18 + | + 1 | import foo, bar, baz + | ^^^ + | + info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + Ok(()) +} + #[test] fn pyvenv_cfg_file_annotation_showing_where_python_version_set() -> anyhow::Result<()> { let case = CliTest::with_files([ @@ -762,7 +807,7 @@ fn unix_system_installation_with_no_lib_directory() -> anyhow::Result<()> { WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. ty failed Cause: Failed to discover the site-packages directory - Cause: Failed to iterate over the contents of the `lib` directory of the Python installation + Cause: Failed to iterate over the contents of the `lib`/`lib64` directories of the Python installation --> Invalid setting in configuration file `/pyproject.toml` | @@ -771,8 +816,6 @@ fn unix_system_installation_with_no_lib_directory() -> anyhow::Result<()> { 3 | python = "directory-but-no-site-packages" | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - - Cause: No such file or directory (os error 2) "#); Ok(()) diff --git a/crates/ty_python_semantic/src/site_packages.rs b/crates/ty_python_semantic/src/site_packages.rs index a278805f31109..dd01a49771928 100644 --- a/crates/ty_python_semantic/src/site_packages.rs +++ b/crates/ty_python_semantic/src/site_packages.rs @@ -23,6 +23,7 @@ use ruff_python_ast::PythonVersion; use ruff_python_trivia::Cursor; use ruff_source_file::{LineIndex, OneIndexed, SourceCode}; use ruff_text_size::{TextLen, TextRange}; +use strum::IntoEnumIterator; use ty_static::EnvVars; type SitePackagesDiscoveryResult = Result; @@ -49,8 +50,8 @@ type StdlibDiscoveryResult = Result; pub struct SitePackagesPaths(IndexSet); impl SitePackagesPaths { - fn single(path: SystemPathBuf) -> Self { - Self(IndexSet::from([path])) + fn is_empty(&self) -> bool { + self.0.is_empty() } fn insert(&mut self, path: SystemPathBuf) { @@ -88,7 +89,7 @@ impl SitePackagesPaths { let parent_component = site_packages_ancestor_components.next()?; - if site_packages_ancestor_components.next()? != "lib" { + if site_packages_ancestor_components.next()? != UnixLibDir::Lib { return None; } @@ -110,9 +111,9 @@ impl SitePackagesPaths { } } -impl FromIterator for SitePackagesPaths { - fn from_iter>(iter: T) -> Self { - Self(IndexSet::from_iter(iter)) +impl From<[SystemPathBuf; N]> for SitePackagesPaths { + fn from(paths: [SystemPathBuf; N]) -> Self { + Self(IndexSet::from(paths)) } } @@ -240,6 +241,52 @@ impl PythonEnvironment { } } +/// Enumeration of the subdirectories of `sys.prefix` that could contain a +/// `site-packages` directory if the host system is Unix-like. +/// +/// For example, if `sys.prefix` is `.venv` and the Python version is 3.10, +/// the `site-packages` directory could be located at `.venv/lib/python3.10/site-packages`, +/// or at `.venv/lib64/python3.10/site-packages`, or there could indeed be `site-packages` +/// directories at both of these locations. +#[derive(Debug, Clone, Copy, Eq, PartialEq, strum_macros::EnumIter)] +enum UnixLibDir { + Lib, + Lib64, +} + +impl UnixLibDir { + const fn as_str(self) -> &'static str { + match self { + Self::Lib => "lib", + Self::Lib64 => "lib64", + } + } +} + +impl std::fmt::Display for UnixLibDir { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(self.as_str()) + } +} + +impl AsRef for UnixLibDir { + fn as_ref(&self) -> &SystemPath { + SystemPath::new(self.as_str()) + } +} + +impl PartialEq<&str> for UnixLibDir { + fn eq(&self, other: &&str) -> bool { + self.as_str() == *other + } +} + +impl PartialEq for &str { + fn eq(&self, other: &UnixLibDir) -> bool { + other == self + } +} + /// The Python runtime that produced the venv. /// /// We only need to distinguish cases that change the on-disk layout. @@ -258,12 +305,16 @@ pub(crate) enum PythonImplementation { impl PythonImplementation { /// Return the relative path from `sys.prefix` to the `site-packages` directory /// if this is a known implementation. Return `None` if this is an unknown implementation. - fn relative_site_packages_path(self, version: Option) -> Option { + fn relative_site_packages_path( + self, + lib_dir: UnixLibDir, + version: Option, + ) -> Option { match self { Self::CPython | Self::GraalPy => { - version.map(|version| format!("lib/python{version}/site-packages")) + version.map(|version| format!("{lib_dir}/python{version}/site-packages")) } - Self::PyPy => version.map(|version| format!("lib/pypy{version}/site-packages")), + Self::PyPy => version.map(|version| format!("{lib_dir}/pypy{version}/site-packages")), Self::Unknown => None, } } @@ -413,7 +464,7 @@ impl VirtualEnvironment { /// Return a list of `site-packages` directories that are available from this virtual environment /// - /// See the documentation for [`site_packages_directory_from_sys_prefix`] for more details. + /// See the documentation for [`site_packages_directories_from_sys_prefix`] for more details. pub(crate) fn site_packages_directories( &self, system: &dyn System, @@ -429,9 +480,8 @@ impl VirtualEnvironment { let version = version.as_ref().map(|v| v.version); - let mut site_packages_directories = SitePackagesPaths::single( - site_packages_directory_from_sys_prefix(root_path, version, *implementation, system)?, - ); + let mut site_packages_directories = + site_packages_directories_from_sys_prefix(root_path, version, *implementation, system)?; if let Some(parent_env_site_packages) = parent_environment.as_deref() { match parent_env_site_packages.site_packages_paths(system) { @@ -456,14 +506,14 @@ impl VirtualEnvironment { // or if we fail to resolve the `site-packages` from the `sys.prefix` path, // we should probably print a warning but *not* abort type checking if let Some(sys_prefix_path) = system_sys_prefix { - match site_packages_directory_from_sys_prefix( + match site_packages_directories_from_sys_prefix( &sys_prefix_path, version, *implementation, system, ) { - Ok(site_packages_directory) => { - site_packages_directories.insert(site_packages_directory); + Ok(system_directories) => { + site_packages_directories.extend(system_directories); } Err(error) => tracing::warn!( "{error}. System site-packages will not be used for module resolution." @@ -665,7 +715,7 @@ impl SystemEnvironment { /// Create a new system environment from the given path. /// /// At this time, there is no eager validation and this is infallible. Instead, validation - /// will occur in [`site_packages_directory_from_sys_prefix`] — which will fail if there is not + /// will occur in [`site_packages_directories_from_sys_prefix`] — which will fail if there is not /// a Python environment at the given path. pub(crate) fn new(path: SysPrefixPath) -> Self { Self { root_path: path } @@ -673,20 +723,19 @@ impl SystemEnvironment { /// Return a list of `site-packages` directories that are available from this environment. /// - /// See the documentation for [`site_packages_directory_from_sys_prefix`] for more details. + /// See the documentation for [`site_packages_directories_from_sys_prefix`] for more details. pub(crate) fn site_packages_directories( &self, system: &dyn System, ) -> SitePackagesDiscoveryResult { let SystemEnvironment { root_path } = self; - let site_packages_directories = - SitePackagesPaths::single(site_packages_directory_from_sys_prefix( - root_path, - None, - PythonImplementation::Unknown, - system, - )?); + let site_packages_directories = site_packages_directories_from_sys_prefix( + root_path, + None, + PythonImplementation::Unknown, + system, + )?; tracing::debug!( "Resolved site-packages directories for this environment are: {site_packages_directories:?}" @@ -696,7 +745,7 @@ impl SystemEnvironment { /// Return a list of `site-packages` directories that are available from this environment. /// - /// See the documentation for [`site_packages_directory_from_sys_prefix`] for more details. + /// See the documentation for [`site_packages_directories_from_sys_prefix`] for more details. pub(crate) fn real_stdlib_directory( &self, system: &dyn System, @@ -740,7 +789,7 @@ pub enum SitePackagesDiscoveryError { /// would be relative to the `sys.prefix` path, and we tried to fallback to iterating /// through the `/lib` directory looking for a `site-packages` directory, /// but we came across some I/O error while trying to do so. - CouldNotReadLibDirectory(SysPrefixPath, io::Error), + CouldNotReadLibDirectory(SysPrefixPath), /// We looked everywhere we could think of for the `site-packages` directory, /// but none could be found despite our best endeavours. @@ -771,9 +820,9 @@ impl std::error::Error for SitePackagesDiscoveryError { io_err.as_ref().map(|e| e as &dyn std::error::Error) } Self::NoPyvenvCfgFile(_, io_err) => Some(io_err), - Self::PyvenvCfgParseError(_, _) => None, - Self::CouldNotReadLibDirectory(_, io_err) => Some(io_err), - Self::NoSitePackagesDirFound(_) => None, + Self::PyvenvCfgParseError(_, _) + | Self::CouldNotReadLibDirectory(_) + | Self::NoSitePackagesDirFound(_) => None, } } } @@ -811,11 +860,11 @@ impl std::fmt::Display for SitePackagesDiscoveryError { "Failed to parse the `pyvenv.cfg` file at `{path}` because {kind}" ) } - Self::CouldNotReadLibDirectory(SysPrefixPath { inner, origin }, _) => display_error( + Self::CouldNotReadLibDirectory(SysPrefixPath { inner, origin }) => display_error( f, origin, inner, - "Failed to iterate over the contents of the `lib` directory of the Python installation", + "Failed to iterate over the contents of the `lib`/`lib64` directories of the Python installation", None, ), Self::NoSitePackagesDirFound(SysPrefixPath { inner, origin }) => display_error( @@ -963,19 +1012,19 @@ when trying to resolve the `home` value to a directory on disk: {io_err}" } } -/// Attempt to retrieve the `site-packages` directory +/// Attempt to retrieve the `site-packages` directories /// associated with a given Python installation. /// -/// The location of the `site-packages` directory can vary according to the +/// The location of the `site-packages` directories can vary according to the /// Python version that this installation represents. The Python version may /// or may not be known at this point, which is why the `python_version` /// parameter is an `Option`. -fn site_packages_directory_from_sys_prefix( +fn site_packages_directories_from_sys_prefix( sys_prefix_path: &SysPrefixPath, python_version: Option, implementation: PythonImplementation, system: &dyn System, -) -> SitePackagesDiscoveryResult { +) -> SitePackagesDiscoveryResult { tracing::debug!( "Searching for site-packages directory in sys.prefix {}", sys_prefix_path.inner @@ -985,10 +1034,10 @@ fn site_packages_directory_from_sys_prefix( let site_packages = sys_prefix_path.join(r"Lib\site-packages"); return system .is_directory(&site_packages) - .then_some(site_packages) - .ok_or(SitePackagesDiscoveryError::NoSitePackagesDirFound( - sys_prefix_path.to_owned(), - )); + .then(|| SitePackagesPaths::from([site_packages])) + .ok_or_else(|| { + SitePackagesDiscoveryError::NoSitePackagesDirFound(sys_prefix_path.to_owned()) + }); } // In the Python standard library's `site.py` module (used for finding `site-packages` @@ -1000,43 +1049,52 @@ fn site_packages_directory_from_sys_prefix( // libdirs.append("lib") // ``` // - // Pyright therefore searches for both a `lib/python3.X/site-packages` directory - // and a `lib64/python3.X/site-packages` directory on non-MacOS Unix systems, - // since `sys.platlibdir` can sometimes be equal to `"lib64"`. - // - // However, we only care about the `site-packages` directory insofar as it allows + // We generally only care about the `site-packages` directory insofar as it allows // us to discover Python source code that can be used for inferring type - // information regarding third-party dependencies. That means that we don't need - // to care about any possible `lib64/site-packages` directories, since - // [the `sys`-module documentation] states that `sys.platlibdir` is *only* ever - // used for C extensions, never for pure-Python modules. + // information regarding third-party dependencies. In theory, therefore, that means + // that we don't need to care about any possible `lib64/site-packages` directories, + // since [the `sys`-module documentation] states that `sys.platlibdir` is *only* ever + // used for C extensions, never for pure-Python modules. However, in practice, + // some installers appear to do [some strange things on Fedora] that mean that `.py` + // files *can* end up in `lib64/site-packages` in some edge cases. And we'll probably + // need to start looking in `lib64/site-packages` directories in the future anyway, in + // order to distinguish between "unresolved import" and "resolved to an opaque C + // extension" in diagnostic messages. // // [the non-Windows branch]: https://github.com/python/cpython/blob/a8be8fc6c4682089be45a87bd5ee1f686040116c/Lib/site.py#L401-L410 // [the `sys`-module documentation]: https://docs.python.org/3/library/sys.html#sys.platlibdir + // [some strange things on Fedora]: https://github.com/astral-sh/ty/issues/1043 - // If we were able to figure out what Python version this installation is, - // we should be able to avoid iterating through all items in the `lib/` directory: - if let Some(expected_relative_path) = implementation.relative_site_packages_path(python_version) - { - let expected_absolute_path = sys_prefix_path.join(expected_relative_path); - if system.is_directory(&expected_absolute_path) { - return Ok(expected_absolute_path); - } + let mut directories = SitePackagesPaths::default(); - // CPython free-threaded (3.13+) variant: pythonXYt - if matches!(implementation, PythonImplementation::CPython) - && python_version.is_some_and(PythonVersion::free_threaded_build_available) + // If we were able to figure out what Python version this installation is, + // we should be able to avoid iterating through all items in the `lib/` and `lib64/` directories: + for lib_dir in UnixLibDir::iter() { + if let Some(expected_relative_path) = + implementation.relative_site_packages_path(lib_dir, python_version) { - let alternative_path = sys_prefix_path.join(format!( - "lib/python{}t/site-packages", - python_version.unwrap() - )); - if system.is_directory(&alternative_path) { - return Ok(alternative_path); + let expected_absolute_path = sys_prefix_path.join(expected_relative_path); + if system.is_directory(&expected_absolute_path) { + directories.insert(expected_absolute_path); + } else if matches!(implementation, PythonImplementation::CPython) + && python_version.is_some_and(PythonVersion::free_threaded_build_available) + { + // CPython free-threaded (3.13+) variant: pythonX.Yt + let alternative_path = sys_prefix_path.join(format!( + "{lib_dir}/python{}t/site-packages", + python_version.unwrap() + )); + if system.is_directory(&alternative_path) { + directories.insert(alternative_path); + } } } } + if !directories.is_empty() { + return Ok(directories); + } + // Either we couldn't figure out the version before calling this function // (e.g., from a `pyvenv.cfg` file if this was a venv), // or we couldn't find a `site-packages` folder at the expected location given @@ -1045,38 +1103,55 @@ fn site_packages_directory_from_sys_prefix( // Note: the `python3.x` part of the `site-packages` path can't be computed from // the `--python-version` the user has passed, as they might be running Python 3.12 locally // even if they've requested that we type check their code "as if" they're running 3.8. - for entry_result in system - .read_directory(&sys_prefix_path.join("lib")) - .map_err(|io_err| { - SitePackagesDiscoveryError::CouldNotReadLibDirectory(sys_prefix_path.to_owned(), io_err) - })? - { - let Ok(entry) = entry_result else { + let mut found_at_least_one_lib_dir = false; + + for lib_dir in UnixLibDir::iter() { + let Ok(directory_iterator) = system.read_directory(&sys_prefix_path.join(lib_dir)) else { + tracing::debug!("Could not find a `/{lib_dir}` directory; continuing"); continue; }; - if !entry.file_type().is_directory() { - continue; - } + found_at_least_one_lib_dir = true; + + for entry_result in directory_iterator { + let Ok(entry) = entry_result else { + continue; + }; - let mut path = entry.into_path(); + if !entry.file_type().is_directory() { + continue; + } - let name = path - .file_name() - .expect("File name to be non-null because path is guaranteed to be a child of `lib`"); + let mut path = entry.into_path(); - if !(name.starts_with("python3.") || name.starts_with("pypy3.")) { - continue; + let name = path.file_name().unwrap_or_else(|| panic!( + "File name should be non-null because path is guaranteed to be a child of `{lib_dir}`", + )); + + if !(name.starts_with("python3.") || name.starts_with("pypy3.")) { + continue; + } + + path.push("site-packages"); + if system.is_directory(&path) { + directories.insert(path); + } } + } - path.push("site-packages"); - if system.is_directory(&path) { - return Ok(path); + if directories.is_empty() { + if found_at_least_one_lib_dir { + Err(SitePackagesDiscoveryError::NoSitePackagesDirFound( + sys_prefix_path.to_owned(), + )) + } else { + Err(SitePackagesDiscoveryError::CouldNotReadLibDirectory( + sys_prefix_path.to_owned(), + )) } + } else { + Ok(directories) } - Err(SitePackagesDiscoveryError::NoSitePackagesDirFound( - sys_prefix_path.to_owned(), - )) } /// Attempt to retrieve the real stdlib directory @@ -1133,7 +1208,8 @@ fn real_stdlib_directory_from_sys_prefix( // the `--python-version` the user has passed, as they might be running Python 3.12 locally // even if they've requested that we type check their code "as if" they're running 3.8. for entry_result in system - .read_directory(&sys_prefix_path.join("lib")) + // must be `lib`, not `lib64`, for the stdlib + .read_directory(&sys_prefix_path.join(UnixLibDir::Lib)) .map_err(|io_err| { StdlibDiscoveryError::CouldNotReadLibDirectory(sys_prefix_path.to_owned(), io_err) })? @@ -1148,9 +1224,9 @@ fn real_stdlib_directory_from_sys_prefix( let path = entry.into_path(); - let name = path - .file_name() - .expect("File name to be non-null because path is guaranteed to be a child of `lib`"); + let name = path.file_name().expect( + "File name should be non-null because path is guaranteed to be a child of `lib`", + ); if !(name.starts_with("python3.") || name.starts_with("pypy3.")) { continue; @@ -1314,7 +1390,7 @@ impl SysPrefixPath { let path = entry.into_path(); let name = path.file_name().expect( - "File name to be non-null because path is guaranteed to be a child of `lib`", + "File name should be non-null because path is guaranteed to be a child of `lib`", ); if !(name.starts_with("python3.") || name.starts_with("pypy3.")) { From 0967e7e08893e1544852c41fce3beacf38a67793 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 19 Aug 2025 10:39:23 -0400 Subject: [PATCH 046/160] Update Rust crate glob to v0.3.3 (#19959) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [glob](https://github.com/rust-lang/glob) | workspace.dependencies | patch | `0.3.2` -> `0.3.3` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
rust-lang/glob (glob) ### [`v0.3.3`](https://github.com/rust-lang/glob/blob/HEAD/CHANGELOG.md#033---2025-08-11) [Compare Source](https://github.com/rust-lang/glob/compare/v0.3.2...v0.3.3) - Optimize memory allocations ([#​147](https://github.com/rust-lang/glob/pull/147)) - Bump the MSRV to 1.63 ([#​172](https://github.com/rust-lang/glob/pull/172)) - Fix spelling in pattern documentation ([#​164](https://github.com/rust-lang/glob/pull/164)) - Fix version numbers and some formatting ([#​157](https://github.com/rust-lang/glob/pull/157)) - Style fixes ([#​137](https://github.com/rust-lang/glob/pull/137))
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Brent Westbrook --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e310958413383..37ce50f4c9531 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1218,9 +1218,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "globset" From 5e943d3539e66606f860e45fbf4b2579de017e5a Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Mon, 18 Aug 2025 10:31:22 -0400 Subject: [PATCH 047/160] [ty] Ask the LSP client to watch all project search paths This change rejiggers how we register globs for file watching with the LSP client. Previously, we registered a few globs like `**/*.py`, `**/pyproject.toml` and more. There were two problems with this approach. Firstly, it only watches files within the project root. Search paths may be outside the project root. Such as virtualenv directory. Secondly, there is variation on how tools interact with virtual environments. In the case of uv, depending on its link mode, we might not get any file change notifications after running `uv add foo` or `uv remove foo`. To remedy this, we instead just list for file change notifications on all files for all search paths. This simplifies the globs we use, but does potentially increase the number of notifications we'll get. However, given the somewhat simplistic interface supported by the LSP protocol, I think this is unavoidable (unless we used our own file watcher, which has its own considerably downsides). Moreover, this is seemingly consistent with how `ty check --watch` works. This also required moving file watcher registration to *after* workspaces are initialized, or else we don't know what the right search paths are. This change is in service of #19883, which in order for cache invalidation to work right, the LSP client needs to send notifications whenever a dependency is added or removed. This change should make that possible. I tried this patch with #19883 in addition to my work to activate Salsa caching, and everything seems to work as I'd expect. That is, completions no longer show stale results after a dependency is added or removed. --- crates/ty_server/src/capabilities.rs | 27 ++++-- crates/ty_server/src/server/main_loop.rs | 73 ++-------------- crates/ty_server/src/session.rs | 104 ++++++++++++++++++++++- 3 files changed, 128 insertions(+), 76 deletions(-) diff --git a/crates/ty_server/src/capabilities.rs b/crates/ty_server/src/capabilities.rs index d864ac78e2ae4..f0b77a9533b5d 100644 --- a/crates/ty_server/src/capabilities.rs +++ b/crates/ty_server/src/capabilities.rs @@ -30,9 +30,10 @@ bitflags::bitflags! { const HIERARCHICAL_DOCUMENT_SYMBOL_SUPPORT = 1 << 10; const WORK_DONE_PROGRESS = 1 << 11; const FILE_WATCHER_SUPPORT = 1 << 12; - const DIAGNOSTIC_DYNAMIC_REGISTRATION = 1 << 13; - const WORKSPACE_CONFIGURATION = 1 << 14; - const RENAME_DYNAMIC_REGISTRATION = 1 << 15; + const RELATIVE_FILE_WATCHER_SUPPORT = 1 << 13; + const DIAGNOSTIC_DYNAMIC_REGISTRATION = 1 << 14; + const WORKSPACE_CONFIGURATION = 1 << 15; + const RENAME_DYNAMIC_REGISTRATION = 1 << 16; } } @@ -107,6 +108,14 @@ impl ResolvedClientCapabilities { self.contains(Self::FILE_WATCHER_SUPPORT) } + /// Returns `true` if the client supports relative file watcher capabilities. + /// + /// This permits specifying a "base uri" that a glob is interpreted + /// relative to. + pub(crate) const fn supports_relative_file_watcher(self) -> bool { + self.contains(Self::RELATIVE_FILE_WATCHER_SUPPORT) + } + /// Returns `true` if the client supports dynamic registration for diagnostic capabilities. pub(crate) const fn supports_diagnostic_dynamic_registration(self) -> bool { self.contains(Self::DIAGNOSTIC_DYNAMIC_REGISTRATION) @@ -144,11 +153,15 @@ impl ResolvedClientCapabilities { flags |= Self::INLAY_HINT_REFRESH; } - if workspace - .and_then(|workspace| workspace.did_change_watched_files?.dynamic_registration) - .unwrap_or_default() + if let Some(capabilities) = + workspace.and_then(|workspace| workspace.did_change_watched_files.as_ref()) { - flags |= Self::FILE_WATCHER_SUPPORT; + if capabilities.dynamic_registration == Some(true) { + flags |= Self::FILE_WATCHER_SUPPORT; + } + if capabilities.relative_pattern_support == Some(true) { + flags |= Self::RELATIVE_FILE_WATCHER_SUPPORT; + } } if text_document.is_some_and(|text_document| text_document.diagnostic.is_some()) { diff --git a/crates/ty_server/src/server/main_loop.rs b/crates/ty_server/src/server/main_loop.rs index 6ae2cf19b3684..cbd707f60d747 100644 --- a/crates/ty_server/src/server/main_loop.rs +++ b/crates/ty_server/src/server/main_loop.rs @@ -5,10 +5,8 @@ use crate::session::{ClientOptions, SuspendedWorkspaceDiagnosticRequest}; use anyhow::anyhow; use crossbeam::select; use lsp_server::Message; -use lsp_types::notification::{DidChangeWatchedFiles, Notification}; -use lsp_types::{ - ConfigurationParams, DidChangeWatchedFilesRegistrationOptions, FileSystemWatcher, Url, -}; +use lsp_types::notification::Notification; +use lsp_types::{ConfigurationParams, Url}; use serde_json::Value; pub(crate) type ConnectionSender = crossbeam::channel::Sender; @@ -154,6 +152,10 @@ impl Server { Action::InitializeWorkspaces(workspaces_with_options) => { self.session .initialize_workspaces(workspaces_with_options, &client); + // We do this here after workspaces have been initialized + // so that the file watcher globs can take project search + // paths into account. + // self.try_register_file_watcher(&client); } }, } @@ -195,7 +197,6 @@ impl Server { fn initialize(&mut self, client: &Client) { self.request_workspace_configurations(client); - self.try_register_file_watcher(client); } /// Requests workspace configurations from the client for all the workspaces in the session. @@ -282,68 +283,6 @@ impl Server { }, ); } - - /// Try to register the file watcher provided by the client if the client supports it. - fn try_register_file_watcher(&mut self, client: &Client) { - static FILE_WATCHER_REGISTRATION_ID: &str = "ty/workspace/didChangeWatchedFiles"; - - if !self.session.client_capabilities().supports_file_watcher() { - tracing::warn!("Client does not support file system watching"); - return; - } - - let registration = lsp_types::Registration { - id: FILE_WATCHER_REGISTRATION_ID.to_owned(), - method: DidChangeWatchedFiles::METHOD.to_owned(), - register_options: Some( - serde_json::to_value(DidChangeWatchedFilesRegistrationOptions { - watchers: vec![ - FileSystemWatcher { - glob_pattern: lsp_types::GlobPattern::String("**/ty.toml".into()), - kind: None, - }, - FileSystemWatcher { - glob_pattern: lsp_types::GlobPattern::String("**/.gitignore".into()), - kind: None, - }, - FileSystemWatcher { - glob_pattern: lsp_types::GlobPattern::String("**/.ignore".into()), - kind: None, - }, - FileSystemWatcher { - glob_pattern: lsp_types::GlobPattern::String( - "**/pyproject.toml".into(), - ), - kind: None, - }, - FileSystemWatcher { - glob_pattern: lsp_types::GlobPattern::String("**/*.py".into()), - kind: None, - }, - FileSystemWatcher { - glob_pattern: lsp_types::GlobPattern::String("**/*.pyi".into()), - kind: None, - }, - FileSystemWatcher { - glob_pattern: lsp_types::GlobPattern::String("**/*.ipynb".into()), - kind: None, - }, - ], - }) - .unwrap(), - ), - }; - - client.send_request::( - &self.session, - lsp_types::RegistrationParams { - registrations: vec![registration], - }, - |_: &Client, ()| { - tracing::info!("File watcher registration completed successfully"); - }, - ); - } } /// An action that should be performed on the main loop. diff --git a/crates/ty_server/src/session.rs b/crates/ty_server/src/session.rs index 1a21a3aec5850..7c13121d1cceb 100644 --- a/crates/ty_server/src/session.rs +++ b/crates/ty_server/src/session.rs @@ -3,13 +3,14 @@ use anyhow::{Context, anyhow}; use index::DocumentQueryError; use lsp_server::{Message, RequestId}; -use lsp_types::notification::{Exit, Notification}; +use lsp_types::notification::{DidChangeWatchedFiles, Exit, Notification}; use lsp_types::request::{ DocumentDiagnosticRequest, RegisterCapability, Rename, Request, Shutdown, UnregisterCapability, WorkspaceDiagnosticRequest, }; use lsp_types::{ - DiagnosticRegistrationOptions, DiagnosticServerCapabilities, Registration, RegistrationParams, + DiagnosticRegistrationOptions, DiagnosticServerCapabilities, + DidChangeWatchedFilesRegistrationOptions, FileSystemWatcher, Registration, RegistrationParams, TextDocumentContentChangeEvent, Unregistration, UnregistrationParams, Url, }; use options::GlobalOptions; @@ -308,6 +309,14 @@ impl Session { &self.project_state(path).db } + /// Returns an iterator, in arbitrary order, over all project databases + /// in this session. + pub(crate) fn project_dbs(&self) -> impl Iterator { + self.projects + .values() + .map(|project_state| &project_state.db) + } + /// Returns a mutable reference to the project's [`ProjectDatabase`] in which the given `path` /// belongs. /// @@ -600,6 +609,7 @@ impl Session { fn register_capabilities(&mut self, client: &Client) { static DIAGNOSTIC_REGISTRATION_ID: &str = "ty/textDocument/diagnostic"; static RENAME_REGISTRATION_ID: &str = "ty/textDocument/rename"; + static FILE_WATCHER_REGISTRATION_ID: &str = "ty/workspace/didChangeWatchedFiles"; let mut registrations = vec![]; let mut unregistrations = vec![]; @@ -665,6 +675,20 @@ impl Session { } } + if let Some(register_options) = self.file_watcher_registration_options() { + if self.registrations.contains(DidChangeWatchedFiles::METHOD) { + unregistrations.push(Unregistration { + id: FILE_WATCHER_REGISTRATION_ID.into(), + method: DidChangeWatchedFiles::METHOD.into(), + }); + } + registrations.push(Registration { + id: FILE_WATCHER_REGISTRATION_ID.into(), + method: DidChangeWatchedFiles::METHOD.into(), + register_options: Some(serde_json::to_value(register_options).unwrap()), + }); + } + // First, unregister any existing capabilities and then register or re-register them. self.unregister_dynamic_capability(client, unregistrations); self.register_dynamic_capability(client, registrations); @@ -719,6 +743,82 @@ impl Session { ); } + /// Try to register the file watcher provided by the client if the client supports it. + /// + /// Note that this should be called *after* workspaces/projects have been initialized. + /// This is required because the globs we use for registering file watching take + /// project search paths into account. + fn file_watcher_registration_options( + &self, + ) -> Option { + fn make_watcher(glob: &str) -> FileSystemWatcher { + FileSystemWatcher { + glob_pattern: lsp_types::GlobPattern::String(glob.into()), + kind: Some(lsp_types::WatchKind::all()), + } + } + + fn make_relative_watcher(relative_to: &SystemPath, glob: &str) -> FileSystemWatcher { + let base_uri = Url::from_file_path(relative_to.as_std_path()) + .expect("system path must be a valid URI"); + let glob_pattern = lsp_types::GlobPattern::Relative(lsp_types::RelativePattern { + base_uri: lsp_types::OneOf::Right(base_uri), + pattern: glob.to_string(), + }); + FileSystemWatcher { + glob_pattern, + kind: Some(lsp_types::WatchKind::all()), + } + } + + if !self.client_capabilities().supports_file_watcher() { + tracing::warn!( + "Your LSP client doesn't support file watching: \ + You may see stale results when files change outside the editor" + ); + return None; + } + + // We also want to watch everything in the search paths as + // well. But this seems to require "relative" watcher support. + // I had trouble getting this working without using a base uri. + // + // Specifically, I tried this for each search path: + // + // make_watcher(&format!("{path}/**")) + // + // But while this seemed to work for the project root, it + // simply wouldn't result in any file notifications for changes + // to files outside of the project root. + #[allow(clippy::if_not_else)] // no! it reads better this way ---AG + let watchers = if !self.client_capabilities().supports_relative_file_watcher() { + tracing::warn!( + "Your LSP client doesn't support file watching outside of project: \ + You may see stale results when dependencies change" + ); + // Initialize our list of watchers with the standard globs relative + // to the project root if we can't use relative globs. + vec![make_watcher("**")] + } else { + // Gather up all of our project roots and all of the corresponding + // project root system paths, then deduplicate them relative to + // one another. Then listen to everything. + let roots = self.project_dbs().map(|db| db.project().root(db)); + let paths = self + .project_dbs() + .flat_map(|db| { + ty_python_semantic::system_module_search_paths(db).map(move |path| (db, path)) + }) + .filter(|(db, path)| !path.starts_with(db.project().root(*db))) + .map(|(_, path)| path) + .chain(roots); + ruff_db::system::deduplicate_nested_paths(paths) + .map(|path| make_relative_watcher(path, "**")) + .collect() + }; + Some(DidChangeWatchedFilesRegistrationOptions { watchers }) + } + /// Creates a document snapshot with the URL referencing the document to snapshot. pub(crate) fn take_document_snapshot(&self, url: Url) -> DocumentSnapshot { let key = self From 59b078b1bf3a9482e08fe5a00a41076efbbc3974 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 19 Aug 2025 13:12:08 -0400 Subject: [PATCH 048/160] Update outdated links to https://typing.python.org/en/latest/source/stubs.html (#19992) --- .../flake8_pyi/rules/future_annotations_in_stub.rs | 2 +- .../src/rules/pycodestyle/rules/blank_lines.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs index 20c70336eb642..b85059e756b52 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/future_annotations_in_stub.rs @@ -16,7 +16,7 @@ use crate::{checkers::ast::Checker, fix}; /// statement has no effect and should be omitted. /// /// ## References -/// - [Static Typing with Python: Type Stubs](https://typing.python.org/en/latest/source/stubs.html) +/// - [Typing Style Guide](https://typing.python.org/en/latest/guides/writing_stubs.html#language-features) #[derive(ViolationMetadata)] pub(crate) struct FutureAnnotationsInStub; diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs index d737882124509..07f5627f36a72 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/blank_lines.rs @@ -60,7 +60,7 @@ const BLANK_LINES_NESTED_LEVEL: u32 = 1; /// ## References /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E301.html) -/// - [Typing Style Guide](https://typing.python.org/en/latest/source/stubs.html#blank-lines) +/// - [Typing Style Guide](https://typing.python.org/en/latest/guides/writing_stubs.html#blank-lines) #[derive(ViolationMetadata)] pub(crate) struct BlankLineBetweenMethods; @@ -113,7 +113,7 @@ impl AlwaysFixableViolation for BlankLineBetweenMethods { /// ## References /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E302.html) -/// - [Typing Style Guide](https://typing.python.org/en/latest/source/stubs.html#blank-lines) +/// - [Typing Style Guide](https://typing.python.org/en/latest/guides/writing_stubs.html#blank-lines) #[derive(ViolationMetadata)] pub(crate) struct BlankLinesTopLevel { actual_blank_lines: u32, @@ -180,7 +180,7 @@ impl AlwaysFixableViolation for BlankLinesTopLevel { /// ## References /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E303.html) -/// - [Typing Style Guide](https://typing.python.org/en/latest/source/stubs.html#blank-lines) +/// - [Typing Style Guide](https://typing.python.org/en/latest/guides/writing_stubs.html#blank-lines) #[derive(ViolationMetadata)] pub(crate) struct TooManyBlankLines { actual_blank_lines: u32, @@ -277,7 +277,7 @@ impl AlwaysFixableViolation for BlankLineAfterDecorator { /// ## References /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E305.html) -/// - [Typing Style Guide](https://typing.python.org/en/latest/source/stubs.html#blank-lines) +/// - [Typing Style Guide](https://typing.python.org/en/latest/guides/writing_stubs.html#blank-lines) #[derive(ViolationMetadata)] pub(crate) struct BlankLinesAfterFunctionOrClass { actual_blank_lines: u32, @@ -331,7 +331,7 @@ impl AlwaysFixableViolation for BlankLinesAfterFunctionOrClass { /// ## References /// - [PEP 8: Blank Lines](https://peps.python.org/pep-0008/#blank-lines) /// - [Flake 8 rule](https://www.flake8rules.com/rules/E306.html) -/// - [Typing Style Guide](https://typing.python.org/en/latest/source/stubs.html#blank-lines) +/// - [Typing Style Guide](https://typing.python.org/en/latest/guides/writing_stubs.html#blank-lines) #[derive(ViolationMetadata)] pub(crate) struct BlankLinesBeforeNestedDefinition; From c6dcfe36d060f693d771e4ae3f6156527b67c816 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Tue, 19 Aug 2025 13:31:44 -0400 Subject: [PATCH 049/160] [ty] introduce multiline pretty printer (#19979) Requires some iteration, but this includes the most tedious part -- threading a new concept of DisplaySettings through every type display impl. Currently it only holds a boolean for multiline, but in the future it could also take other things like "render to markdown" or "here's your base indent if you make a newline". For types which have exposed display functions I've left the old signature as a compatibility polyfill to avoid having to audit everywhere that prints types right off the bat (notably I originally tried doing multiline functions unconditionally and a ton of things churned that clearly weren't ready for multi-line (diagnostics). The only real use of this API in this PR is to multiline render function types in hovers, which is the highest impact (see snapshot changes). Fixes https://github.com/astral-sh/ty/issues/1000 --- crates/ty_ide/src/hover.rs | 273 +++++++- crates/ty_python_semantic/src/lib.rs | 1 + crates/ty_python_semantic/src/types.rs | 1 + .../ty_python_semantic/src/types/display.rs | 622 +++++++++++++++--- 4 files changed, 792 insertions(+), 105 deletions(-) diff --git a/crates/ty_ide/src/hover.rs b/crates/ty_ide/src/hover.rs index 0ede0fc2f76b0..5480d73b5403f 100644 --- a/crates/ty_ide/src/hover.rs +++ b/crates/ty_ide/src/hover.rs @@ -6,8 +6,8 @@ use ruff_db::parsed::parsed_module; use ruff_text_size::{Ranged, TextSize}; use std::fmt; use std::fmt::Formatter; -use ty_python_semantic::SemanticModel; use ty_python_semantic::types::Type; +use ty_python_semantic::{DisplaySettings, SemanticModel}; pub fn hover(db: &dyn Db, file: File, offset: TextSize) -> Option>> { let parsed = parsed_module(db, file).load(db); @@ -135,7 +135,10 @@ impl fmt::Display for DisplayHoverContent<'_, '_> { match self.content { HoverContent::Type(ty) => self .kind - .fenced_code_block(ty.display(self.db), "python") + .fenced_code_block( + ty.display_with(self.db, DisplaySettings::default().multiline()), + "python", + ) .fmt(f), HoverContent::Docstring(docstring) => docstring.render(self.kind).fmt(f), } @@ -201,7 +204,10 @@ mod tests { ); assert_snapshot!(test.hover(), @r" - def my_func(a, b) -> Unknown + def my_func( + a, + b + ) -> Unknown --------------------------------------------- This is such a great func!! @@ -211,7 +217,10 @@ mod tests { --------------------------------------------- ```python - def my_func(a, b) -> Unknown + def my_func( + a, + b + ) -> Unknown ``` --- ```text @@ -253,7 +262,10 @@ mod tests { ); assert_snapshot!(test.hover(), @r" - def my_func(a, b) -> Unknown + def my_func( + a, + b + ) -> Unknown --------------------------------------------- This is such a great func!! @@ -263,7 +275,10 @@ mod tests { --------------------------------------------- ```python - def my_func(a, b) -> Unknown + def my_func( + a, + b + ) -> Unknown ``` --- ```text @@ -519,7 +534,10 @@ mod tests { ); assert_snapshot!(test.hover(), @r" - bound method MyClass.my_method(a, b) -> Unknown + bound method MyClass.my_method( + a, + b + ) -> Unknown --------------------------------------------- This is such a great func!! @@ -529,7 +547,10 @@ mod tests { --------------------------------------------- ```python - bound method MyClass.my_method(a, b) -> Unknown + bound method MyClass.my_method( + a, + b + ) -> Unknown ``` --- ```text @@ -601,10 +622,16 @@ mod tests { ); assert_snapshot!(test.hover(), @r" - def foo(a, b) -> Unknown + def foo( + a, + b + ) -> Unknown --------------------------------------------- ```python - def foo(a, b) -> Unknown + def foo( + a, + b + ) -> Unknown ``` --------------------------------------------- info[hover]: Hovered content is @@ -763,6 +790,128 @@ mod tests { "); } + #[test] + fn hover_overload() { + let test = cursor_test( + r#" + from typing import overload + + @overload + def foo(a: int, b): + """The first overload""" + return 0 + + @overload + def foo(a: str, b): + """The second overload""" + return 1 + + if random.choice([True, False]): + a = 1 + else: + a = "hello" + + foo(a, 2) + "#, + ); + + assert_snapshot!(test.hover(), @r#" + ( + a: int, + b + ) -> Unknown + ( + a: str, + b + ) -> Unknown + --------------------------------------------- + The first overload + + --------------------------------------------- + ```python + ( + a: int, + b + ) -> Unknown + ( + a: str, + b + ) -> Unknown + ``` + --- + ```text + The first overload + + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:19:13 + | + 17 | a = "hello" + 18 | + 19 | foo(a, 2) + | ^^^- Cursor offset + | | + | source + | + "#); + } + + #[test] + fn hover_overload_compact() { + let test = cursor_test( + r#" + from typing import overload + + @overload + def foo(a: int): + """The first overload""" + return 0 + + @overload + def foo(a: str): + """The second overload""" + return 1 + + if random.choice([True, False]): + a = 1 + else: + a = "hello" + + foo(a) + "#, + ); + + assert_snapshot!(test.hover(), @r#" + (a: int) -> Unknown + (a: str) -> Unknown + --------------------------------------------- + The first overload + + --------------------------------------------- + ```python + (a: int) -> Unknown + (a: str) -> Unknown + ``` + --- + ```text + The first overload + + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:19:13 + | + 17 | a = "hello" + 18 | + 19 | foo(a) + | ^^^- Cursor offset + | | + | source + | + "#); + } + #[test] fn hover_module() { let mut test = cursor_test( @@ -1231,6 +1380,110 @@ mod tests { assert_snapshot!(test.hover(), @"Hover provided no content"); } + #[test] + fn hover_complex_type1() { + let test = cursor_test( + r#" + from typing import Callable, Any, List + def ab(x: int, y: Callable[[int, int], Any], z: List[int]) -> int: ... + + ab + "#, + ); + + assert_snapshot!(test.hover(), @r" + def ab( + x: int, + y: (int, int, /) -> Any, + z: list[int] + ) -> int + --------------------------------------------- + ```python + def ab( + x: int, + y: (int, int, /) -> Any, + z: list[int] + ) -> int + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:5:9 + | + 3 | def ab(x: int, y: Callable[[int, int], Any], z: List[int]) -> int: ... + 4 | + 5 | ab + | ^- + | || + | |Cursor offset + | source + | + "); + } + + #[test] + fn hover_complex_type2() { + let test = cursor_test( + r#" + from typing import Callable, Tuple, Any + ab: Tuple[Any, int, Callable[[int, int], Any]] = ... + + ab + "#, + ); + + assert_snapshot!(test.hover(), @r" + tuple[Any, int, (int, int, /) -> Any] + --------------------------------------------- + ```python + tuple[Any, int, (int, int, /) -> Any] + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:5:9 + | + 3 | ab: Tuple[Any, int, Callable[[int, int], Any]] = ... + 4 | + 5 | ab + | ^- + | || + | |Cursor offset + | source + | + "); + } + + #[test] + fn hover_complex_type3() { + let test = cursor_test( + r#" + from typing import Callable, Any + ab: Callable[[int, int], Any] | None = ... + + ab + "#, + ); + + assert_snapshot!(test.hover(), @r" + ((int, int, /) -> Any) | None + --------------------------------------------- + ```python + ((int, int, /) -> Any) | None + ``` + --------------------------------------------- + info[hover]: Hovered content is + --> main.py:5:9 + | + 3 | ab: Callable[[int, int], Any] | None = ... + 4 | + 5 | ab + | ^- + | || + | |Cursor offset + | source + | + "); + } + #[test] fn hover_docstring() { let test = cursor_test( diff --git a/crates/ty_python_semantic/src/lib.rs b/crates/ty_python_semantic/src/lib.rs index ba4075ef2aefd..b3e4ef3c7e5cd 100644 --- a/crates/ty_python_semantic/src/lib.rs +++ b/crates/ty_python_semantic/src/lib.rs @@ -19,6 +19,7 @@ pub use semantic_model::{ Completion, CompletionKind, HasDefinition, HasType, NameKind, SemanticModel, }; pub use site_packages::{PythonEnvironment, SitePackagesPaths, SysPrefixPathOrigin}; +pub use types::DisplaySettings; pub use types::ide_support::{ ImportAliasResolution, ResolvedDefinition, definitions_for_attribute, definitions_for_imported_symbol, definitions_for_name, map_stub_definition, diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 30e01fdc97edc..b0d33ee097ec0 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -41,6 +41,7 @@ use crate::types::class::{CodeGeneratorKind, Field}; pub(crate) use crate::types::class_base::ClassBase; use crate::types::context::{LintDiagnosticGuard, LintDiagnosticGuardBuilder}; use crate::types::diagnostic::{INVALID_AWAIT, INVALID_TYPE_FORM, UNSUPPORTED_BOOL_CONVERSION}; +pub use crate::types::display::DisplaySettings; use crate::types::enums::{enum_metadata, is_single_member_enum}; use crate::types::function::{ DataclassTransformerParams, FunctionDecorators, FunctionSpans, FunctionType, KnownFunction, diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index 3d23a8393d25a..dd8412f4cf6c3 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -18,12 +18,50 @@ use crate::types::{ SubclassOfInner, Type, UnionType, WrapperDescriptorKind, }; +/// Settings for displaying types and signatures +#[derive(Debug, Copy, Clone, Default)] +pub struct DisplaySettings { + /// Whether rendering can be multiline + pub multiline: bool, +} + +impl DisplaySettings { + #[must_use] + pub fn multiline(self) -> Self { + Self { multiline: true } + } + + #[must_use] + pub fn singleline(self) -> Self { + Self { multiline: false } + } +} + impl<'db> Type<'db> { pub fn display(&self, db: &'db dyn Db) -> DisplayType<'_> { - DisplayType { ty: self, db } + DisplayType { + ty: self, + settings: DisplaySettings::default(), + db, + } + } + pub fn display_with(&self, db: &'db dyn Db, settings: DisplaySettings) -> DisplayType<'_> { + DisplayType { + ty: self, + db, + settings, + } } - fn representation(self, db: &'db dyn Db) -> DisplayRepresentation<'db> { - DisplayRepresentation { db, ty: self } + fn representation( + self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayRepresentation<'db> { + DisplayRepresentation { + db, + ty: self, + settings, + } } } @@ -31,11 +69,12 @@ impl<'db> Type<'db> { pub struct DisplayType<'db> { ty: &'db Type<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayType<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - let representation = self.ty.representation(self.db); + let representation = self.ty.representation(self.db, self.settings); match self.ty { Type::ClassLiteral(literal) if literal.is_known(self.db, KnownClass::Any) => { write!(f, "typing.Any") @@ -64,6 +103,7 @@ impl fmt::Debug for DisplayType<'_> { struct DisplayRepresentation<'db> { ty: Type<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayRepresentation<'_> { @@ -81,17 +121,19 @@ impl Display for DisplayRepresentation<'_> { .specialization(self.db) .tuple(self.db) .expect("Specialization::tuple() should always return `Some()` for `KnownClass::Tuple`") - .display(self.db) + .display_with(self.db, self.settings) .fmt(f), (ClassType::NonGeneric(class), _) => f.write_str(class.name(self.db)), - (ClassType::Generic(alias), _) => alias.display(self.db).fmt(f), + (ClassType::Generic(alias), _) => alias.display_with(self.db, self.settings).fmt(f), } } Type::ProtocolInstance(protocol) => match protocol.inner { Protocol::FromClass(ClassType::NonGeneric(class)) => { f.write_str(class.name(self.db)) } - Protocol::FromClass(ClassType::Generic(alias)) => alias.display(self.db).fmt(f), + Protocol::FromClass(ClassType::Generic(alias)) => { + alias.display_with(self.db, self.settings).fmt(f) + } Protocol::Synthesized(synthetic) => { f.write_str(" { Type::ClassLiteral(class) => { write!(f, "", class.name(self.db)) } - Type::GenericAlias(generic) => write!(f, "", generic.display(self.db)), + Type::GenericAlias(generic) => write!( + f, + "", + generic.display_with(self.db, self.settings.singleline()) + ), Type::SubclassOf(subclass_of_ty) => match subclass_of_ty.subclass_of() { SubclassOfInner::Class(ClassType::NonGeneric(class)) => { write!(f, "type[{}]", class.name(self.db)) } SubclassOfInner::Class(ClassType::Generic(alias)) => { - write!(f, "type[{}]", alias.display(self.db)) + write!( + f, + "type[{}]", + alias.display_with(self.db, self.settings.singleline()) + ) } SubclassOfInner::Dynamic(dynamic) => write!(f, "type[{dynamic}]"), }, Type::SpecialForm(special_form) => special_form.fmt(f), Type::KnownInstance(known_instance) => known_instance.repr(self.db).fmt(f), - Type::FunctionLiteral(function) => function.display(self.db).fmt(f), - Type::Callable(callable) => callable.display(self.db).fmt(f), + Type::FunctionLiteral(function) => function.display_with(self.db, self.settings).fmt(f), + Type::Callable(callable) => callable.display_with(self.db, self.settings).fmt(f), Type::BoundMethod(bound_method) => { let function = bound_method.function(self.db); let self_ty = bound_method.self_instance(self.db); @@ -138,31 +188,38 @@ impl Display for DisplayRepresentation<'_> { let type_parameters = DisplayOptionalGenericContext { generic_context: signature.generic_context.as_ref(), db: self.db, + settings: self.settings, }; write!( f, "bound method {instance}.{method}{type_parameters}{signature}", method = function.name(self.db), - instance = self_ty.display(self.db), + instance = self_ty.display_with(self.db, self.settings.singleline()), type_parameters = type_parameters, signature = signature .bind_self(self.db, Some(typing_self_ty)) - .display(self.db) + .display_with(self.db, self.settings) ) } signatures => { // TODO: How to display overloads? - f.write_str("Overload[")?; - let mut join = f.join(", "); + if !self.settings.multiline { + f.write_str("Overload[")?; + } + let separator = if self.settings.multiline { "\n" } else { ", " }; + let mut join = f.join(separator); for signature in signatures { join.entry( &signature .bind_self(self.db, Some(typing_self_ty)) - .display(self.db), + .display_with(self.db, self.settings), ); } - f.write_str("]") + if !self.settings.multiline { + f.write_str("]")?; + } + Ok(()) } } } @@ -203,11 +260,13 @@ impl Display for DisplayRepresentation<'_> { Type::DataclassTransformer(_) => { f.write_str("") } - Type::Union(union) => union.display(self.db).fmt(f), - Type::Intersection(intersection) => intersection.display(self.db).fmt(f), + Type::Union(union) => union.display_with(self.db, self.settings).fmt(f), + Type::Intersection(intersection) => { + intersection.display_with(self.db, self.settings).fmt(f) + } Type::IntLiteral(n) => n.fmt(f), Type::BooleanLiteral(boolean) => f.write_str(if boolean { "True" } else { "False" }), - Type::StringLiteral(string) => string.display(self.db).fmt(f), + Type::StringLiteral(string) => string.display_with(self.db, self.settings).fmt(f), Type::LiteralString => f.write_str("LiteralString"), Type::BytesLiteral(bytes) => { let escape = AsciiEscape::with_preferred_quote(bytes.value(self.db), Quote::Double); @@ -236,13 +295,20 @@ impl Display for DisplayRepresentation<'_> { write!( f, "", - pivot = Type::from(bound_super.pivot_class(self.db)).display(self.db), - owner = bound_super.owner(self.db).into_type().display(self.db) + pivot = Type::from(bound_super.pivot_class(self.db)) + .display_with(self.db, self.settings.singleline()), + owner = bound_super + .owner(self.db) + .into_type() + .display_with(self.db, self.settings.singleline()) ) } Type::TypeIs(type_is) => { f.write_str("TypeIs[")?; - type_is.return_type(self.db).display(self.db).fmt(f)?; + type_is + .return_type(self.db) + .display_with(self.db, self.settings.singleline()) + .fmt(f)?; if let Some(name) = type_is.place_name(self.db) { f.write_str(" @ ")?; f.write_str(&name)?; @@ -256,14 +322,23 @@ impl Display for DisplayRepresentation<'_> { } impl<'db> TupleSpec<'db> { - pub(crate) fn display(&'db self, db: &'db dyn Db) -> DisplayTuple<'db> { - DisplayTuple { tuple: self, db } + pub(crate) fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayTuple<'db> { + DisplayTuple { + tuple: self, + db, + settings, + } } } pub(crate) struct DisplayTuple<'db> { tuple: &'db TupleSpec<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayTuple<'_> { @@ -275,7 +350,9 @@ impl Display for DisplayTuple<'_> { if elements.is_empty() { f.write_str("()")?; } else { - elements.display(self.db).fmt(f)?; + elements + .display_with(self.db, self.settings.singleline()) + .fmt(f)?; } } @@ -295,20 +372,29 @@ impl Display for DisplayTuple<'_> { // trailing `]` are printed elsewhere. The `yyy, ...` is printed no matter what.) TupleSpec::Variable(tuple) => { if !tuple.prefix.is_empty() { - tuple.prefix.display(self.db).fmt(f)?; + tuple + .prefix + .display_with(self.db, self.settings.singleline()) + .fmt(f)?; f.write_str(", ")?; } if !tuple.prefix.is_empty() || !tuple.suffix.is_empty() { f.write_str("*tuple[")?; } - tuple.variable.display(self.db).fmt(f)?; + tuple + .variable + .display_with(self.db, self.settings.singleline()) + .fmt(f)?; f.write_str(", ...")?; if !tuple.prefix.is_empty() || !tuple.suffix.is_empty() { f.write_str("]")?; } if !tuple.suffix.is_empty() { f.write_str(", ")?; - tuple.suffix.display(self.db).fmt(f)?; + tuple + .suffix + .display_with(self.db, self.settings.singleline()) + .fmt(f)?; } } } @@ -320,13 +406,26 @@ impl<'db> OverloadLiteral<'db> { // Not currently used, but useful for debugging. #[expect(dead_code)] pub(crate) fn display(self, db: &'db dyn Db) -> DisplayOverloadLiteral<'db> { - DisplayOverloadLiteral { literal: self, db } + Self::display_with(self, db, DisplaySettings::default()) + } + + pub(crate) fn display_with( + self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayOverloadLiteral<'db> { + DisplayOverloadLiteral { + literal: self, + db, + settings, + } } } pub(crate) struct DisplayOverloadLiteral<'db> { literal: OverloadLiteral<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayOverloadLiteral<'_> { @@ -335,6 +434,7 @@ impl Display for DisplayOverloadLiteral<'_> { let type_parameters = DisplayOptionalGenericContext { generic_context: signature.generic_context.as_ref(), db: self.db, + settings: self.settings, }; write!( @@ -342,20 +442,29 @@ impl Display for DisplayOverloadLiteral<'_> { "def {name}{type_parameters}{signature}", name = self.literal.name(self.db), type_parameters = type_parameters, - signature = signature.display(self.db) + signature = signature.display_with(self.db, self.settings) ) } } impl<'db> FunctionType<'db> { - pub(crate) fn display(self, db: &'db dyn Db) -> DisplayFunctionType<'db> { - DisplayFunctionType { ty: self, db } + pub(crate) fn display_with( + self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayFunctionType<'db> { + DisplayFunctionType { + ty: self, + db, + settings, + } } } pub(crate) struct DisplayFunctionType<'db> { ty: FunctionType<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayFunctionType<'_> { @@ -367,6 +476,7 @@ impl Display for DisplayFunctionType<'_> { let type_parameters = DisplayOptionalGenericContext { generic_context: signature.generic_context.as_ref(), db: self.db, + settings: self.settings, }; write!( @@ -374,28 +484,39 @@ impl Display for DisplayFunctionType<'_> { "def {name}{type_parameters}{signature}", name = self.ty.name(self.db), type_parameters = type_parameters, - signature = signature.display(self.db) + signature = signature.display_with(self.db, self.settings) ) } signatures => { // TODO: How to display overloads? - f.write_str("Overload[")?; - let mut join = f.join(", "); + if !self.settings.multiline { + f.write_str("Overload[")?; + } + let separator = if self.settings.multiline { "\n" } else { ", " }; + let mut join = f.join(separator); for signature in signatures { - join.entry(&signature.display(self.db)); + join.entry(&signature.display_with(self.db, self.settings)); } - f.write_str("]") + if !self.settings.multiline { + f.write_str("]")?; + } + Ok(()) } } } } impl<'db> GenericAlias<'db> { - pub(crate) fn display(&'db self, db: &'db dyn Db) -> DisplayGenericAlias<'db> { + pub(crate) fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayGenericAlias<'db> { DisplayGenericAlias { origin: self.origin(db), specialization: self.specialization(db), db, + settings, } } } @@ -404,12 +525,13 @@ pub(crate) struct DisplayGenericAlias<'db> { origin: ClassLiteral<'db>, specialization: Specialization<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayGenericAlias<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { if let Some(tuple) = self.specialization.tuple(self.db) { - tuple.display(self.db).fmt(f) + tuple.display_with(self.db, self.settings).fmt(f) } else { write!( f, @@ -426,9 +548,17 @@ impl Display for DisplayGenericAlias<'_> { impl<'db> GenericContext<'db> { pub fn display(&'db self, db: &'db dyn Db) -> DisplayGenericContext<'db> { + Self::display_with(self, db, DisplaySettings::default()) + } + pub fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayGenericContext<'db> { DisplayGenericContext { generic_context: self, db, + settings, } } } @@ -436,6 +566,7 @@ impl<'db> GenericContext<'db> { struct DisplayOptionalGenericContext<'db> { generic_context: Option<&'db GenericContext<'db>>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayOptionalGenericContext<'_> { @@ -444,6 +575,7 @@ impl Display for DisplayOptionalGenericContext<'_> { DisplayGenericContext { generic_context, db: self.db, + settings: self.settings, } .fmt(f) } else { @@ -455,6 +587,8 @@ impl Display for DisplayOptionalGenericContext<'_> { pub struct DisplayGenericContext<'db> { generic_context: &'db GenericContext<'db>, db: &'db dyn Db, + #[expect(dead_code)] + settings: DisplaySettings, } impl Display for DisplayGenericContext<'_> { @@ -492,6 +626,7 @@ impl<'db> Specialization<'db> { types: self.types(db), db, tuple_specialization, + settings: DisplaySettings::default(), } } } @@ -500,6 +635,7 @@ pub struct DisplaySpecialization<'db> { types: &'db [Type<'db>], db: &'db dyn Db, tuple_specialization: TupleSpecialization, + settings: DisplaySettings, } impl Display for DisplaySpecialization<'_> { @@ -509,7 +645,7 @@ impl Display for DisplaySpecialization<'_> { if idx > 0 { f.write_str(", ")?; } - ty.display(self.db).fmt(f)?; + ty.display_with(self.db, self.settings).fmt(f)?; } if self.tuple_specialization.is_yes() { f.write_str(", ...")?; @@ -540,9 +676,18 @@ impl TupleSpecialization { impl<'db> CallableType<'db> { pub(crate) fn display(&'db self, db: &'db dyn Db) -> DisplayCallableType<'db> { + Self::display_with(self, db, DisplaySettings::default()) + } + + pub(crate) fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayCallableType<'db> { DisplayCallableType { signatures: self.signatures(db), db, + settings, } } } @@ -550,21 +695,28 @@ impl<'db> CallableType<'db> { pub(crate) struct DisplayCallableType<'db> { signatures: &'db CallableSignature<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayCallableType<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self.signatures.overloads.as_slice() { - [signature] => signature.display(self.db).fmt(f), + [signature] => signature.display_with(self.db, self.settings).fmt(f), signatures => { // TODO: How to display overloads? - f.write_str("Overload[")?; - let mut join = f.join(", "); + if !self.settings.multiline { + f.write_str("Overload[")?; + } + let separator = if self.settings.multiline { "\n" } else { ", " }; + let mut join = f.join(separator); for signature in signatures { - join.entry(&signature.display(self.db)); + join.entry(&signature.display_with(self.db, self.settings)); } join.finish()?; - f.write_char(']') + if !self.settings.multiline { + f.write_char(']')?; + } + Ok(()) } } } @@ -572,10 +724,19 @@ impl Display for DisplayCallableType<'_> { impl<'db> Signature<'db> { pub(crate) fn display(&'db self, db: &'db dyn Db) -> DisplaySignature<'db> { + Self::display_with(self, db, DisplaySettings::default()) + } + + pub(crate) fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplaySignature<'db> { DisplaySignature { parameters: self.parameters(), return_ty: self.return_ty, db, + settings, } } } @@ -584,6 +745,7 @@ pub(crate) struct DisplaySignature<'db> { parameters: &'db Parameters<'db>, return_ty: Option>, db: &'db dyn Db, + settings: DisplaySettings, } impl DisplaySignature<'_> { @@ -600,9 +762,12 @@ impl DisplaySignature<'_> { /// Internal method to write signature with the signature writer fn write_signature(&self, writer: &mut SignatureWriter) -> fmt::Result { + let multiline = self.settings.multiline && self.parameters.len() > 1; // Opening parenthesis writer.write_char('(')?; - + if multiline { + writer.write_str("\n ")?; + } if self.parameters.is_gradual() { // We represent gradual form as `...` in the signature, internally the parameters still // contain `(*args, **kwargs)` parameters. @@ -611,12 +776,13 @@ impl DisplaySignature<'_> { let mut star_added = false; let mut needs_slash = false; let mut first = true; + let arg_separator = if multiline { ",\n " } else { ", " }; for parameter in self.parameters.as_slice() { // Handle special separators if !star_added && parameter.is_keyword_only() { if !first { - writer.write_str(", ")?; + writer.write_str(arg_separator)?; } writer.write_char('*')?; star_added = true; @@ -626,7 +792,7 @@ impl DisplaySignature<'_> { needs_slash = true; } else if needs_slash { if !first { - writer.write_str(", ")?; + writer.write_str(arg_separator)?; } writer.write_char('/')?; needs_slash = false; @@ -635,30 +801,36 @@ impl DisplaySignature<'_> { // Add comma before parameter if not first if !first { - writer.write_str(", ")?; + writer.write_str(arg_separator)?; } // Write parameter with range tracking let param_name = parameter.display_name(); - writer.write_parameter(¶meter.display(self.db), param_name.as_deref())?; + writer.write_parameter( + ¶meter.display_with(self.db, self.settings.singleline()), + param_name.as_deref(), + )?; first = false; } if needs_slash { if !first { - writer.write_str(", ")?; + writer.write_str(arg_separator)?; } writer.write_char('/')?; } } + if multiline { + writer.write_char('\n')?; + } // Closing parenthesis writer.write_char(')')?; // Return type let return_ty = self.return_ty.unwrap_or_else(Type::unknown); - writer.write_return_type(&return_ty.display(self.db))?; + writer.write_return_type(&return_ty.display_with(self.db, self.settings.singleline()))?; Ok(()) } @@ -774,14 +946,23 @@ pub(crate) struct SignatureDisplayDetails { } impl<'db> Parameter<'db> { - fn display(&'db self, db: &'db dyn Db) -> DisplayParameter<'db> { - DisplayParameter { param: self, db } + fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayParameter<'db> { + DisplayParameter { + param: self, + db, + settings, + } } } struct DisplayParameter<'db> { param: &'db Parameter<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayParameter<'_> { @@ -789,34 +970,47 @@ impl Display for DisplayParameter<'_> { if let Some(name) = self.param.display_name() { f.write_str(&name)?; if let Some(annotated_type) = self.param.annotated_type() { - write!(f, ": {}", annotated_type.display(self.db))?; + write!( + f, + ": {}", + annotated_type.display_with(self.db, self.settings) + )?; } // Default value can only be specified if `name` is given. if let Some(default_ty) = self.param.default_type() { if self.param.annotated_type().is_some() { - write!(f, " = {}", default_ty.display(self.db))?; + write!(f, " = {}", default_ty.display_with(self.db, self.settings))?; } else { - write!(f, "={}", default_ty.display(self.db))?; + write!(f, "={}", default_ty.display_with(self.db, self.settings))?; } } } else if let Some(ty) = self.param.annotated_type() { // This case is specifically for the `Callable` signature where name and default value // cannot be provided. - ty.display(self.db).fmt(f)?; + ty.display_with(self.db, self.settings).fmt(f)?; } Ok(()) } } impl<'db> UnionType<'db> { - fn display(&'db self, db: &'db dyn Db) -> DisplayUnionType<'db> { - DisplayUnionType { db, ty: self } + fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayUnionType<'db> { + DisplayUnionType { + db, + ty: self, + settings, + } } } struct DisplayUnionType<'db> { ty: &'db UnionType<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayUnionType<'_> { @@ -849,12 +1043,14 @@ impl Display for DisplayUnionType<'_> { join.entry(&DisplayLiteralGroup { literals: condensed_types, db: self.db, + settings: self.settings.singleline(), }); } } else { join.entry(&DisplayMaybeParenthesizedType { ty: *element, db: self.db, + settings: self.settings.singleline(), }); } } @@ -874,27 +1070,41 @@ impl fmt::Debug for DisplayUnionType<'_> { struct DisplayLiteralGroup<'db> { literals: Vec>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayLiteralGroup<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.write_str("Literal[")?; f.join(", ") - .entries(self.literals.iter().map(|ty| ty.representation(self.db))) + .entries( + self.literals + .iter() + .map(|ty| ty.representation(self.db, self.settings.singleline())), + ) .finish()?; f.write_str("]") } } impl<'db> IntersectionType<'db> { - fn display(&'db self, db: &'db dyn Db) -> DisplayIntersectionType<'db> { - DisplayIntersectionType { db, ty: self } + fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayIntersectionType<'db> { + DisplayIntersectionType { + db, + ty: self, + settings, + } } } struct DisplayIntersectionType<'db> { ty: &'db IntersectionType<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayIntersectionType<'_> { @@ -906,6 +1116,7 @@ impl Display for DisplayIntersectionType<'_> { .map(|&ty| DisplayMaybeNegatedType { ty, db: self.db, + settings: self.settings.singleline(), negated: false, }) .chain( @@ -915,6 +1126,7 @@ impl Display for DisplayIntersectionType<'_> { .map(|&ty| DisplayMaybeNegatedType { ty, db: self.db, + settings: self.settings.singleline(), negated: true, }), ); @@ -932,6 +1144,7 @@ struct DisplayMaybeNegatedType<'db> { ty: Type<'db>, db: &'db dyn Db, negated: bool, + settings: DisplaySettings, } impl Display for DisplayMaybeNegatedType<'_> { @@ -942,6 +1155,7 @@ impl Display for DisplayMaybeNegatedType<'_> { DisplayMaybeParenthesizedType { ty: self.ty, db: self.db, + settings: self.settings, } .fmt(f) } @@ -950,11 +1164,13 @@ impl Display for DisplayMaybeNegatedType<'_> { struct DisplayMaybeParenthesizedType<'db> { ty: Type<'db>, db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayMaybeParenthesizedType<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - let write_parentheses = |f: &mut Formatter<'_>| write!(f, "({})", self.ty.display(self.db)); + let write_parentheses = + |f: &mut Formatter<'_>| write!(f, "({})", self.ty.display_with(self.db, self.settings)); match self.ty { Type::Callable(_) | Type::MethodWrapper(_) @@ -964,58 +1180,94 @@ impl Display for DisplayMaybeParenthesizedType<'_> { Type::Intersection(intersection) if !intersection.has_one_element(self.db) => { write_parentheses(f) } - _ => self.ty.display(self.db).fmt(f), + _ => self.ty.display_with(self.db, self.settings).fmt(f), } } } pub(crate) trait TypeArrayDisplay<'db> { - fn display(&self, db: &'db dyn Db) -> DisplayTypeArray<'_, 'db>; + fn display_with(&self, db: &'db dyn Db, settings: DisplaySettings) + -> DisplayTypeArray<'_, 'db>; } impl<'db> TypeArrayDisplay<'db> for Box<[Type<'db>]> { - fn display(&self, db: &'db dyn Db) -> DisplayTypeArray<'_, 'db> { - DisplayTypeArray { types: self, db } + fn display_with( + &self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayTypeArray<'_, 'db> { + DisplayTypeArray { + types: self, + db, + settings, + } } } impl<'db> TypeArrayDisplay<'db> for Vec> { - fn display(&self, db: &'db dyn Db) -> DisplayTypeArray<'_, 'db> { - DisplayTypeArray { types: self, db } + fn display_with( + &self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayTypeArray<'_, 'db> { + DisplayTypeArray { + types: self, + db, + settings, + } } } impl<'db> TypeArrayDisplay<'db> for [Type<'db>] { - fn display(&self, db: &'db dyn Db) -> DisplayTypeArray<'_, 'db> { - DisplayTypeArray { types: self, db } + fn display_with( + &self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayTypeArray<'_, 'db> { + DisplayTypeArray { + types: self, + db, + settings, + } } } pub(crate) struct DisplayTypeArray<'b, 'db> { types: &'b [Type<'db>], db: &'db dyn Db, + settings: DisplaySettings, } impl Display for DisplayTypeArray<'_, '_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.join(", ") - .entries(self.types.iter().map(|ty| ty.display(self.db))) + .entries( + self.types + .iter() + .map(|ty| ty.display_with(self.db, self.settings.singleline())), + ) .finish() } } impl<'db> StringLiteralType<'db> { - fn display(&'db self, db: &'db dyn Db) -> DisplayStringLiteralType<'db> { - display_quoted_string(self.value(db)) + fn display_with( + &'db self, + db: &'db dyn Db, + settings: DisplaySettings, + ) -> DisplayStringLiteralType<'db> { + display_quoted_string(self.value(db), settings) } } -fn display_quoted_string(string: &str) -> DisplayStringLiteralType<'_> { - DisplayStringLiteralType { string } +fn display_quoted_string(string: &str, settings: DisplaySettings) -> DisplayStringLiteralType<'_> { + DisplayStringLiteralType { string, settings } } struct DisplayStringLiteralType<'db> { string: &'db str, + #[expect(dead_code)] + settings: DisplaySettings, } impl Display for DisplayStringLiteralType<'_> { @@ -1035,6 +1287,7 @@ impl Display for DisplayStringLiteralType<'_> { #[cfg(test)] mod tests { + use insta::assert_snapshot; use ruff_python_ast::name::Name; use crate::Db; @@ -1095,31 +1348,41 @@ mod tests { .to_string() } + fn display_signature_multiline<'db>( + db: &dyn Db, + parameters: impl IntoIterator>, + return_ty: Option>, + ) -> String { + Signature::new(Parameters::new(parameters), return_ty) + .display_with(db, super::DisplaySettings::default().multiline()) + .to_string() + } + #[test] fn signature_display() { let db = setup_db(); // Empty parameters with no return type. - assert_eq!(display_signature(&db, [], None), "() -> Unknown"); + assert_snapshot!(display_signature(&db, [], None), @"() -> Unknown"); // Empty parameters with a return type. - assert_eq!( + assert_snapshot!( display_signature(&db, [], Some(Type::none(&db))), - "() -> None" + @"() -> None" ); // Single parameter type (no name) with a return type. - assert_eq!( + assert_snapshot!( display_signature( &db, [Parameter::positional_only(None).with_annotated_type(Type::none(&db))], Some(Type::none(&db)) ), - "(None, /) -> None" + @"(None, /) -> None" ); // Two parameters where one has annotation and the other doesn't. - assert_eq!( + assert_snapshot!( display_signature( &db, [ @@ -1131,11 +1394,11 @@ mod tests { ], Some(Type::none(&db)) ), - "(x=int, y: str = str) -> None" + @"(x=int, y: str = str) -> None" ); // All positional only parameters. - assert_eq!( + assert_snapshot!( display_signature( &db, [ @@ -1144,11 +1407,11 @@ mod tests { ], Some(Type::none(&db)) ), - "(x, y, /) -> None" + @"(x, y, /) -> None" ); // Positional-only parameters mixed with non-positional-only parameters. - assert_eq!( + assert_snapshot!( display_signature( &db, [ @@ -1157,11 +1420,11 @@ mod tests { ], Some(Type::none(&db)) ), - "(x, /, y) -> None" + @"(x, /, y) -> None" ); // All keyword-only parameters. - assert_eq!( + assert_snapshot!( display_signature( &db, [ @@ -1170,11 +1433,11 @@ mod tests { ], Some(Type::none(&db)) ), - "(*, x, y) -> None" + @"(*, x, y) -> None" ); // Keyword-only parameters mixed with non-keyword-only parameters. - assert_eq!( + assert_snapshot!( display_signature( &db, [ @@ -1183,11 +1446,11 @@ mod tests { ], Some(Type::none(&db)) ), - "(x, *, y) -> None" + @"(x, *, y) -> None" ); // A mix of all parameter kinds. - assert_eq!( + assert_snapshot!( display_signature( &db, [ @@ -1216,9 +1479,178 @@ mod tests { ], Some(KnownClass::Bytes.to_instance(&db)) ), - "(a, b: int, c=Literal[1], d: int = Literal[2], \ + @"(a, b: int, c=Literal[1], d: int = Literal[2], \ /, e=Literal[3], f: int = Literal[4], *args: object, \ *, g=Literal[5], h: int = Literal[6], **kwargs: str) -> bytes" ); } + + #[test] + fn signature_display_multiline() { + let db = setup_db(); + + // Empty parameters with no return type. + assert_snapshot!(display_signature_multiline(&db, [], None), @"() -> Unknown"); + + // Empty parameters with a return type. + assert_snapshot!( + display_signature_multiline(&db, [], Some(Type::none(&db))), + @"() -> None" + ); + + // Single parameter type (no name) with a return type. + assert_snapshot!( + display_signature_multiline( + &db, + [Parameter::positional_only(None).with_annotated_type(Type::none(&db))], + Some(Type::none(&db)) + ), + @"(None, /) -> None" + ); + + // Two parameters where one has annotation and the other doesn't. + assert_snapshot!( + display_signature_multiline( + &db, + [ + Parameter::positional_or_keyword(Name::new_static("x")) + .with_default_type(KnownClass::Int.to_instance(&db)), + Parameter::positional_or_keyword(Name::new_static("y")) + .with_annotated_type(KnownClass::Str.to_instance(&db)) + .with_default_type(KnownClass::Str.to_instance(&db)), + ], + Some(Type::none(&db)) + ), + @r" + ( + x=int, + y: str = str + ) -> None + " + ); + + // All positional only parameters. + assert_snapshot!( + display_signature_multiline( + &db, + [ + Parameter::positional_only(Some(Name::new_static("x"))), + Parameter::positional_only(Some(Name::new_static("y"))), + ], + Some(Type::none(&db)) + ), + @r" + ( + x, + y, + / + ) -> None + " + ); + + // Positional-only parameters mixed with non-positional-only parameters. + assert_snapshot!( + display_signature_multiline( + &db, + [ + Parameter::positional_only(Some(Name::new_static("x"))), + Parameter::positional_or_keyword(Name::new_static("y")), + ], + Some(Type::none(&db)) + ), + @r" + ( + x, + /, + y + ) -> None + " + ); + + // All keyword-only parameters. + assert_snapshot!( + display_signature_multiline( + &db, + [ + Parameter::keyword_only(Name::new_static("x")), + Parameter::keyword_only(Name::new_static("y")), + ], + Some(Type::none(&db)) + ), + @r" + ( + *, + x, + y + ) -> None + " + ); + + // Keyword-only parameters mixed with non-keyword-only parameters. + assert_snapshot!( + display_signature_multiline( + &db, + [ + Parameter::positional_or_keyword(Name::new_static("x")), + Parameter::keyword_only(Name::new_static("y")), + ], + Some(Type::none(&db)) + ), + @r" + ( + x, + *, + y + ) -> None + " + ); + + // A mix of all parameter kinds. + assert_snapshot!( + display_signature_multiline( + &db, + [ + Parameter::positional_only(Some(Name::new_static("a"))), + Parameter::positional_only(Some(Name::new_static("b"))) + .with_annotated_type(KnownClass::Int.to_instance(&db)), + Parameter::positional_only(Some(Name::new_static("c"))) + .with_default_type(Type::IntLiteral(1)), + Parameter::positional_only(Some(Name::new_static("d"))) + .with_annotated_type(KnownClass::Int.to_instance(&db)) + .with_default_type(Type::IntLiteral(2)), + Parameter::positional_or_keyword(Name::new_static("e")) + .with_default_type(Type::IntLiteral(3)), + Parameter::positional_or_keyword(Name::new_static("f")) + .with_annotated_type(KnownClass::Int.to_instance(&db)) + .with_default_type(Type::IntLiteral(4)), + Parameter::variadic(Name::new_static("args")) + .with_annotated_type(Type::object(&db)), + Parameter::keyword_only(Name::new_static("g")) + .with_default_type(Type::IntLiteral(5)), + Parameter::keyword_only(Name::new_static("h")) + .with_annotated_type(KnownClass::Int.to_instance(&db)) + .with_default_type(Type::IntLiteral(6)), + Parameter::keyword_variadic(Name::new_static("kwargs")) + .with_annotated_type(KnownClass::Str.to_instance(&db)), + ], + Some(KnownClass::Bytes.to_instance(&db)) + ), + @r" + ( + a, + b: int, + c=Literal[1], + d: int = Literal[2], + /, + e=Literal[3], + f: int = Literal[4], + *args: object, + *, + g=Literal[5], + h: int = Literal[6], + **kwargs: str + ) -> bytes + " + ); + } } From 58efd19f11af5e24eed665e4381d5b9e0bdf130e Mon Sep 17 00:00:00 2001 From: Eric Jolibois Date: Tue, 19 Aug 2025 20:01:35 +0200 Subject: [PATCH 050/160] [ty] apply `KW_ONLY` sentinel only to local fields (#19986) fix https://github.com/astral-sh/ty/issues/1047 ## Summary This PR fixes how `KW_ONLY` is applied in dataclasses. Previously, the sentinel leaked into subclasses and incorrectly marked their fields as keyword-only; now it only affects fields declared in the same class. ```py from dataclasses import dataclass, KW_ONLY @dataclass class D: x: int _: KW_ONLY y: str @dataclass class E(D): z: bytes # This should work: x=1 (positional), z=b"foo" (positional), y="foo" (keyword-only) E(1, b"foo", y="foo") reveal_type(E.__init__) # revealed: (self: E, x: int, z: bytes, *, y: str) -> None ``` ## Test Plan mdtests --- .../mdtest/dataclasses/dataclasses.md | 22 ++++++++ ..._ONLY\342\200\246_(dd1b8f2f71487f16).snap" | 28 ++++++++++ crates/ty_python_semantic/src/types/class.rs | 53 ++++++++++++------- crates/ty_python_semantic/src/types/infer.rs | 35 ++++-------- 4 files changed, 93 insertions(+), 45 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses.md b/crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses.md index e181652cc0c13..608b4f348ef53 100644 --- a/crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses.md +++ b/crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses.md @@ -988,6 +988,28 @@ class D: # error: [duplicate-kw-only] z: float ``` +`KW_ONLY` should only affect fields declared after it within the same class, not fields in +subclasses: + +```py +from dataclasses import dataclass, KW_ONLY + +@dataclass +class D: + x: int + _: KW_ONLY + y: str + +@dataclass +class E(D): + z: bytes + +# This should work: x=1 (positional), z=b"foo" (positional), y="foo" (keyword-only) +E(1, b"foo", y="foo") + +reveal_type(E.__init__) # revealed: (self: E, x: int, z: bytes, *, y: str) -> None +``` + ## Other special cases ### `dataclasses.dataclass` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/dataclasses.md_-_Dataclasses_-_`dataclasses.KW_ONLY\342\200\246_(dd1b8f2f71487f16).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/dataclasses.md_-_Dataclasses_-_`dataclasses.KW_ONLY\342\200\246_(dd1b8f2f71487f16).snap" index 00b925ed42552..2cd0c99649889 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/dataclasses.md_-_Dataclasses_-_`dataclasses.KW_ONLY\342\200\246_(dd1b8f2f71487f16).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/dataclasses.md_-_Dataclasses_-_`dataclasses.KW_ONLY\342\200\246_(dd1b8f2f71487f16).snap" @@ -49,6 +49,22 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/dataclasses/dataclasses. 35 | y: str 36 | _2: KW_ONLY 37 | z: float +38 | from dataclasses import dataclass, KW_ONLY +39 | +40 | @dataclass +41 | class D: +42 | x: int +43 | _: KW_ONLY +44 | y: str +45 | +46 | @dataclass +47 | class E(D): +48 | z: bytes +49 | +50 | # This should work: x=1 (positional), z=b"foo" (positional), y="foo" (keyword-only) +51 | E(1, b"foo", y="foo") +52 | +53 | reveal_type(E.__init__) # revealed: (self: E, x: int, z: bytes, *, y: str) -> None ``` # Diagnostics @@ -141,3 +157,15 @@ info: `KW_ONLY` fields: `_1`, `_2` info: rule `duplicate-kw-only` is enabled by default ``` + +``` +info[revealed-type]: Revealed type + --> src/mdtest_snippet.py:53:13 + | +51 | E(1, b"foo", y="foo") +52 | +53 | reveal_type(E.__init__) # revealed: (self: E, x: int, z: bytes, *, y: str) -> None + | ^^^^^^^^^^ `(self: E, x: int, z: bytes, *, y: str) -> None` + | + +``` diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 97f3862819efa..59929bf59c341 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -1179,6 +1179,16 @@ pub(crate) struct Field<'db> { pub(crate) kw_only: Option, } +impl<'db> Field<'db> { + /// Returns true if this field is a `dataclasses.KW_ONLY` sentinel. + /// + pub(crate) fn is_kw_only_sentinel(&self, db: &'db dyn Db) -> bool { + self.declared_ty + .into_nominal_instance() + .is_some_and(|instance| instance.class(db).is_known(db, KnownClass::KwOnly)) + } +} + /// Representation of a class definition statement in the AST: either a non-generic class, or a /// generic class that has not been specialized. /// @@ -1932,10 +1942,9 @@ impl<'db> ClassLiteral<'db> { Type::instance(db, self.apply_optional_specialization(db, specialization)); let signature_from_fields = |mut parameters: Vec<_>, return_ty: Option>| { - let mut kw_only_field_seen = false; for ( field_name, - Field { + field @ Field { declared_ty: mut field_ty, mut default_ty, init_only: _, @@ -1949,14 +1958,10 @@ impl<'db> ClassLiteral<'db> { continue; } - if field_ty - .into_nominal_instance() - .is_some_and(|instance| instance.class(db).is_known(db, KnownClass::KwOnly)) - { + if field.is_kw_only_sentinel(db) { // Attributes annotated with `dataclass.KW_ONLY` are not present in the synthesized // `__init__` method; they are used to indicate that the following parameters are // keyword-only. - kw_only_field_seen = true; continue; } @@ -2006,9 +2011,7 @@ impl<'db> ClassLiteral<'db> { } let is_kw_only = name == "__replace__" - || kw_only.unwrap_or( - has_dataclass_param(DataclassParams::KW_ONLY) || kw_only_field_seen, - ); + || kw_only.unwrap_or(has_dataclass_param(DataclassParams::KW_ONLY)); let mut parameter = if is_kw_only { Parameter::keyword_only(field_name) @@ -2307,6 +2310,7 @@ impl<'db> ClassLiteral<'db> { let table = place_table(db, class_body_scope); let use_def = use_def_map(db, class_body_scope); + let mut kw_only_sentinel_field_seen = false; for (symbol_id, declarations) in use_def.all_end_of_scope_symbol_declarations() { // Here, we exclude all declarations that are not annotated assignments. We need this because // things like function definitions and nested classes would otherwise be considered dataclass @@ -2351,16 +2355,25 @@ impl<'db> ClassLiteral<'db> { kw_only = field.kw_only(db); } - attributes.insert( - symbol.name().clone(), - Field { - declared_ty: attr_ty.apply_optional_specialization(db, specialization), - default_ty, - init_only: attr.is_init_var(), - init, - kw_only, - }, - ); + let mut field = Field { + declared_ty: attr_ty.apply_optional_specialization(db, specialization), + default_ty, + init_only: attr.is_init_var(), + init, + kw_only, + }; + + // Check if this is a KW_ONLY sentinel and mark subsequent fields as keyword-only + if field.is_kw_only_sentinel(db) { + kw_only_sentinel_field_seen = true; + } + + // If no explicit kw_only setting and we've seen KW_ONLY sentinel, mark as keyword-only + if field.kw_only.is_none() && kw_only_sentinel_field_seen { + field.kw_only = Some(true); + } + + attributes.insert(symbol.name().clone(), field); } } diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index ff5799770791b..86a289d300007 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -90,7 +90,7 @@ use crate::semantic_index::{ ApplicableConstraints, EnclosingSnapshotResult, SemanticIndex, place_table, semantic_index, }; use crate::types::call::{Binding, Bindings, CallArguments, CallError, CallErrorKind}; -use crate::types::class::{CodeGeneratorKind, Field, MetaclassErrorKind}; +use crate::types::class::{CodeGeneratorKind, MetaclassErrorKind}; use crate::types::diagnostic::{ self, CALL_NON_CALLABLE, CONFLICTING_DECLARATIONS, CONFLICTING_METACLASS, CYCLIC_CLASS_DEFINITION, DIVISION_BY_ZERO, DUPLICATE_KW_ONLY, INCONSISTENT_MRO, @@ -1405,31 +1405,16 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { CodeGeneratorKind::from_class(self.db(), class) { let specialization = None; - let mut kw_only_field_names = vec![]; - for ( - name, - Field { - declared_ty: field_ty, - .. - }, - ) in class.fields(self.db(), specialization, field_policy) - { - let Some(instance) = field_ty.into_nominal_instance() else { - continue; - }; - - if !instance - .class(self.db()) - .is_known(self.db(), KnownClass::KwOnly) - { - continue; - } - - kw_only_field_names.push(name); - } + let kw_only_sentinel_fields: Vec<_> = class + .fields(self.db(), specialization, field_policy) + .into_iter() + .filter_map(|(name, field)| { + field.is_kw_only_sentinel(self.db()).then_some(name) + }) + .collect(); - if kw_only_field_names.len() > 1 { + if kw_only_sentinel_fields.len() > 1 { // TODO: The fields should be displayed in a subdiagnostic. if let Some(builder) = self .context @@ -1441,7 +1426,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { diagnostic.info(format_args!( "`KW_ONLY` fields: {}", - kw_only_field_names + kw_only_sentinel_fields .iter() .map(|name| format!("`{name}`")) .join(", ") From c82e255ca8570a683fcd0cde1e62bd1086837c12 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Tue, 19 Aug 2025 16:34:39 -0400 Subject: [PATCH 051/160] [ty] Fix namespace packages that behave like partial stubs (#19994) In implementing partial stubs I had observed that this continue in the namespace package code seemed erroneous since the same continue for partial stubs didn't work. Unfortunately I wasn't confident enough to push on that hunch. Fortunately I remembered that hunch to make this an easy fix. The issue with the continue is that it bails out of the current search-path without testing any .py files. This breaks when for example `google` and `google-stubs`/`types-google` are both in the same site-packages dir -- failing to find a module in `types-google` has us completely skip over `google`! Fixes https://github.com/astral-sh/ty/issues/520 --- .../mdtest/import/partial_stub_packages.md | 69 +++++++++++++++---- .../src/module_resolver/resolver.rs | 3 +- 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md index 3d01aa3ab4de2..b84faf4c8561f 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md +++ b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md @@ -54,9 +54,9 @@ partial ```pyi ``` -`/packages/foo-stubs/both.py`: +`/packages/foo-stubs/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -107,9 +107,9 @@ extra-paths = ["/packages"] ```pyi ``` -`/packages/foo-stubs/both.py`: +`/packages/foo-stubs/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -165,9 +165,9 @@ extra-paths = ["/packages"] ```pyi ``` -`/packages/foo-stubs/both.py`: +`/packages/foo-stubs/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -230,9 +230,9 @@ extra-paths = ["/packages"] ```pyi ``` -`/packages/foo-stubs/bar/both.py`: +`/packages/foo-stubs/bar/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -305,9 +305,9 @@ partial/n ```pyi ``` -`/packages/foo-stubs/bar/both.py`: +`/packages/foo-stubs/bar/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -380,9 +380,9 @@ pArTiAl\n ```pyi ``` -`/packages/foo-stubs/bar/both.py`: +`/packages/foo-stubs/bar/both.pyi`: -```py +```pyi class Both: both: str other: int @@ -423,3 +423,48 @@ reveal_type(Both().both) # revealed: str reveal_type(Impl().impl) # revealed: Unknown reveal_type(Fake().fake) # revealed: Unknown ``` + +## Namespace stub with missing module + +Namespace stubs are always partial. + +This is a regression test for . + +```toml +[environment] +extra-paths = ["/packages"] +``` + +`/packages/parent-stubs/foo/both.pyi`: + +```pyi +class Both: + both: str + other: int +``` + +`/packages/parent/foo/both.py`: + +```py +class Both: ... +``` + +`/packages/parent/foo/impl.py`: + +```py +class Impl: + impl: str + other: int +``` + +`main.py`: + +```py +from parent.foo.both import Both +from parent.foo.impl import Impl +from parent.foo.fake import Fake # error: "Cannot resolve" + +reveal_type(Both().both) # revealed: str +reveal_type(Impl().impl) # revealed: str +reveal_type(Fake().fake) # revealed: Unknown +``` diff --git a/crates/ty_python_semantic/src/module_resolver/resolver.rs b/crates/ty_python_semantic/src/module_resolver/resolver.rs index 783bc4dfe3ea4..d1974fac18418 100644 --- a/crates/ty_python_semantic/src/module_resolver/resolver.rs +++ b/crates/ty_python_semantic/src/module_resolver/resolver.rs @@ -723,8 +723,7 @@ fn resolve_name(db: &dyn Db, name: &ModuleName, mode: ModuleResolveMode) -> Opti `{name}` but it is a namespace package, keep going." ); // stub exists, but the module doesn't. But this is a namespace package, - // keep searching the next search path for a stub package with the same name. - continue; + // fall through to looking for a non-stub package } } } From 662d18bd0515f2a06c3bbb91fd7d6684485b1292 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Aug 2025 22:11:30 +0100 Subject: [PATCH 052/160] [ty] Add precise inference for unpacking a TypeVar if the TypeVar has an upper bound with a precise tuple spec (#19985) --- .../mdtest/generics/legacy/functions.md | 42 +++++++++++++++++++ .../mdtest/generics/pep695/functions.md | 40 ++++++++++++++++++ crates/ty_python_semantic/src/types.rs | 14 ++++++- 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/generics/legacy/functions.md b/crates/ty_python_semantic/resources/mdtest/generics/legacy/functions.md index 412243139fd31..34347ea1aac03 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/legacy/functions.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/legacy/functions.md @@ -455,3 +455,45 @@ def overloaded_outer(t: T | None = None) -> None: if t is not None: inner(t) ``` + +## Unpacking a TypeVar + +We can infer precise heterogeneous types from the result of an unpacking operation applied to a type +variable if the type variable's upper bound is a type with a precise tuple spec: + +```py +from dataclasses import dataclass +from typing import NamedTuple, Final, TypeVar, Generic + +T = TypeVar("T", bound=tuple[int, str]) + +def f(x: T) -> T: + a, b = x + reveal_type(a) # revealed: int + reveal_type(b) # revealed: str + return x + +@dataclass +class Team(Generic[T]): + employees: list[T] + +def x(team: Team[T]) -> Team[T]: + age, name = team.employees[0] + reveal_type(age) # revealed: int + reveal_type(name) # revealed: str + return team + +class Age(int): ... +class Name(str): ... + +class Employee(NamedTuple): + age: Age + name: Name + +EMPLOYEES: Final = (Employee(name=Name("alice"), age=Age(42)),) +team = Team(employees=list(EMPLOYEES)) +reveal_type(team.employees) # revealed: list[Employee] +age, name = team.employees[0] +reveal_type(age) # revealed: Age +reveal_type(name) # revealed: Name +``` diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/functions.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/functions.md index eb053739175b5..2645221f01e8b 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/functions.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/functions.md @@ -454,3 +454,43 @@ def overloaded_outer[T](t: T | None = None) -> None: if t is not None: inner(t) ``` + +## Unpacking a TypeVar + +We can infer precise heterogeneous types from the result of an unpacking operation applied to a +TypeVar if the TypeVar's upper bound is a type with a precise tuple spec: + +```py +from dataclasses import dataclass +from typing import NamedTuple, Final + +def f[T: tuple[int, str]](x: T) -> T: + a, b = x + reveal_type(a) # revealed: int + reveal_type(b) # revealed: str + return x + +@dataclass +class Team[T: tuple[int, str]]: + employees: list[T] + +def x[T: tuple[int, str]](team: Team[T]) -> Team[T]: + age, name = team.employees[0] + reveal_type(age) # revealed: int + reveal_type(name) # revealed: str + return team + +class Age(int): ... +class Name(str): ... + +class Employee(NamedTuple): + age: Age + name: Name + +EMPLOYEES: Final = (Employee(name=Name("alice"), age=Age(42)),) +team = Team(employees=list(EMPLOYEES)) +reveal_type(team.employees) # revealed: list[Employee] +age, name = team.employees[0] +reveal_type(age) # revealed: Age +reveal_type(name) # revealed: Name +``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index b0d33ee097ec0..378583d9ae103 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -4870,6 +4870,18 @@ impl<'db> Type<'db> { Type::TypeAlias(alias) => { return alias.value_type(db).try_iterate_with_mode(db, mode); } + Type::NonInferableTypeVar(tvar) => match tvar.typevar(db).bound_or_constraints(db) { + Some(TypeVarBoundOrConstraints::UpperBound(bound)) => { + return bound.try_iterate_with_mode(db, mode); + } + // TODO: could we create a "union of tuple specs"...? + // (Same question applies to the `Type::Union()` branch lower down) + Some(TypeVarBoundOrConstraints::Constraints(_)) | None => {} + }, + Type::TypeVar(_) => unreachable!( + "should not be able to iterate over type variable {} in inferable position", + self.display(db) + ), Type::Dynamic(_) | Type::FunctionLiteral(_) | Type::GenericAlias(_) @@ -4895,8 +4907,6 @@ impl<'db> Type<'db> { | Type::EnumLiteral(_) | Type::LiteralString | Type::BytesLiteral(_) - | Type::TypeVar(_) - | Type::NonInferableTypeVar(_) | Type::BoundSuper(_) | Type::TypeIs(_) | Type::TypedDict(_) => {} From e0f4cec7a160ef82b3dd233e1f517470bb6e0b63 Mon Sep 17 00:00:00 2001 From: Dan Parizher <105245560+danparizher@users.noreply.github.com> Date: Tue, 19 Aug 2025 18:12:15 -0400 Subject: [PATCH 053/160] [`pyupgrade`] Handle nested `Optional`s (`UP045`) (#19770) ## Summary Fixes #19746 --------- Co-authored-by: Brent Westbrook --- crates/ruff/tests/lint.rs | 29 ++++ .../test/fixtures/pyupgrade/UP045.py | 7 + .../pyupgrade/rules/use_pep604_annotation.rs | 16 ++- ...er__rules__pyupgrade__tests__UP045.py.snap | 131 ++++++++++++++++++ 4 files changed, 181 insertions(+), 2 deletions(-) diff --git a/crates/ruff/tests/lint.rs b/crates/ruff/tests/lint.rs index c3f908c7fe6db..b54e69996d197 100644 --- a/crates/ruff/tests/lint.rs +++ b/crates/ruff/tests/lint.rs @@ -5801,3 +5801,32 @@ fn future_annotations_preview_warning() { ", ); } + +#[test] +fn up045_nested_optional_flatten_all() { + let contents = "\ +from typing import Optional +nested_optional: Optional[Optional[Optional[str]]] = None +"; + + assert_cmd_snapshot!( + Command::new(get_cargo_bin(BIN_NAME)) + .args(STDIN_BASE_OPTIONS) + .args(["--select", "UP045", "--diff", "--target-version", "py312"]) + .arg("-") + .pass_stdin(contents), + @r" + success: false + exit_code: 1 + ----- stdout ----- + @@ -1,2 +1,2 @@ + from typing import Optional + -nested_optional: Optional[Optional[Optional[str]]] = None + +nested_optional: str | None = None + + + ----- stderr ----- + Would fix 1 error. + ", + ); +} diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP045.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP045.py index de2b18b52d739..5ac77746fb7ff 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP045.py +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP045.py @@ -69,3 +69,10 @@ class ServiceRefOrValue: a8: typing_extensions.Optional[typing.NamedTuple] = None a9: "Optional[NamedTuple]" = None a10: Optional[NamedTupleTE] = None + + +# Test for: https://github.com/astral-sh/ruff/issues/19746 +# Nested Optional types should be flattened +nested_optional: Optional[Optional[str]] = None +nested_optional_typing: typing.Optional[Optional[int]] = None +triple_nested_optional: Optional[Optional[Optional[str]]] = None diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs index a6a5b7187a953..784bc5c65e5e5 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/use_pep604_annotation.rs @@ -2,7 +2,7 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::PythonVersion; use ruff_python_ast::helpers::{pep_604_optional, pep_604_union}; use ruff_python_ast::{self as ast, Expr}; -use ruff_python_semantic::analyze::typing::Pep604Operator; +use ruff_python_semantic::analyze::typing::{Pep604Operator, to_pep604_operator}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -171,10 +171,22 @@ pub(crate) fn non_pep604_annotation( // Invalid type annotation. } _ => { + // Unwrap all nested Optional[...] and wrap once as `X | None`. + let mut inner = slice; + while let Expr::Subscript(ast::ExprSubscript { value, slice, .. }) = inner { + if let Some(Pep604Operator::Optional) = + to_pep604_operator(value, slice, checker.semantic()) + { + inner = slice; + } else { + break; + } + } + diagnostic.set_fix(Fix::applicable_edit( Edit::range_replacement( pad( - checker.generator().expr(&pep_604_optional(slice)), + checker.generator().expr(&pep_604_optional(inner)), expr.range(), checker.locator(), ), diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP045.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP045.py.snap index 5d03d490cddb2..e753f42872330 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP045.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP045.py.snap @@ -171,3 +171,134 @@ UP045 Use `X | None` for type annotations | ^^^^^^^^^^^^^^ | help: Convert to `X | None` + +UP045 [*] Use `X | None` for type annotations + --> UP045.py:76:18 + | +74 | # Test for: https://github.com/astral-sh/ruff/issues/19746 +75 | # Nested Optional types should be flattened +76 | nested_optional: Optional[Optional[str]] = None + | ^^^^^^^^^^^^^^^^^^^^^^^ +77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + | +help: Convert to `X | None` + +ℹ Safe fix +73 73 | +74 74 | # Test for: https://github.com/astral-sh/ruff/issues/19746 +75 75 | # Nested Optional types should be flattened +76 |-nested_optional: Optional[Optional[str]] = None + 76 |+nested_optional: str | None = None +77 77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + +UP045 [*] Use `X | None` for type annotations + --> UP045.py:76:27 + | +74 | # Test for: https://github.com/astral-sh/ruff/issues/19746 +75 | # Nested Optional types should be flattened +76 | nested_optional: Optional[Optional[str]] = None + | ^^^^^^^^^^^^^ +77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + | +help: Convert to `X | None` + +ℹ Safe fix +73 73 | +74 74 | # Test for: https://github.com/astral-sh/ruff/issues/19746 +75 75 | # Nested Optional types should be flattened +76 |-nested_optional: Optional[Optional[str]] = None + 76 |+nested_optional: Optional[str | None] = None +77 77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + +UP045 [*] Use `X | None` for type annotations + --> UP045.py:77:25 + | +75 | # Nested Optional types should be flattened +76 | nested_optional: Optional[Optional[str]] = None +77 | nested_optional_typing: typing.Optional[Optional[int]] = None + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + | +help: Convert to `X | None` + +ℹ Safe fix +74 74 | # Test for: https://github.com/astral-sh/ruff/issues/19746 +75 75 | # Nested Optional types should be flattened +76 76 | nested_optional: Optional[Optional[str]] = None +77 |-nested_optional_typing: typing.Optional[Optional[int]] = None + 77 |+nested_optional_typing: int | None = None +78 78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + +UP045 [*] Use `X | None` for type annotations + --> UP045.py:77:41 + | +75 | # Nested Optional types should be flattened +76 | nested_optional: Optional[Optional[str]] = None +77 | nested_optional_typing: typing.Optional[Optional[int]] = None + | ^^^^^^^^^^^^^ +78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + | +help: Convert to `X | None` + +ℹ Safe fix +74 74 | # Test for: https://github.com/astral-sh/ruff/issues/19746 +75 75 | # Nested Optional types should be flattened +76 76 | nested_optional: Optional[Optional[str]] = None +77 |-nested_optional_typing: typing.Optional[Optional[int]] = None + 77 |+nested_optional_typing: typing.Optional[int | None] = None +78 78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + +UP045 [*] Use `X | None` for type annotations + --> UP045.py:78:25 + | +76 | nested_optional: Optional[Optional[str]] = None +77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Convert to `X | None` + +ℹ Safe fix +75 75 | # Nested Optional types should be flattened +76 76 | nested_optional: Optional[Optional[str]] = None +77 77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 |-triple_nested_optional: Optional[Optional[Optional[str]]] = None + 78 |+triple_nested_optional: str | None = None + +UP045 [*] Use `X | None` for type annotations + --> UP045.py:78:34 + | +76 | nested_optional: Optional[Optional[str]] = None +77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Convert to `X | None` + +ℹ Safe fix +75 75 | # Nested Optional types should be flattened +76 76 | nested_optional: Optional[Optional[str]] = None +77 77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 |-triple_nested_optional: Optional[Optional[Optional[str]]] = None + 78 |+triple_nested_optional: Optional[str | None] = None + +UP045 [*] Use `X | None` for type annotations + --> UP045.py:78:43 + | +76 | nested_optional: Optional[Optional[str]] = None +77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 | triple_nested_optional: Optional[Optional[Optional[str]]] = None + | ^^^^^^^^^^^^^ + | +help: Convert to `X | None` + +ℹ Safe fix +75 75 | # Nested Optional types should be flattened +76 76 | nested_optional: Optional[Optional[str]] = None +77 77 | nested_optional_typing: typing.Optional[Optional[int]] = None +78 |-triple_nested_optional: Optional[Optional[Optional[str]]] = None + 78 |+triple_nested_optional: Optional[Optional[str | None]] = None From 656fc335f2b93779e635d609166897503c9cee4a Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Tue, 19 Aug 2025 23:45:41 +0100 Subject: [PATCH 054/160] [ty] Strict validation of protocol members (#17750) --- crates/ty/docs/rules.md | 165 +++++++++++------- .../resources/mdtest/protocols.md | 109 ++++++++++-- ..._prot\342\200\246_(585a3e9545d41b64).snap" | 140 +++++++++++++++ ...s_in_\342\200\246_(21be5d9bdab1c844).snap" | 68 ++++++++ .../src/semantic_index/definition.rs | 4 + .../src/types/diagnostic.rs | 133 +++++++++++++- crates/ty_python_semantic/src/types/infer.rs | 4 + .../src/types/protocol_class.rs | 62 ++++++- ty.schema.json | 12 +- 9 files changed, 619 insertions(+), 78 deletions(-) create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Diagnostics_for_prot\342\200\246_(585a3e9545d41b64).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Protocol_members_in_\342\200\246_(21be5d9bdab1c844).snap" diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index 1e190e7dd6f89..cd207b21f3dcd 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -36,7 +36,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-non-callable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L104) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L109) **What it does** @@ -58,7 +58,7 @@ Calling a non-callable object will raise a `TypeError` at runtime. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-argument-forms) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L148) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L153) **What it does** @@ -88,7 +88,7 @@ f(int) # error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-declarations) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L174) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L179) **What it does** @@ -117,7 +117,7 @@ a = 1 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L199) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L204) **What it does** @@ -147,7 +147,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20cyclic-class-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L225) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L230) **What it does** @@ -177,7 +177,7 @@ class B(A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L290) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L295) **What it does** @@ -202,7 +202,7 @@ class B(A, A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-kw-only) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L311) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L316) **What it does** @@ -306,7 +306,7 @@ def test(): -> "Literal[5]": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20inconsistent-mro) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L479) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L519) **What it does** @@ -334,7 +334,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20index-out-of-bounds) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L503) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L543) **What it does** @@ -358,7 +358,7 @@ t[3] # IndexError: tuple index out of range Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20instance-layout-conflict) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L343) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L348) **What it does** @@ -445,7 +445,7 @@ an atypical memory layout. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-argument-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L548) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L588) **What it does** @@ -470,7 +470,7 @@ func("foo") # error: [invalid-argument-type] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-assignment) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L588) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L628) **What it does** @@ -496,7 +496,7 @@ a: int = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-attribute-access) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1622) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1662) **What it does** @@ -528,7 +528,7 @@ C.instance_var = 3 # error: Cannot assign to instance variable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-await) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L610) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L650) **What it does** @@ -562,7 +562,7 @@ asyncio.run(main()) Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L640) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L680) **What it does** @@ -584,7 +584,7 @@ class A(42): ... # error: [invalid-base] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-context-manager) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L691) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L731) **What it does** @@ -609,7 +609,7 @@ with 1: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-declaration) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L712) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L752) **What it does** @@ -636,7 +636,7 @@ a: str Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-exception-caught) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L735) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L775) **What it does** @@ -678,7 +678,7 @@ except ZeroDivisionError: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-generic-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L771) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L811) **What it does** @@ -709,7 +709,7 @@ class C[U](Generic[T]): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-key) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L523) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L563) **What it does** @@ -738,7 +738,7 @@ alice["height"] # KeyError: 'height' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-legacy-type-variable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L797) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L837) **What it does** @@ -771,7 +771,7 @@ def f(t: TypeVar("U")): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L846) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L886) **What it does** @@ -803,7 +803,7 @@ class B(metaclass=f): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-named-tuple) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L453) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L493) **What it does** @@ -833,7 +833,7 @@ TypeError: can only inherit from a NamedTuple type and Generic Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L873) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L913) **What it does** @@ -881,7 +881,7 @@ def foo(x: int) -> int: ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-parameter-default) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L916) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L956) **What it does** @@ -905,12 +905,12 @@ def f(a: int = ''): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-protocol) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L425) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L430) **What it does** -Checks for invalidly defined protocol classes. +Checks for protocol classes that will raise `TypeError` at runtime. **Why is this bad?** @@ -937,7 +937,7 @@ TypeError: Protocols can only inherit from other protocols, got Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-raise) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L936) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L976) Checks for `raise` statements that raise non-exceptions or use invalid @@ -984,7 +984,7 @@ def g(): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-return-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L569) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L609) **What it does** @@ -1007,7 +1007,7 @@ def func() -> int: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-super-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L979) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1019) **What it does** @@ -1061,7 +1061,7 @@ TODO #14889 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-alias-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L825) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L865) **What it does** @@ -1086,7 +1086,7 @@ NewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name mus Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-checking-constant) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1018) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1058) **What it does** @@ -1114,7 +1114,7 @@ TYPE_CHECKING = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-form) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1042) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1082) **What it does** @@ -1142,7 +1142,7 @@ b: Annotated[int] # `Annotated` expects at least two arguments Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1094) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1134) **What it does** @@ -1174,7 +1174,7 @@ f(10) # Error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1066) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1106) **What it does** @@ -1206,7 +1206,7 @@ class C: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-variable-constraints) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1122) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1162) **What it does** @@ -1239,7 +1239,7 @@ T = TypeVar('T', bound=str) # valid bound TypeVar Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1151) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1191) **What it does** @@ -1262,7 +1262,7 @@ func() # TypeError: func() missing 1 required positional argument: 'x' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20no-matching-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1170) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1210) **What it does** @@ -1289,7 +1289,7 @@ func("string") # error: [no-matching-overload] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20non-subscriptable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1193) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1233) **What it does** @@ -1311,7 +1311,7 @@ Subscripting an object that does not support it will raise a `TypeError` at runt Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20not-iterable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1211) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1251) **What it does** @@ -1335,7 +1335,7 @@ for i in 34: # TypeError: 'int' object is not iterable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20parameter-already-assigned) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1262) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1302) **What it does** @@ -1389,7 +1389,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20static-assert-error) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1598) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1638) **What it does** @@ -1417,7 +1417,7 @@ static_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known tr Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20subclass-of-final-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1353) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1393) **What it does** @@ -1444,7 +1444,7 @@ class B(A): ... # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20too-many-positional-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1398) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1438) **What it does** @@ -1469,7 +1469,7 @@ f("foo") # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20type-assertion-failure) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1376) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1416) **What it does** @@ -1495,7 +1495,7 @@ def _(x: int): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unavailable-implicit-super-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1419) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1459) **What it does** @@ -1539,7 +1539,7 @@ class A: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unknown-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1476) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1516) **What it does** @@ -1564,7 +1564,7 @@ f(x=1, y=2) # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1497) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1537) **What it does** @@ -1590,7 +1590,7 @@ A().foo # AttributeError: 'A' object has no attribute 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1519) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1559) **What it does** @@ -1613,7 +1613,7 @@ import foo # ModuleNotFoundError: No module named 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1538) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1578) **What it does** @@ -1636,7 +1636,7 @@ print(x) # NameError: name 'x' is not defined Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-bool-conversion) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1231) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1271) **What it does** @@ -1671,7 +1671,7 @@ b1 < b2 < b1 # exception raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-operator) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1557) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1597) **What it does** @@ -1697,7 +1697,7 @@ A() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20zero-stepsize-in-slice) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1579) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1619) **What it does** @@ -1715,12 +1715,51 @@ l = list(range(10)) l[1:10:0] # ValueError: slice step cannot be zero ``` +## `ambiguous-protocol-member` + + +Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · +[Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20ambiguous-protocol-member) · +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L458) + + +**What it does** + +Checks for protocol classes with members that will lead to ambiguous interfaces. + +**Why is this bad?** + +Assigning to an undeclared variable in a protocol class leads to an ambiguous +interface which may lead to the type checker inferring unexpected things. It's +recommended to ensure that all members of a protocol class are explicitly declared. + +**Examples** + + +```py +from typing import Protocol + +class BaseProto(Protocol): + a: int # fine (explicitly declared as `int`) + def method_member(self) -> int: ... # fine: a method definition using `def` is considered a declaration + c = "some variable" # error: no explicit declaration, leading to ambiguity + b = method_member # error: no explicit declaration, leading to ambiguity + + # error: this creates implicit assignments of `d` and `e` in the protocol class body. + # Were they really meant to be considered protocol members? + for d, e in enumerate(range(42)): + pass + +class SubProto(BaseProto, Protocol): + a = 42 # fine (declared in superclass) +``` + ## `deprecated` Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20deprecated) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L269) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L274) **What it does** @@ -1773,7 +1812,7 @@ a = 20 / 0 # type: ignore Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1283) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1323) **What it does** @@ -1799,7 +1838,7 @@ A.c # AttributeError: type object 'A' has no attribute 'c' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-implicit-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L122) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L127) **What it does** @@ -1829,7 +1868,7 @@ A()[0] # TypeError: 'A' object is not subscriptable Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1305) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1345) **What it does** @@ -1859,7 +1898,7 @@ from module import a # ImportError: cannot import name 'a' from 'module' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20redundant-cast) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1650) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1690) **What it does** @@ -1884,7 +1923,7 @@ cast(int, f()) # Redundant Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20undefined-reveal) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1458) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1498) **What it does** @@ -1935,7 +1974,7 @@ a = 20 / 0 # ty: ignore[division-by-zero] Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-global) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1671) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1711) **What it does** @@ -1989,7 +2028,7 @@ def g(): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L658) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L698) **What it does** @@ -2026,7 +2065,7 @@ class D(C): ... # error: [unsupported-base] Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20division-by-zero) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L251) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L256) **What it does** @@ -2048,7 +2087,7 @@ Dividing by zero raises a `ZeroDivisionError` at runtime. Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1331) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1371) **What it does** diff --git a/crates/ty_python_semantic/resources/mdtest/protocols.md b/crates/ty_python_semantic/resources/mdtest/protocols.md index ae8dc65d9ddde..5ad6f576d518d 100644 --- a/crates/ty_python_semantic/resources/mdtest/protocols.md +++ b/crates/ty_python_semantic/resources/mdtest/protocols.md @@ -482,6 +482,8 @@ reveal_type(get_protocol_members(Baz2)) ## Protocol members in statically known branches + + The list of protocol members does not include any members declared in branches that are statically known to be unreachable: @@ -492,7 +494,7 @@ python-version = "3.9" ```py import sys -from typing_extensions import Protocol, get_protocol_members +from typing_extensions import Protocol, get_protocol_members, reveal_type class Foo(Protocol): if sys.version_info >= (3, 10): @@ -501,7 +503,7 @@ class Foo(Protocol): def c(self) -> None: ... else: d: int - e = 56 + e = 56 # error: [ambiguous-protocol-member] def f(self) -> None: ... reveal_type(get_protocol_members(Foo)) # revealed: frozenset[Literal["d", "e", "f"]] @@ -797,9 +799,9 @@ def f(arg: HasXWithDefault): ``` Assignments in a class body of a protocol -- of any kind -- are not permitted by ty unless the -symbol being assigned to is also explicitly declared in the protocol's class body. Note that this is -stricter validation of protocol members than many other type checkers currently apply (as of -2025/04/21). +symbol being assigned to is also explicitly declared in the body of the protocol class or one of its +superclasses. Note that this is stricter validation of protocol members than many other type +checkers currently apply (as of 2025/04/21). The reason for this strict validation is that undeclared variables in the class body would lead to an ambiguous interface being declared by the protocol. @@ -823,24 +825,75 @@ class LotsOfBindings(Protocol): class Nested: ... # also weird, but we should also probably allow it class NestedProtocol(Protocol): ... # same here... - e = 72 # TODO: this should error with `[invalid-protocol]` (`e` is not declared) + e = 72 # error: [ambiguous-protocol-member] - f, g = (1, 2) # TODO: this should error with `[invalid-protocol]` (`f` and `g` are not declared) + # error: [ambiguous-protocol-member] "Consider adding an annotation, e.g. `f: int = ...`" + # error: [ambiguous-protocol-member] "Consider adding an annotation, e.g. `g: int = ...`" + f, g = (1, 2) - h: int = (i := 3) # TODO: this should error with `[invalid-protocol]` (`i` is not declared) + h: int = (i := 3) # error: [ambiguous-protocol-member] - for j in range(42): # TODO: this should error with `[invalid-protocol]` (`j` is not declared) + for j in range(42): # error: [ambiguous-protocol-member] pass - with MyContext() as k: # TODO: this should error with `[invalid-protocol]` (`k` is not declared) + with MyContext() as k: # error: [ambiguous-protocol-member] pass match object(): - case l: # TODO: this should error with `[invalid-protocol]` (`l` is not declared) + case l: # error: [ambiguous-protocol-member] ... # revealed: frozenset[Literal["Nested", "NestedProtocol", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]] reveal_type(get_protocol_members(LotsOfBindings)) + +class Foo(Protocol): + a: int + +class Bar(Foo, Protocol): + a = 42 # fine, because it's declared in the superclass + +reveal_type(get_protocol_members(Bar)) # revealed: frozenset[Literal["a"]] +``` + +A binding-without-declaration will not be reported if it occurs in a branch that we can statically +determine to be unreachable. The reason is that we don't consider it to be a protocol member at all +if all definitions for the variable are in unreachable blocks: + +```py +import sys + +class Protocol694(Protocol): + if sys.version_info > (3, 694): + x = 42 # no error! +``` + +If there are multiple bindings of the variable in the class body, however, and at least one of the +bindings occurs in a block of code that is understood to be (possibly) reachable, a diagnostic will +be reported. The diagnostic will be attached to the first binding that occurs in the class body, +even if that first definition occurs in an unreachable block: + +```py +class Protocol695(Protocol): + if sys.version_info > (3, 695): + x = 42 + else: + x = 42 + + x = 56 # error: [ambiguous-protocol-member] +``` + +In order for the variable to be considered declared, the declaration of the variable must also take +place in a block of code that is understood to be (possibly) reachable: + +```py +class Protocol696(Protocol): + if sys.version_info > (3, 696): + x: int + else: + x = 42 # error: [ambiguous-protocol-member] + y: int + + y = 56 # no error ``` Attribute members are allowed to have assignments in methods on the protocol class, just like @@ -943,6 +996,40 @@ static_assert(not is_assignable_to(HasX, Foo)) static_assert(not is_subtype_of(HasX, Foo)) ``` +## Diagnostics for protocols with invalid attribute members + +This is a short appendix to the previous section with the `snapshot-diagnostics` directive enabled +(enabling snapshots for the previous section in its entirety would lead to a huge snapshot, since +it's a large section). + + + +```py +from typing import Protocol + +def coinflip() -> bool: + return True + +class A(Protocol): + # The `x` and `y` members attempt to use Python-2-style type comments + # to indicate that the type should be `int | None` and `str` respectively, + # but we don't support those + + # error: [ambiguous-protocol-member] + a = None # type: int + # error: [ambiguous-protocol-member] + b = ... # type: str + + if coinflip(): + c = 1 # error: [ambiguous-protocol-member] + else: + c = 2 + + # error: [ambiguous-protocol-member] + for d in range(42): + pass +``` + ## Equivalence of protocols Two protocols are considered equivalent types if they specify the same interface, even if they have diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Diagnostics_for_prot\342\200\246_(585a3e9545d41b64).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Diagnostics_for_prot\342\200\246_(585a3e9545d41b64).snap" new file mode 100644 index 0000000000000..425665b4868e7 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Diagnostics_for_prot\342\200\246_(585a3e9545d41b64).snap" @@ -0,0 +1,140 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: protocols.md - Protocols - Diagnostics for protocols with invalid attribute members +mdtest path: crates/ty_python_semantic/resources/mdtest/protocols.md +--- + +# Python source files + +## mdtest_snippet.py + +``` + 1 | from typing import Protocol + 2 | + 3 | def coinflip() -> bool: + 4 | return True + 5 | + 6 | class A(Protocol): + 7 | # The `x` and `y` members attempt to use Python-2-style type comments + 8 | # to indicate that the type should be `int | None` and `str` respectively, + 9 | # but we don't support those +10 | +11 | # error: [ambiguous-protocol-member] +12 | a = None # type: int +13 | # error: [ambiguous-protocol-member] +14 | b = ... # type: str +15 | +16 | if coinflip(): +17 | c = 1 # error: [ambiguous-protocol-member] +18 | else: +19 | c = 2 +20 | +21 | # error: [ambiguous-protocol-member] +22 | for d in range(42): +23 | pass +``` + +# Diagnostics + +``` +warning[ambiguous-protocol-member]: Cannot assign to undeclared variable in the body of a protocol class + --> src/mdtest_snippet.py:12:5 + | +11 | # error: [ambiguous-protocol-member] +12 | a = None # type: int + | ^^^^^^^^ Consider adding an annotation for `a` +13 | # error: [ambiguous-protocol-member] +14 | b = ... # type: str + | +info: Assigning to an undeclared variable in a protocol class leads to an ambiguous interface + --> src/mdtest_snippet.py:6:7 + | +4 | return True +5 | +6 | class A(Protocol): + | ^^^^^^^^^^^ `A` declared as a protocol here +7 | # The `x` and `y` members attempt to use Python-2-style type comments +8 | # to indicate that the type should be `int | None` and `str` respectively, + | +info: No declarations found for `a` in the body of `A` or any of its superclasses +info: rule `ambiguous-protocol-member` is enabled by default + +``` + +``` +warning[ambiguous-protocol-member]: Cannot assign to undeclared variable in the body of a protocol class + --> src/mdtest_snippet.py:14:5 + | +12 | a = None # type: int +13 | # error: [ambiguous-protocol-member] +14 | b = ... # type: str + | ^^^^^^^ Consider adding an annotation for `b` +15 | +16 | if coinflip(): + | +info: Assigning to an undeclared variable in a protocol class leads to an ambiguous interface + --> src/mdtest_snippet.py:6:7 + | +4 | return True +5 | +6 | class A(Protocol): + | ^^^^^^^^^^^ `A` declared as a protocol here +7 | # The `x` and `y` members attempt to use Python-2-style type comments +8 | # to indicate that the type should be `int | None` and `str` respectively, + | +info: No declarations found for `b` in the body of `A` or any of its superclasses +info: rule `ambiguous-protocol-member` is enabled by default + +``` + +``` +warning[ambiguous-protocol-member]: Cannot assign to undeclared variable in the body of a protocol class + --> src/mdtest_snippet.py:17:9 + | +16 | if coinflip(): +17 | c = 1 # error: [ambiguous-protocol-member] + | ^^^^^ Consider adding an annotation, e.g. `c: int = ...` +18 | else: +19 | c = 2 + | +info: Assigning to an undeclared variable in a protocol class leads to an ambiguous interface + --> src/mdtest_snippet.py:6:7 + | +4 | return True +5 | +6 | class A(Protocol): + | ^^^^^^^^^^^ `A` declared as a protocol here +7 | # The `x` and `y` members attempt to use Python-2-style type comments +8 | # to indicate that the type should be `int | None` and `str` respectively, + | +info: No declarations found for `c` in the body of `A` or any of its superclasses +info: rule `ambiguous-protocol-member` is enabled by default + +``` + +``` +warning[ambiguous-protocol-member]: Cannot assign to undeclared variable in the body of a protocol class + --> src/mdtest_snippet.py:22:9 + | +21 | # error: [ambiguous-protocol-member] +22 | for d in range(42): + | ^ `d` is not declared as a protocol member +23 | pass + | +info: Assigning to an undeclared variable in a protocol class leads to an ambiguous interface + --> src/mdtest_snippet.py:6:7 + | +4 | return True +5 | +6 | class A(Protocol): + | ^^^^^^^^^^^ `A` declared as a protocol here +7 | # The `x` and `y` members attempt to use Python-2-style type comments +8 | # to indicate that the type should be `int | None` and `str` respectively, + | +info: No declarations found for `d` in the body of `A` or any of its superclasses +info: rule `ambiguous-protocol-member` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Protocol_members_in_\342\200\246_(21be5d9bdab1c844).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Protocol_members_in_\342\200\246_(21be5d9bdab1c844).snap" new file mode 100644 index 0000000000000..d7436cbec743e --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/protocols.md_-_Protocols_-_Protocol_members_in_\342\200\246_(21be5d9bdab1c844).snap" @@ -0,0 +1,68 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: protocols.md - Protocols - Protocol members in statically known branches +mdtest path: crates/ty_python_semantic/resources/mdtest/protocols.md +--- + +# Python source files + +## mdtest_snippet.py + +``` + 1 | import sys + 2 | from typing_extensions import Protocol, get_protocol_members, reveal_type + 3 | + 4 | class Foo(Protocol): + 5 | if sys.version_info >= (3, 10): + 6 | a: int + 7 | b = 42 + 8 | def c(self) -> None: ... + 9 | else: +10 | d: int +11 | e = 56 # error: [ambiguous-protocol-member] +12 | def f(self) -> None: ... +13 | +14 | reveal_type(get_protocol_members(Foo)) # revealed: frozenset[Literal["d", "e", "f"]] +``` + +# Diagnostics + +``` +warning[ambiguous-protocol-member]: Cannot assign to undeclared variable in the body of a protocol class + --> src/mdtest_snippet.py:11:9 + | + 9 | else: +10 | d: int +11 | e = 56 # error: [ambiguous-protocol-member] + | ^^^^^^ Consider adding an annotation, e.g. `e: int = ...` +12 | def f(self) -> None: ... + | +info: Assigning to an undeclared variable in a protocol class leads to an ambiguous interface + --> src/mdtest_snippet.py:4:7 + | +2 | from typing_extensions import Protocol, get_protocol_members, reveal_type +3 | +4 | class Foo(Protocol): + | ^^^^^^^^^^^^^ `Foo` declared as a protocol here +5 | if sys.version_info >= (3, 10): +6 | a: int + | +info: No declarations found for `e` in the body of `Foo` or any of its superclasses +info: rule `ambiguous-protocol-member` is enabled by default + +``` + +``` +info[revealed-type]: Revealed type + --> src/mdtest_snippet.py:14:13 + | +12 | def f(self) -> None: ... +13 | +14 | reveal_type(get_protocol_members(Foo)) # revealed: frozenset[Literal["d", "e", "f"]] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ `frozenset[Literal["d", "e", "f"]]` + | + +``` diff --git a/crates/ty_python_semantic/src/semantic_index/definition.rs b/crates/ty_python_semantic/src/semantic_index/definition.rs index 0e44e1a9c49e0..2e2ff104de12a 100644 --- a/crates/ty_python_semantic/src/semantic_index/definition.rs +++ b/crates/ty_python_semantic/src/semantic_index/definition.rs @@ -702,6 +702,10 @@ impl DefinitionKind<'_> { ) } + pub(crate) const fn is_unannotated_assignment(&self) -> bool { + matches!(self, DefinitionKind::Assignment(_)) + } + pub(crate) fn as_typevar(&self) -> Option<&AstNodeRef> { match self { DefinitionKind::TypeVar(type_var) => Some(type_var), diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index bbbeff5044131..4930dd4f9e5f6 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -7,8 +7,9 @@ use super::{ }; use crate::lint::{Level, LintRegistryBuilder, LintStatus}; use crate::semantic_index::SemanticIndex; +use crate::semantic_index::definition::Definition; +use crate::semantic_index::place::{PlaceTable, ScopedPlaceId}; use crate::suppression::FileSuppressionId; -use crate::types::LintDiagnosticGuard; use crate::types::class::{Field, SolidBase, SolidBaseKind}; use crate::types::function::KnownFunction; use crate::types::string_annotation::{ @@ -16,6 +17,9 @@ use crate::types::string_annotation::{ IMPLICIT_CONCATENATED_STRING_TYPE_ANNOTATION, INVALID_SYNTAX_IN_FORWARD_ANNOTATION, RAW_STRING_TYPE_ANNOTATION, }; +use crate::types::{ + DynamicType, LintDiagnosticGuard, Protocol, ProtocolInstanceType, SubclassOfInner, binding_type, +}; use crate::types::{SpecialFormType, Type, protocol_class::ProtocolClassLiteral}; use crate::util::diagnostics::format_enumeration; use crate::{Db, FxIndexMap, FxOrderMap, Module, ModuleName, Program, declare_lint}; @@ -29,6 +33,7 @@ use std::fmt::Formatter; /// Registers all known type check lints. pub(crate) fn register_lints(registry: &mut LintRegistryBuilder) { + registry.register_lint(&AMBIGUOUS_PROTOCOL_MEMBER); registry.register_lint(&CALL_NON_CALLABLE); registry.register_lint(&POSSIBLY_UNBOUND_IMPLICIT_CALL); registry.register_lint(&CONFLICTING_ARGUMENT_FORMS); @@ -424,7 +429,7 @@ declare_lint! { declare_lint! { /// ## What it does - /// Checks for invalidly defined protocol classes. + /// Checks for protocol classes that will raise `TypeError` at runtime. /// /// ## Why is this bad? /// An invalidly defined protocol class may lead to the type checker inferring @@ -450,6 +455,41 @@ declare_lint! { } } +declare_lint! { + /// ## What it does + /// Checks for protocol classes with members that will lead to ambiguous interfaces. + /// + /// ## Why is this bad? + /// Assigning to an undeclared variable in a protocol class leads to an ambiguous + /// interface which may lead to the type checker inferring unexpected things. It's + /// recommended to ensure that all members of a protocol class are explicitly declared. + /// + /// ## Examples + /// + /// ```py + /// from typing import Protocol + /// + /// class BaseProto(Protocol): + /// a: int # fine (explicitly declared as `int`) + /// def method_member(self) -> int: ... # fine: a method definition using `def` is considered a declaration + /// c = "some variable" # error: no explicit declaration, leading to ambiguity + /// b = method_member # error: no explicit declaration, leading to ambiguity + /// + /// # error: this creates implicit assignments of `d` and `e` in the protocol class body. + /// # Were they really meant to be considered protocol members? + /// for d, e in enumerate(range(42)): + /// pass + /// + /// class SubProto(BaseProto, Protocol): + /// a = 42 # fine (declared in superclass) + /// ``` + pub(crate) static AMBIGUOUS_PROTOCOL_MEMBER = { + summary: "detects protocol classes with ambiguous interfaces", + status: LintStatus::preview("1.0.0"), + default_level: Level::Warn, + } +} + declare_lint! { /// ## What it does /// Checks for invalidly defined `NamedTuple` classes. @@ -2456,6 +2496,95 @@ pub(crate) fn report_attempted_protocol_instantiation( diagnostic.sub(class_def_diagnostic); } +pub(crate) fn report_undeclared_protocol_member( + context: &InferContext, + definition: Definition, + protocol_class: ProtocolClassLiteral, + class_symbol_table: &PlaceTable, +) { + /// We want to avoid suggesting an annotation for e.g. `x = None`, + /// because the user almost certainly doesn't want to write `x: None = None`. + /// We also want to avoid suggesting invalid syntax such as `x: = int`. + fn should_give_hint<'db>(db: &'db dyn Db, ty: Type<'db>) -> bool { + let class = match ty { + Type::ProtocolInstance(ProtocolInstanceType { + inner: Protocol::FromClass(_), + .. + }) => return true, + Type::SubclassOf(subclass_of) => match subclass_of.subclass_of() { + SubclassOfInner::Class(class) => class, + SubclassOfInner::Dynamic(DynamicType::Any) => return true, + SubclassOfInner::Dynamic(_) => return false, + }, + Type::NominalInstance(instance) => instance.class(db), + _ => return false, + }; + + !matches!( + class.known(db), + Some(KnownClass::NoneType | KnownClass::EllipsisType) + ) + } + + let db = context.db(); + + let Some(builder) = context.report_lint( + &AMBIGUOUS_PROTOCOL_MEMBER, + definition.full_range(db, context.module()), + ) else { + return; + }; + + let ScopedPlaceId::Symbol(symbol_id) = definition.place(db) else { + return; + }; + + let symbol_name = class_symbol_table.symbol(symbol_id).name(); + let class_name = protocol_class.name(db); + + let mut diagnostic = builder + .into_diagnostic("Cannot assign to undeclared variable in the body of a protocol class"); + + if definition.kind(db).is_unannotated_assignment() { + let binding_type = binding_type(db, definition); + + let suggestion = binding_type + .literal_fallback_instance(db) + .unwrap_or(binding_type); + + if should_give_hint(db, suggestion) { + diagnostic.set_primary_message(format_args!( + "Consider adding an annotation, e.g. `{symbol_name}: {} = ...`", + suggestion.display(db) + )); + } else { + diagnostic.set_primary_message(format_args!( + "Consider adding an annotation for `{symbol_name}`" + )); + } + } else { + diagnostic.set_primary_message(format_args!( + "`{symbol_name}` is not declared as a protocol member" + )); + } + + let mut class_def_diagnostic = SubDiagnostic::new( + SubDiagnosticSeverity::Info, + "Assigning to an undeclared variable in a protocol class \ + leads to an ambiguous interface", + ); + class_def_diagnostic.annotate( + Annotation::primary(protocol_class.header_span(db)) + .message(format_args!("`{class_name}` declared as a protocol here",)), + ); + diagnostic.sub(class_def_diagnostic); + + diagnostic.info(format_args!( + "No declarations found for `{symbol_name}` \ + in the body of `{class_name}` or any of its superclasses" + )); +} + pub(crate) fn report_duplicate_bases( context: &InferContext, class: ClassLiteral, diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 86a289d300007..5502715e381d2 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -1434,6 +1434,10 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } } + + if let Some(protocol) = class.into_protocol_class(self.db()) { + protocol.validate_members(&self.context, self.index); + } } } diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index 2d5c996a8f086..12fb5fb988273 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -7,7 +7,10 @@ use ruff_python_ast::name::Name; use rustc_hash::FxHashMap; use super::TypeVarVariance; -use crate::semantic_index::place_table; +use crate::semantic_index::place::ScopedPlaceId; +use crate::semantic_index::{SemanticIndex, place_table}; +use crate::types::context::InferContext; +use crate::types::diagnostic::report_undeclared_protocol_member; use crate::{ Db, FxOrderSet, place::{Boundness, Place, PlaceAndQualifiers, place_from_bindings, place_from_declarations}, @@ -55,6 +58,59 @@ impl<'db> ProtocolClassLiteral<'db> { self.known_function_decorators(db) .contains(&KnownFunction::RuntimeCheckable) } + + /// Iterate through the body of the protocol class. Check that all definitions + /// in the protocol class body are either explicitly declared directly in the + /// class body, or are declared in a superclass of the protocol class. + pub(super) fn validate_members(self, context: &InferContext, index: &SemanticIndex<'db>) { + let db = context.db(); + let interface = self.interface(db); + let class_place_table = index.place_table(self.body_scope(db).file_scope_id(db)); + + for (symbol_id, mut bindings_iterator) in + use_def_map(db, self.body_scope(db)).all_end_of_scope_symbol_bindings() + { + let symbol_name = class_place_table.symbol(symbol_id).name(); + + if !interface.includes_member(db, symbol_name) { + continue; + } + + let has_declaration = self + .iter_mro(db, None) + .filter_map(ClassBase::into_class) + .any(|superclass| { + let superclass_scope = superclass.class_literal(db).0.body_scope(db); + let Some(scoped_symbol_id) = + place_table(db, superclass_scope).symbol_id(symbol_name) + else { + return false; + }; + !place_from_declarations( + db, + index + .use_def_map(superclass_scope.file_scope_id(db)) + .end_of_scope_declarations(ScopedPlaceId::Symbol(scoped_symbol_id)), + ) + .into_place_and_conflicting_declarations() + .0 + .place + .is_unbound() + }); + + if has_declaration { + continue; + } + + let Some(first_definition) = + bindings_iterator.find_map(|binding| binding.binding.definition()) + else { + continue; + }; + + report_undeclared_protocol_member(context, first_definition, self, class_place_table); + } + } } impl<'db> Deref for ProtocolClassLiteral<'db> { @@ -147,6 +203,10 @@ impl<'db> ProtocolInterface<'db> { }) } + pub(super) fn includes_member(self, db: &'db dyn Db, name: &str) -> bool { + self.inner(db).contains_key(name) + } + pub(super) fn instance_member(self, db: &'db dyn Db, name: &str) -> PlaceAndQualifiers<'db> { self.member_by_name(db, name) .map(|member| PlaceAndQualifiers { diff --git a/ty.schema.json b/ty.schema.json index f6043e2d8f706..c8b9668506900 100644 --- a/ty.schema.json +++ b/ty.schema.json @@ -271,6 +271,16 @@ "Rules": { "type": "object", "properties": { + "ambiguous-protocol-member": { + "title": "detects protocol classes with ambiguous interfaces", + "description": "## What it does\nChecks for protocol classes with members that will lead to ambiguous interfaces.\n\n## Why is this bad?\nAssigning to an undeclared variable in a protocol class leads to an ambiguous\ninterface which may lead to the type checker inferring unexpected things. It's\nrecommended to ensure that all members of a protocol class are explicitly declared.\n\n## Examples\n\n```py\nfrom typing import Protocol\n\nclass BaseProto(Protocol):\n a: int # fine (explicitly declared as `int`)\n def method_member(self) -> int: ... # fine: a method definition using `def` is considered a declaration\n c = \"some variable\" # error: no explicit declaration, leading to ambiguity\n b = method_member # error: no explicit declaration, leading to ambiguity\n\n # error: this creates implicit assignments of `d` and `e` in the protocol class body.\n # Were they really meant to be considered protocol members?\n for d, e in enumerate(range(42)):\n pass\n\nclass SubProto(BaseProto, Protocol):\n a = 42 # fine (declared in superclass)\n```", + "default": "warn", + "oneOf": [ + { + "$ref": "#/definitions/Level" + } + ] + }, "byte-string-type-annotation": { "title": "detects byte strings in type annotation positions", "description": "## What it does\nChecks for byte-strings in type annotation positions.\n\n## Why is this bad?\nStatic analysis tools like ty can't analyze type annotations that use byte-string notation.\n\n## Examples\n```python\ndef test(): -> b\"int\":\n ...\n```\n\nUse instead:\n```python\ndef test(): -> \"int\":\n ...\n```", @@ -593,7 +603,7 @@ }, "invalid-protocol": { "title": "detects invalid protocol class definitions", - "description": "## What it does\nChecks for invalidly defined protocol classes.\n\n## Why is this bad?\nAn invalidly defined protocol class may lead to the type checker inferring\nunexpected things. It may also lead to `TypeError`s at runtime.\n\n## Examples\nA `Protocol` class cannot inherit from a non-`Protocol` class;\nthis raises a `TypeError` at runtime:\n\n```pycon\n>>> from typing import Protocol\n>>> class Foo(int, Protocol): ...\n...\nTraceback (most recent call last):\n File \"\", line 1, in \n class Foo(int, Protocol): ...\nTypeError: Protocols can only inherit from other protocols, got \n```", + "description": "## What it does\nChecks for protocol classes that will raise `TypeError` at runtime.\n\n## Why is this bad?\nAn invalidly defined protocol class may lead to the type checker inferring\nunexpected things. It may also lead to `TypeError`s at runtime.\n\n## Examples\nA `Protocol` class cannot inherit from a non-`Protocol` class;\nthis raises a `TypeError` at runtime:\n\n```pycon\n>>> from typing import Protocol\n>>> class Foo(int, Protocol): ...\n...\nTraceback (most recent call last):\n File \"\", line 1, in \n class Foo(int, Protocol): ...\nTypeError: Protocols can only inherit from other protocols, got \n```", "default": "error", "oneOf": [ { From 33030b34cd3266a70f0d75e83d886dd8ac0b49ed Mon Sep 17 00:00:00 2001 From: Eric Mark Martin Date: Tue, 19 Aug 2025 20:54:09 -0400 Subject: [PATCH 055/160] [ty] linear variance inference for PEP-695 type parameters (#18713) ## Summary Implement linear-time variance inference for type variables (https://github.com/astral-sh/ty/issues/488). Inspired by Martin Huschenbett's [PyCon 2025 Talk](https://www.youtube.com/watch?v=7uixlNTOY4s&t=9705s). ## Test Plan update tests, add new tests, including for mutually recursive classes --------- Co-authored-by: Carl Meyer --- .../mdtest/generics/pep695/classes.md | 19 + .../mdtest/generics/pep695/variance.md | 544 ++++++++++++++++-- .../resources/mdtest/narrow/type.md | 4 +- crates/ty_python_semantic/src/types.rs | 185 +++++- crates/ty_python_semantic/src/types/class.rs | 182 +++++- .../ty_python_semantic/src/types/generics.rs | 11 +- crates/ty_python_semantic/src/types/infer.rs | 6 +- .../ty_python_semantic/src/types/instance.rs | 37 +- .../src/types/protocol_class.rs | 11 +- .../src/types/signatures.rs | 34 +- .../src/types/subclass_of.rs | 12 +- .../ty_python_semantic/src/types/variance.rs | 138 +++++ 12 files changed, 1088 insertions(+), 95 deletions(-) create mode 100644 crates/ty_python_semantic/src/types/variance.rs diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md index 92840bcf1abec..467b6ed42c970 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/classes.md @@ -237,10 +237,15 @@ If the type of a constructor parameter is a class typevar, we can use that to in parameter. The types inferred from a type context and from a constructor parameter must be consistent with each other. +We have to add `x: T` to the classes to ensure they're not bivariant in `T` (__new__ and __init__ +signatures don't count towards variance). + ### `__new__` only ```py class C[T]: + x: T + def __new__(cls, x: T) -> "C[T]": return object.__new__(cls) @@ -254,6 +259,8 @@ wrong_innards: C[int] = C("five") ```py class C[T]: + x: T + def __init__(self, x: T) -> None: ... reveal_type(C(1)) # revealed: C[int] @@ -266,6 +273,8 @@ wrong_innards: C[int] = C("five") ```py class C[T]: + x: T + def __new__(cls, x: T) -> "C[T]": return object.__new__(cls) @@ -281,6 +290,8 @@ wrong_innards: C[int] = C("five") ```py class C[T]: + x: T + def __new__(cls, *args, **kwargs) -> "C[T]": return object.__new__(cls) @@ -292,6 +303,8 @@ reveal_type(C(1)) # revealed: C[int] wrong_innards: C[int] = C("five") class D[T]: + x: T + def __new__(cls, x: T) -> "D[T]": return object.__new__(cls) @@ -378,6 +391,8 @@ def func8(t1: tuple[complex, list[int]], t2: tuple[int, *tuple[str, ...]], t3: t ```py class C[T]: + x: T + def __init__[S](self, x: T, y: S) -> None: ... reveal_type(C(1, 1)) # revealed: C[int] @@ -395,6 +410,10 @@ from __future__ import annotations from typing import overload class C[T]: + # we need to use the type variable or else the class is bivariant in T, and + # specializations become meaningless + x: T + @overload def __init__(self: C[str], x: str) -> None: ... @overload diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/variance.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/variance.md index e98d01a35fd02..58ec406333597 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/variance.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/variance.md @@ -40,8 +40,6 @@ class C[T]: class D[U](C[U]): pass -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(C[B], C[A])) static_assert(not is_assignable_to(C[A], C[B])) static_assert(is_assignable_to(C[A], C[Any])) @@ -49,8 +47,6 @@ static_assert(is_assignable_to(C[B], C[Any])) static_assert(is_assignable_to(C[Any], C[A])) static_assert(is_assignable_to(C[Any], C[B])) -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(D[B], C[A])) static_assert(not is_assignable_to(D[A], C[B])) static_assert(is_assignable_to(D[A], C[Any])) @@ -58,8 +54,6 @@ static_assert(is_assignable_to(D[B], C[Any])) static_assert(is_assignable_to(D[Any], C[A])) static_assert(is_assignable_to(D[Any], C[B])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(C[B], C[A])) static_assert(not is_subtype_of(C[A], C[B])) static_assert(not is_subtype_of(C[A], C[Any])) @@ -67,8 +61,6 @@ static_assert(not is_subtype_of(C[B], C[Any])) static_assert(not is_subtype_of(C[Any], C[A])) static_assert(not is_subtype_of(C[Any], C[B])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(D[B], C[A])) static_assert(not is_subtype_of(D[A], C[B])) static_assert(not is_subtype_of(D[A], C[Any])) @@ -124,8 +116,6 @@ class D[U](C[U]): pass static_assert(not is_assignable_to(C[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(C[A], C[B])) static_assert(is_assignable_to(C[A], C[Any])) static_assert(is_assignable_to(C[B], C[Any])) @@ -133,8 +123,6 @@ static_assert(is_assignable_to(C[Any], C[A])) static_assert(is_assignable_to(C[Any], C[B])) static_assert(not is_assignable_to(D[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(D[A], C[B])) static_assert(is_assignable_to(D[A], C[Any])) static_assert(is_assignable_to(D[B], C[Any])) @@ -142,8 +130,6 @@ static_assert(is_assignable_to(D[Any], C[A])) static_assert(is_assignable_to(D[Any], C[B])) static_assert(not is_subtype_of(C[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(C[A], C[B])) static_assert(not is_subtype_of(C[A], C[Any])) static_assert(not is_subtype_of(C[B], C[Any])) @@ -151,8 +137,6 @@ static_assert(not is_subtype_of(C[Any], C[A])) static_assert(not is_subtype_of(C[Any], C[B])) static_assert(not is_subtype_of(D[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(D[A], C[B])) static_assert(not is_subtype_of(D[A], C[Any])) static_assert(not is_subtype_of(D[B], C[Any])) @@ -297,34 +281,22 @@ class C[T]: class D[U](C[U]): pass -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(C[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(C[A], C[B])) static_assert(is_assignable_to(C[A], C[Any])) static_assert(is_assignable_to(C[B], C[Any])) static_assert(is_assignable_to(C[Any], C[A])) static_assert(is_assignable_to(C[Any], C[B])) -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(D[B], C[A])) static_assert(is_subtype_of(C[A], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_assignable_to(D[A], C[B])) static_assert(is_assignable_to(D[A], C[Any])) static_assert(is_assignable_to(D[B], C[Any])) static_assert(is_assignable_to(D[Any], C[A])) static_assert(is_assignable_to(D[Any], C[B])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(C[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(C[A], C[B])) static_assert(not is_subtype_of(C[A], C[Any])) static_assert(not is_subtype_of(C[B], C[Any])) @@ -332,11 +304,7 @@ static_assert(not is_subtype_of(C[Any], C[A])) static_assert(not is_subtype_of(C[Any], C[B])) static_assert(not is_subtype_of(C[Any], C[Any])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(D[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_subtype_of(D[A], C[B])) static_assert(not is_subtype_of(D[A], C[Any])) static_assert(not is_subtype_of(D[B], C[Any])) @@ -345,23 +313,11 @@ static_assert(not is_subtype_of(D[Any], C[B])) static_assert(is_equivalent_to(C[A], C[A])) static_assert(is_equivalent_to(C[B], C[B])) -# TODO: no error -# error: [static-assert-error] static_assert(is_equivalent_to(C[B], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_equivalent_to(C[A], C[B])) -# TODO: no error -# error: [static-assert-error] static_assert(is_equivalent_to(C[A], C[Any])) -# TODO: no error -# error: [static-assert-error] static_assert(is_equivalent_to(C[B], C[Any])) -# TODO: no error -# error: [static-assert-error] static_assert(is_equivalent_to(C[Any], C[A])) -# TODO: no error -# error: [static-assert-error] static_assert(is_equivalent_to(C[Any], C[B])) static_assert(not is_equivalent_to(D[A], C[A])) @@ -380,4 +336,504 @@ static_assert(not is_equivalent_to(D[Any], C[Any])) static_assert(not is_equivalent_to(D[Any], C[Unknown])) ``` +## Mutual Recursion + +This example due to Martin Huschenbett's PyCon 2025 talk, +[Linear Time variance Inference for PEP 695][linear-time-variance-talk] + +```py +from ty_extensions import is_subtype_of, static_assert +from typing import Any + +class A: ... +class B(A): ... + +class C[X]: + def f(self) -> "D[X]": + return D() + + def g(self, x: X) -> None: ... + +class D[Y]: + def h(self) -> C[Y]: + return C() +``` + +`C` is contravariant in `X`, and `D` in `Y`: + +- `C` has two occurrences of `X` + - `X` occurs in the return type of `f` as `D[X]` (`X` is substituted in for `Y`) + - `D` has one occurrence of `Y` + - `Y` occurs in the return type of `h` as `C[Y]` + - `X` occurs contravariantly as a parameter in `g` + +Thus the variance of `X` in `C` depends on itself. We want to infer the least restrictive possible +variance, so in such cases we begin by assuming that the point where we detect the cycle is +bivariant. + +If we thus assume `X` is bivariant in `C`, then `Y` will be bivariant in `D`, as `D`'s only +occurrence of `Y` is in `C`. Then we consider `X` in `C` once more. We have two occurrences: `D[X]` +covariantly in a return type, and `X` contravariantly in an argument type. With one bivariant and +one contravariant occurrence, we update our inference of `X` in `C` to contravariant---the supremum +of contravariant and bivariant in the lattice. + +Now that we've updated the variance of `X` in `C`, we re-evaluate `Y` in `D`. It only has the one +occurrence `C[Y]`, which we now infer is contravariant, and so we infer contravariance for `Y` in +`D` as well. + +Because the variance of `X` in `C` depends on that of `Y` in `D`, we have to re-evaluate now that +we've updated the latter to contravariant. The variance of `X` in `C` is now the supremum of +contravariant and contravariant---giving us contravariant---and so remains unchanged. + +Once we've completed a turn around the cycle with nothing changed, we've reached a fixed-point---the +variance inference will not change any further---and so we finally conclude that both `X` in `C` and +`Y` in `D` are contravariant. + +```py +static_assert(not is_subtype_of(C[B], C[A])) +static_assert(is_subtype_of(C[A], C[B])) +static_assert(not is_subtype_of(C[A], C[Any])) +static_assert(not is_subtype_of(C[B], C[Any])) +static_assert(not is_subtype_of(C[Any], C[A])) +static_assert(not is_subtype_of(C[Any], C[B])) + +static_assert(not is_subtype_of(D[B], D[A])) +static_assert(is_subtype_of(D[A], D[B])) +static_assert(not is_subtype_of(D[A], D[Any])) +static_assert(not is_subtype_of(D[B], D[Any])) +static_assert(not is_subtype_of(D[Any], D[A])) +static_assert(not is_subtype_of(D[Any], D[B])) +``` + +## Class Attributes + +### Mutable Attributes + +Normal attributes are mutable, and so make the enclosing class invariant in this typevar (see +[inv]). + +```py +from ty_extensions import is_subtype_of, static_assert + +class A: ... +class B(A): ... + +class C[T]: + x: T + +static_assert(not is_subtype_of(C[B], C[A])) +static_assert(not is_subtype_of(C[A], C[B])) +``` + +One might think that occurrences in the types of normal attributes are covariant, but they are +mutable, and thus the occurrences are invariant. + +### Immutable Attributes + +Immutable attributes can't be written to, and thus constrain the typevar to covariance, not +invariance. + +#### Final attributes + +```py +from typing import Final +from ty_extensions import is_subtype_of, static_assert + +class A: ... +class B(A): ... + +class C[T]: + x: Final[T] + +static_assert(is_subtype_of(C[B], C[A])) +static_assert(not is_subtype_of(C[A], C[B])) +``` + +#### Underscore-prefixed attributes + +Underscore-prefixed instance attributes are considered private, and thus are assumed not externally +mutated. + +```py +from ty_extensions import is_subtype_of, static_assert + +class A: ... +class B(A): ... + +class C[T]: + _x: T + + @property + def x(self) -> T: + return self._x + +static_assert(is_subtype_of(C[B], C[A])) +static_assert(not is_subtype_of(C[A], C[B])) + +class D[T]: + def __init__(self, x: T): + self._x = x + + @property + def x(self) -> T: + return self._x + +static_assert(is_subtype_of(D[B], D[A])) +static_assert(not is_subtype_of(D[A], D[B])) +``` + +#### Frozen dataclasses in Python 3.12 and earlier + +```py +from dataclasses import dataclass, field +from ty_extensions import is_subtype_of, static_assert + +class A: ... +class B(A): ... + +@dataclass(frozen=True) +class D[U]: + y: U + +static_assert(is_subtype_of(D[B], D[A])) +static_assert(not is_subtype_of(D[A], D[B])) + +@dataclass(frozen=True) +class E[U]: + y: U = field() + +static_assert(is_subtype_of(E[B], E[A])) +static_assert(not is_subtype_of(E[A], E[B])) +``` + +#### Frozen dataclasses in Python 3.13 and later + +```toml +[environment] +python-version = "3.13" +``` + +Python 3.13 introduced a new synthesized `__replace__` method on dataclasses, which uses every field +type in a contravariant position (as a parameter to `__replace__`). This means that frozen +dataclasses on Python 3.13+ can't be covariant in their field types. + +```py +from dataclasses import dataclass +from ty_extensions import is_subtype_of, static_assert + +class A: ... +class B(A): ... + +@dataclass(frozen=True) +class D[U]: + y: U + +static_assert(not is_subtype_of(D[B], D[A])) +static_assert(not is_subtype_of(D[A], D[B])) +``` + +#### NamedTuple + +```py +from typing import NamedTuple +from ty_extensions import is_subtype_of, static_assert + +class A: ... +class B(A): ... + +class E[V](NamedTuple): + z: V + +static_assert(is_subtype_of(E[B], E[A])) +static_assert(not is_subtype_of(E[A], E[B])) +``` + +A subclass of a `NamedTuple` can still be covariant: + +```py +class D[T](E[T]): + pass + +static_assert(is_subtype_of(D[B], D[A])) +static_assert(not is_subtype_of(D[A], D[B])) +``` + +But adding a new generic attribute on the subclass makes it invariant (the added attribute is not a +`NamedTuple` field, and thus not immutable): + +```py +class C[T](E[T]): + w: T + +static_assert(not is_subtype_of(C[B], C[A])) +static_assert(not is_subtype_of(C[A], C[B])) +``` + +### Properties + +Properties constrain to covariance if they are get-only and invariant if they are get-set: + +```py +from ty_extensions import static_assert, is_subtype_of + +class A: ... +class B(A): ... + +class C[T]: + @property + def x(self) -> T | None: + return None + +class D[U]: + @property + def y(self) -> U | None: + return None + + @y.setter + def y(self, value: U): ... + +static_assert(is_subtype_of(C[B], C[A])) +static_assert(not is_subtype_of(C[A], C[B])) +static_assert(not is_subtype_of(D[B], D[A])) +static_assert(not is_subtype_of(D[A], D[B])) +``` + +### Implicit Attributes + +Implicit attributes work like normal ones + +```py +from ty_extensions import static_assert, is_subtype_of + +class A: ... +class B(A): ... + +class C[T]: + def f(self) -> None: + self.x: T | None = None + +static_assert(not is_subtype_of(C[B], C[A])) +static_assert(not is_subtype_of(C[A], C[B])) +``` + +### Constructors: excluding `__init__` and `__new__` + +We consider it invalid to call `__init__` explicitly on an existing object. Likewise, `__new__` is +only used at the beginning of an object's life. As such, we don't need to worry about the variance +impact of these methods. + +```py +from ty_extensions import static_assert, is_subtype_of + +class A: ... +class B(A): ... + +class C[T]: + def __init__(self, x: T): ... + def __new__(self, x: T): ... + +static_assert(is_subtype_of(C[B], C[A])) +static_assert(is_subtype_of(C[A], C[B])) +``` + +This example is then bivariant because it doesn't use `T` outside of the two exempted methods. + +This holds likewise for dataclasses with synthesized `__init__`: + +```py +from dataclasses import dataclass + +@dataclass(init=True, frozen=True) +class D[T]: + x: T + +# Covariant due to the read-only T-typed attribute; the `__init__` is ignored and doesn't make it +# invariant: + +static_assert(is_subtype_of(D[B], D[A])) +static_assert(not is_subtype_of(D[A], D[B])) +``` + +## Union Types + +Union types are covariant in all their members. If `A <: B`, then `A | C <: B | C` and +`C | A <: C | B`. + +```py +from ty_extensions import is_assignable_to, is_subtype_of, static_assert + +class A: ... +class B(A): ... +class C: ... + +# Union types are covariant in their members +static_assert(is_subtype_of(B | C, A | C)) +static_assert(is_subtype_of(C | B, C | A)) +static_assert(not is_subtype_of(A | C, B | C)) +static_assert(not is_subtype_of(C | A, C | B)) + +# Assignability follows the same pattern +static_assert(is_assignable_to(B | C, A | C)) +static_assert(is_assignable_to(C | B, C | A)) +static_assert(not is_assignable_to(A | C, B | C)) +static_assert(not is_assignable_to(C | A, C | B)) +``` + +## Intersection Types + +Intersection types cannot be expressed directly in Python syntax, but they occur when type narrowing +creates constraints through control flow. In ty's representation, intersection types are covariant +in their positive conjuncts and contravariant in their negative conjuncts. + +```py +from ty_extensions import is_assignable_to, is_subtype_of, static_assert, Intersection, Not + +class A: ... +class B(A): ... +class C: ... + +# Test covariance in positive conjuncts +# If B <: A, then Intersection[X, B] <: Intersection[X, A] +static_assert(is_subtype_of(Intersection[C, B], Intersection[C, A])) +static_assert(not is_subtype_of(Intersection[C, A], Intersection[C, B])) + +static_assert(is_assignable_to(Intersection[C, B], Intersection[C, A])) +static_assert(not is_assignable_to(Intersection[C, A], Intersection[C, B])) + +# Test contravariance in negative conjuncts +# If B <: A, then Intersection[X, Not[A]] <: Intersection[X, Not[B]] +# (excluding supertype A is more restrictive than excluding subtype B) +static_assert(is_subtype_of(Intersection[C, Not[A]], Intersection[C, Not[B]])) +static_assert(not is_subtype_of(Intersection[C, Not[B]], Intersection[C, Not[A]])) + +static_assert(is_assignable_to(Intersection[C, Not[A]], Intersection[C, Not[B]])) +static_assert(not is_assignable_to(Intersection[C, Not[B]], Intersection[C, Not[A]])) +``` + +## Subclass Types (type[T]) + +The `type[T]` construct represents the type of classes that are subclasses of `T`. It is covariant +in `T` because if `A <: B`, then `type[A] <: type[B]` holds. + +```py +from ty_extensions import is_assignable_to, is_subtype_of, static_assert + +class A: ... +class B(A): ... + +# type[T] is covariant in T +static_assert(is_subtype_of(type[B], type[A])) +static_assert(not is_subtype_of(type[A], type[B])) + +static_assert(is_assignable_to(type[B], type[A])) +static_assert(not is_assignable_to(type[A], type[B])) + +# With generic classes using type[T] +class ClassContainer[T]: + def __init__(self, cls: type[T]) -> None: + self.cls = cls + + def create_instance(self) -> T: + return self.cls() + +# ClassContainer is covariant in T due to type[T] +static_assert(is_subtype_of(ClassContainer[B], ClassContainer[A])) +static_assert(not is_subtype_of(ClassContainer[A], ClassContainer[B])) + +static_assert(is_assignable_to(ClassContainer[B], ClassContainer[A])) +static_assert(not is_assignable_to(ClassContainer[A], ClassContainer[B])) + +# Practical example: you can pass a ClassContainer[B] where ClassContainer[A] is expected +# because type[B] can safely be used where type[A] is expected +def use_a_class_container(container: ClassContainer[A]) -> A: + return container.create_instance() + +b_container = ClassContainer[B](B) +a_instance: A = use_a_class_container(b_container) # This should work +``` + +## Inheriting from generic classes with inferred variance + +When inheriting from a generic class with our type variable substituted in, we count its occurrences +as well. In the following example, `T` is covariant in `C`, and contravariant in the subclass `D` if +you only count its own occurrences. Because we count both then, `T` is invariant in `D`. + +```py +from ty_extensions import is_subtype_of, static_assert + +class A: + pass + +class B(A): + pass + +class C[T]: + def f() -> T | None: + pass + +static_assert(is_subtype_of(C[B], C[A])) +static_assert(not is_subtype_of(C[A], C[B])) + +class D[T](C[T]): + def g(x: T) -> None: + pass + +static_assert(not is_subtype_of(D[B], D[A])) +static_assert(not is_subtype_of(D[A], D[B])) +``` + +## Inheriting from generic classes with explicit variance + +```py +from typing import TypeVar, Generic +from ty_extensions import is_subtype_of, static_assert + +T = TypeVar("T") +T_co = TypeVar("T_co", covariant=True) +T_contra = TypeVar("T_contra", contravariant=True) + +class A: + pass + +class B(A): + pass + +class Invariant(Generic[T]): + pass + +static_assert(not is_subtype_of(Invariant[B], Invariant[A])) +static_assert(not is_subtype_of(Invariant[A], Invariant[B])) + +class DerivedInvariant[T](Invariant[T]): + pass + +static_assert(not is_subtype_of(DerivedInvariant[B], DerivedInvariant[A])) +static_assert(not is_subtype_of(DerivedInvariant[A], DerivedInvariant[B])) + +class Covariant(Generic[T_co]): + pass + +static_assert(is_subtype_of(Covariant[B], Covariant[A])) +static_assert(not is_subtype_of(Covariant[A], Covariant[B])) + +class DerivedCovariant[T](Covariant[T]): + pass + +static_assert(is_subtype_of(DerivedCovariant[B], DerivedCovariant[A])) +static_assert(not is_subtype_of(DerivedCovariant[A], DerivedCovariant[B])) + +class Contravariant(Generic[T_contra]): + pass + +static_assert(not is_subtype_of(Contravariant[B], Contravariant[A])) +static_assert(is_subtype_of(Contravariant[A], Contravariant[B])) + +class DerivedContravariant[T](Contravariant[T]): + pass + +static_assert(not is_subtype_of(DerivedContravariant[B], DerivedContravariant[A])) +static_assert(is_subtype_of(DerivedContravariant[A], DerivedContravariant[B])) +``` + +[linear-time-variance-talk]: https://www.youtube.com/watch?v=7uixlNTOY4s&t=9705s [spec]: https://typing.python.org/en/latest/spec/generics.html#variance diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/type.md b/crates/ty_python_semantic/resources/mdtest/narrow/type.md index fccd6e54faa0f..3cf1aa23dbd3c 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/type.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/type.md @@ -217,8 +217,8 @@ class B: ... def _[T](x: A | B): if type(x) is A[str]: - # `type()` never returns a generic alias, so `type(x)` cannot be `A[str]` - reveal_type(x) # revealed: Never + # TODO: `type()` never returns a generic alias, so `type(x)` cannot be `A[str]` + reveal_type(x) # revealed: A[int] | B else: reveal_type(x) # revealed: A[int] | B ``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 378583d9ae103..a910e6a2066f5 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -60,6 +60,7 @@ use crate::types::mro::{Mro, MroError, MroIterator}; pub(crate) use crate::types::narrow::infer_narrowing_constraint; use crate::types::signatures::{Parameter, ParameterForm, Parameters, walk_signature}; use crate::types::tuple::TupleSpec; +use crate::types::variance::{TypeVarVariance, VarianceInferable}; use crate::unpack::EvaluationMode; pub use crate::util::diagnostics::add_inferred_python_version_hint_to_diagnostic; use crate::{Db, FxOrderMap, FxOrderSet, Module, Program}; @@ -92,6 +93,7 @@ mod subclass_of; mod tuple; mod type_ordering; mod unpacker; +mod variance; mod visitor; mod definition; @@ -322,6 +324,29 @@ fn class_lookup_cycle_initial<'db>( Place::bound(Type::Never).into() } +#[allow(clippy::trivially_copy_pass_by_ref)] +fn variance_cycle_recover<'db, T>( + _db: &'db dyn Db, + _value: &TypeVarVariance, + count: u32, + _self: T, + _typevar: BoundTypeVarInstance<'db>, +) -> salsa::CycleRecoveryAction { + assert!( + count <= 2, + "Should only be able to cycle at most twice: there are only three levels in the lattice, each cycle should move us one" + ); + salsa::CycleRecoveryAction::Iterate +} + +fn variance_cycle_initial<'db, T>( + _db: &'db dyn Db, + _self: T, + _typevar: BoundTypeVarInstance<'db>, +) -> TypeVarVariance { + TypeVarVariance::Bivariant +} + /// Meta data for `Type::Todo`, which represents a known limitation in ty. #[cfg(debug_assertions)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, get_size2::GetSize)] @@ -755,7 +780,7 @@ impl<'db> Type<'db> { Name::new_static("T_all"), None, None, - variance, + Some(variance), None, TypeVarKind::Pep695, ), @@ -963,7 +988,6 @@ impl<'db> Type<'db> { .expect("Expected a Type::FunctionLiteral variant") } - #[cfg(test)] pub(crate) const fn is_function_literal(&self) -> bool { matches!(self, Type::FunctionLiteral(..)) } @@ -5533,7 +5557,10 @@ impl<'db> Type<'db> { ast::name::Name::new_static("Self"), Some(class_definition), Some(TypeVarBoundOrConstraints::UpperBound(instance).into()), - TypeVarVariance::Invariant, + // According to the [spec], we can consider `Self` + // equivalent to an invariant type variable + // [spec]: https://typing.python.org/en/latest/spec/generics.html#self + Some(TypeVarVariance::Invariant), None, TypeVarKind::TypingSelf, ); @@ -6315,6 +6342,99 @@ impl<'db> From<&Type<'db>> for Type<'db> { } } +impl<'db> VarianceInferable<'db> for Type<'db> { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + tracing::debug!( + "Checking variance of '{tvar}' in `{ty:?}`", + tvar = typevar.typevar(db).name(db), + ty = self.display(db), + ); + + let v = match self { + Type::ClassLiteral(class_literal) => class_literal.variance_of(db, typevar), + + Type::FunctionLiteral(function_type) => { + // TODO: do we need to replace self? + function_type.signature(db).variance_of(db, typevar) + } + + Type::BoundMethod(method_type) => { + // TODO: do we need to replace self? + method_type + .function(db) + .signature(db) + .variance_of(db, typevar) + } + + Type::NominalInstance(nominal_instance_type) => { + nominal_instance_type.variance_of(db, typevar) + } + Type::GenericAlias(generic_alias) => generic_alias.variance_of(db, typevar), + Type::Callable(callable_type) => callable_type.signatures(db).variance_of(db, typevar), + Type::TypeVar(other_typevar) | Type::NonInferableTypeVar(other_typevar) + if other_typevar == typevar => + { + // type variables are covariant in themselves + TypeVarVariance::Covariant + } + Type::ProtocolInstance(protocol_instance_type) => { + protocol_instance_type.variance_of(db, typevar) + } + Type::Union(union_type) => union_type + .elements(db) + .iter() + .map(|ty| ty.variance_of(db, typevar)) + .collect(), + Type::Intersection(intersection_type) => intersection_type + .positive(db) + .iter() + .map(|ty| ty.variance_of(db, typevar)) + .chain(intersection_type.negative(db).iter().map(|ty| { + ty.with_polarity(TypeVarVariance::Contravariant) + .variance_of(db, typevar) + })) + .collect(), + Type::PropertyInstance(property_instance_type) => property_instance_type + .getter(db) + .iter() + .chain(&property_instance_type.setter(db)) + .map(|ty| ty.variance_of(db, typevar)) + .collect(), + Type::SubclassOf(subclass_of_type) => subclass_of_type.variance_of(db, typevar), + Type::Dynamic(_) + | Type::Never + | Type::WrapperDescriptor(_) + | Type::MethodWrapper(_) + | Type::DataclassDecorator(_) + | Type::DataclassTransformer(_) + | Type::ModuleLiteral(_) + | Type::IntLiteral(_) + | Type::BooleanLiteral(_) + | Type::StringLiteral(_) + | Type::EnumLiteral(_) + | Type::LiteralString + | Type::BytesLiteral(_) + | Type::SpecialForm(_) + | Type::KnownInstance(_) + | Type::AlwaysFalsy + | Type::AlwaysTruthy + | Type::BoundSuper(_) + | Type::TypeVar(_) + | Type::NonInferableTypeVar(_) + | Type::TypeIs(_) + | Type::TypedDict(_) + | Type::TypeAlias(_) => TypeVarVariance::Bivariant, + }; + + tracing::debug!( + "Result of variance of '{tvar}' in `{ty:?}` is `{v:?}`", + tvar = typevar.typevar(db).name(db), + ty = self.display(db), + ); + v + } +} + /// A mapping that can be applied to a type, producing another type. This is applied inductively to /// the components of complex types. /// @@ -6972,8 +7092,8 @@ pub struct TypeVarInstance<'db> { /// instead (to evaluate any lazy bound or constraints). _bound_or_constraints: Option>, - /// The variance of the TypeVar - variance: TypeVarVariance, + /// The explicitly specified variance of the TypeVar + explicit_variance: Option, /// The default type for this TypeVar, if any. Don't use this field directly, use the /// `default_type` method instead (to evaluate any lazy default). @@ -7065,7 +7185,7 @@ impl<'db> TypeVarInstance<'db> { .lazy_constraints(db) .map(|constraints| constraints.normalized_impl(db, visitor).into()), }), - self.variance(db), + self.explicit_variance(db), self._default(db).and_then(|default| match default { TypeVarDefaultEvaluation::Eager(ty) => Some(ty.normalized_impl(db, visitor).into()), TypeVarDefaultEvaluation::Lazy => self @@ -7093,7 +7213,7 @@ impl<'db> TypeVarInstance<'db> { .lazy_constraints(db) .map(|constraints| constraints.materialize(db, variance).into()), }), - self.variance(db), + self.explicit_variance(db), self._default(db).and_then(|default| match default { TypeVarDefaultEvaluation::Eager(ty) => Some(ty.materialize(db, variance).into()), TypeVarDefaultEvaluation::Lazy => self @@ -7118,7 +7238,7 @@ impl<'db> TypeVarInstance<'db> { Name::new(format!("{}'instance", self.name(db))), None, Some(bound_or_constraints.into()), - self.variance(db), + self.explicit_variance(db), None, self.kind(db), )) @@ -7187,6 +7307,33 @@ pub struct BoundTypeVarInstance<'db> { // The Salsa heap is tracked separately. impl get_size2::GetSize for BoundTypeVarInstance<'_> {} +impl<'db> BoundTypeVarInstance<'db> { + pub(crate) fn variance_with_polarity( + self, + db: &'db dyn Db, + polarity: TypeVarVariance, + ) -> TypeVarVariance { + let _span = tracing::trace_span!("variance_with_polarity").entered(); + match self.typevar(db).explicit_variance(db) { + Some(explicit_variance) => explicit_variance.compose(polarity), + None => match self.binding_context(db) { + BindingContext::Definition(definition) => { + let type_inference = infer_definition_types(db, definition); + type_inference + .binding_type(definition) + .with_polarity(polarity) + .variance_of(db, self) + } + BindingContext::Synthetic => TypeVarVariance::Invariant, + }, + } + } + + pub(crate) fn variance(self, db: &'db dyn Db) -> TypeVarVariance { + self.variance_with_polarity(db, TypeVarVariance::Covariant) + } +} + fn walk_bound_type_var_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( db: &'db dyn Db, bound_typevar: BoundTypeVarInstance<'db>, @@ -7250,28 +7397,6 @@ impl<'db> BoundTypeVarInstance<'db> { } } -#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, salsa::Update, get_size2::GetSize)] -pub enum TypeVarVariance { - Invariant, - Covariant, - Contravariant, - Bivariant, -} - -impl TypeVarVariance { - /// Flips the polarity of the variance. - /// - /// Covariant becomes contravariant, contravariant becomes covariant, others remain unchanged. - pub(crate) const fn flip(self) -> Self { - match self { - TypeVarVariance::Invariant => TypeVarVariance::Invariant, - TypeVarVariance::Covariant => TypeVarVariance::Contravariant, - TypeVarVariance::Contravariant => TypeVarVariance::Covariant, - TypeVarVariance::Bivariant => TypeVarVariance::Bivariant, - } - } -} - /// Whether a typevar default is eagerly specified or lazily evaluated. #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, salsa::Update, get_size2::GetSize)] pub enum TypeVarDefaultEvaluation<'db> { diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 59929bf59c341..8580dfb61f3df 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -13,8 +13,10 @@ use crate::module_resolver::KnownModule; use crate::semantic_index::definition::{Definition, DefinitionState}; use crate::semantic_index::place::ScopedPlaceId; use crate::semantic_index::scope::NodeWithScopeKind; +use crate::semantic_index::symbol::Symbol; use crate::semantic_index::{ BindingWithConstraints, DeclarationWithConstraint, SemanticIndex, attribute_declarations, + attribute_scopes, }; use crate::types::context::InferContext; use crate::types::diagnostic::{INVALID_LEGACY_TYPE_VARIABLE, INVALID_TYPE_ALIAS_TYPE}; @@ -28,8 +30,8 @@ use crate::types::{ ApplyTypeMappingVisitor, BareTypeAliasType, Binding, BoundSuperError, BoundSuperType, CallableType, DataclassParams, DeprecatedInstance, HasRelationToVisitor, KnownInstanceType, NormalizedVisitor, PropertyInstanceType, StringLiteralType, TypeAliasType, TypeMapping, - TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, declaration_type, - infer_definition_types, todo_type, + TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, VarianceInferable, + declaration_type, infer_definition_types, todo_type, }; use crate::{ Db, FxIndexMap, FxOrderSet, Program, @@ -314,6 +316,51 @@ impl<'db> From> for Type<'db> { } } +#[salsa::tracked] +impl<'db> VarianceInferable<'db> for GenericAlias<'db> { + #[salsa::tracked] + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + let origin = self.origin(db); + + let specialization = self.specialization(db); + + // if the class is the thing defining the variable, then it can + // reference it without it being applied to the specialization + std::iter::once(origin.variance_of(db, typevar)) + .chain( + specialization + .generic_context(db) + .variables(db) + .iter() + .zip(specialization.types(db)) + .map(|(generic_typevar, ty)| { + if let Some(explicit_variance) = + generic_typevar.typevar(db).explicit_variance(db) + { + ty.with_polarity(explicit_variance).variance_of(db, typevar) + } else { + // `with_polarity` composes the passed variance with the + // inferred one. The inference is done lazily, as we can + // sometimes determine the result just from the passed + // variance. This operation is commutative, so we could + // infer either first. We choose to make the `ClassLiteral` + // variance lazy, as it is known to be expensive, requiring + // that we traverse all members. + // + // If salsa let us look at the cache, we could check first + // to see if the class literal query was already run. + + let typevar_variance_in_substituted_type = ty.variance_of(db, typevar); + origin + .with_polarity(typevar_variance_in_substituted_type) + .variance_of(db, *generic_typevar) + } + }), + ) + .collect() + } +} + /// Represents a class type, which might be a non-generic class, or a specialization of a generic /// class. #[derive( @@ -1136,6 +1183,15 @@ impl<'db> From> for Type<'db> { } } +impl<'db> VarianceInferable<'db> for ClassType<'db> { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + match self { + Self::NonGeneric(class) => class.variance_of(db, typevar), + Self::Generic(generic) => generic.variance_of(db, typevar), + } + } +} + /// A filter that describes which methods are considered when looking for implicit attribute assignments /// in [`ClassLiteral::implicit_attribute`]. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -3060,6 +3116,126 @@ impl<'db> From> for ClassType<'db> { } } +#[salsa::tracked] +impl<'db> VarianceInferable<'db> for ClassLiteral<'db> { + #[salsa::tracked(cycle_fn=crate::types::variance_cycle_recover, cycle_initial=crate::types::variance_cycle_initial)] + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + let typevar_in_generic_context = self + .generic_context(db) + .is_some_and(|generic_context| generic_context.variables(db).contains(&typevar)); + + if !typevar_in_generic_context { + return TypeVarVariance::Bivariant; + } + let class_body_scope = self.body_scope(db); + + let file = class_body_scope.file(db); + let index = semantic_index(db, file); + + let explicit_bases_variances = self + .explicit_bases(db) + .iter() + .map(|class| class.variance_of(db, typevar)); + + let default_attribute_variance = { + let is_namedtuple = CodeGeneratorKind::NamedTuple.matches(db, self); + // Python 3.13 introduced a synthesized `__replace__` method on dataclasses which uses + // their field types in contravariant position, thus meaning a frozen dataclass must + // still be invariant in its field types. Other synthesized methods on dataclasses are + // not considered here, since they don't use field types in their signatures. TODO: + // ideally we'd have a single source of truth for information about synthesized + // methods, so we just look them up normally and don't hardcode this knowledge here. + let is_frozen_dataclass = Program::get(db).python_version(db) <= PythonVersion::PY312 + && self + .dataclass_params(db) + .is_some_and(|params| params.contains(DataclassParams::FROZEN)); + if is_namedtuple || is_frozen_dataclass { + TypeVarVariance::Covariant + } else { + TypeVarVariance::Invariant + } + }; + + let init_name: &Name = &"__init__".into(); + let new_name: &Name = &"__new__".into(); + + let use_def_map = index.use_def_map(class_body_scope.file_scope_id(db)); + let table = place_table(db, class_body_scope); + let attribute_places_and_qualifiers = + use_def_map + .all_end_of_scope_symbol_declarations() + .map(|(symbol_id, declarations)| { + let place_and_qual = + place_from_declarations(db, declarations).ignore_conflicting_declarations(); + (symbol_id, place_and_qual) + }) + .chain(use_def_map.all_end_of_scope_symbol_bindings().map( + |(symbol_id, bindings)| (symbol_id, place_from_bindings(db, bindings).into()), + )) + .filter_map(|(symbol_id, place_and_qual)| { + if let Some(name) = table.place(symbol_id).as_symbol().map(Symbol::name) { + (![init_name, new_name].contains(&name)) + .then_some((name.to_string(), place_and_qual)) + } else { + None + } + }); + + // Dataclasses can have some additional synthesized methods (`__eq__`, `__hash__`, + // `__lt__`, etc.) but none of these will have field types type variables in their signatures, so we + // don't need to consider them for variance. + + let attribute_names = attribute_scopes(db, self.body_scope(db)) + .flat_map(|function_scope_id| { + index + .place_table(function_scope_id) + .members() + .filter_map(|member| member.as_instance_attribute()) + .filter(|name| *name != init_name && *name != new_name) + .map(std::string::ToString::to_string) + .collect::>() + }) + .dedup(); + + let attribute_variances = attribute_names + .map(|name| { + let place_and_quals = self.own_instance_member(db, &name); + (name, place_and_quals) + }) + .chain(attribute_places_and_qualifiers) + .dedup() + .filter_map(|(name, place_and_qual)| { + place_and_qual.place.ignore_possibly_unbound().map(|ty| { + let variance = if place_and_qual + .qualifiers + // `CLASS_VAR || FINAL` is really `all()`, but + // we want to be robust against new qualifiers + .intersects(TypeQualifiers::CLASS_VAR | TypeQualifiers::FINAL) + // We don't allow mutation of methods or properties + || ty.is_function_literal() + || ty.is_property_instance() + // Underscore-prefixed attributes are assumed not to be externally mutated + || name.starts_with('_') + { + // CLASS_VAR: class vars generally shouldn't contain the + // type variable, but they could if it's a + // callable type. They can't be mutated on instances. + // + // FINAL: final attributes are immutable, and thus covariant + TypeVarVariance::Covariant + } else { + default_attribute_variance + }; + ty.with_polarity(variance).variance_of(db, typevar) + }) + }); + + attribute_variances + .chain(explicit_bases_variances) + .collect() + } +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, get_size2::GetSize)] pub(super) enum InheritanceCycle { /// The class is cyclically defined and is a participant in the cycle. @@ -4673,7 +4849,7 @@ impl KnownClass { &target.id, Some(containing_assignment), bound_or_constraint, - variance, + Some(variance), default.map(Into::into), TypeVarKind::Legacy, ), diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index e0619e8343698..049b953949445 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -549,12 +549,7 @@ impl<'db> Specialization<'db> { .into_iter() .zip(self.types(db)) .map(|(bound_typevar, vartype)| { - let variance = match bound_typevar.typevar(db).variance(db) { - TypeVarVariance::Invariant => TypeVarVariance::Invariant, - TypeVarVariance::Covariant => variance, - TypeVarVariance::Contravariant => variance.flip(), - TypeVarVariance::Bivariant => unreachable!(), - }; + let variance = bound_typevar.variance_with_polarity(db, variance); vartype.materialize(db, variance) }) .collect(); @@ -599,7 +594,7 @@ impl<'db> Specialization<'db> { // - contravariant: verify that other_type <: self_type // - invariant: verify that self_type <: other_type AND other_type <: self_type // - bivariant: skip, can't make subtyping/assignability false - let compatible = match bound_typevar.typevar(db).variance(db) { + let compatible = match bound_typevar.variance(db) { TypeVarVariance::Invariant => match relation { TypeRelation::Subtyping => self_type.is_equivalent_to(db, *other_type), TypeRelation::Assignability => { @@ -639,7 +634,7 @@ impl<'db> Specialization<'db> { // - contravariant: verify that other_type == self_type // - invariant: verify that self_type == other_type // - bivariant: skip, can't make equivalence false - let compatible = match bound_typevar.typevar(db).variance(db) { + let compatible = match bound_typevar.variance(db) { TypeVarVariance::Invariant | TypeVarVariance::Covariant | TypeVarVariance::Contravariant => self_type.is_equivalent_to(db, *other_type), diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 5502715e381d2..07f82a732949c 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -124,8 +124,8 @@ use crate::types::{ MemberLookupPolicy, MetaclassCandidate, PEP695TypeAliasType, Parameter, ParameterForm, Parameters, SpecialFormType, SubclassOfType, Truthiness, Type, TypeAliasType, TypeAndQualifiers, TypeIsType, TypeQualifiers, TypeVarBoundOrConstraintsEvaluation, - TypeVarDefaultEvaluation, TypeVarInstance, TypeVarKind, TypeVarVariance, UnionBuilder, - UnionType, binding_type, todo_type, + TypeVarDefaultEvaluation, TypeVarInstance, TypeVarKind, UnionBuilder, UnionType, binding_type, + todo_type, }; use crate::unpack::{EvaluationMode, Unpack, UnpackPosition}; use crate::util::diagnostics::format_enumeration; @@ -3470,7 +3470,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { &name.id, Some(definition), bound_or_constraint, - TypeVarVariance::Invariant, // TODO: infer this + None, default.as_deref().map(|_| TypeVarDefaultEvaluation::Lazy), TypeVarKind::Pep695, ))); diff --git a/crates/ty_python_semantic/src/types/instance.rs b/crates/ty_python_semantic/src/types/instance.rs index ca837cd294279..eb6978af2232a 100644 --- a/crates/ty_python_semantic/src/types/instance.rs +++ b/crates/ty_python_semantic/src/types/instance.rs @@ -12,7 +12,7 @@ use crate::types::protocol_class::walk_protocol_interface; use crate::types::tuple::{TupleSpec, TupleType}; use crate::types::{ ApplyTypeMappingVisitor, ClassBase, DynamicType, HasRelationToVisitor, IsDisjointVisitor, - NormalizedVisitor, TypeMapping, TypeRelation, TypeTransformer, + NormalizedVisitor, TypeMapping, TypeRelation, TypeTransformer, VarianceInferable, }; use crate::{Db, FxOrderSet}; @@ -406,6 +406,12 @@ pub(crate) struct SliceLiteral { pub(crate) step: Option, } +impl<'db> VarianceInferable<'db> for NominalInstanceType<'db> { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + self.class(db).variance_of(db, typevar) + } +} + /// A `ProtocolInstanceType` represents the set of all possible runtime objects /// that conform to the interface described by a certain protocol. #[derive( @@ -593,6 +599,12 @@ impl<'db> ProtocolInstanceType<'db> { } } +impl<'db> VarianceInferable<'db> for ProtocolInstanceType<'db> { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + self.inner.variance_of(db, typevar) + } +} + /// An enumeration of the two kinds of protocol types: those that originate from a class /// definition in source code, and those that are synthesized from a set of members. #[derive( @@ -618,12 +630,23 @@ impl<'db> Protocol<'db> { } } +impl<'db> VarianceInferable<'db> for Protocol<'db> { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + match self { + Protocol::FromClass(class_type) => class_type.variance_of(db, typevar), + Protocol::Synthesized(synthesized_protocol_type) => { + synthesized_protocol_type.variance_of(db, typevar) + } + } + } +} + mod synthesized_protocol { use crate::semantic_index::definition::Definition; use crate::types::protocol_class::ProtocolInterface; use crate::types::{ ApplyTypeMappingVisitor, BoundTypeVarInstance, NormalizedVisitor, TypeMapping, - TypeVarVariance, + TypeVarVariance, VarianceInferable, }; use crate::{Db, FxOrderSet}; @@ -676,4 +699,14 @@ mod synthesized_protocol { self.0 } } + + impl<'db> VarianceInferable<'db> for SynthesizedProtocolType<'db> { + fn variance_of( + self, + db: &'db dyn Db, + typevar: BoundTypeVarInstance<'db>, + ) -> TypeVarVariance { + self.0.variance_of(db, typevar) + } + } } diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index 12fb5fb988273..d910bdc1ce2ed 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -18,7 +18,7 @@ use crate::{ types::{ BoundTypeVarInstance, CallableType, ClassBase, ClassLiteral, IsDisjointVisitor, KnownFunction, NormalizedVisitor, PropertyInstanceType, Signature, Type, TypeMapping, - TypeQualifiers, TypeRelation, TypeTransformer, + TypeQualifiers, TypeRelation, TypeTransformer, VarianceInferable, signatures::{Parameter, Parameters}, }, }; @@ -301,6 +301,15 @@ impl<'db> ProtocolInterface<'db> { } } +impl<'db> VarianceInferable<'db> for ProtocolInterface<'db> { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + self.members(db) + // TODO do we need to switch on member kind? + .map(|member| member.ty().variance_of(db, typevar)) + .collect() + } +} + #[derive(Debug, PartialEq, Eq, Clone, Hash, salsa::Update, get_size2::GetSize)] pub(super) struct ProtocolMemberData<'db> { kind: ProtocolMemberKind<'db>, diff --git a/crates/ty_python_semantic/src/types/signatures.rs b/crates/ty_python_semantic/src/types/signatures.rs index 8d1492adc6970..4c80c375717e3 100644 --- a/crates/ty_python_semantic/src/types/signatures.rs +++ b/crates/ty_python_semantic/src/types/signatures.rs @@ -20,7 +20,7 @@ use crate::semantic_index::definition::Definition; use crate::types::generics::{GenericContext, walk_generic_context}; use crate::types::{ BindingContext, BoundTypeVarInstance, KnownClass, NormalizedVisitor, TypeMapping, TypeRelation, - todo_type, + VarianceInferable, todo_type, }; use crate::{Db, FxOrderSet}; use ruff_python_ast::{self as ast, name::Name}; @@ -223,6 +223,16 @@ impl<'a, 'db> IntoIterator for &'a CallableSignature<'db> { } } +impl<'db> VarianceInferable<'db> for &CallableSignature<'db> { + // TODO: possibly need to replace self + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + self.overloads + .iter() + .map(|signature| signature.variance_of(db, typevar)) + .collect() + } +} + /// The signature of one of the overloads of a callable. #[derive(Clone, Debug, salsa::Update, get_size2::GetSize)] pub struct Signature<'db> { @@ -982,6 +992,28 @@ impl std::hash::Hash for Signature<'_> { } } +impl<'db> VarianceInferable<'db> for &Signature<'db> { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + tracing::debug!( + "Checking variance of `{tvar}` in `{self:?}`", + tvar = typevar.typevar(db).name(db) + ); + itertools::chain( + self.parameters + .iter() + .filter_map(|parameter| match parameter.form { + ParameterForm::Type => None, + ParameterForm::Value => parameter.annotated_type().map(|ty| { + ty.with_polarity(TypeVarVariance::Contravariant) + .variance_of(db, typevar) + }), + }), + self.return_ty.map(|ty| ty.variance_of(db, typevar)), + ) + .collect() + } +} + #[derive(Clone, Debug, PartialEq, Eq, Hash, salsa::Update, get_size2::GetSize)] pub(crate) struct Parameters<'db> { // TODO: use SmallVec here once invariance bug is fixed diff --git a/crates/ty_python_semantic/src/types/subclass_of.rs b/crates/ty_python_semantic/src/types/subclass_of.rs index 02cb7bbebc3c1..eeb329436360e 100644 --- a/crates/ty_python_semantic/src/types/subclass_of.rs +++ b/crates/ty_python_semantic/src/types/subclass_of.rs @@ -2,6 +2,7 @@ use ruff_python_ast::name::Name; use crate::place::PlaceAndQualifiers; use crate::semantic_index::definition::Definition; +use crate::types::variance::VarianceInferable; use crate::types::{ ApplyTypeMappingVisitor, BindingContext, BoundTypeVarInstance, ClassType, DynamicType, HasRelationToVisitor, KnownClass, MemberLookupPolicy, NormalizedVisitor, Type, TypeMapping, @@ -103,7 +104,7 @@ impl<'db> SubclassOfType<'db> { ) .into(), ), - variance, + Some(variance), None, TypeVarKind::Pep695, ), @@ -215,6 +216,15 @@ impl<'db> SubclassOfType<'db> { } } +impl<'db> VarianceInferable<'db> for SubclassOfType<'db> { + fn variance_of(self, db: &dyn Db, typevar: BoundTypeVarInstance<'_>) -> TypeVarVariance { + match self.subclass_of { + SubclassOfInner::Dynamic(_) => TypeVarVariance::Bivariant, + SubclassOfInner::Class(class) => class.variance_of(db, typevar), + } + } +} + /// An enumeration of the different kinds of `type[]` types that a [`SubclassOfType`] can represent: /// /// 1. A "subclass of a class": `type[C]` for any class object `C` diff --git a/crates/ty_python_semantic/src/types/variance.rs b/crates/ty_python_semantic/src/types/variance.rs new file mode 100644 index 0000000000000..63d250db56ad3 --- /dev/null +++ b/crates/ty_python_semantic/src/types/variance.rs @@ -0,0 +1,138 @@ +use crate::{Db, types::BoundTypeVarInstance}; + +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, salsa::Update, get_size2::GetSize)] +pub enum TypeVarVariance { + Invariant, + Covariant, + Contravariant, + Bivariant, +} + +impl TypeVarVariance { + pub const fn bottom() -> Self { + TypeVarVariance::Bivariant + } + + pub const fn top() -> Self { + TypeVarVariance::Invariant + } + + // supremum + #[must_use] + pub(crate) const fn join(self, other: Self) -> Self { + use TypeVarVariance::{Bivariant, Contravariant, Covariant, Invariant}; + match (self, other) { + (Invariant, _) | (_, Invariant) => Invariant, + (Covariant, Covariant) => Covariant, + (Contravariant, Contravariant) => Contravariant, + (Covariant, Contravariant) | (Contravariant, Covariant) => Invariant, + (Bivariant, other) | (other, Bivariant) => other, + } + } + + /// Compose two variances: useful for combining use-site and definition-site variances, e.g. + /// `C[D[T]]` or function argument/return position variances. + /// + /// `other` is a thunk to avoid unnecessary computation when `self` is `Bivariant`. + /// + /// Based on the variance composition/transformation operator in + /// , page 5 + /// + /// While their operation would have `compose(Invariant, Bivariant) == + /// Invariant`, we instead have it evaluate to `Bivariant`. This is a valid + /// choice, as discussed on that same page, where type equality is semantic + /// rather than syntactic. To see that this holds for our setting consider + /// the type + /// ```python + /// type ConstantInt[T] = int + /// ``` + /// We would say `ConstantInt[str]` = `ConstantInt[float]`, so we qualify as + /// using semantic equivalence. + #[must_use] + pub(crate) fn compose(self, other: Self) -> Self { + self.compose_thunk(|| other) + } + + /// Like `compose`, but takes `other` as a thunk to avoid unnecessary + /// computation when `self` is `Bivariant`. + #[must_use] + pub(crate) fn compose_thunk(self, other: F) -> Self + where + F: FnOnce() -> Self, + { + match self { + TypeVarVariance::Covariant => other(), + TypeVarVariance::Contravariant => other().flip(), + TypeVarVariance::Bivariant => TypeVarVariance::Bivariant, + TypeVarVariance::Invariant => { + if TypeVarVariance::Bivariant == other() { + TypeVarVariance::Bivariant + } else { + TypeVarVariance::Invariant + } + } + } + } + + /// Flips the polarity of the variance. + /// + /// Covariant becomes contravariant, contravariant becomes covariant, others remain unchanged. + pub(crate) const fn flip(self) -> Self { + match self { + TypeVarVariance::Invariant => TypeVarVariance::Invariant, + TypeVarVariance::Covariant => TypeVarVariance::Contravariant, + TypeVarVariance::Contravariant => TypeVarVariance::Covariant, + TypeVarVariance::Bivariant => TypeVarVariance::Bivariant, + } + } +} + +impl std::iter::FromIterator for TypeVarVariance { + fn from_iter>(iter: T) -> Self { + use std::ops::ControlFlow; + // TODO: use `into_value` when control_flow_into_value is stable + let (ControlFlow::Break(variance) | ControlFlow::Continue(variance)) = iter + .into_iter() + .try_fold(TypeVarVariance::Bivariant, |acc, variance| { + let supremum = acc.join(variance); + match supremum { + // short circuit at top + TypeVarVariance::Invariant => ControlFlow::Break(supremum), + TypeVarVariance::Bivariant + | TypeVarVariance::Covariant + | TypeVarVariance::Contravariant => ControlFlow::Continue(supremum), + } + }); + variance + } +} + +pub(crate) trait VarianceInferable<'db>: Sized { + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance; + + fn with_polarity(self, polarity: TypeVarVariance) -> WithPolarity { + WithPolarity { + variance_inferable: self, + polarity, + } + } +} + +pub(crate) struct WithPolarity { + variance_inferable: T, + polarity: TypeVarVariance, +} + +impl<'db, T> VarianceInferable<'db> for WithPolarity +where + T: VarianceInferable<'db>, +{ + fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { + let WithPolarity { + variance_inferable, + polarity, + } = self; + + polarity.compose_thunk(|| variance_inferable.variance_of(db, typevar)) + } +} From f019cfd15f8947b95ab0f200551d14558705f6e7 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 20 Aug 2025 09:39:05 +0530 Subject: [PATCH 056/160] [ty] Use specialized parameter type for overload filter (#19964) ## Summary Closes: https://github.com/astral-sh/ty/issues/669 (This turned out to be simpler that I thought :)) ## Test Plan Update existing test cases. ### Ecosystem report Most of them are basically because ty has now started inferring more precise types for the return type to an overloaded call and a lot of the types are defined using type aliases, here's some examples:
Details

> attrs (https://github.com/python-attrs/attrs) > + tests/test_make.py:146:14: error[unresolved-attribute] Type `Literal[42]` has no attribute `default` > - Found 555 diagnostics > + Found 556 diagnostics This is accurate now that we infer the type as `Literal[42]` instead of `Unknown` (Pyright infers it as `int`) > optuna (https://github.com/optuna/optuna) > + optuna/_gp/search_space.py:181:53: error[invalid-argument-type] Argument to function `_round_one_normalized_param` is incorrect: Expected `tuple[int | float, int | float]`, found `tuple[Unknown | ndarray[Unknown, ], Unknown | ndarray[Unknown, ]]` > + optuna/_gp/search_space.py:181:83: error[invalid-argument-type] Argument to function `_round_one_normalized_param` is incorrect: Expected `int | float`, found `Unknown | ndarray[Unknown, ]` > + tests/gp_tests/test_search_space.py:109:13: error[invalid-argument-type] Argument to function `_unnormalize_one_param` is incorrect: Expected `tuple[int | float, int | float]`, found `Unknown | ndarray[Unknown, ]` > + tests/gp_tests/test_search_space.py:110:13: error[invalid-argument-type] Argument to function `_unnormalize_one_param` is incorrect: Expected `int | float`, found `Unknown | ndarray[Unknown, ]` > - Found 559 diagnostics > + Found 563 diagnostics Same as above where ty is now inferring a more precise type like `Unknown | ndarray[tuple[int, int], ]` instead of just `Unknown` as before > jinja (https://github.com/pallets/jinja) > + src/jinja2/bccache.py:298:39: error[invalid-argument-type] Argument to bound method `write_bytecode` is incorrect: Expected `IO[bytes]`, found `_TemporaryFileWrapper[str]` > - Found 186 diagnostics > + Found 187 diagnostics This requires support for type aliases to match the correct overload. > hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen) > + src/hydra_zen/wrapper/_implementations.py:945:16: error[invalid-return-type] Return type does not match returned value: expected `DataClass_ | type[@Todo(type[T] for protocols)] | ListConfig | DictConfig`, found `@Todo(unsupported type[X] special form) | (((...) -> Any) & dict[Unknown, Unknown]) | (DataClass_ & dict[Unknown, Unknown]) | dict[Any, Any] | (ListConfig & dict[Unknown, Unknown]) | (DictConfig & dict[Unknown, Unknown]) | (((...) -> Any) & list[Unknown]) | (DataClass_ & list[Unknown]) | list[Any] | (ListConfig & list[Unknown]) | (DictConfig & list[Unknown])` > + tests/annotations/behaviors.py:60:28: error[call-non-callable] Object of type `Path` is not callable > + tests/annotations/behaviors.py:64:21: error[call-non-callable] Object of type `Path` is not callable > + tests/annotations/declarations.py:167:17: error[call-non-callable] Object of type `Path` is not callable > + tests/annotations/declarations.py:524:17: error[unresolved-attribute] Type `` has no attribute `_target_` > - Found 561 diagnostics > + Found 566 diagnostics Same as above, this requires support for type aliases to match the correct overload. > paasta (https://github.com/yelp/paasta) > + paasta_tools/utils.py:4188:19: warning[redundant-cast] Value is already of type `list[str]` > - Found 888 diagnostics > + Found 889 diagnostics This is correct. > colour (https://github.com/colour-science/colour) > + colour/plotting/diagrams.py:448:13: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Sequence[@Todo(Support for `typing.TypeAlias`)]`, found `ndarray[tuple[int, int, int], dtype[Unknown]]` > + colour/plotting/diagrams.py:462:13: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Sequence[@Todo(Support for `typing.TypeAlias`)]`, found `ndarray[tuple[int, int, int], dtype[Unknown]]` > + colour/plotting/models.py:419:13: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Sequence[@Todo(Support for `typing.TypeAlias`)]`, found `ndarray[tuple[int, int, int], dtype[Unknown]]` > + colour/plotting/temperature.py:230:9: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Sequence[@Todo(Support for `typing.TypeAlias`)]`, found `ndarray[tuple[int, int, int], dtype[Unknown]]` > + colour/plotting/temperature.py:474:13: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Sequence[@Todo(Support for `typing.TypeAlias`)]`, found `ndarray[tuple[int, int, int], dtype[Unknown]]` > + colour/plotting/temperature.py:495:17: error[invalid-argument-type] Argument to bound method `__init__` is incorrect: Expected `Sequence[@Todo(Support for `typing.TypeAlias`)]`, found `ndarray[tuple[int, int, int], dtype[Unknown]]` > + colour/plotting/temperature.py:513:13: error[invalid-argument-type] Argument to bound method `text` is incorrect: Expected `int | float`, found `ndarray[@Todo(Support for `typing.TypeAlias`), dtype[Unknown]]` > + colour/plotting/temperature.py:514:13: error[invalid-argument-type] Argument to bound method `text` is incorrect: Expected `int | float`, found `ndarray[@Todo(Support for `typing.TypeAlias`), dtype[Unknown]]` > - Found 480 diagnostics > + Found 488 diagnostics Most of them are correct except for the last two diagnostics which I'm not sure what's happening, it's trying to index into an `np.ndarray` type (which is inferred correctly) but I think it might be picking up an incorrect overload for the `__getitem__` method. Scipy's diagnostics also requires support for type alises to pick the correct overload.

--- .../resources/mdtest/call/overloads.md | 3 +-- crates/ty_python_semantic/src/types/call/bind.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/call/overloads.md b/crates/ty_python_semantic/resources/mdtest/call/overloads.md index 8d1f2930cdf44..ca447b6063e7e 100644 --- a/crates/ty_python_semantic/resources/mdtest/call/overloads.md +++ b/crates/ty_python_semantic/resources/mdtest/call/overloads.md @@ -876,8 +876,7 @@ def _(list_int: list[int], list_str: list[str], list_any: list[Any], any: Any): # TODO: revealed: A reveal_type(f(*(list_int,))) # revealed: Unknown - # TODO: Should be `str` - reveal_type(f(list_str)) # revealed: Unknown + reveal_type(f(list_str)) # revealed: str # TODO: Should be `str` reveal_type(f(*(list_str,))) # revealed: Unknown diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index e0642122253c9..226454e748952 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -1497,9 +1497,17 @@ impl<'db> CallableBinding<'db> { } // TODO: For an unannotated `self` / `cls` parameter, the type should be // `typing.Self` / `type[typing.Self]` - let parameter_type = overload.signature.parameters()[*parameter_index] + let mut parameter_type = overload.signature.parameters()[*parameter_index] .annotated_type() .unwrap_or(Type::unknown()); + if let Some(specialization) = overload.specialization { + parameter_type = + parameter_type.apply_specialization(db, specialization); + } + if let Some(inherited_specialization) = overload.inherited_specialization { + parameter_type = + parameter_type.apply_specialization(db, inherited_specialization); + } current_parameter_types.push(parameter_type); } } From 276405b44eefd70e212abe1d37a11ce419ec6813 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 20 Aug 2025 10:28:30 +0200 Subject: [PATCH 057/160] [ty] Fix server hang (#19991) --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- fuzz/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 37ce50f4c9531..768c871516c16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3450,7 +3450,7 @@ checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "salsa" version = "0.23.0" -source = "git+https://github.com/salsa-rs/salsa.git?rev=918d35d873b2b73a0237536144ef4d22e8d57f27#918d35d873b2b73a0237536144ef4d22e8d57f27" +source = "git+https://github.com/salsa-rs/salsa.git?rev=a3ffa22cb26756473d56f867aedec3fd907c4dd9#a3ffa22cb26756473d56f867aedec3fd907c4dd9" dependencies = [ "boxcar", "compact_str", @@ -3474,12 +3474,12 @@ dependencies = [ [[package]] name = "salsa-macro-rules" version = "0.23.0" -source = "git+https://github.com/salsa-rs/salsa.git?rev=918d35d873b2b73a0237536144ef4d22e8d57f27#918d35d873b2b73a0237536144ef4d22e8d57f27" +source = "git+https://github.com/salsa-rs/salsa.git?rev=a3ffa22cb26756473d56f867aedec3fd907c4dd9#a3ffa22cb26756473d56f867aedec3fd907c4dd9" [[package]] name = "salsa-macros" version = "0.23.0" -source = "git+https://github.com/salsa-rs/salsa.git?rev=918d35d873b2b73a0237536144ef4d22e8d57f27#918d35d873b2b73a0237536144ef4d22e8d57f27" +source = "git+https://github.com/salsa-rs/salsa.git?rev=a3ffa22cb26756473d56f867aedec3fd907c4dd9#a3ffa22cb26756473d56f867aedec3fd907c4dd9" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index ce3061284af48..c7ac8d0596793 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -143,7 +143,7 @@ regex-automata = { version = "0.4.9" } rustc-hash = { version = "2.0.0" } rustc-stable-hash = { version = "0.1.2" } # When updating salsa, make sure to also update the revision in `fuzz/Cargo.toml` -salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "918d35d873b2b73a0237536144ef4d22e8d57f27", default-features = false, features = [ +salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "a3ffa22cb26756473d56f867aedec3fd907c4dd9", default-features = false, features = [ "compact_str", "macros", "salsa_unstable", diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 98ece64da97b7..4fa0f0d77a37a 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -30,7 +30,7 @@ ty_python_semantic = { path = "../crates/ty_python_semantic" } ty_vendored = { path = "../crates/ty_vendored" } libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer", default-features = false } -salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "918d35d873b2b73a0237536144ef4d22e8d57f27", default-features = false, features = [ +salsa = { git = "https://github.com/salsa-rs/salsa.git", rev = "a3ffa22cb26756473d56f867aedec3fd907c4dd9", default-features = false, features = [ "compact_str", "macros", "salsa_unstable", From 1d2128f918a2315a5fc81042b5417f9d8cf34282 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Wed, 20 Aug 2025 09:07:42 -0400 Subject: [PATCH 058/160] [ty] distinguish base conda from child conda (#19990) This is a port of the logic in https://github.com/astral-sh/uv/pull/7691 The basic idea is we use CONDA_DEFAULT_ENV as a signal for whether CONDA_PREFIX is just the ambient system conda install, or the user has explicitly activated a custom one. If the former, then the conda is treated like a system install (having lowest priority). If the latter, the conda is treated like an activated venv (having priority over everything but an Actual activated venv). Fixes https://github.com/astral-sh/ty/issues/611 --- crates/ty/tests/cli/python_environment.rs | 517 +++++++++++++++++- .../ty_python_semantic/src/site_packages.rs | 77 ++- crates/ty_static/src/env_vars.rs | 3 + 3 files changed, 565 insertions(+), 32 deletions(-) diff --git a/crates/ty/tests/cli/python_environment.rs b/crates/ty/tests/cli/python_environment.rs index a3362b3875eff..3c9714d00ef8b 100644 --- a/crates/ty/tests/cli/python_environment.rs +++ b/crates/ty/tests/cli/python_environment.rs @@ -900,73 +900,540 @@ fn defaults_to_a_new_python_version() -> anyhow::Result<()> { /// The `site-packages` directory is used by ty for external import. /// Ty does the following checks to discover the `site-packages` directory in the order: /// 1) If `VIRTUAL_ENV` environment variable is set -/// 2) If `CONDA_PREFIX` environment variable is set +/// 2) If `CONDA_PREFIX` environment variable is set (and .filename != `CONDA_DEFAULT_ENV`) /// 3) If a `.venv` directory exists at the project root +/// 4) If `CONDA_PREFIX` environment variable is set (and .filename == `CONDA_DEFAULT_ENV`) /// -/// This test is aiming at validating the logic around `CONDA_PREFIX`. +/// This test (and the next one) is aiming at validating the logic around these cases. /// -/// A conda-like environment file structure is used -/// We test by first not setting the `CONDA_PREFIX` and expect a fail. -/// Then we test by setting `CONDA_PREFIX` to `conda-env` and expect a pass. +/// To do this we create a program that has these 4 imports: +/// +/// ```python +/// from package1 import ActiveVenv +/// from package1 import ChildConda +/// from package1 import WorkingVenv +/// from package1 import BaseConda +/// ``` +/// +/// We then create 4 different copies of package1. Each copy defines all of these +/// classes... except the one that describes it. Therefore we know we got e.g. +/// the working venv if we get a diagnostic like this: +/// +/// ```text +/// Unresolved import +/// 4 | from package1 import WorkingVenv +/// | ^^^^^^^^^^^ +/// ``` +/// +/// This test uses a directory structure as follows: /// /// ├── project -/// │ └── test.py -/// └── conda-env -/// └── lib -/// └── python3.13 -/// └── site-packages -/// └── package1 -/// └── __init__.py +/// │ ├── test.py +/// │ └── .venv +/// │ ├── pyvenv.cfg +/// │ └── lib +/// │ └── python3.13 +/// │ └── site-packages +/// │ └── package1 +/// │ └── __init__.py +/// ├── myvenv +/// │ ├── pyvenv.cfg +/// │ └── lib +/// │ └── python3.13 +/// │ └── site-packages +/// │ └── package1 +/// │ └── __init__.py +/// ├── conda-env +/// │ └── lib +/// │ └── python3.13 +/// │ └── site-packages +/// │ └── package1 +/// │ └── __init__.py +/// └── conda +/// └── envs +/// └── base +/// └── lib +/// └── python3.13 +/// └── site-packages +/// └── package1 +/// └── __init__.py /// /// test.py imports package1 /// And the command is run in the `child` directory. #[test] -fn check_conda_prefix_var_to_resolve_path() -> anyhow::Result<()> { - let conda_package1_path = if cfg!(windows) { +fn check_venv_resolution_with_working_venv() -> anyhow::Result<()> { + let child_conda_package1_path = if cfg!(windows) { "conda-env/Lib/site-packages/package1/__init__.py" } else { "conda-env/lib/python3.13/site-packages/package1/__init__.py" }; + let base_conda_package1_path = if cfg!(windows) { + "conda/envs/base/Lib/site-packages/package1/__init__.py" + } else { + "conda/envs/base/lib/python3.13/site-packages/package1/__init__.py" + }; + + let working_venv_package1_path = if cfg!(windows) { + "project/.venv/Lib/site-packages/package1/__init__.py" + } else { + "project/.venv/lib/python3.13/site-packages/package1/__init__.py" + }; + + let active_venv_package1_path = if cfg!(windows) { + "myvenv/Lib/site-packages/package1/__init__.py" + } else { + "myvenv/lib/python3.13/site-packages/package1/__init__.py" + }; + let case = CliTest::with_files([ ( "project/test.py", r#" - import package1 + from package1 import ActiveVenv + from package1 import ChildConda + from package1 import WorkingVenv + from package1 import BaseConda + "#, + ), + ( + "project/.venv/pyvenv.cfg", + r#" +home = ./ + + "#, + ), + ( + "myvenv/pyvenv.cfg", + r#" +home = ./ + "#, ), ( - conda_package1_path, + active_venv_package1_path, r#" + class ChildConda: ... + class WorkingVenv: ... + class BaseConda: ... + "#, + ), + ( + child_conda_package1_path, + r#" + class ActiveVenv: ... + class WorkingVenv: ... + class BaseConda: ... + "#, + ), + ( + working_venv_package1_path, + r#" + class ActiveVenv: ... + class ChildConda: ... + class BaseConda: ... + "#, + ), + ( + base_conda_package1_path, + r#" + class ActiveVenv: ... + class ChildConda: ... + class WorkingVenv: ... "#, ), ])?; - assert_cmd_snapshot!(case.command().current_dir(case.root().join("project")), @r" + // Run with nothing set, should find the working venv + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `WorkingVenv` + --> test.py:4:22 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + | ^^^^^^^^^^^ + 5 | from package1 import BaseConda + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // Run with VIRTUAL_ENV set, should find the active venv + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("VIRTUAL_ENV", case.root().join("myvenv")), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `ActiveVenv` + --> test.py:2:22 + | + 2 | from package1 import ActiveVenv + | ^^^^^^^^^^ + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // run with CONDA_PREFIX set, should find the child conda + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda-env")), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `ChildConda` + --> test.py:3:22 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + | ^^^^^^^^^^ + 4 | from package1 import WorkingVenv + 5 | from package1 import BaseConda + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // run with CONDA_PREFIX and CONDA_DEFAULT_ENV set (unequal), should find child conda + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda-env")) + .env("CONDA_DEFAULT_ENV", "base"), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `ChildConda` + --> test.py:3:22 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + | ^^^^^^^^^^ + 4 | from package1 import WorkingVenv + 5 | from package1 import BaseConda + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // run with CONDA_PREFIX and CONDA_DEFAULT_ENV (unequal) and VIRTUAL_ENV set, + // should find child active venv + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda-env")) + .env("CONDA_DEFAULT_ENV", "base") + .env("VIRTUAL_ENV", case.root().join("myvenv")), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `ActiveVenv` + --> test.py:2:22 + | + 2 | from package1 import ActiveVenv + | ^^^^^^^^^^ + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // run with CONDA_PREFIX and CONDA_DEFAULT_ENV (equal!) set, should find working venv + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda/envs/base")) + .env("CONDA_DEFAULT_ENV", "base"), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `WorkingVenv` + --> test.py:4:22 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + | ^^^^^^^^^^^ + 5 | from package1 import BaseConda + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + Ok(()) +} + +/// The exact same test as above, but without a working venv +/// +/// In this case the Base Conda should be a possible outcome. +#[test] +fn check_venv_resolution_without_working_venv() -> anyhow::Result<()> { + let child_conda_package1_path = if cfg!(windows) { + "conda-env/Lib/site-packages/package1/__init__.py" + } else { + "conda-env/lib/python3.13/site-packages/package1/__init__.py" + }; + + let base_conda_package1_path = if cfg!(windows) { + "conda/envs/base/Lib/site-packages/package1/__init__.py" + } else { + "conda/envs/base/lib/python3.13/site-packages/package1/__init__.py" + }; + + let active_venv_package1_path = if cfg!(windows) { + "myvenv/Lib/site-packages/package1/__init__.py" + } else { + "myvenv/lib/python3.13/site-packages/package1/__init__.py" + }; + + let case = CliTest::with_files([ + ( + "project/test.py", + r#" + from package1 import ActiveVenv + from package1 import ChildConda + from package1 import WorkingVenv + from package1 import BaseConda + "#, + ), + ( + "myvenv/pyvenv.cfg", + r#" +home = ./ + + "#, + ), + ( + active_venv_package1_path, + r#" + class ChildConda: ... + class WorkingVenv: ... + class BaseConda: ... + "#, + ), + ( + child_conda_package1_path, + r#" + class ActiveVenv: ... + class WorkingVenv: ... + class BaseConda: ... + "#, + ), + ( + base_conda_package1_path, + r#" + class ActiveVenv: ... + class ChildConda: ... + class WorkingVenv: ... + "#, + ), + ])?; + + // Run with nothing set, should fail to find anything + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")), @r" success: false exit_code: 1 ----- stdout ----- error[unresolved-import]: Cannot resolve imported module `package1` - --> test.py:2:8 + --> test.py:2:6 | - 2 | import package1 - | ^^^^^^^^ + 2 | from package1 import ActiveVenv + | ^^^^^^^^ + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv | info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default + error[unresolved-import]: Cannot resolve imported module `package1` + --> test.py:3:6 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + | ^^^^^^^^ + 4 | from package1 import WorkingVenv + 5 | from package1 import BaseConda + | + info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment + info: rule `unresolved-import` is enabled by default + + error[unresolved-import]: Cannot resolve imported module `package1` + --> test.py:4:6 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + | ^^^^^^^^ + 5 | from package1 import BaseConda + | + info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment + info: rule `unresolved-import` is enabled by default + + error[unresolved-import]: Cannot resolve imported module `package1` + --> test.py:5:6 + | + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + 5 | from package1 import BaseConda + | ^^^^^^^^ + | + info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment + info: rule `unresolved-import` is enabled by default + + Found 4 diagnostics + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // Run with VIRTUAL_ENV set, should find the active venv + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("VIRTUAL_ENV", case.root().join("myvenv")), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `ActiveVenv` + --> test.py:2:22 + | + 2 | from package1 import ActiveVenv + | ^^^^^^^^^^ + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + | + info: rule `unresolved-import` is enabled by default + Found 1 diagnostic ----- stderr ----- WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. "); - // do command : CONDA_PREFIX=/conda_env - assert_cmd_snapshot!(case.command().current_dir(case.root().join("project")).env("CONDA_PREFIX", case.root().join("conda-env")), @r" - success: true - exit_code: 0 + // run with CONDA_PREFIX set, should find the child conda + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda-env")), @r" + success: false + exit_code: 1 ----- stdout ----- - All checks passed! + error[unresolved-import]: Module `package1` has no member `ChildConda` + --> test.py:3:22 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + | ^^^^^^^^^^ + 4 | from package1 import WorkingVenv + 5 | from package1 import BaseConda + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // run with CONDA_PREFIX and CONDA_DEFAULT_ENV set (unequal), should find child conda + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda-env")) + .env("CONDA_DEFAULT_ENV", "base"), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `ChildConda` + --> test.py:3:22 + | + 2 | from package1 import ActiveVenv + 3 | from package1 import ChildConda + | ^^^^^^^^^^ + 4 | from package1 import WorkingVenv + 5 | from package1 import BaseConda + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // run with CONDA_PREFIX and CONDA_DEFAULT_ENV (unequal) and VIRTUAL_ENV set, + // should find child active venv + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda-env")) + .env("CONDA_DEFAULT_ENV", "base") + .env("VIRTUAL_ENV", case.root().join("myvenv")), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `ActiveVenv` + --> test.py:2:22 + | + 2 | from package1 import ActiveVenv + | ^^^^^^^^^^ + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic + + ----- stderr ----- + WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. + "); + + // run with CONDA_PREFIX and CONDA_DEFAULT_ENV (equal!) set, should find base conda + assert_cmd_snapshot!(case.command() + .current_dir(case.root().join("project")) + .env("CONDA_PREFIX", case.root().join("conda/envs/base")) + .env("CONDA_DEFAULT_ENV", "base"), @r" + success: false + exit_code: 1 + ----- stdout ----- + error[unresolved-import]: Module `package1` has no member `BaseConda` + --> test.py:5:22 + | + 3 | from package1 import ChildConda + 4 | from package1 import WorkingVenv + 5 | from package1 import BaseConda + | ^^^^^^^^^ + | + info: rule `unresolved-import` is enabled by default + + Found 1 diagnostic ----- stderr ----- WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. diff --git a/crates/ty_python_semantic/src/site_packages.rs b/crates/ty_python_semantic/src/site_packages.rs index dd01a49771928..1e94670365894 100644 --- a/crates/ty_python_semantic/src/site_packages.rs +++ b/crates/ty_python_semantic/src/site_packages.rs @@ -139,6 +139,12 @@ pub enum PythonEnvironment { } impl PythonEnvironment { + /// Discover the python environment using the following priorities: + /// + /// 1. activated virtual environment + /// 2. conda (child) + /// 3. working dir virtual environment + /// 4. conda (base) pub fn discover( project_root: &SystemPath, system: &dyn System, @@ -161,13 +167,9 @@ impl PythonEnvironment { .map(Some); } - if let Ok(conda_env) = system.env_var(EnvVars::CONDA_PREFIX) { - return resolve_environment( - system, - SystemPath::new(&conda_env), - SysPrefixPathOrigin::CondaPrefixVar, - ) - .map(Some); + if let Some(conda_env) = conda_environment_from_env(system, CondaEnvironmentKind::Child) { + return resolve_environment(system, &conda_env, SysPrefixPathOrigin::CondaPrefixVar) + .map(Some); } tracing::debug!("Discovering virtual environment in `{project_root}`"); @@ -190,6 +192,11 @@ impl PythonEnvironment { } } + if let Some(conda_env) = conda_environment_from_env(system, CondaEnvironmentKind::Base) { + return resolve_environment(system, &conda_env, SysPrefixPathOrigin::CondaPrefixVar) + .map(Some); + } + Ok(None) } @@ -589,6 +596,62 @@ System stdlib will not be used for module definitions.", } } +/// Different kinds of conda environment +#[derive(Debug, PartialEq, Eq, Copy, Clone)] +pub(crate) enum CondaEnvironmentKind { + /// The base Conda environment; treated like a system Python environment. + Base, + /// Any other Conda environment; treated like a virtual environment. + Child, +} + +impl CondaEnvironmentKind { + /// Compute the kind of `CONDA_PREFIX` we have. + /// + /// When the base environment is used, `CONDA_DEFAULT_ENV` will be set to a name, i.e., `base` or + /// `root` which does not match the prefix, e.g. `/usr/local` instead of + /// `/usr/local/conda/envs/`. + fn from_prefix_path(system: &dyn System, path: &SystemPath) -> Self { + // If we cannot read `CONDA_DEFAULT_ENV`, there's no way to know if the base environment + let Ok(default_env) = system.env_var(EnvVars::CONDA_DEFAULT_ENV) else { + return CondaEnvironmentKind::Child; + }; + + // These are the expected names for the base environment + if default_env != "base" && default_env != "root" { + return CondaEnvironmentKind::Child; + } + + let Some(name) = path.file_name() else { + return CondaEnvironmentKind::Child; + }; + + if name == default_env { + CondaEnvironmentKind::Base + } else { + CondaEnvironmentKind::Child + } + } +} + +/// Read `CONDA_PREFIX` and confirm that it has the expected kind +pub(crate) fn conda_environment_from_env( + system: &dyn System, + kind: CondaEnvironmentKind, +) -> Option { + let dir = system + .env_var(EnvVars::CONDA_PREFIX) + .ok() + .filter(|value| !value.is_empty())?; + let path = SystemPathBuf::from(dir); + + if kind != CondaEnvironmentKind::from_prefix_path(system, &path) { + return None; + } + + Some(path) +} + /// A parser for `pyvenv.cfg` files: metadata files for virtual environments. /// /// Note that a `pyvenv.cfg` file *looks* like a `.ini` file, but actually isn't valid `.ini` syntax! diff --git a/crates/ty_static/src/env_vars.rs b/crates/ty_static/src/env_vars.rs index 178dd46a7e440..ebad90e8e5eb5 100644 --- a/crates/ty_static/src/env_vars.rs +++ b/crates/ty_static/src/env_vars.rs @@ -42,6 +42,9 @@ impl EnvVars { /// Used to detect an activated virtual environment. pub const VIRTUAL_ENV: &'static str = "VIRTUAL_ENV"; + /// Used to determine if an active Conda environment is the base environment or not. + pub const CONDA_DEFAULT_ENV: &'static str = "CONDA_DEFAULT_ENV"; + /// Used to detect an activated Conda environment location. /// If both `VIRTUAL_ENV` and `CONDA_PREFIX` are present, `VIRTUAL_ENV` will be preferred. pub const CONDA_PREFIX: &'static str = "CONDA_PREFIX"; From f4be05a83be770c8c9781088508275170396b411 Mon Sep 17 00:00:00 2001 From: Andrey Date: Wed, 20 Aug 2025 15:19:18 +0200 Subject: [PATCH 059/160] [`flake8-annotations`] Remove unused import in example (`ANN401`) (#20000) ## Summary Remove unused import in the "Use instead" example. ## Test Plan It's just a text description, no test needed --- .../src/rules/flake8_annotations/rules/definition.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs index b973b47ef83fd..04159eaadcb9e 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/rules/definition.rs @@ -485,9 +485,6 @@ impl Violation for MissingReturnTypeClassMethod { /// Use instead: /// /// ```python -/// from typing import Any -/// -/// /// def foo(x: int): ... /// ``` /// From e0c98874e244ef3519f28c91aab79b11c6ee7d0a Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Wed, 6 Aug 2025 11:08:10 -0400 Subject: [PATCH 060/160] [ty] Add more path helper functions This makes it easier to do exhaustive case analysis on a `SearchPath` depending on whether it is a vendored or system path. --- .../src/module_resolver/path.rs | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/crates/ty_python_semantic/src/module_resolver/path.rs b/crates/ty_python_semantic/src/module_resolver/path.rs index 77b0219afe35c..484b97bb69b7d 100644 --- a/crates/ty_python_semantic/src/module_resolver/path.rs +++ b/crates/ty_python_semantic/src/module_resolver/path.rs @@ -621,29 +621,28 @@ impl SearchPath { } #[must_use] - pub(crate) fn as_system_path(&self) -> Option<&SystemPath> { - match &*self.0 { - SearchPathInner::Extra(path) - | SearchPathInner::FirstParty(path) - | SearchPathInner::StandardLibraryCustom(path) - | SearchPathInner::StandardLibraryReal(path) - | SearchPathInner::SitePackages(path) - | SearchPathInner::Editable(path) => Some(path), - SearchPathInner::StandardLibraryVendored(_) => None, + pub(super) fn as_path(&self) -> SystemOrVendoredPathRef<'_> { + match *self.0 { + SearchPathInner::Extra(ref path) + | SearchPathInner::FirstParty(ref path) + | SearchPathInner::StandardLibraryCustom(ref path) + | SearchPathInner::StandardLibraryReal(ref path) + | SearchPathInner::SitePackages(ref path) + | SearchPathInner::Editable(ref path) => SystemOrVendoredPathRef::System(path), + SearchPathInner::StandardLibraryVendored(ref path) => { + SystemOrVendoredPathRef::Vendored(path) + } } } + #[must_use] + pub(crate) fn as_system_path(&self) -> Option<&SystemPath> { + self.as_path().as_system_path() + } + #[must_use] pub(crate) fn as_vendored_path(&self) -> Option<&VendoredPath> { - match &*self.0 { - SearchPathInner::StandardLibraryVendored(path) => Some(path), - SearchPathInner::Extra(_) - | SearchPathInner::FirstParty(_) - | SearchPathInner::StandardLibraryCustom(_) - | SearchPathInner::StandardLibraryReal(_) - | SearchPathInner::SitePackages(_) - | SearchPathInner::Editable(_) => None, - } + self.as_path().as_vendored_path() } } @@ -740,6 +739,20 @@ impl<'db> SystemOrVendoredPathRef<'db> { Self::Vendored(vendored) => vendored.parent().map(Self::Vendored), } } + + fn as_system_path(&self) -> Option<&'db SystemPath> { + match self { + SystemOrVendoredPathRef::System(path) => Some(path), + SystemOrVendoredPathRef::Vendored(_) => None, + } + } + + fn as_vendored_path(&self) -> Option<&'db VendoredPath> { + match self { + SystemOrVendoredPathRef::Vendored(path) => Some(path), + SystemOrVendoredPathRef::System(_) => None, + } + } } impl std::fmt::Display for SystemOrVendoredPathRef<'_> { From a4cd13c6e22ac940c304388130fe596ea8b17173 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 13:59:56 -0400 Subject: [PATCH 061/160] [ty] Expose some routines in the module resolver We'll want to use these when implementing the "list modules" API. --- crates/ty_python_semantic/src/module_resolver/resolver.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/ty_python_semantic/src/module_resolver/resolver.rs b/crates/ty_python_semantic/src/module_resolver/resolver.rs index d1974fac18418..0dcd42b0dd3e9 100644 --- a/crates/ty_python_semantic/src/module_resolver/resolver.rs +++ b/crates/ty_python_semantic/src/module_resolver/resolver.rs @@ -656,7 +656,7 @@ struct ModuleNameIngredient<'db> { /// This includes "builtin" modules, which can never be shadowed at runtime either, as well as the /// `types` module, which tends to be imported early in Python startup, so can't be consistently /// shadowed, and is important to type checking. -fn is_non_shadowable(minor_version: u8, module_name: &str) -> bool { +pub(super) fn is_non_shadowable(minor_version: u8, module_name: &str) -> bool { module_name == "types" || ruff_python_stdlib::sys::is_builtin_module(minor_version, module_name) } @@ -890,7 +890,10 @@ fn resolve_name_in_search_path( /// /// `.pyi` files take priority, as they always have priority when /// resolving modules. -fn resolve_file_module(module: &ModulePath, resolver_state: &ResolverContext) -> Option { +pub(super) fn resolve_file_module( + module: &ModulePath, + resolver_state: &ResolverContext, +) -> Option { // Stubs have precedence over source files let stub_file = if resolver_state.mode.stubs_allowed() { module.with_pyi_extension().to_file(resolver_state) From 306ef3bb02e8ebe6f2681cc6b15edf290d488b50 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:01:59 -0400 Subject: [PATCH 062/160] [ty] Add stub-file tests to existing module resolver These tests capture existing behavior. I added these when I stumbled upon what I thought was an oddity: we prioritize `foo.pyi` over `foo.py`, but prioritize `foo/__init__.py` over `foo.pyi`. (I plan to investigate this more closely in follow-up work. Particularly, to look at other type checkers. It seems like we may want to change this to always prioritize stubs.) --- .../src/module_resolver/resolver.rs | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/crates/ty_python_semantic/src/module_resolver/resolver.rs b/crates/ty_python_semantic/src/module_resolver/resolver.rs index 0dcd42b0dd3e9..d9774480fac14 100644 --- a/crates/ty_python_semantic/src/module_resolver/resolver.rs +++ b/crates/ty_python_semantic/src/module_resolver/resolver.rs @@ -1152,6 +1152,64 @@ mod tests { ); } + #[test] + fn stubs_over_module_source() { + let TestCase { db, src, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo.py", ""), ("foo.pyi", "")]) + .build(); + + let foo_module_name = ModuleName::new_static("foo").unwrap(); + let foo_module = resolve_module(&db, &foo_module_name).unwrap(); + + assert_eq!( + Some(&foo_module), + resolve_module(&db, &foo_module_name).as_ref() + ); + + assert_eq!("foo", foo_module.name(&db)); + assert_eq!(&src, foo_module.search_path(&db).unwrap()); + assert_eq!(ModuleKind::Module, foo_module.kind(&db)); + + let expected_foo_path = src.join("foo.pyi"); + assert_eq!(&expected_foo_path, foo_module.file(&db).unwrap().path(&db)); + assert_eq!( + Some(foo_module), + path_to_module(&db, &FilePath::System(expected_foo_path)) + ); + } + + /// Tests precedence when there is a package and a sibling stub file. + /// + /// NOTE: I am unsure if this is correct. I wrote this test to match + /// behavior while implementing "list modules." Notably, in this case, the + /// regular source file gets priority. But in `stubs_over_module_source` + /// above, the stub file gets priority. + #[test] + fn stubs_over_package_source() { + let TestCase { db, src, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo/__init__.py", ""), ("foo.pyi", "")]) + .build(); + + let foo_module_name = ModuleName::new_static("foo").unwrap(); + let foo_module = resolve_module(&db, &foo_module_name).unwrap(); + + assert_eq!( + Some(&foo_module), + resolve_module(&db, &foo_module_name).as_ref() + ); + + assert_eq!("foo", foo_module.name(&db)); + assert_eq!(&src, foo_module.search_path(&db).unwrap()); + assert_eq!(ModuleKind::Package, foo_module.kind(&db)); + + let expected_foo_path = src.join("foo/__init__.py"); + assert_eq!(&expected_foo_path, foo_module.file(&db).unwrap().path(&db)); + assert_eq!( + Some(foo_module), + path_to_module(&db, &FilePath::System(expected_foo_path)) + ); + } + #[test] fn builtins_vendored() { let TestCase { db, stdlib, .. } = TestCaseBuilder::new() From 5b00ec981bde8f253867c29ed885d04921042328 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:02:45 -0400 Subject: [PATCH 063/160] [ty] Split out another constructor for `ModuleName` This makes it a little more flexible to call. For example, we might have a `StmtImport` and not a `StmtImportFrom`. --- crates/ty_python_semantic/src/module_name.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/ty_python_semantic/src/module_name.rs b/crates/ty_python_semantic/src/module_name.rs index 79a9c0fd63e58..df7ae09e2a0d0 100644 --- a/crates/ty_python_semantic/src/module_name.rs +++ b/crates/ty_python_semantic/src/module_name.rs @@ -285,10 +285,16 @@ impl ModuleName { range: _, node_index: _, } = node; + Self::from_identifier_parts(db, importing_file, module.as_deref(), *level) + } - let module = module.as_deref(); - - if let Some(level) = NonZeroU32::new(*level) { + pub(crate) fn from_identifier_parts( + db: &dyn Db, + importing_file: File, + module: Option<&str>, + level: u32, + ) -> Result { + if let Some(level) = NonZeroU32::new(level) { relative_module_name(db, importing_file, module, level) } else { module From a0ddf1f7c429a691414db2ec906af16d5c77d6b2 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:10:02 -0400 Subject: [PATCH 064/160] [ty] Fix a bug when converting `ModulePath` to `ModuleName` Previously, if the module was just `foo-stubs`, we'd skip over stripping the `-stubs` suffix which would lead to us returning `None`. This function is now a little convoluted and could be simpler if we did an intermediate allocation. But I kept the iterative approach and added a special case to handle `foo-stubs`. --- .../src/module_resolver/path.rs | 70 +++++++++++++++++-- 1 file changed, 66 insertions(+), 4 deletions(-) diff --git a/crates/ty_python_semantic/src/module_resolver/path.rs b/crates/ty_python_semantic/src/module_resolver/path.rs index 484b97bb69b7d..c2c735bdd9362 100644 --- a/crates/ty_python_semantic/src/module_resolver/path.rs +++ b/crates/ty_python_semantic/src/module_resolver/path.rs @@ -231,6 +231,10 @@ impl ModulePath { #[must_use] pub(crate) fn to_module_name(&self) -> Option { + fn strip_stubs(component: &str) -> &str { + component.strip_suffix("-stubs").unwrap_or(component) + } + let ModulePath { search_path: _, relative_path, @@ -239,13 +243,28 @@ impl ModulePath { stdlib_path_to_module_name(relative_path) } else { let parent = relative_path.parent()?; + let name = relative_path.file_stem()?; + if parent.as_str().is_empty() { + // Stubs should only be stripped when there is no + // extension. e.g., `foo-stubs` should be stripped + // by not `foo-stubs.pyi`. In the latter case, + // `ModuleName::new` will fail (which is what we want). + return ModuleName::new(if relative_path.extension().is_some() { + name + } else { + strip_stubs(relative_path.as_str()) + }); + } + let parent_components = parent.components().enumerate().map(|(index, component)| { let component = component.as_str(); - // For stub packages, strip the `-stubs` suffix from the first component - // because it isn't a valid module name part AND the module name is the name without the `-stubs`. + // For stub packages, strip the `-stubs` suffix from + // the first component because it isn't a valid module + // name part AND the module name is the name without + // the `-stubs`. if index == 0 { - component.strip_suffix("-stubs").unwrap_or(component) + strip_stubs(component) } else { component } @@ -256,7 +275,7 @@ impl ModulePath { if skip_final_part { ModuleName::from_components(parent_components) } else { - ModuleName::from_components(parent_components.chain(relative_path.file_stem())) + ModuleName::from_components(parent_components.chain([name])) } } } @@ -1245,4 +1264,47 @@ mod tests { assert!(!xml_etree.is_directory(&resolver)); assert!(!xml_etree.is_regular_package(&resolver)); } + + #[test] + fn strip_not_top_level_stubs_suffix() { + let TestCase { db, src, .. } = TestCaseBuilder::new().build(); + let sp = SearchPath::first_party(db.system(), src).unwrap(); + let mut mp = sp.to_module_path(); + mp.push("foo-stubs"); + mp.push("quux"); + assert_eq!( + mp.to_module_name(), + Some(ModuleName::new_static("foo.quux").unwrap()) + ); + } + + /// Tests that a module path of just `foo-stubs` will correctly be + /// converted to a module name of just `foo`. + /// + /// This is a regression test where this conversion ended up + /// treating the module path as invalid and returning `None` from + /// `ModulePath::to_module_name` instead. + #[test] + fn strip_top_level_stubs_suffix() { + let TestCase { db, src, .. } = TestCaseBuilder::new().build(); + let sp = SearchPath::first_party(db.system(), src).unwrap(); + let mut mp = sp.to_module_path(); + mp.push("foo-stubs"); + assert_eq!( + mp.to_module_name(), + Some(ModuleName::new_static("foo").unwrap()) + ); + } + + /// Tests that paths like `foo-stubs.pyi` don't have `-stubs` + /// stripped. (And this leads to failing to create a `ModuleName`, + /// which is what we want.) + #[test] + fn no_strip_with_extension() { + let TestCase { db, src, .. } = TestCaseBuilder::new().build(); + let sp = SearchPath::first_party(db.system(), src).unwrap(); + let mut mp = sp.to_module_path(); + mp.push("foo-stubs.pyi"); + assert_eq!(mp.to_module_name(), None); + } } From 79b275421531209794b60067abafd7bee4d0cc1d Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:12:09 -0400 Subject: [PATCH 065/160] [ty] Add some more helper routines to `ModulePath` --- .../src/module_resolver/path.rs | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/crates/ty_python_semantic/src/module_resolver/path.rs b/crates/ty_python_semantic/src/module_resolver/path.rs index c2c735bdd9362..9a697f27f1fc2 100644 --- a/crates/ty_python_semantic/src/module_resolver/path.rs +++ b/crates/ty_python_semantic/src/module_resolver/path.rs @@ -37,6 +37,26 @@ impl ModulePath { ) } + /// Returns true if this is a path to a "stub file." + /// + /// i.e., A module whose file extension is `pyi`. + #[must_use] + pub(crate) fn is_stub_file(&self) -> bool { + self.relative_path.extension() == Some("pyi") + } + + /// Returns true if this is a path to a "stub package." + /// + /// i.e., A module whose top-most parent package corresponds to a + /// directory with a `-stubs` suffix in its name. + #[must_use] + pub(crate) fn is_stub_package(&self) -> bool { + let Some(first) = self.relative_path.components().next() else { + return false; + }; + first.as_str().ends_with("-stubs") + } + pub(crate) fn push(&mut self, component: &str) { if let Some(component_extension) = camino::Utf8Path::new(component).extension() { assert!( @@ -663,6 +683,23 @@ impl SearchPath { pub(crate) fn as_vendored_path(&self) -> Option<&VendoredPath> { self.as_path().as_vendored_path() } + + /// Returns a succinct string representing the *internal kind* of this + /// search path. This is useful in snapshot tests where one wants to + /// capture this specific detail about search paths. + #[cfg(test)] + #[must_use] + pub(crate) fn debug_kind(&self) -> &'static str { + match *self.0 { + SearchPathInner::Extra(_) => "extra", + SearchPathInner::FirstParty(_) => "first-party", + SearchPathInner::StandardLibraryCustom(_) => "std-custom", + SearchPathInner::StandardLibraryReal(_) => "std-real", + SearchPathInner::SitePackages(_) => "site-packages", + SearchPathInner::Editable(_) => "editable", + SearchPathInner::StandardLibraryVendored(_) => "std-vendored", + } + } } impl PartialEq for SearchPath { @@ -749,6 +786,13 @@ impl<'db> SystemOrVendoredPathRef<'db> { } } + pub(super) fn extension(&self) -> Option<&str> { + match self { + Self::System(system) => system.extension(), + Self::Vendored(vendored) => vendored.extension(), + } + } + pub(super) fn parent<'a>(&'a self) -> Option> where 'a: 'db, @@ -774,6 +818,18 @@ impl<'db> SystemOrVendoredPathRef<'db> { } } +impl<'a> From<&'a SystemPath> for SystemOrVendoredPathRef<'a> { + fn from(path: &'a SystemPath) -> SystemOrVendoredPathRef<'a> { + SystemOrVendoredPathRef::System(path) + } +} + +impl<'a> From<&'a VendoredPath> for SystemOrVendoredPathRef<'a> { + fn from(path: &'a VendoredPath) -> SystemOrVendoredPathRef<'a> { + SystemOrVendoredPathRef::Vendored(path) + } +} + impl std::fmt::Display for SystemOrVendoredPathRef<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { From ec7c2efef9f6711e0da5307bf6a325d912afcd08 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:12:55 -0400 Subject: [PATCH 066/160] [ty] Lightly expose `FileModule` and `NamespacePackage` fields This will make it easier to emit this info into snapshots for testing. --- .../src/module_resolver/module.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/crates/ty_python_semantic/src/module_resolver/module.rs b/crates/ty_python_semantic/src/module_resolver/module.rs index 8e0a89a1551a6..e61717364ec0c 100644 --- a/crates/ty_python_semantic/src/module_resolver/module.rs +++ b/crates/ty_python_semantic/src/module_resolver/module.rs @@ -72,6 +72,9 @@ impl<'db> Module<'db> { } /// The search path from which the module was resolved. + /// + /// It is guaranteed that if `None` is returned, then this is a namespace + /// package. Otherwise, this is a regular package or file module. pub(crate) fn search_path(self, db: &'db dyn Database) -> Option<&'db SearchPath> { match self { Module::File(module) => Some(module.search_path(db)), @@ -214,12 +217,12 @@ fn all_submodule_names_for_package(db: &dyn Db, file: File) -> Option> #[salsa::tracked(debug, heap_size=ruff_memory_usage::heap_size)] pub struct FileModule<'db> { #[returns(ref)] - name: ModuleName, - kind: ModuleKind, + pub(super) name: ModuleName, + pub(super) kind: ModuleKind, #[returns(ref)] - search_path: SearchPath, - file: File, - known: Option, + pub(super) search_path: SearchPath, + pub(super) file: File, + pub(super) known: Option, } /// A namespace package. @@ -229,7 +232,7 @@ pub struct FileModule<'db> { #[salsa::tracked(debug, heap_size=ruff_memory_usage::heap_size)] pub struct NamespacePackage<'db> { #[returns(ref)] - name: ModuleName, + pub(super) name: ModuleName, } #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, get_size2::GetSize)] From 4db20f459c8178326560c20c522d04563ad85511 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:14:31 -0400 Subject: [PATCH 067/160] [ty] Add "list modules" implementation The actual implementation wasn't too bad. It's not long but pretty fiddly. I copied over the tests from the existing module resolver and adapted them to work with this API. Then I added a number of my own tests as well. --- crates/ty_python_semantic/src/lib.rs | 4 +- .../src/module_resolver/list.rs | 1675 +++++++++++++++++ .../src/module_resolver/mod.rs | 2 + 3 files changed, 1679 insertions(+), 2 deletions(-) create mode 100644 crates/ty_python_semantic/src/module_resolver/list.rs diff --git a/crates/ty_python_semantic/src/lib.rs b/crates/ty_python_semantic/src/lib.rs index b3e4ef3c7e5cd..afd61f44caf8f 100644 --- a/crates/ty_python_semantic/src/lib.rs +++ b/crates/ty_python_semantic/src/lib.rs @@ -7,8 +7,8 @@ use crate::suppression::{INVALID_IGNORE_COMMENT, UNKNOWN_RULE, UNUSED_IGNORE_COM pub use db::Db; pub use module_name::ModuleName; pub use module_resolver::{ - Module, SearchPathValidationError, SearchPaths, resolve_module, resolve_real_module, - system_module_search_paths, + Module, SearchPath, SearchPathValidationError, SearchPaths, list_modules, resolve_module, + resolve_real_module, system_module_search_paths, }; pub use program::{ Program, ProgramSettings, PythonVersionFileSource, PythonVersionSource, diff --git a/crates/ty_python_semantic/src/module_resolver/list.rs b/crates/ty_python_semantic/src/module_resolver/list.rs new file mode 100644 index 0000000000000..47765702b0610 --- /dev/null +++ b/crates/ty_python_semantic/src/module_resolver/list.rs @@ -0,0 +1,1675 @@ +use std::collections::btree_map::{BTreeMap, Entry}; + +use ruff_python_ast::PythonVersion; + +use crate::db::Db; +use crate::module_name::ModuleName; +use crate::program::Program; + +use super::module::{Module, ModuleKind}; +use super::path::{ModulePath, SearchPath, SystemOrVendoredPathRef}; +use super::resolver::{ + ModuleResolveMode, ResolverContext, is_non_shadowable, resolve_file_module, search_paths, +}; + +/// List all available modules. +#[salsa::tracked] +pub fn list_modules(db: &dyn Db) -> Vec> { + let mut lister = Lister::new(db); + for search_path in search_paths(db, ModuleResolveMode::StubsAllowed) { + match search_path.as_path() { + SystemOrVendoredPathRef::System(system_search_path) => { + let Ok(it) = db.system().read_directory(system_search_path) else { + continue; + }; + for result in it { + let Ok(entry) = result else { continue }; + lister.add_path(search_path, &entry.path().into(), entry.file_type().into()); + } + } + SystemOrVendoredPathRef::Vendored(vendored_search_path) => { + for entry in db.vendored().read_directory(vendored_search_path) { + lister.add_path(search_path, &entry.path().into(), entry.file_type().into()); + } + } + } + } + lister.into_modules() +} + +/// An implementation helper for "list all modules." +/// +/// This is responsible for accumulating modules indexed by +/// module name. It also handles precedence by implementing the +/// rules that determine which module gets priority when there is +/// otherwise ambiguity (e.g., `foo.py` versus `foo/__init__.py` +/// in the same directory). +struct Lister<'db> { + db: &'db dyn Db, + program: Program, + modules: BTreeMap<&'db ModuleName, Module<'db>>, +} + +impl<'db> Lister<'db> { + /// Create new state that can accumulate modules from a list + /// of file paths. + fn new(db: &'db dyn Db) -> Lister<'db> { + let program = Program::get(db); + Lister { + db, + program, + modules: BTreeMap::new(), + } + } + + /// Returns the modules collected, sorted by module name. + fn into_modules(self) -> Vec> { + self.modules.into_values().collect() + } + + /// Add the given `path` (from `search_path`) as a possible + /// module to this lister. The `file_type` should be the type + /// of `path` (file, directory or symlink). + /// + /// This may decide that the given path does not correspond to + /// a valid Python module. In which case, it is dropped and this + /// is a no-op. + fn add_path( + &mut self, + search_path: &SearchPath, + path: &SystemOrVendoredPathRef<'_>, + file_type: FileType, + ) { + let mut has_py_extension = false; + // We must have no extension, a Python source file extension (`.py`) + // or a Python stub file extension (`.pyi`). + if let Some(ext) = path.extension() { + has_py_extension = is_python_extension(ext); + if !has_py_extension { + return; + } + } + + let Some(name) = path.file_name() else { return }; + let mut module_path = search_path.to_module_path(); + module_path.push(name); + let Some(module_name) = module_path.to_module_name() else { + return; + }; + + // Some modules cannot shadow a subset of special + // modules from the standard library. + if !search_path.is_standard_library() && self.is_non_shadowable(&module_name) { + return; + } + + if file_type.is_possibly_directory() { + if module_path.is_regular_package(&self.context()) { + module_path.push("__init__"); + if let Some(file) = resolve_file_module(&module_path, &self.context()) { + self.add_module( + &module_path, + Module::file_module( + self.db, + module_name, + ModuleKind::Package, + search_path.clone(), + file, + ), + ); + return; + } + module_path.pop(); + } + + // Otherwise, we kind of have to assume that we have a + // namespace package, which can be any directory that + // *doesn't* contain an `__init__.{py,pyi}`. We do need to + // know if we have a real directory or not. If we have a + // symlink, then this requires hitting the file system. + // + // Note though that if we find a "regular" module in a + // lower priority search path, that will be allowed to + // overwrite this namespace package. + // + // We only do this when in a standard library search + // path, which matches how the "resolve this module" + // implementation works. In particular, typeshed doesn't + // use any namespace packages at time of writing + // (2025-08-08), so if we're in a standard library search + // path, we "know" this can't actually be a package. + // + // NOTE: Note that the + // `module_path.is_regular_package()` check above takes + // `VERSIONS` into consideration. Which means it can return + // `false` even when, say, `package/__init__.py` exists. In + // that case, outside of a standard library search path, + // we'd incorrectly report it here as a namespace package. + // HOWEVER, `VERSIONS` is only applicable for typeshed, so + // this ends up working okay. But if typeshed ever uses + // namespace packages, then this will need to be accounted + // for. + let is_dir = + file_type.is_definitely_directory() || module_path.is_directory(&self.context()); + if is_dir { + if !search_path.is_standard_library() { + self.add_module( + &module_path, + Module::namespace_package(self.db, module_name), + ); + } + return; + } + // At this point, we have a symlink that we know is not a + // directory, so press on as if it were a regular file... + } + + // At this point, we're looking for a file module. + // For a file module, we require a `.py` or `.pyi` + // extension. + if !has_py_extension { + return; + } + // We also require stub packages to be packages, not + // single-file modules. + if module_path.is_stub_package() { + return; + } + + let Some(file) = module_path.to_file(&self.context()) else { + return; + }; + self.add_module( + &module_path, + Module::file_module( + self.db, + module_name, + ModuleKind::Module, + search_path.clone(), + file, + ), + ); + } + + /// Adds the given module to the collection. + /// + /// If the module had already been added and shouldn't override any + /// existing entry, then this is a no-op. That is, this assumes that the + /// caller looks for modules in search path priority order. + fn add_module(&mut self, path: &ModulePath, module: Module<'db>) { + let mut entry = match self.modules.entry(module.name(self.db)) { + Entry::Vacant(entry) => { + entry.insert(module); + return; + } + Entry::Occupied(entry) => entry, + }; + + let existing = entry.get(); + match (existing.search_path(self.db), module.search_path(self.db)) { + // When we had a namespace package and now try to + // insert a non-namespace package, the latter always + // takes precedent, even if it's in a lower priority + // search path. + (None, Some(_)) => { + entry.insert(module); + } + (Some(search_path_existing), Some(search_path_new)) => { + // Merging across search paths is only necessary for + // namespace packages. For all other modules, entries + // from earlier search paths take precedence. Thus, all + // of the cases below require that we're in the same + // directory. + if search_path_existing != search_path_new { + return; + } + // When we have a `foo/__init__.py` and a `foo.py` in + // the same directory, the former takes precedent. + // (This case can only occur when both have a search + // path.) + if existing.kind(self.db) == ModuleKind::Module + && module.kind(self.db) == ModuleKind::Package + { + entry.insert(module); + return; + } + // Or if we have two file modules and the new one + // is a stub, then the stub takes priority. + if existing.kind(self.db) == ModuleKind::Module + && module.kind(self.db) == ModuleKind::Module + && path.is_stub_file() + { + entry.insert(module); + return; + } + // Or... if we have a stub package, the stub package + // always gets priority. + if path.is_stub_package() { + entry.insert(module); + } + } + _ => {} + } + } + + /// Returns true if the given module name cannot be shadowable. + fn is_non_shadowable(&self, name: &ModuleName) -> bool { + is_non_shadowable(self.python_version().minor, name.as_str()) + } + + /// Returns the Python version we want to perform module resolution + /// with. + fn python_version(&self) -> PythonVersion { + self.program.python_version(self.db) + } + + /// Constructs a resolver context for use with some APIs that require it. + fn context(&self) -> ResolverContext<'db> { + ResolverContext { + db: self.db, + python_version: self.python_version(), + // We don't currently support listing modules + // in a "no stubs allowed" mode. + mode: ModuleResolveMode::StubsAllowed, + } + } +} + +/// The type of a file. +#[derive(Clone, Copy, Debug)] +enum FileType { + File, + Directory, + Symlink, +} + +impl FileType { + fn is_possibly_directory(self) -> bool { + matches!(self, FileType::Directory | FileType::Symlink) + } + + fn is_definitely_directory(self) -> bool { + matches!(self, FileType::Directory) + } +} + +impl From for FileType { + fn from(ft: ruff_db::vendored::FileType) -> FileType { + match ft { + ruff_db::vendored::FileType::File => FileType::File, + ruff_db::vendored::FileType::Directory => FileType::Directory, + } + } +} + +impl From for FileType { + fn from(ft: ruff_db::system::FileType) -> FileType { + match ft { + ruff_db::system::FileType::File => FileType::File, + ruff_db::system::FileType::Directory => FileType::Directory, + ruff_db::system::FileType::Symlink => FileType::Symlink, + } + } +} + +/// Returns true if and only if the given file extension corresponds +/// to a Python source or stub file. +fn is_python_extension(ext: &str) -> bool { + matches!(ext, "py" | "pyi") +} + +#[cfg(test)] +mod tests { + use camino::{Utf8Component, Utf8Path}; + use ruff_db::Db as _; + use ruff_db::files::{File, FilePath}; + use ruff_db::system::{ + DbWithTestSystem, DbWithWritableSystem, OsSystem, SystemPath, SystemPathBuf, + }; + use ruff_db::testing::assert_function_query_was_not_run; + use ruff_python_ast::PythonVersion; + + use crate::db::{Db, tests::TestDb}; + use crate::module_resolver::module::Module; + use crate::module_resolver::resolver::{ + ModuleResolveMode, ModuleResolveModeIngredient, dynamic_resolution_paths, + }; + use crate::module_resolver::testing::{FileSpec, MockedTypeshed, TestCase, TestCaseBuilder}; + use crate::program::{Program, ProgramSettings, SearchPathSettings}; + use crate::{PythonPlatform, PythonVersionSource, PythonVersionWithSource}; + + use super::list_modules; + + struct ModuleDebugSnapshot<'db> { + db: &'db dyn Db, + module: Module<'db>, + } + + impl std::fmt::Debug for ModuleDebugSnapshot<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self.module { + Module::Namespace(pkg) => { + write!(f, "Module::Namespace({name:?})", name = pkg.name(self.db)) + } + Module::File(module) => { + // For snapshots, just normalize all paths to using + // Unix slashes for simplicity. + let path_components = match module.file(self.db).path(self.db) { + FilePath::System(path) => path.as_path().components(), + FilePath::Vendored(path) => path.as_path().components(), + FilePath::SystemVirtual(path) => Utf8Path::new(path.as_str()).components(), + }; + let nice_path = path_components + // Avoid including a root component, since that + // results in a platform dependent separator. + // Convert to an empty string so that we get a + // path beginning with `/` regardless of platform. + .map(|component| { + if let Utf8Component::RootDir = component { + Utf8Component::Normal("") + } else { + component + } + }) + .map(|component| component.as_str()) + .collect::>() + .join("/"); + write!( + f, + "Module::File({name:?}, {search_path:?}, {path:?}, {kind:?}, {known:?})", + name = module.name(self.db).as_str(), + search_path = module.search_path(self.db).debug_kind(), + path = nice_path, + kind = module.kind(self.db), + known = module.known(self.db), + ) + } + } + } + } + + fn sorted_list(db: &dyn Db) -> Vec> { + let mut modules = list_modules(db); + modules.sort_by(|m1, m2| m1.name(db).cmp(m2.name(db))); + modules + } + + fn list_snapshot(db: &dyn Db) -> Vec> { + list_snapshot_filter(db, |_| true) + } + + fn list_snapshot_filter<'db>( + db: &'db dyn Db, + predicate: impl Fn(&Module<'db>) -> bool, + ) -> Vec> { + sorted_list(db) + .into_iter() + .filter(predicate) + .map(|module| ModuleDebugSnapshot { db, module }) + .collect() + } + + #[test] + fn first_party_module() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo.py", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo.py", Module, None), + ] + "#, + ); + } + + #[test] + fn stubs_over_module_source() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo.py", ""), ("foo.pyi", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn stubs_over_package_source() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo/__init__.py", ""), ("foo.pyi", "")]) + .build(); + + // NOTE: This matches the behavior of the "resolve this module" + // implementation, even though it seems inconsistent with the + // `stubs_over_module_source` test. + // + // TODO: Check what other type checkers do. It seems like this (and + // "resolve this module") should prefer the stub file, although the + // typing spec isn't perfectly clear on this point: + // https://typing.python.org/en/latest/spec/distributing.html#stub-files + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo/__init__.py", Package, None), + ] + "#, + ); + } + + /// Tests that if we have a `foo.py` and a `foo/__init__.py`, then the + /// latter takes precedence. + /// + /// This is somewhat difficult to test using the in-memory file system, + /// since it always returns directory entries in lexicographic order. This + /// in turn implies that `foo` will always appear before `foo.py`. But to + /// truly test this, we would like to also be correct in the case where + /// `foo.py` appears before `foo` (which can certainly happen in the real + /// world). + #[test] + fn package_over_module1() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo.py", ""), ("foo/__init__.py", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo/__init__.py", Package, None), + ] + "#, + ); + } + + /// Similar to `package_over_module1`, but flips the order of files. + /// + /// (At time of writing, 2025-08-07, this doesn't actually make a + /// difference since the in-memory file system sorts directory entries.) + #[test] + fn package_over_module2() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo/__init__.py", ""), ("foo.py", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo/__init__.py", Package, None), + ] + "#, + ); + } + + #[test] + fn builtins_vendored() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_vendored_typeshed() + .with_src_files(&[("builtins.py", "FOOOO = 42")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot_filter(&db, |m| m.name(&db).as_str() == "builtins"), + @r#" + [ + Module::File("builtins", "std-vendored", "stdlib/builtins.pyi", Module, Some(Builtins)), + ] + "#, + ); + } + + #[test] + fn builtins_custom() { + const TYPESHED: MockedTypeshed = MockedTypeshed { + stdlib_files: &[("builtins.pyi", "def min(a, b): ...")], + versions: "builtins: 3.8-", + }; + + const SRC: &[FileSpec] = &[("builtins.py", "FOOOO = 42")]; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(SRC) + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("builtins", "std-custom", "/typeshed/stdlib/builtins.pyi", Module, Some(Builtins)), + ] + "#, + ); + } + + #[test] + fn stdlib() { + const TYPESHED: MockedTypeshed = MockedTypeshed { + stdlib_files: &[("functools.pyi", "def update_wrapper(): ...")], + versions: "functools: 3.8-", + }; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn stdlib_resolution_respects_versions_file_py38_existing_modules() { + const VERSIONS: &str = "\ + asyncio: 3.8- # 'Regular' package on py38+ + asyncio.tasks: 3.9-3.11 # Submodule on py39+ only + functools: 3.8- # Top-level single-file module + random: 3.8- # 'Regular' file module on py38+ + xml: 3.8-3.8 # Namespace package on py38 only + "; + + const STDLIB: &[FileSpec] = &[ + ("asyncio/__init__.pyi", ""), + ("asyncio/tasks.pyi", ""), + ("functools.pyi", ""), + ("random.pyi", ""), + ("xml/etree.pyi", ""), + ]; + + const TYPESHED: MockedTypeshed = MockedTypeshed { + stdlib_files: STDLIB, + versions: VERSIONS, + }; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + // NOTE: This currently doesn't return `xml` since + // the implementation assumes that typeshed doesn't + // have namespace packages. But our test setup (copied + // from the "resolve this module" tests) does. + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("asyncio", "std-custom", "/typeshed/stdlib/asyncio/__init__.pyi", Package, None), + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + Module::File("random", "std-custom", "/typeshed/stdlib/random.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn stdlib_resolution_respects_versions_file_py38_nonexisting_modules() { + const VERSIONS: &str = "\ + asyncio: 3.8- # 'Regular' package on py38+ + asyncio.tasks: 3.9-3.11 # Submodule on py39+ only + collections: 3.9- # 'Regular' package on py39+ + importlib: 3.9- # Namespace package on py39+ + random: 3.9- # 'Regular' file module on py39+ + xml: 3.8-3.8 # Namespace package on 3.8 only + foo: 3.9- + "; + + const STDLIB: &[FileSpec] = &[ + ("collections/__init__.pyi", ""), + ("asyncio/__init__.pyi", ""), + ("asyncio/tasks.pyi", ""), + ("importlib/abc.pyi", ""), + ("random.pyi", ""), + ("xml/etree.pyi", ""), + ]; + + const TYPESHED: MockedTypeshed = MockedTypeshed { + stdlib_files: STDLIB, + versions: VERSIONS, + }; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + // NOTE: This currently doesn't return any of the namespace + // packages defined above in our mock typeshed (that is, + // `importlib` and `xml`) because our implementation assumes + // namespace packages cannot occur in typeshed. + // + // Relatedly, `collections` and `random` should not appear + // because they are limited to 3.9+. + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("asyncio", "std-custom", "/typeshed/stdlib/asyncio/__init__.pyi", Package, None), + ] + "#, + ); + } + + #[test] + fn stdlib_resolution_respects_versions_file_py39_existing_modules() { + const VERSIONS: &str = "\ + asyncio: 3.8- # 'Regular' package on py38+ + asyncio.tasks: 3.9-3.11 # Submodule on py39+ only + collections: 3.9- # 'Regular' package on py39+ + functools: 3.8- # Top-level single-file module + importlib: 3.9- # Namespace package on py39+ + "; + + const STDLIB: &[FileSpec] = &[ + ("asyncio/__init__.pyi", ""), + ("asyncio/tasks.pyi", ""), + ("collections/__init__.pyi", ""), + ("functools.pyi", ""), + ("importlib/abc.pyi", ""), + ]; + + const TYPESHED: MockedTypeshed = MockedTypeshed { + stdlib_files: STDLIB, + versions: VERSIONS, + }; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY39) + .build(); + + // NOTE: This currently doesn't return any of the namespace + // packages defined above in our mock typeshed (that is, + // `importlib`) because our implementation assumes namespace + // packages cannot occur in typeshed. + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("asyncio", "std-custom", "/typeshed/stdlib/asyncio/__init__.pyi", Package, None), + Module::File("collections", "std-custom", "/typeshed/stdlib/collections/__init__.pyi", Package, Some(Collections)), + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn stdlib_resolution_respects_versions_file_py39_nonexisting_modules() { + const VERSIONS: &str = "\ + importlib: 3.9- # 'Regular' package on py39+ + xml: 3.8-3.8 # 'Regular' package on 3.8 only + "; + + // Since our implementation assumes typeshed doesn't contain + // any namespace packages (as an optimization), this test case + // is modified from the corresponding test in the "resolve a + // file" implementation so that both namespace packages are + // just regular packages. ---AG + const STDLIB: &[FileSpec] = &[ + ("importlib/__init__.pyi", ""), + ("importlib/abc.pyi", ""), + ("xml/__init__.pyi", ""), + ("xml/etree.pyi", ""), + ]; + + const TYPESHED: MockedTypeshed = MockedTypeshed { + stdlib_files: STDLIB, + versions: VERSIONS, + }; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY39) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("importlib", "std-custom", "/typeshed/stdlib/importlib/__init__.pyi", Package, Some(ImportLib)), + ] + "#, + ); + } + + #[test] + fn first_party_precedence_over_stdlib() { + const SRC: &[FileSpec] = &[("functools.py", "def update_wrapper(): ...")]; + + const TYPESHED: MockedTypeshed = MockedTypeshed { + stdlib_files: &[("functools.pyi", "def update_wrapper(): ...")], + versions: "functools: 3.8-", + }; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(SRC) + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "first-party", "/src/functools.py", Module, None), + ] + "#, + ); + } + + #[test] + fn stdlib_uses_vendored_typeshed_when_no_custom_typeshed_supplied() { + let TestCase { db, .. } = TestCaseBuilder::new().with_vendored_typeshed().build(); + + insta::assert_debug_snapshot!( + list_snapshot_filter(&db, |m| m.name(&db).as_str().contains("pydoc_data")), + @r#" + [ + Module::File("pydoc_data", "std-vendored", "stdlib/pydoc_data/__init__.pyi", Package, None), + ] + "#, + ); + } + + #[test] + fn resolve_package() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo/__init__.py", "print('Hello, world!'")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo/__init__.py", Package, None), + ] + "#, + ); + } + + #[test] + fn package_priority_over_module() { + const SRC: &[FileSpec] = &[ + ("foo/__init__.py", "print('Hello, world!')"), + ("foo.py", "print('Hello, world!')"), + ]; + + let TestCase { db, .. } = TestCaseBuilder::new().with_src_files(SRC).build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo/__init__.py", Package, None), + ] + "#, + ); + } + + #[test] + fn typing_stub_over_module() { + const SRC: &[FileSpec] = &[("foo.py", "print('Hello, world!')"), ("foo.pyi", "x: int")]; + + let TestCase { db, .. } = TestCaseBuilder::new().with_src_files(SRC).build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn sub_packages() { + const SRC: &[FileSpec] = &[ + ("foo/__init__.py", ""), + ("foo/bar/__init__.py", ""), + ("foo/bar/baz.py", "print('Hello, world!)'"), + ]; + + let TestCase { db, .. } = TestCaseBuilder::new().with_src_files(SRC).build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo/__init__.py", Package, None), + ] + "#, + ); + } + + #[test] + fn module_search_path_priority() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo.py", "")]) + .with_site_packages_files(&[("foo.py", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo.py", Module, None), + ] + "#, + ); + } + + #[test] + #[cfg(target_family = "unix")] + fn symlink() -> anyhow::Result<()> { + use anyhow::Context; + + let mut db = TestDb::new(); + + let temp_dir = tempfile::TempDir::with_prefix("PREFIX-SENTINEL")?; + let root = temp_dir + .path() + .canonicalize() + .context("Failed to canonicalize temp dir")?; + let root = SystemPath::from_std_path(&root).unwrap(); + db.use_system(OsSystem::new(root)); + + let src = root.join("src"); + let site_packages = root.join("site-packages"); + let custom_typeshed = root.join("typeshed"); + + let foo = src.join("foo.py"); + let bar = src.join("bar.py"); + + std::fs::create_dir_all(src.as_std_path())?; + std::fs::create_dir_all(site_packages.as_std_path())?; + std::fs::create_dir_all(custom_typeshed.join("stdlib").as_std_path())?; + std::fs::File::create(custom_typeshed.join("stdlib/VERSIONS").as_std_path())?; + + std::fs::write(foo.as_std_path(), "")?; + std::os::unix::fs::symlink(foo.as_std_path(), bar.as_std_path())?; + + Program::from_settings( + &db, + ProgramSettings { + python_version: PythonVersionWithSource { + version: PythonVersion::PY38, + source: PythonVersionSource::default(), + }, + python_platform: PythonPlatform::default(), + search_paths: SearchPathSettings { + custom_typeshed: Some(custom_typeshed), + site_packages_paths: vec![site_packages], + ..SearchPathSettings::new(vec![src]) + } + .to_search_paths(db.system(), db.vendored()) + .expect("Valid search path settings"), + }, + ); + + // From the original test in the "resolve this module" + // implementation, this test seems to symlink a Python module + // and assert that they are treated as two distinct modules. + // That's what we capture here when listing modules as well. + insta::with_settings!({ + // Temporary directory often have random chars in them, so + // get rid of that part for a stable snapshot. + filters => [(r#""\S*PREFIX-SENTINEL.*?/"#, r#""/"#)], + }, { + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("bar", "first-party", "/src/bar.py", Module, None), + Module::File("foo", "first-party", "/src/foo.py", Module, None), + ] + "#, + ); + }); + + Ok(()) + } + + // NOTE: I've omitted the + // `deleting_an_unrelated_file_doesnt_change_module_resolution` + // test here since it likely seems inapplicable to "listing" + // modules. ---AG + + #[test] + fn adding_file_on_which_module_resolution_depends_invalidates_previously_failing_query_that_now_succeeds() + -> anyhow::Result<()> { + let TestCase { mut db, src, .. } = TestCaseBuilder::new().build(); + let foo_path = src.join("foo.py"); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @"[]", + ); + + // Now write the foo file + db.write_file(&foo_path, "x = 1")?; + + // FIXME: This is obviously wrong. The Salsa cache + // isn't being invalidated. + insta::assert_debug_snapshot!( + list_snapshot(&db), + @"[]", + ); + + Ok(()) + } + + #[test] + fn removing_file_on_which_module_resolution_depends_invalidates_previously_successful_query_that_now_fails() + -> anyhow::Result<()> { + const SRC: &[FileSpec] = &[("foo.py", "x = 1"), ("foo/__init__.py", "x = 2")]; + + let TestCase { mut db, src, .. } = TestCaseBuilder::new().with_src_files(SRC).build(); + let foo_path = src.join("foo/__init__.py"); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo/__init__.py", Package, None), + ] + "#, + ); + + // Delete `foo/__init__.py` and the `foo` folder. `foo` should + // now resolve to `foo.py` + db.memory_file_system().remove_file(&foo_path)?; + db.memory_file_system() + .remove_directory(foo_path.parent().unwrap())?; + // NOTE: This is present in the test for the "resolve this + // module" implementation as well. It seems like it kind of + // defeats the point to me. Shouldn't this be the thing we're + // testing? ---AG + File::sync_path(&mut db, &foo_path); + File::sync_path(&mut db, foo_path.parent().unwrap()); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo.py", Module, None), + ] + "#, + ); + + Ok(()) + } + + // Slightly changed from + // `adding_file_to_search_path_with_lower_priority_does_not_invalidate_query` + // to just check that adding a file doesn't change the results. (i.e., This is + // no longer a test of caching.) + #[test] + fn adding_file_to_search_path_with_lower_priority_does_not_change_results() { + const TYPESHED: MockedTypeshed = MockedTypeshed { + versions: "functools: 3.8-", + stdlib_files: &[("functools.pyi", "def update_wrapper(): ...")], + }; + + let TestCase { + mut db, + site_packages, + .. + } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + ] + "#, + ); + + // Adding a file to site-packages does not invalidate the query, + // since site-packages takes lower priority in the module resolution + db.clear_salsa_events(); + let site_packages_functools_path = site_packages.join("functools.py"); + db.write_file(&site_packages_functools_path, "f: int") + .unwrap(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn adding_file_to_search_path_with_higher_priority_invalidates_the_query() { + const TYPESHED: MockedTypeshed = MockedTypeshed { + versions: "functools: 3.8-", + stdlib_files: &[("functools.pyi", "def update_wrapper(): ...")], + }; + + let TestCase { mut db, src, .. } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + ] + "#, + ); + + // Adding a first-party file should do some kind of cache + // invalidation here, since first-party files take higher + // priority in module resolution: + let src_functools_path = src.join("functools.py"); + db.write_file(&src_functools_path, "FOO: int").unwrap(); + + // FIXME: This looks wrong! This is a cache invalidation + // problem, not a logic problem in the "list modules" + // implementation. + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn deleting_file_from_higher_priority_search_path_invalidates_the_query() { + const SRC: &[FileSpec] = &[("functools.py", "FOO: int")]; + + const TYPESHED: MockedTypeshed = MockedTypeshed { + versions: "functools: 3.8-", + stdlib_files: &[("functools.pyi", "def update_wrapper(): ...")], + }; + + let TestCase { mut db, src, .. } = TestCaseBuilder::new() + .with_src_files(SRC) + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + let src_functools_path = src.join("functools.py"); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "first-party", "/src/functools.py", Module, None), + ] + "#, + ); + + // If we now delete the first-party file, + // it should resolve to the stdlib: + db.memory_file_system() + .remove_file(&src_functools_path) + .unwrap(); + // NOTE: This is present in the test for the "resolve this + // module" implementation as well. It seems like it kind of + // defeats the point to me. Shouldn't this be the thing we're + // testing? In any case, removing it results in the cache not + // being invalidated. ---AG + File::sync_path(&mut db, &src_functools_path); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn editable_install_absolute_path() { + const SITE_PACKAGES: &[FileSpec] = &[("_foo.pth", "/x/src")]; + let x_directory = [("/x/src/foo/__init__.py", ""), ("/x/src/foo/bar.py", "")]; + + let TestCase { mut db, .. } = TestCaseBuilder::new() + .with_site_packages_files(SITE_PACKAGES) + .build(); + + db.write_files(x_directory).unwrap(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "editable", "/x/src/foo/__init__.py", Package, None), + ] + "#, + ); + } + + #[test] + fn editable_install_pth_file_with_whitespace() { + const SITE_PACKAGES: &[FileSpec] = &[ + ("_foo.pth", " /x/src"), + ("_bar.pth", "/y/src "), + ]; + let external_files = [("/x/src/foo.py", ""), ("/y/src/bar.py", "")]; + + let TestCase { mut db, .. } = TestCaseBuilder::new() + .with_site_packages_files(SITE_PACKAGES) + .build(); + + db.write_files(external_files).unwrap(); + + // Lines with leading whitespace in `.pth` files do not parse, + // so this excludes `foo`. Lines with trailing whitespace in + // `.pth` files do parse, so this includes `bar`. + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("bar", "editable", "/y/src/bar.py", Module, None), + ] + "#, + ); + } + + #[test] + fn editable_install_relative_path() { + const SITE_PACKAGES: &[FileSpec] = &[ + ("_foo.pth", "../../x/../x/y/src"), + ("../x/y/src/foo.pyi", ""), + ]; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_site_packages_files(SITE_PACKAGES) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "editable", "/x/y/src/foo.pyi", Module, None), + ] + "#, + ); + } + + #[test] + fn editable_install_multiple_pth_files_with_multiple_paths() { + const COMPLEX_PTH_FILE: &str = "\ +/ + +# a comment +/baz + +import not_an_editable_install; do_something_else_crazy_dynamic() + +# another comment +spam + +not_a_directory +"; + + const SITE_PACKAGES: &[FileSpec] = &[ + ("_foo.pth", "../../x/../x/y/src"), + ("_lots_of_others.pth", COMPLEX_PTH_FILE), + ("../x/y/src/foo.pyi", ""), + ("spam/spam.py", ""), + ]; + + let root_files = [("/a.py", ""), ("/baz/b.py", "")]; + + let TestCase { mut db, .. } = TestCaseBuilder::new() + .with_site_packages_files(SITE_PACKAGES) + .build(); + + db.write_files(root_files).unwrap(); + + // NOTE: The `src`, `typeshed` and `x` namespace packages here + // are a bit odd, but this seems to be a result of `/` in the + // pth file. It's also consistent with "resolve this module," + // which will indeed happily resolve `src`, `typeshed` or `x` + // as top-level modules. ---AG + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("a", "editable", "/a.py", Module, None), + Module::File("b", "editable", "/baz/b.py", Module, None), + Module::Namespace(ModuleName("baz")), + Module::File("foo", "editable", "/x/y/src/foo.pyi", Module, None), + Module::File("spam", "editable", "/site-packages/spam/spam.py", Module, None), + Module::Namespace(ModuleName("src")), + Module::Namespace(ModuleName("typeshed")), + Module::Namespace(ModuleName("x")), + ] + "#, + ); + } + + #[test] + fn module_resolution_paths_cached_between_different_module_resolutions() { + const SITE_PACKAGES: &[FileSpec] = &[("_foo.pth", "/x/src"), ("_bar.pth", "/y/src")]; + let external_directories = [("/x/src/foo.py", ""), ("/y/src/bar.py", "")]; + + let TestCase { mut db, .. } = TestCaseBuilder::new() + .with_site_packages_files(SITE_PACKAGES) + .build(); + + db.write_files(external_directories).unwrap(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("bar", "editable", "/y/src/bar.py", Module, None), + Module::File("foo", "editable", "/x/src/foo.py", Module, None), + ] + "#, + ); + + db.clear_salsa_events(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("bar", "editable", "/y/src/bar.py", Module, None), + Module::File("foo", "editable", "/x/src/foo.py", Module, None), + ] + "#, + ); + + let events = db.take_salsa_events(); + assert_function_query_was_not_run( + &db, + dynamic_resolution_paths, + ModuleResolveModeIngredient::new(&db, ModuleResolveMode::StubsAllowed), + &events, + ); + } + + #[test] + fn deleting_pth_file_on_which_module_resolution_depends_invalidates_cache() { + const SITE_PACKAGES: &[FileSpec] = &[("_foo.pth", "/x/src")]; + let x_directory = [("/x/src/foo.py", "")]; + + let TestCase { + mut db, + site_packages, + .. + } = TestCaseBuilder::new() + .with_site_packages_files(SITE_PACKAGES) + .build(); + + db.write_files(x_directory).unwrap(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "editable", "/x/src/foo.py", Module, None), + ] + "#, + ); + + db.memory_file_system() + .remove_file(site_packages.join("_foo.pth")) + .unwrap(); + // NOTE: This is present in the test for the "resolve this + // module" implementation as well. It seems like it kind of + // defeats the point to me. Shouldn't this be the thing we're + // testing? ---AG + File::sync_path(&mut db, &site_packages.join("_foo.pth")); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @"[]", + ); + } + + #[test] + fn deleting_editable_install_on_which_module_resolution_depends_invalidates_cache() { + const SITE_PACKAGES: &[FileSpec] = &[("_foo.pth", "/x/src")]; + let x_directory = [("/x/src/foo.py", "")]; + + let TestCase { mut db, .. } = TestCaseBuilder::new() + .with_site_packages_files(SITE_PACKAGES) + .build(); + let src_path = SystemPathBuf::from("/x/src"); + + db.write_files(x_directory).unwrap(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "editable", "/x/src/foo.py", Module, None), + ] + "#, + ); + + db.memory_file_system() + .remove_file(src_path.join("foo.py")) + .unwrap(); + db.memory_file_system().remove_directory(&src_path).unwrap(); + // NOTE: This is present in the test for the "resolve this + // module" implementation as well. It seems like it kind of + // defeats the point to me. Shouldn't this be the thing we're + // testing? ---AG + File::sync_path(&mut db, &src_path.join("foo.py")); + File::sync_path(&mut db, &src_path); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @"[]", + ); + } + + #[test] + fn multiple_site_packages_with_editables() { + let mut db = TestDb::new(); + + let venv_site_packages = SystemPathBuf::from("/venv-site-packages"); + let site_packages_pth = venv_site_packages.join("foo.pth"); + let system_site_packages = SystemPathBuf::from("/system-site-packages"); + let editable_install_location = SystemPathBuf::from("/x/y/a.py"); + let system_site_packages_location = system_site_packages.join("a.py"); + + db.memory_file_system() + .create_directory_all("/src") + .unwrap(); + db.write_files([ + (&site_packages_pth, "/x/y"), + (&editable_install_location, ""), + (&system_site_packages_location, ""), + ]) + .unwrap(); + + Program::from_settings( + &db, + ProgramSettings { + python_version: PythonVersionWithSource::default(), + python_platform: PythonPlatform::default(), + search_paths: SearchPathSettings { + site_packages_paths: vec![venv_site_packages, system_site_packages], + ..SearchPathSettings::new(vec![SystemPathBuf::from("/src")]) + } + .to_search_paths(db.system(), db.vendored()) + .expect("Valid search path settings"), + }, + ); + + // The editable installs discovered from the `.pth` file in the + // first `site-packages` directory take precedence over the + // second `site-packages` directory... + insta::assert_debug_snapshot!( + list_snapshot_filter(&db, |m| m.name(&db).as_str() == "a"), + @r#" + [ + Module::File("a", "editable", "/x/y/a.py", Module, None), + ] + "#, + ); + + db.memory_file_system() + .remove_file(&site_packages_pth) + .unwrap(); + // NOTE: This is present in the test for the "resolve this + // module" implementation as well. It seems like it kind of + // defeats the point to me. Shouldn't this be the thing we're + // testing? ---AG + File::sync_path(&mut db, &site_packages_pth); + + // ...But now that the `.pth` file in the first `site-packages` + // directory has been deleted, the editable install no longer + // exists, so the module now resolves to the file in the second + // `site-packages` directory + insta::assert_debug_snapshot!( + list_snapshot_filter(&db, |m| m.name(&db).as_str() == "a"), + @r#" + [ + Module::File("a", "site-packages", "/system-site-packages/a.py", Module, None), + ] + "#, + ); + } + + #[test] + #[cfg(unix)] + fn case_sensitive_resolution_with_symlinked_directory() -> anyhow::Result<()> { + use anyhow::Context; + + let temp_dir = tempfile::TempDir::with_prefix("PREFIX-SENTINEL")?; + let root = SystemPathBuf::from_path_buf( + temp_dir + .path() + .canonicalize() + .context("Failed to canonicalized path")?, + ) + .expect("UTF8 path for temp dir"); + + let mut db = TestDb::new(); + + let src = root.join("src"); + let a_package_target = root.join("a-package"); + let a_src = src.join("a"); + + db.use_system(OsSystem::new(&root)); + + db.write_file( + a_package_target.join("__init__.py"), + "class Foo: x: int = 4", + ) + .context("Failed to write `a-package/__init__.py`")?; + + db.write_file(src.join("main.py"), "print('Hy')") + .context("Failed to write `main.py`")?; + + // The symlink triggers the slow-path in the `OsSystem`'s + // `exists_path_case_sensitive` code because canonicalizing the path + // for `a/__init__.py` results in `a-package/__init__.py` + std::os::unix::fs::symlink(a_package_target.as_std_path(), a_src.as_std_path()) + .context("Failed to symlink `src/a` to `a-package`")?; + + Program::from_settings( + &db, + ProgramSettings { + python_version: PythonVersionWithSource::default(), + python_platform: PythonPlatform::default(), + search_paths: SearchPathSettings::new(vec![src]) + .to_search_paths(db.system(), db.vendored()) + .expect("valid search path settings"), + }, + ); + + insta::with_settings!({ + // Temporary directory often have random chars in them, so + // get rid of that part for a stable snapshot. + filters => [(r#""\S*PREFIX-SENTINEL.*?/"#, r#""/"#)], + }, { + insta::assert_debug_snapshot!( + list_snapshot_filter(&db, |m| matches!(m.name(&db).as_str(), "A" | "a")), + @r#" + [ + Module::File("a", "first-party", "/src/a/__init__.py", Package, None), + ] + "#, + ); + }); + + Ok(()) + } + + #[test] + fn file_to_module_where_one_search_path_is_subdirectory_of_other() { + let project_directory = SystemPathBuf::from("/project"); + let site_packages = project_directory.join(".venv/lib/python3.13/site-packages"); + let installed_foo_module = site_packages.join("foo/__init__.py"); + + let mut db = TestDb::new(); + db.write_file(&installed_foo_module, "").unwrap(); + + Program::from_settings( + &db, + ProgramSettings { + python_version: PythonVersionWithSource::default(), + python_platform: PythonPlatform::default(), + search_paths: SearchPathSettings { + site_packages_paths: vec![site_packages], + ..SearchPathSettings::new(vec![project_directory]) + } + .to_search_paths(db.system(), db.vendored()) + .unwrap(), + }, + ); + + insta::assert_debug_snapshot!( + list_snapshot_filter(&db, |m| m.name(&db).as_str() == "foo"), + @r#" + [ + Module::File("foo", "site-packages", "/project/.venv/lib/python3.13/site-packages/foo/__init__.py", Package, None), + ] + "#, + ); + } + + #[test] + fn namespace_package() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo/bar.py", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::Namespace(ModuleName("foo")), + ] + "#, + ); + } + + /// Regardless of search path priority, if we have a "regular" package of + /// the same name as a namespace package, the regular package always takes + /// priority. + #[test] + fn namespace_package_precedence() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo/bar.py", "")]) + .with_site_packages_files(&[("foo.py", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "site-packages", "/site-packages/foo.py", Module, None), + ] + "#, + ); + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo.py", "")]) + .with_site_packages_files(&[("foo/bar.py", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo.py", Module, None), + ] + "#, + ); + } + + #[test] + fn stub_package() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo-stubs/__init__.pyi", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo-stubs/__init__.pyi", Package, None), + ] + "#, + ); + } + + #[test] + fn stub_file_module_not_allowed() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo-stubs.pyi", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @"[]", + ); + } + + #[test] + fn stub_package_precedence() { + let TestCase { db, .. } = TestCaseBuilder::new() + .with_src_files(&[("foo/__init__.py", ""), ("foo-stubs/__init__.pyi", "")]) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [ + Module::File("foo", "first-party", "/src/foo-stubs/__init__.pyi", Package, None), + ] + "#, + ); + } + + #[test] + fn stub_package_not_allowed_in_typeshed() { + const TYPESHED: MockedTypeshed = MockedTypeshed { + versions: "foo: 3.8-", + stdlib_files: &[("foo-stubs/__init__.pyi", "")], + }; + + let TestCase { db, .. } = TestCaseBuilder::new() + .with_mocked_typeshed(TYPESHED) + .with_python_version(PythonVersion::PY38) + .build(); + + insta::assert_debug_snapshot!( + list_snapshot(&db), + @r#" + [] + "#, + ); + } +} diff --git a/crates/ty_python_semantic/src/module_resolver/mod.rs b/crates/ty_python_semantic/src/module_resolver/mod.rs index 5fb2fa1a527d3..f894d618aee62 100644 --- a/crates/ty_python_semantic/src/module_resolver/mod.rs +++ b/crates/ty_python_semantic/src/module_resolver/mod.rs @@ -1,5 +1,6 @@ use std::iter::FusedIterator; +pub use list::list_modules; pub(crate) use module::KnownModule; pub use module::Module; pub use path::SearchPathValidationError; @@ -12,6 +13,7 @@ use crate::Db; use crate::module_resolver::resolver::{ModuleResolveMode, search_paths}; use resolver::SearchPathIterator; +mod list; mod module; mod path; mod resolver; From 05478d5cc7a2cf6cd58876bcb2b79a12261c6cf8 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:15:47 -0400 Subject: [PATCH 068/160] [ty] Tweak some completion tests These tests were added as a regression check that a panic didn't occur. So we were asserting a bit more than necessary. In particular, these will soon return completions for modules, which creates large snapshots that we don't need. So modify these to just check there is sensible output that doesn't panic. --- crates/ty_ide/src/completion.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index 72d4a29756fc0..2470308c41a6d 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -2262,7 +2262,11 @@ import fo ", ); - assert_snapshot!(test.completions_without_builtins(), @""); + // This snapshot would generate a big list of modules, + // which is kind of annoying. So just assert that it + // runs without panicking and produces some non-empty + // output. + assert!(!test.completions_without_builtins().is_empty()); } // Ref: https://github.com/astral-sh/ty/issues/572 @@ -2274,7 +2278,11 @@ import foo as ba ", ); - assert_snapshot!(test.completions_without_builtins(), @""); + // This snapshot would generate a big list of modules, + // which is kind of annoying. So just assert that it + // runs without panicking and produces some non-empty + // output. + assert!(!test.completions_without_builtins().is_empty()); } // Ref: https://github.com/astral-sh/ty/issues/572 @@ -2286,7 +2294,11 @@ from fo import wat ", ); - assert_snapshot!(test.completions_without_builtins(), @""); + // This snapshot would generate a big list of modules, + // which is kind of annoying. So just assert that it + // runs without panicking and produces some non-empty + // output. + assert!(!test.completions_without_builtins().is_empty()); } // Ref: https://github.com/astral-sh/ty/issues/572 From 2e9c241d7ee5765b8e7413c72344c4255e42d489 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Tue, 12 Aug 2025 14:17:10 -0400 Subject: [PATCH 069/160] [ty] Wire up "list modules" API to make module completions work This makes `import ` and `from ` completions work. This also makes `import os.` and `from os.` completions work. In this case, we are careful to only offer submodule completions. --- crates/ty_ide/src/completion.rs | 308 +++++++++++++++++- .../ty_python_semantic/src/semantic_model.rs | 104 +++++- 2 files changed, 396 insertions(+), 16 deletions(-) diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index 2470308c41a6d..dc7072dfd73a5 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -23,7 +23,18 @@ pub fn completion(db: &dyn Db, file: File, offset: TextSize) -> Vec model.attribute_completions(expr), - CompletionTargetAst::ImportFrom { import, name } => model.import_completions(import, name), + CompletionTargetAst::ObjectDotInImport { import, name } => { + model.import_submodule_completions(import, name) + } + CompletionTargetAst::ObjectDotInImportFrom { import } => { + model.from_import_submodule_completions(import) + } + CompletionTargetAst::ImportFrom { import, name } => { + model.from_import_completions(import, name) + } + CompletionTargetAst::Import { .. } | CompletionTargetAst::ImportViaFrom { .. } => { + model.import_completions() + } CompletionTargetAst::Scoped { node } => model.scoped_completions(node), }; completions.sort_by(compare_suggestions); @@ -50,11 +61,11 @@ enum CompletionTargetTokens<'t> { object: &'t Token, /// The token, if non-empty, following the dot. /// - /// This is currently unused, but we should use this - /// eventually to remove completions that aren't a - /// prefix of what has already been typed. (We are - /// currently relying on the LSP client to do this.) - #[expect(dead_code)] + /// For right now, this is only used to determine which + /// module in an `import` statement to return submodule + /// completions for. But we could use it for other things, + /// like only returning completions that start with a prefix + /// corresponding to this token. attribute: Option<&'t Token>, }, /// A `from module import attribute` token form was found, where @@ -63,6 +74,20 @@ enum CompletionTargetTokens<'t> { /// The module being imported from. module: &'t Token, }, + /// A `import module` token form was found, where `module` may be + /// empty. + Import { + /// The token corresponding to the `import` keyword. + import: &'t Token, + /// The token closest to the cursor. + /// + /// This is currently unused, but we should use this + /// eventually to remove completions that aren't a + /// prefix of what has already been typed. (We are + /// currently relying on the LSP client to do this.) + #[expect(dead_code)] + module: &'t Token, + }, /// A token was found under the cursor, but it didn't /// match any of our anticipated token patterns. Generic { token: &'t Token }, @@ -105,6 +130,8 @@ impl<'t> CompletionTargetTokens<'t> { } } else if let Some(module) = import_from_tokens(before) { CompletionTargetTokens::ImportFrom { module } + } else if let Some((import, module)) = import_tokens(before) { + CompletionTargetTokens::Import { import, module } } else if let Some([_]) = token_suffix_by_kinds(before, [TokenKind::Float]) { // If we're writing a `float`, then we should // specifically not offer completions. This wouldn't @@ -140,19 +167,47 @@ impl<'t> CompletionTargetTokens<'t> { offset: TextSize, ) -> Option> { match *self { - CompletionTargetTokens::PossibleObjectDot { object, .. } => { + CompletionTargetTokens::PossibleObjectDot { object, attribute } => { let covering_node = covering_node(parsed.syntax().into(), object.range()) - // We require that the end of the node range not - // exceed the cursor offset. This avoids selecting - // a node "too high" in the AST in cases where - // completions are requested in the middle of an - // expression. e.g., `foo..bar`. - .find_last(|node| node.is_expr_attribute() && node.range().end() <= offset) + .find_last(|node| { + // We require that the end of the node range not + // exceed the cursor offset. This avoids selecting + // a node "too high" in the AST in cases where + // completions are requested in the middle of an + // expression. e.g., `foo..bar`. + if node.is_expr_attribute() { + return node.range().end() <= offset; + } + // For import statements though, they can't be + // nested, so we don't care as much about the + // cursor being strictly after the statement. + // And indeed, sometimes it won't be! e.g., + // + // import re, os.p, zlib + // + // So just return once we find an import. + node.is_stmt_import() || node.is_stmt_import_from() + }) .ok()?; match covering_node.node() { ast::AnyNodeRef::ExprAttribute(expr) => { Some(CompletionTargetAst::ObjectDot { expr }) } + ast::AnyNodeRef::StmtImport(import) => { + let range = attribute + .map(Ranged::range) + .unwrap_or_else(|| object.range()); + // Find the name that overlaps with the + // token we identified for the attribute. + let name = import + .names + .iter() + .position(|alias| alias.range().contains_range(range))?; + Some(CompletionTargetAst::ObjectDotInImport { import, name }) + } + ast::AnyNodeRef::StmtImportFrom(import) => { + Some(CompletionTargetAst::ObjectDotInImportFrom { import }) + } _ => None, } } @@ -165,6 +220,20 @@ impl<'t> CompletionTargetTokens<'t> { }; Some(CompletionTargetAst::ImportFrom { import, name: None }) } + CompletionTargetTokens::Import { import, .. } => { + let covering_node = covering_node(parsed.syntax().into(), import.range()) + .find_first(|node| node.is_stmt_import() || node.is_stmt_import_from()) + .ok()?; + match covering_node.node() { + ast::AnyNodeRef::StmtImport(import) => { + Some(CompletionTargetAst::Import { import, name: None }) + } + ast::AnyNodeRef::StmtImportFrom(import) => { + Some(CompletionTargetAst::ImportViaFrom { import }) + } + _ => None, + } + } CompletionTargetTokens::Generic { token } => { let covering_node = covering_node(parsed.syntax().into(), token.range()); Some(CompletionTargetAst::Scoped { @@ -188,6 +257,18 @@ enum CompletionTargetAst<'t> { /// A `object.attribute` scenario, where we want to /// list attributes on `object` for completions. ObjectDot { expr: &'t ast::ExprAttribute }, + /// A `import module.submodule` scenario, where we only want to + /// list submodules for completions. + ObjectDotInImport { + /// The import statement. + import: &'t ast::StmtImport, + /// An index into `import.names`. The index is guaranteed to be + /// valid. + name: usize, + }, + /// A `from module.submodule` scenario, where we only want to list + /// submodules for completions. + ObjectDotInImportFrom { import: &'t ast::StmtImportFrom }, /// A `from module import attribute` scenario, where we want to /// list attributes on `module` for completions. ImportFrom { @@ -197,6 +278,24 @@ enum CompletionTargetAst<'t> { /// set, the index is guaranteed to be valid. name: Option, }, + /// A `import module` scenario, where we want to + /// list available modules for completions. + Import { + /// The import statement. + #[expect(dead_code)] + import: &'t ast::StmtImport, + /// An index into `import.names` if relevant. When this is + /// set, the index is guaranteed to be valid. + #[expect(dead_code)] + name: Option, + }, + /// A `from module` scenario, where we want to + /// list available modules for completions. + ImportViaFrom { + /// The import statement. + #[expect(dead_code)] + import: &'t ast::StmtImportFrom, + }, /// A scoped scenario, where we want to list all items available in /// the most narrow scope containing the giving AST node. Scoped { node: ast::AnyNodeRef<'t> }, @@ -317,6 +416,52 @@ fn import_from_tokens(tokens: &[Token]) -> Option<&Token> { None } +/// Looks for the start of a `import ` statement. +/// +/// This also handles cases like `import foo, c, bar`. +/// +/// If found, a token corresponding to the `import` or `from` keyword +/// and the the closest point of the `` is returned. +/// +/// It is assumed that callers will call `from_import_tokens` first to +/// try and recognize a `from ... import ...` statement before using +/// this. +fn import_tokens(tokens: &[Token]) -> Option<(&Token, &Token)> { + use TokenKind as TK; + + /// A look-back limit, in order to bound work. + /// + /// See `LIMIT` in `import_from_tokens` for more context. + const LIMIT: usize = 1_000; + + /// A state used to "parse" the tokens preceding the user's cursor, + /// in reverse, to detect a `import` statement. + enum S { + Start, + Names, + } + + let mut state = S::Start; + let module_token = tokens.last()?; + // Move backward through the tokens until we get to + // the `import` token. + for token in tokens.iter().rev().take(LIMIT) { + state = match (state, token.kind()) { + // It's okay to pop off a newline token here initially, + // since it may occur when the name being imported is + // empty. + (S::Start, TK::Newline) => S::Names, + // Munch through tokens that can make up an alias. + (S::Start | S::Names, TK::Name | TK::Comma | TK::As | TK::Unknown) => S::Names, + (S::Start | S::Names, TK::Import | TK::From) => { + return Some((token, module_token)); + } + _ => return None, + }; + } + None +} + /// Order completions lexicographically, with these exceptions: /// /// 1) A `_[^_]` prefix sorts last and @@ -2709,6 +2854,143 @@ importlib. test.assert_completions_include("resources"); } + #[test] + fn import_with_leading_character() { + let test = cursor_test( + "\ +import c +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_without_leading_character() { + let test = cursor_test( + "\ +import +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_multiple() { + let test = cursor_test( + "\ +import re, c, sys +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_with_aliases() { + let test = cursor_test( + "\ +import re as regexp, c, sys as system +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_over_multiple_lines() { + let test = cursor_test( + "\ +import re as regexp, \\ + c, \\ + sys as system +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_unknown_in_module() { + let test = cursor_test( + "\ +import ?, +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_via_from_with_leading_character() { + let test = cursor_test( + "\ +from c +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_via_from_without_leading_character() { + let test = cursor_test( + "\ +from +", + ); + test.assert_completions_include("collections"); + } + + #[test] + fn import_statement_with_submodule_with_leading_character() { + let test = cursor_test( + "\ +import os.p +", + ); + test.assert_completions_include("path"); + test.assert_completions_do_not_include("abspath"); + } + + #[test] + fn import_statement_with_submodule_multiple() { + let test = cursor_test( + "\ +import re, os.p, zlib +", + ); + test.assert_completions_include("path"); + test.assert_completions_do_not_include("abspath"); + } + + #[test] + fn import_statement_with_submodule_without_leading_character() { + let test = cursor_test( + "\ +import os. +", + ); + test.assert_completions_include("path"); + test.assert_completions_do_not_include("abspath"); + } + + #[test] + fn import_via_from_with_submodule_with_leading_character() { + let test = cursor_test( + "\ +from os.p +", + ); + test.assert_completions_include("path"); + test.assert_completions_do_not_include("abspath"); + } + + #[test] + fn import_via_from_with_submodule_without_leading_character() { + let test = cursor_test( + "\ +from os. +", + ); + test.assert_completions_include("path"); + test.assert_completions_do_not_include("abspath"); + } + #[test] fn regression_test_issue_642() { // Regression test for https://github.com/astral-sh/ty/issues/642 diff --git a/crates/ty_python_semantic/src/semantic_model.rs b/crates/ty_python_semantic/src/semantic_model.rs index f038111c5f1fa..47eacbb3a5764 100644 --- a/crates/ty_python_semantic/src/semantic_model.rs +++ b/crates/ty_python_semantic/src/semantic_model.rs @@ -6,7 +6,7 @@ use ruff_source_file::LineIndex; use crate::Db; use crate::module_name::ModuleName; -use crate::module_resolver::{KnownModule, Module, resolve_module}; +use crate::module_resolver::{KnownModule, Module, list_modules, resolve_module}; use crate::semantic_index::definition::Definition; use crate::semantic_index::scope::FileScopeId; use crate::semantic_index::semantic_index; @@ -41,8 +41,24 @@ impl<'db> SemanticModel<'db> { resolve_module(self.db, module_name) } + /// Returns completions for symbols available in a `import ` context. + pub fn import_completions(&self) -> Vec> { + list_modules(self.db) + .into_iter() + .map(|module| { + let builtin = module.is_known(self.db, KnownModule::Builtins); + let ty = Type::module_literal(self.db, self.file, module); + Completion { + name: Name::new(module.name(self.db).as_str()), + ty, + builtin, + } + }) + .collect() + } + /// Returns completions for symbols available in a `from module import ` context. - pub fn import_completions( + pub fn from_import_completions( &self, import: &ast::StmtImportFrom, _name: Option, @@ -61,6 +77,79 @@ impl<'db> SemanticModel<'db> { self.module_completions(&module_name) } + /// Returns completions only for submodules for the module + /// identified by `name` in `import`. + /// + /// For example, `import re, os., zlib`. + pub fn import_submodule_completions( + &self, + import: &ast::StmtImport, + name: usize, + ) -> Vec> { + let module_ident = &import.names[name].name; + let Some((parent_ident, _)) = module_ident.rsplit_once('.') else { + return vec![]; + }; + let module_name = + match ModuleName::from_identifier_parts(self.db, self.file, Some(parent_ident), 0) { + Ok(module_name) => module_name, + Err(err) => { + tracing::debug!( + "Could not extract module name from `{module:?}`: {err:?}", + module = module_ident, + ); + return vec![]; + } + }; + self.import_submodule_completions_for_name(&module_name) + } + + /// Returns completions only for submodules for the module + /// used in a `from module import attribute` statement. + /// + /// For example, `from os.`. + pub fn from_import_submodule_completions( + &self, + import: &ast::StmtImportFrom, + ) -> Vec> { + let level = import.level; + let Some(module_ident) = import.module.as_deref() else { + return vec![]; + }; + let Some((parent_ident, _)) = module_ident.rsplit_once('.') else { + return vec![]; + }; + let module_name = match ModuleName::from_identifier_parts( + self.db, + self.file, + Some(parent_ident), + level, + ) { + Ok(module_name) => module_name, + Err(err) => { + tracing::debug!( + "Could not extract module name from `{module:?}` with level {level}: {err:?}", + module = import.module, + level = import.level, + ); + return vec![]; + } + }; + self.import_submodule_completions_for_name(&module_name) + } + + /// Returns submodule-only completions for the given module. + fn import_submodule_completions_for_name( + &self, + module_name: &ModuleName, + ) -> Vec> { + let Some(module) = resolve_module(self.db, module_name) else { + tracing::debug!("Could not resolve module from `{module_name:?}`"); + return vec![]; + }; + self.submodule_completions(&module) + } + /// Returns completions for symbols available in the given module as if /// it were imported by this model's `File`. fn module_completions(&self, module_name: &ModuleName) -> Vec> { @@ -75,11 +164,20 @@ impl<'db> SemanticModel<'db> { for crate::types::Member { name, ty } in crate::types::all_members(self.db, ty) { completions.push(Completion { name, ty, builtin }); } + completions.extend(self.submodule_completions(&module)); + completions + } + + /// Returns completions for submodules of the given module. + fn submodule_completions(&self, module: &Module<'db>) -> Vec> { + let builtin = module.is_known(self.db, KnownModule::Builtins); + + let mut completions = vec![]; for submodule_basename in module.all_submodules(self.db) { let Some(basename) = ModuleName::new(submodule_basename.as_str()) else { continue; }; - let mut submodule_name = module_name.clone(); + let mut submodule_name = module.name(self.db).clone(); submodule_name.extend(&basename); let Some(submodule) = resolve_module(self.db, &submodule_name) else { From 468eb37d7572acaa354c0159875157ffceb9d447 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Wed, 13 Aug 2025 09:44:05 -0400 Subject: [PATCH 070/160] [ty] Test "list modules" versus "resolve module" in every mdtest This ensures there is some level of consistency between the APIs. This did require exposing a couple more things on `Module` for good error messages. This also motivated a switch to an interned struct instead of a tracked struct. This ensures that `list_modules` and `resolve_modules` reuse the same `Module` values when the inputs are the same. Ref https://github.com/astral-sh/ruff/pull/19883#discussion_r2272520194 --- .../src/module_resolver/mod.rs | 2 +- .../src/module_resolver/module.rs | 8 +- crates/ty_test/src/lib.rs | 139 +++++++++++++++--- 3 files changed, 126 insertions(+), 23 deletions(-) diff --git a/crates/ty_python_semantic/src/module_resolver/mod.rs b/crates/ty_python_semantic/src/module_resolver/mod.rs index f894d618aee62..901adbf4ef667 100644 --- a/crates/ty_python_semantic/src/module_resolver/mod.rs +++ b/crates/ty_python_semantic/src/module_resolver/mod.rs @@ -3,7 +3,7 @@ use std::iter::FusedIterator; pub use list::list_modules; pub(crate) use module::KnownModule; pub use module::Module; -pub use path::SearchPathValidationError; +pub use path::{SearchPath, SearchPathValidationError}; pub use resolver::SearchPaths; pub(crate) use resolver::file_to_module; pub use resolver::{resolve_module, resolve_real_module}; diff --git a/crates/ty_python_semantic/src/module_resolver/module.rs b/crates/ty_python_semantic/src/module_resolver/module.rs index e61717364ec0c..a7d50829b06fc 100644 --- a/crates/ty_python_semantic/src/module_resolver/module.rs +++ b/crates/ty_python_semantic/src/module_resolver/module.rs @@ -59,7 +59,7 @@ impl<'db> Module<'db> { } /// Is this a module that we special-case somehow? If so, which one? - pub(crate) fn known(self, db: &'db dyn Database) -> Option { + pub fn known(self, db: &'db dyn Database) -> Option { match self { Module::File(module) => module.known(db), Module::Namespace(_) => None, @@ -75,7 +75,7 @@ impl<'db> Module<'db> { /// /// It is guaranteed that if `None` is returned, then this is a namespace /// package. Otherwise, this is a regular package or file module. - pub(crate) fn search_path(self, db: &'db dyn Database) -> Option<&'db SearchPath> { + pub fn search_path(self, db: &'db dyn Database) -> Option<&'db SearchPath> { match self { Module::File(module) => Some(module.search_path(db)), Module::Namespace(_) => None, @@ -214,7 +214,7 @@ fn all_submodule_names_for_package(db: &dyn Db, file: File) -> Option> } /// A module that resolves to a file (`lib.py` or `package/__init__.py`) -#[salsa::tracked(debug, heap_size=ruff_memory_usage::heap_size)] +#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)] pub struct FileModule<'db> { #[returns(ref)] pub(super) name: ModuleName, @@ -229,7 +229,7 @@ pub struct FileModule<'db> { /// /// Namespace packages are special because there are /// multiple possible paths and they have no corresponding code file. -#[salsa::tracked(debug, heap_size=ruff_memory_usage::heap_size)] +#[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)] pub struct NamespacePackage<'db> { #[returns(ref)] pub(super) name: ModuleName, diff --git a/crates/ty_test/src/lib.rs b/crates/ty_test/src/lib.rs index 10dc4a7ce1b40..877954addb8cb 100644 --- a/crates/ty_test/src/lib.rs +++ b/crates/ty_test/src/lib.rs @@ -18,8 +18,9 @@ use std::fmt::Write; use ty_python_semantic::pull_types::pull_types; use ty_python_semantic::types::check_types; use ty_python_semantic::{ - Program, ProgramSettings, PythonEnvironment, PythonPlatform, PythonVersionSource, - PythonVersionWithSource, SearchPathSettings, SysPrefixPathOrigin, + Module, Program, ProgramSettings, PythonEnvironment, PythonPlatform, PythonVersionSource, + PythonVersionWithSource, SearchPath, SearchPathSettings, SysPrefixPathOrigin, list_modules, + resolve_module, }; mod assertion; @@ -68,13 +69,16 @@ pub fn run( Log::Filter(filter) => setup_logging_with_filter(filter), }); - if let Err(failures) = run_test(&mut db, relative_fixture_path, snapshot_path, &test) { - any_failures = true; + let failures = run_test(&mut db, relative_fixture_path, snapshot_path, &test); + let inconsistencies = run_module_resolution_consistency_test(&db); + let this_test_failed = failures.is_err() || inconsistencies.is_err(); + any_failures = any_failures || this_test_failed; - if output_format.is_cli() { - println!("\n{}\n", test.name().bold().underline()); - } + if this_test_failed && output_format.is_cli() { + println!("\n{}\n", test.name().bold().underline()); + } + if let Err(failures) = run_test(&mut db, relative_fixture_path, snapshot_path, &test) { let md_index = LineIndex::from_source_text(&source); for test_failures in failures { @@ -100,19 +104,32 @@ pub fn run( } } } + } + if let Err(inconsistencies) = run_module_resolution_consistency_test(&db) { + any_failures = true; + for inconsistency in inconsistencies { + match output_format { + OutputFormat::Cli => { + let info = relative_fixture_path.to_string().cyan(); + println!(" {info} {inconsistency}"); + } + OutputFormat::GitHub => { + println!("::error file={absolute_fixture_path}::{inconsistency}"); + } + } + } + } + if this_test_failed && output_format.is_cli() { let escaped_test_name = test.name().replace('\'', "\\'"); - - if output_format.is_cli() { - println!( - "\nTo rerun this specific test, set the environment variable: {}='{escaped_test_name}'", - EnvVars::MDTEST_TEST_FILTER, - ); - println!( - "{}='{escaped_test_name}' cargo test -p ty_python_semantic --test mdtest -- {test_name}", - EnvVars::MDTEST_TEST_FILTER, - ); - } + println!( + "\nTo rerun this specific test, set the environment variable: {}='{escaped_test_name}'", + EnvVars::MDTEST_TEST_FILTER, + ); + println!( + "{}='{escaped_test_name}' cargo test -p ty_python_semantic --test mdtest -- {test_name}", + EnvVars::MDTEST_TEST_FILTER, + ); } } @@ -406,6 +423,92 @@ fn run_test( } } +/// Reports an inconsistency between "list modules" and "resolve module." +/// +/// Values of this type are only constructed when `from_list` and +/// `from_resolve` are not equivalent. +struct ModuleInconsistency<'db> { + db: &'db db::Db, + /// The module returned from `list_module`. + from_list: Module<'db>, + /// The module returned, if any, from `resolve_module`. + from_resolve: Option>, +} + +/// Tests that "list modules" is consistent with "resolve module." +/// +/// This only checks that everything returned by `list_module` is the +/// identical module we get back from `resolve_module`. It does not +/// check that all possible outputs of `resolve_module` are captured by +/// `list_module`. +fn run_module_resolution_consistency_test(db: &db::Db) -> Result<(), Vec>> { + let mut errs = vec![]; + for from_list in list_modules(db) { + errs.push(match resolve_module(db, from_list.name(db)) { + None => ModuleInconsistency { + db, + from_list, + from_resolve: None, + }, + Some(from_resolve) if from_list != from_resolve => ModuleInconsistency { + db, + from_list, + from_resolve: Some(from_resolve), + }, + _ => continue, + }); + } + if errs.is_empty() { Ok(()) } else { Err(errs) } +} + +impl std::fmt::Display for ModuleInconsistency<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + fn fmt_module( + db: &db::Db, + f: &mut std::fmt::Formatter, + module: &Module<'_>, + ) -> std::fmt::Result { + let name = module.name(db); + let path = module + .file(db) + .map(|file| file.path(db).to_string()) + .unwrap_or_else(|| "N/A".to_string()); + let search_path = module + .search_path(db) + .map(SearchPath::to_string) + .unwrap_or_else(|| "N/A".to_string()); + let known = module + .known(db) + .map(|known| known.to_string()) + .unwrap_or_else(|| "N/A".to_string()); + write!( + f, + "Module(\ + name={name}, \ + file={path}, \ + kind={kind:?}, \ + search_path={search_path}, \ + known={known}\ + )", + kind = module.kind(db), + ) + } + write!(f, "Found ")?; + fmt_module(self.db, f, &self.from_list)?; + match self.from_resolve { + None => write!( + f, + " when listing modules, but `resolve_module` returned `None`", + )?, + Some(ref got) => { + write!(f, " when listing modules, but `resolve_module` returned ",)?; + fmt_module(self.db, f, got)?; + } + } + Ok(()) + } +} + type Failures = Vec; /// The failures for a single file in a test by line number. From ddd4bab67c6d94eea312e4951fcc2c7bc8299fa4 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 14 Aug 2025 14:18:40 -0400 Subject: [PATCH 071/160] [ty] Re-arrange "list modules" implementation for Salsa caching This basically splits `list_modules` into a higher level "aggregation" routine and a lower level "get modules for one search path" routine. This permits Salsa to cache the lower level components, e.g., many search paths refer to directories that rarely change. This saves us interaction with the system. This did require a fair bit of surgery in terms of being careful about adding file roots. Namely, now that we rely even more on file roots existing for correct handling of cache invalidation, there were several spots in our code that needed to be updated to add roots (that we weren't previously doing). This feels Not Great, and it would be better if we had some kind of abstraction that handled this for us. But it isn't clear to me at this time what that looks like. --- .../src/module_resolver/list.rs | 158 +++++++++++++----- .../src/module_resolver/resolver.rs | 9 +- .../src/module_resolver/testing.rs | 51 +++++- crates/ty_test/src/lib.rs | 6 +- 4 files changed, 177 insertions(+), 47 deletions(-) diff --git a/crates/ty_python_semantic/src/module_resolver/list.rs b/crates/ty_python_semantic/src/module_resolver/list.rs index 47765702b0610..2374a242125cf 100644 --- a/crates/ty_python_semantic/src/module_resolver/list.rs +++ b/crates/ty_python_semantic/src/module_resolver/list.rs @@ -12,28 +12,72 @@ use super::resolver::{ ModuleResolveMode, ResolverContext, is_non_shadowable, resolve_file_module, search_paths, }; -/// List all available modules. +/// List all available top-level modules. #[salsa::tracked] pub fn list_modules(db: &dyn Db) -> Vec> { - let mut lister = Lister::new(db); + let mut modules = BTreeMap::new(); for search_path in search_paths(db, ModuleResolveMode::StubsAllowed) { - match search_path.as_path() { - SystemOrVendoredPathRef::System(system_search_path) => { - let Ok(it) = db.system().read_directory(system_search_path) else { - continue; - }; - for result in it { - let Ok(entry) = result else { continue }; - lister.add_path(search_path, &entry.path().into(), entry.file_type().into()); + for module in list_modules_in(db, SearchPathIngredient::new(db, search_path.clone())) { + match modules.entry(module.name(db)) { + Entry::Vacant(entry) => { + entry.insert(module); } - } - SystemOrVendoredPathRef::Vendored(vendored_search_path) => { - for entry in db.vendored().read_directory(vendored_search_path) { - lister.add_path(search_path, &entry.path().into(), entry.file_type().into()); + Entry::Occupied(mut entry) => { + // The only case where a module can override + // a module with the same name in a higher + // precedent search path is if the higher + // precedent search path contained a namespace + // package and the lower precedent search path + // contained a "regular" module. + if let (None, Some(_)) = (entry.get().search_path(db), module.search_path(db)) { + entry.insert(module); + } } } } } + modules.into_values().collect() +} + +#[salsa::tracked(debug, heap_size=ruff_memory_usage::heap_size)] +struct SearchPathIngredient<'db> { + #[returns(ref)] + path: SearchPath, +} + +/// List all available top-level modules in the given `SearchPath`. +#[salsa::tracked] +fn list_modules_in<'db>( + db: &'db dyn Db, + search_path: SearchPathIngredient<'db>, +) -> Vec> { + let mut lister = Lister::new(db, search_path.path(db)); + match search_path.path(db).as_path() { + SystemOrVendoredPathRef::System(system_search_path) => { + // Read the revision on the corresponding file root to + // register an explicit dependency on this directory. When + // the revision gets bumped, the cache that Salsa creates + // for this routine will be invalidated. + let root = db + .files() + .root(db, system_search_path) + .expect("System search path should have a registered root"); + let _ = root.revision(db); + + let Ok(it) = db.system().read_directory(system_search_path) else { + return vec![]; + }; + for result in it { + let Ok(entry) = result else { continue }; + lister.add_path(&entry.path().into(), entry.file_type().into()); + } + } + SystemOrVendoredPathRef::Vendored(vendored_search_path) => { + for entry in db.vendored().read_directory(vendored_search_path) { + lister.add_path(&entry.path().into(), entry.file_type().into()); + } + } + } lister.into_modules() } @@ -47,17 +91,19 @@ pub fn list_modules(db: &dyn Db) -> Vec> { struct Lister<'db> { db: &'db dyn Db, program: Program, + search_path: &'db SearchPath, modules: BTreeMap<&'db ModuleName, Module<'db>>, } impl<'db> Lister<'db> { /// Create new state that can accumulate modules from a list /// of file paths. - fn new(db: &'db dyn Db) -> Lister<'db> { + fn new(db: &'db dyn Db, search_path: &'db SearchPath) -> Lister<'db> { let program = Program::get(db); Lister { db, program, + search_path, modules: BTreeMap::new(), } } @@ -67,19 +113,17 @@ impl<'db> Lister<'db> { self.modules.into_values().collect() } - /// Add the given `path` (from `search_path`) as a possible - /// module to this lister. The `file_type` should be the type - /// of `path` (file, directory or symlink). + /// Add the given `path` as a possible module to this lister. The + /// `file_type` should be the type of `path` (file, directory or + /// symlink). /// /// This may decide that the given path does not correspond to /// a valid Python module. In which case, it is dropped and this /// is a no-op. - fn add_path( - &mut self, - search_path: &SearchPath, - path: &SystemOrVendoredPathRef<'_>, - file_type: FileType, - ) { + /// + /// Callers must ensure that the path given came from the same + /// `SearchPath` used to create this `Lister`. + fn add_path(&mut self, path: &SystemOrVendoredPathRef<'_>, file_type: FileType) { let mut has_py_extension = false; // We must have no extension, a Python source file extension (`.py`) // or a Python stub file extension (`.pyi`). @@ -91,7 +135,7 @@ impl<'db> Lister<'db> { } let Some(name) = path.file_name() else { return }; - let mut module_path = search_path.to_module_path(); + let mut module_path = self.search_path.to_module_path(); module_path.push(name); let Some(module_name) = module_path.to_module_name() else { return; @@ -99,7 +143,7 @@ impl<'db> Lister<'db> { // Some modules cannot shadow a subset of special // modules from the standard library. - if !search_path.is_standard_library() && self.is_non_shadowable(&module_name) { + if !self.search_path.is_standard_library() && self.is_non_shadowable(&module_name) { return; } @@ -113,7 +157,7 @@ impl<'db> Lister<'db> { self.db, module_name, ModuleKind::Package, - search_path.clone(), + self.search_path.clone(), file, ), ); @@ -152,7 +196,7 @@ impl<'db> Lister<'db> { let is_dir = file_type.is_definitely_directory() || module_path.is_directory(&self.context()); if is_dir { - if !search_path.is_standard_library() { + if !self.search_path.is_standard_library() { self.add_module( &module_path, Module::namespace_package(self.db, module_name), @@ -185,7 +229,7 @@ impl<'db> Lister<'db> { self.db, module_name, ModuleKind::Module, - search_path.clone(), + self.search_path.clone(), file, ), ); @@ -214,15 +258,14 @@ impl<'db> Lister<'db> { (None, Some(_)) => { entry.insert(module); } - (Some(search_path_existing), Some(search_path_new)) => { + (Some(_), Some(_)) => { // Merging across search paths is only necessary for // namespace packages. For all other modules, entries // from earlier search paths take precedence. Thus, all // of the cases below require that we're in the same - // directory. - if search_path_existing != search_path_new { - return; - } + // directory. ... Which is true here, because a `Lister` + // only works for one specific search path. + // When we have a `foo/__init__.py` and a `foo.py` in // the same directory, the former takes precedent. // (This case can only occur when both have a search @@ -322,7 +365,7 @@ fn is_python_extension(ext: &str) -> bool { mod tests { use camino::{Utf8Component, Utf8Path}; use ruff_db::Db as _; - use ruff_db::files::{File, FilePath}; + use ruff_db::files::{File, FilePath, FileRootKind}; use ruff_db::system::{ DbWithTestSystem, DbWithWritableSystem, OsSystem, SystemPath, SystemPathBuf, }; @@ -906,6 +949,12 @@ mod tests { std::fs::write(foo.as_std_path(), "")?; std::os::unix::fs::symlink(foo.as_std_path(), bar.as_std_path())?; + db.files().try_add_root(&db, &src, FileRootKind::Project); + db.files() + .try_add_root(&db, &site_packages, FileRootKind::LibrarySearchPath); + db.files() + .try_add_root(&db, &custom_typeshed, FileRootKind::LibrarySearchPath); + Program::from_settings( &db, ProgramSettings { @@ -966,11 +1015,13 @@ mod tests { // Now write the foo file db.write_file(&foo_path, "x = 1")?; - // FIXME: This is obviously wrong. The Salsa cache - // isn't being invalidated. insta::assert_debug_snapshot!( list_snapshot(&db), - @"[]", + @r#" + [ + Module::File("foo", "first-party", "/src/foo.py", Module, None), + ] + "#, ); Ok(()) @@ -1090,14 +1141,11 @@ mod tests { let src_functools_path = src.join("functools.py"); db.write_file(&src_functools_path, "FOO: int").unwrap(); - // FIXME: This looks wrong! This is a cache invalidation - // problem, not a logic problem in the "list modules" - // implementation. insta::assert_debug_snapshot!( list_snapshot(&db), @r#" [ - Module::File("functools", "std-custom", "/typeshed/stdlib/functools.pyi", Module, None), + Module::File("functools", "first-party", "/src/functools.py", Module, None), ] "#, ); @@ -1157,6 +1205,7 @@ mod tests { let TestCase { mut db, .. } = TestCaseBuilder::new() .with_site_packages_files(SITE_PACKAGES) + .with_library_root("/x") .build(); db.write_files(x_directory).unwrap(); @@ -1181,6 +1230,7 @@ mod tests { let TestCase { mut db, .. } = TestCaseBuilder::new() .with_site_packages_files(SITE_PACKAGES) + .with_library_root("/y/src") .build(); db.write_files(external_files).unwrap(); @@ -1207,6 +1257,7 @@ mod tests { let TestCase { db, .. } = TestCaseBuilder::new() .with_site_packages_files(SITE_PACKAGES) + .with_library_root("/x") .build(); insta::assert_debug_snapshot!( @@ -1246,6 +1297,9 @@ not_a_directory let TestCase { mut db, .. } = TestCaseBuilder::new() .with_site_packages_files(SITE_PACKAGES) + .with_library_root("/x/y/src") + .with_library_root("/") + .with_library_root("/baz") .build(); db.write_files(root_files).unwrap(); @@ -1279,6 +1333,8 @@ not_a_directory let TestCase { mut db, .. } = TestCaseBuilder::new() .with_site_packages_files(SITE_PACKAGES) + .with_library_root("/x") + .with_library_root("/y") .build(); db.write_files(external_directories).unwrap(); @@ -1325,6 +1381,7 @@ not_a_directory .. } = TestCaseBuilder::new() .with_site_packages_files(SITE_PACKAGES) + .with_library_root("/x") .build(); db.write_files(x_directory).unwrap(); @@ -1360,6 +1417,7 @@ not_a_directory let TestCase { mut db, .. } = TestCaseBuilder::new() .with_site_packages_files(SITE_PACKAGES) + .with_library_root("/x") .build(); let src_path = SystemPathBuf::from("/x/src"); @@ -1411,6 +1469,15 @@ not_a_directory ]) .unwrap(); + db.files() + .try_add_root(&db, SystemPath::new("/src"), FileRootKind::Project); + db.files() + .try_add_root(&db, &venv_site_packages, FileRootKind::LibrarySearchPath); + db.files() + .try_add_root(&db, &system_site_packages, FileRootKind::LibrarySearchPath); + db.files() + .try_add_root(&db, SystemPath::new("/x"), FileRootKind::LibrarySearchPath); + Program::from_settings( &db, ProgramSettings { @@ -1497,6 +1564,8 @@ not_a_directory std::os::unix::fs::symlink(a_package_target.as_std_path(), a_src.as_std_path()) .context("Failed to symlink `src/a` to `a-package`")?; + db.files().try_add_root(&db, &root, FileRootKind::Project); + Program::from_settings( &db, ProgramSettings { @@ -1535,6 +1604,11 @@ not_a_directory let mut db = TestDb::new(); db.write_file(&installed_foo_module, "").unwrap(); + db.files() + .try_add_root(&db, &project_directory, FileRootKind::Project); + db.files() + .try_add_root(&db, &site_packages, FileRootKind::LibrarySearchPath); + Program::from_settings( &db, ProgramSettings { diff --git a/crates/ty_python_semantic/src/module_resolver/resolver.rs b/crates/ty_python_semantic/src/module_resolver/resolver.rs index d9774480fac14..6779a76042c1b 100644 --- a/crates/ty_python_semantic/src/module_resolver/resolver.rs +++ b/crates/ty_python_semantic/src/module_resolver/resolver.rs @@ -433,13 +433,16 @@ pub(crate) fn dynamic_resolution_paths<'db>( let site_packages_dir = site_packages_search_path .as_system_path() .expect("Expected site package path to be a system path"); + let site_packages_dir = system + .canonicalize_path(site_packages_dir) + .unwrap_or_else(|_| site_packages_dir.to_path_buf()); - if !existing_paths.insert(Cow::Borrowed(site_packages_dir)) { + if !existing_paths.insert(Cow::Owned(site_packages_dir.clone())) { continue; } let site_packages_root = files - .root(db, site_packages_dir) + .root(db, &site_packages_dir) .expect("Site-package root to have been created"); // This query needs to be re-executed each time a `.pth` file @@ -457,7 +460,7 @@ pub(crate) fn dynamic_resolution_paths<'db>( // containing a (relative or absolute) path. // Each of these paths may point to an editable install of a package, // so should be considered an additional search path. - let pth_file_iterator = match PthFileIterator::new(db, site_packages_dir) { + let pth_file_iterator = match PthFileIterator::new(db, &site_packages_dir) { Ok(iterator) => iterator, Err(error) => { tracing::warn!( diff --git a/crates/ty_python_semantic/src/module_resolver/testing.rs b/crates/ty_python_semantic/src/module_resolver/testing.rs index 9b06764e163dd..c2ff3139015ab 100644 --- a/crates/ty_python_semantic/src/module_resolver/testing.rs +++ b/crates/ty_python_semantic/src/module_resolver/testing.rs @@ -1,4 +1,5 @@ use ruff_db::Db; +use ruff_db::files::FileRootKind; use ruff_db::system::{ DbWithTestSystem as _, DbWithWritableSystem as _, SystemPath, SystemPathBuf, }; @@ -107,6 +108,14 @@ pub(crate) struct TestCaseBuilder { python_platform: PythonPlatform, first_party_files: Vec, site_packages_files: Vec, + // Additional file roots (beyond site_packages, src and stdlib) + // that should be registered with the `Db` abstraction. + // + // This is necessary to make testing "list modules" work. Namely, + // "list modules" relies on caching via a file root's revision, + // and if file roots aren't registered, then the implementation + // can't access the root's revision. + roots: Vec, } impl TestCaseBuilder { @@ -128,6 +137,12 @@ impl TestCaseBuilder { self } + /// Add a "library" root to this test case. + pub(crate) fn with_library_root(mut self, root: impl AsRef) -> Self { + self.roots.push(root.as_ref().to_path_buf()); + self + } + fn write_mock_directory( db: &mut TestDb, location: impl AsRef, @@ -154,6 +169,7 @@ impl TestCaseBuilder { python_platform: PythonPlatform::default(), first_party_files: vec![], site_packages_files: vec![], + roots: vec![], } } @@ -165,6 +181,7 @@ impl TestCaseBuilder { python_platform, first_party_files, site_packages_files, + roots, } = self; TestCaseBuilder { typeshed_option: VendoredTypeshed, @@ -172,6 +189,7 @@ impl TestCaseBuilder { python_platform, first_party_files, site_packages_files, + roots, } } @@ -186,6 +204,7 @@ impl TestCaseBuilder { python_platform, first_party_files, site_packages_files, + roots, } = self; TestCaseBuilder { @@ -194,6 +213,7 @@ impl TestCaseBuilder { python_platform, first_party_files, site_packages_files, + roots, } } @@ -224,6 +244,7 @@ impl TestCaseBuilder { python_platform, first_party_files, site_packages_files, + roots, } = self; let mut db = TestDb::new(); @@ -233,6 +254,19 @@ impl TestCaseBuilder { let src = Self::write_mock_directory(&mut db, "/src", first_party_files); let typeshed = Self::build_typeshed_mock(&mut db, &typeshed_option); + // This root is needed for correct Salsa tracking. + // Namely, a `SearchPath` is treated as an input, and + // thus the revision number must be bumped accordingly + // when the directory tree changes. We rely on detecting + // this revision from the file root. If we don't add them + // here, they won't get added. + // + // Roots for other search paths are added as part of + // search path initialization in `Program::from_settings`, + // and any remaining are added below. + db.files() + .try_add_root(&db, SystemPath::new("/src"), FileRootKind::Project); + Program::from_settings( &db, ProgramSettings { @@ -251,10 +285,17 @@ impl TestCaseBuilder { }, ); + let stdlib = typeshed.join("stdlib"); + db.files() + .try_add_root(&db, &stdlib, FileRootKind::LibrarySearchPath); + for root in &roots { + db.files() + .try_add_root(&db, root, FileRootKind::LibrarySearchPath); + } TestCase { db, src, - stdlib: typeshed.join("stdlib"), + stdlib, site_packages, python_version, } @@ -286,6 +327,7 @@ impl TestCaseBuilder { python_platform, first_party_files, site_packages_files, + roots, } = self; let mut db = TestDb::new(); @@ -294,6 +336,9 @@ impl TestCaseBuilder { Self::write_mock_directory(&mut db, "/site-packages", site_packages_files); let src = Self::write_mock_directory(&mut db, "/src", first_party_files); + db.files() + .try_add_root(&db, SystemPath::new("/src"), FileRootKind::Project); + Program::from_settings( &db, ProgramSettings { @@ -311,6 +356,10 @@ impl TestCaseBuilder { }, ); + for root in &roots { + db.files() + .try_add_root(&db, root, FileRootKind::LibrarySearchPath); + } TestCase { db, src, diff --git a/crates/ty_test/src/lib.rs b/crates/ty_test/src/lib.rs index 877954addb8cb..e5938eddc1c38 100644 --- a/crates/ty_test/src/lib.rs +++ b/crates/ty_test/src/lib.rs @@ -7,7 +7,7 @@ use config::SystemKind; use parser as test_parser; use ruff_db::Db as _; use ruff_db::diagnostic::{Diagnostic, DisplayDiagnosticConfig}; -use ruff_db::files::{File, system_path_to_file}; +use ruff_db::files::{File, FileRootKind, system_path_to_file}; use ruff_db::panic::catch_unwind; use ruff_db::parsed::parsed_module; use ruff_db::system::{DbWithWritableSystem as _, SystemPath, SystemPathBuf}; @@ -184,6 +184,8 @@ fn run_test( let project_root = SystemPathBuf::from("/src"); db.create_directory_all(&project_root) .expect("Creating the project root to succeed"); + db.files() + .try_add_root(db, &project_root, FileRootKind::Project); let src_path = project_root.clone(); let custom_typeshed_path = test.configuration().typeshed(); @@ -255,6 +257,8 @@ fn run_test( // Create a custom typeshed `VERSIONS` file if none was provided. if let Some(typeshed_path) = custom_typeshed_path { + db.files() + .try_add_root(db, typeshed_path, FileRootKind::LibrarySearchPath); if !has_custom_versions_file { let versions_file = typeshed_path.join("stdlib/VERSIONS"); let contents = typeshed_files From 1a38831d53c13c3a957ff2c62d9faa171e9533ce Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Wed, 20 Aug 2025 13:40:49 -0400 Subject: [PATCH 072/160] `Option::unwrap` is now const (#20007) Summary -- I noticed while working on #20006 that we had a custom `unwrap` function for `Option`. This has been const on stable since 1.83 ([docs](https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap), [release notes](https://blog.rust-lang.org/2024/11/28/Rust-1.83.0/)), so I think it's safe to use now. I grepped a bit for related todos and found this one for `AsciiCharSet` but no others. Test Plan -- Existing tests --- .../refurb/rules/hardcoded_string_charset.rs | 7 +------ crates/ruff_source_file/src/line_index.rs | 15 +++------------ 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs b/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs index d29d89244be5f..0bc22b3a332b6 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/hardcoded_string_charset.rs @@ -93,12 +93,7 @@ impl NamedCharset { name, bytes, // SAFETY: The named charset is guaranteed to have only ascii bytes. - // TODO: replace with `.unwrap()`, when `Option::unwrap` will be stable in `const fn` - // https://github.com/rust-lang/rust/issues/67441 - ascii_char_set: match AsciiCharSet::from_bytes(bytes) { - Some(ascii_char_set) => ascii_char_set, - None => unreachable!(), - }, + ascii_char_set: AsciiCharSet::from_bytes(bytes).unwrap(), } } } diff --git a/crates/ruff_source_file/src/line_index.rs b/crates/ruff_source_file/src/line_index.rs index 34631891bd29e..1f04aef2401ce 100644 --- a/crates/ruff_source_file/src/line_index.rs +++ b/crates/ruff_source_file/src/line_index.rs @@ -562,11 +562,11 @@ pub struct OneIndexed(NonZeroUsize); impl OneIndexed { /// The largest value that can be represented by this integer type - pub const MAX: Self = unwrap(Self::new(usize::MAX)); + pub const MAX: Self = Self::new(usize::MAX).unwrap(); // SAFETY: These constants are being initialized with non-zero values /// The smallest value that can be represented by this integer type. - pub const MIN: Self = unwrap(Self::new(1)); - pub const ONE: NonZeroUsize = unwrap(NonZeroUsize::new(1)); + pub const MIN: Self = Self::new(1).unwrap(); + pub const ONE: NonZeroUsize = NonZeroUsize::new(1).unwrap(); /// Creates a non-zero if the given value is not zero. pub const fn new(value: usize) -> Option { @@ -636,15 +636,6 @@ impl fmt::Display for OneIndexed { } } -/// A const `Option::unwrap` without nightly features: -/// [Tracking issue](https://github.com/rust-lang/rust/issues/67441) -const fn unwrap(option: Option) -> T { - match option { - Some(value) => value, - None => panic!("unwrapping None"), - } -} - impl FromStr for OneIndexed { type Err = ParseIntError; fn from_str(s: &str) -> Result { From 39ee71c2a57bd6c51482430ba8bfe3728b4ca443 Mon Sep 17 00:00:00 2001 From: Leandro Braga <18340809+leandrobbraga@users.noreply.github.com> Date: Wed, 20 Aug 2025 15:33:23 -0300 Subject: [PATCH 073/160] [ty] correctly ignore field specifiers when not specified (#20002) This commit corrects the type checker's behavior when handling `dataclass_transform` decorators that don't explicitly specify `field_specifiers`. According to [PEP 681 (Data Class Transforms)](https://peps.python.org/pep-0681/#dataclass-transform-parameters), when `field_specifiers` is not provided, it defaults to an empty tuple, meaning no field specifiers are supported and `dataclasses.field`/`dataclasses.Field` calls should be ignored. Fixes https://github.com/astral-sh/ty/issues/980 --- .../resources/mdtest/dataclasses/fields.md | 44 +++++++++++++++++++ crates/ty_python_semantic/src/types.rs | 9 ++++ .../ty_python_semantic/src/types/call/bind.rs | 12 ++++- crates/ty_python_semantic/src/types/class.rs | 14 +++++- .../ty_python_semantic/src/types/function.rs | 1 + 5 files changed, 77 insertions(+), 3 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/dataclasses/fields.md b/crates/ty_python_semantic/resources/mdtest/dataclasses/fields.md index a547438ea9be0..592190f942f42 100644 --- a/crates/ty_python_semantic/resources/mdtest/dataclasses/fields.md +++ b/crates/ty_python_semantic/resources/mdtest/dataclasses/fields.md @@ -84,3 +84,47 @@ reveal_type(field(default=1)) # revealed: dataclasses.Field[Literal[1]] reveal_type(field(default=None)) # revealed: dataclasses.Field[None] reveal_type(field(default_factory=get_default)) # revealed: dataclasses.Field[str] ``` + +## dataclass_transform field_specifiers + +If `field_specifiers` is not specified, it defaults to an empty tuple, meaning no field specifiers +are supported and `dataclasses.field` and `dataclasses.Field` should not be accepted by default. + +```py +from typing_extensions import dataclass_transform +from dataclasses import field, dataclass +from typing import TypeVar + +T = TypeVar("T") + +@dataclass_transform() +def create_model(*, init: bool = True): + def deco(cls: type[T]) -> type[T]: + return cls + return deco + +@create_model() +class A: + name: str = field(init=False) + +# field(init=False) should be ignored for dataclass_transform without explicit field_specifiers +reveal_type(A.__init__) # revealed: (self: A, name: str = Unknown) -> None + +@dataclass +class B: + name: str = field(init=False) + +# Regular @dataclass should respect field(init=False) +reveal_type(B.__init__) # revealed: (self: B) -> None +``` + +Test constructor calls: + +```py +# This should NOT error because field(init=False) is ignored for A +A(name="foo") + +# This should error because field(init=False) is respected for B +# error: [unknown-argument] +B(name="foo") +``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index a910e6a2066f5..1afe7cd844560 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -510,6 +510,10 @@ bitflags! { const KW_ONLY = 0b0000_1000_0000; const SLOTS = 0b0001_0000_0000; const WEAKREF_SLOT = 0b0010_0000_0000; + // This is not an actual argument from `dataclass(...)` but a flag signaling that no + // `field_specifiers` was specified for the `dataclass_transform`, see [1]. + // [1]: https://typing.python.org/en/latest/spec/dataclasses.html#dataclass-transform-parameters + const NO_FIELD_SPECIFIERS = 0b0100_0000_0000; } } @@ -542,6 +546,11 @@ impl From for DataclassParams { params.contains(DataclassTransformerParams::FROZEN_DEFAULT), ); + result.set( + Self::NO_FIELD_SPECIFIERS, + !params.contains(DataclassTransformerParams::FIELD_SPECIFIERS), + ); + result } } diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index 226454e748952..d904e4c9ab455 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -900,7 +900,7 @@ impl<'db> Bindings<'db> { order_default, kw_only_default, frozen_default, - _field_specifiers, + field_specifiers, _kwargs, ] = overload.parameter_types() { @@ -919,6 +919,16 @@ impl<'db> Bindings<'db> { params |= DataclassTransformerParams::FROZEN_DEFAULT; } + if let Some(field_specifiers_type) = field_specifiers { + // For now, we'll do a simple check: if field_specifiers is not + // None/empty, we assume it might contain dataclasses.field + // TODO: Implement proper parsing to check for + // dataclasses.field/Field specifically + if !field_specifiers_type.is_none(db) { + params |= DataclassTransformerParams::FIELD_SPECIFIERS; + } + } + overload.set_return_type(Type::DataclassTransformer(params)); } } diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 8580dfb61f3df..49ef66960acee 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -2407,8 +2407,18 @@ impl<'db> ClassLiteral<'db> { let mut kw_only = None; if let Some(Type::KnownInstance(KnownInstanceType::Field(field))) = default_ty { default_ty = Some(field.default_type(db)); - init = field.init(db); - kw_only = field.kw_only(db); + if self + .dataclass_params(db) + .map(|params| params.contains(DataclassParams::NO_FIELD_SPECIFIERS)) + .unwrap_or(false) + { + // This happens when constructing a `dataclass` with a `dataclass_transform` + // without defining the `field_specifiers`, meaning it should ignore + // `dataclasses.field` and `dataclasses.Field`. + } else { + init = field.init(db); + kw_only = field.kw_only(db); + } } let mut field = Field { diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index b482e23e7439f..9a9c10ef75c30 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -164,6 +164,7 @@ bitflags! { const ORDER_DEFAULT = 1 << 1; const KW_ONLY_DEFAULT = 1 << 2; const FROZEN_DEFAULT = 1 << 3; + const FIELD_SPECIFIERS= 1 << 4; } } From d04dcd991b634079f37c4c2161e49de096ac7e80 Mon Sep 17 00:00:00 2001 From: chiri Date: Wed, 20 Aug 2025 21:36:07 +0300 Subject: [PATCH 074/160] [`flake8-use-pathlib`] Add fixes for `PTH102` and `PTH103` (#19514) ## Summary Part of https://github.com/astral-sh/ruff/issues/2331 ## Test Plan `cargo nextest run flake8_use_pathlib` --- .../fixtures/flake8_use_pathlib/full_name.py | 20 +- .../src/checkers/ast/analyze/expression.rs | 8 +- crates/ruff_linter/src/codes.rs | 4 +- crates/ruff_linter/src/preview.rs | 10 + .../src/rules/flake8_use_pathlib/helpers.rs | 21 +- .../src/rules/flake8_use_pathlib/rules/mod.rs | 4 + .../flake8_use_pathlib/rules/os_makedirs.rs | 152 +++++++++++++ .../flake8_use_pathlib/rules/os_mkdir.rs | 136 ++++++++++++ .../rules/replaceable_by_pathlib.rs | 18 +- ...ake8_use_pathlib__tests__full_name.py.snap | 74 +++++++ ...ake8_use_pathlib__tests__import_as.py.snap | 2 + ...e8_use_pathlib__tests__import_from.py.snap | 2 + ...use_pathlib__tests__import_from_as.py.snap | 2 + ..._pathlib__tests__preview_full_name.py.snap | 204 +++++++++++++++++- ..._pathlib__tests__preview_import_as.py.snap | 39 +++- ...athlib__tests__preview_import_from.py.snap | 41 +++- ...lib__tests__preview_import_from_as.py.snap | 41 +++- .../rules/flake8_use_pathlib/violations.rs | 90 -------- 18 files changed, 745 insertions(+), 123 deletions(-) create mode 100644 crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs create mode 100644 crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/full_name.py b/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/full_name.py index 9a63baf8c196c..81dba0e2701ce 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/full_name.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/full_name.py @@ -106,4 +106,22 @@ def bar(x: int): os.replace("src", "dst", dst_dir_fd=2) os.getcwd() -os.getcwdb() \ No newline at end of file +os.getcwdb() + +os.mkdir(path="directory") + +os.mkdir( + # comment 1 + "directory", + mode=0o777 +) + +os.mkdir("directory", mode=0o777, dir_fd=1) + +os.makedirs("name", 0o777, exist_ok=False) + +os.makedirs("name", 0o777, False) + +os.makedirs(name="name", mode=0o777, exist_ok=False) + +os.makedirs("name", unknown_kwarg=True) diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index b5270b4f972c8..51824c3a65692 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -1039,8 +1039,6 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { flake8_simplify::rules::zip_dict_keys_and_values(checker, call); } if checker.any_rule_enabled(&[ - Rule::OsMkdir, - Rule::OsMakedirs, Rule::OsStat, Rule::OsPathJoin, Rule::OsPathSplitext, @@ -1120,6 +1118,12 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { if checker.is_rule_enabled(Rule::OsPathSamefile) { flake8_use_pathlib::rules::os_path_samefile(checker, call, segments); } + if checker.is_rule_enabled(Rule::OsMkdir) { + flake8_use_pathlib::rules::os_mkdir(checker, call, segments); + } + if checker.is_rule_enabled(Rule::OsMakedirs) { + flake8_use_pathlib::rules::os_makedirs(checker, call, segments); + } if checker.is_rule_enabled(Rule::PathConstructorCurrentDirectory) { flake8_use_pathlib::rules::path_constructor_current_directory( checker, call, segments, diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index 5addc9592fa23..d395eed6f287c 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -921,8 +921,8 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { // flake8-use-pathlib (Flake8UsePathlib, "100") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsPathAbspath), (Flake8UsePathlib, "101") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsChmod), - (Flake8UsePathlib, "102") => (RuleGroup::Stable, rules::flake8_use_pathlib::violations::OsMkdir), - (Flake8UsePathlib, "103") => (RuleGroup::Stable, rules::flake8_use_pathlib::violations::OsMakedirs), + (Flake8UsePathlib, "102") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsMkdir), + (Flake8UsePathlib, "103") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsMakedirs), (Flake8UsePathlib, "104") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsRename), (Flake8UsePathlib, "105") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsReplace), (Flake8UsePathlib, "106") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::OsRmdir), diff --git a/crates/ruff_linter/src/preview.rs b/crates/ruff_linter/src/preview.rs index 73edcbf71dfdc..64c185989fa08 100644 --- a/crates/ruff_linter/src/preview.rs +++ b/crates/ruff_linter/src/preview.rs @@ -159,6 +159,16 @@ pub(crate) const fn is_fix_os_getcwd_enabled(settings: &LinterSettings) -> bool settings.preview.is_enabled() } +// https://github.com/astral-sh/ruff/pull/19514 +pub(crate) const fn is_fix_os_mkdir_enabled(settings: &LinterSettings) -> bool { + settings.preview.is_enabled() +} + +// https://github.com/astral-sh/ruff/pull/19514 +pub(crate) const fn is_fix_os_makedirs_enabled(settings: &LinterSettings) -> bool { + settings.preview.is_enabled() +} + // https://github.com/astral-sh/ruff/pull/11436 // https://github.com/astral-sh/ruff/pull/11168 pub(crate) const fn is_dunder_init_fix_unused_import_enabled(settings: &LinterSettings) -> bool { diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs index b71a635493c48..19a00b26b0ac5 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/helpers.rs @@ -1,10 +1,11 @@ -use crate::checkers::ast::Checker; -use crate::importer::ImportRequest; -use crate::{Applicability, Edit, Fix, Violation}; use ruff_python_ast::{self as ast, Expr, ExprCall}; use ruff_python_semantic::{SemanticModel, analyze::typing}; use ruff_text_size::Ranged; +use crate::checkers::ast::Checker; +use crate::importer::ImportRequest; +use crate::{Applicability, Edit, Fix, Violation}; + pub(crate) fn is_keyword_only_argument_non_default(arguments: &ast::Arguments, name: &str) -> bool { arguments .find_keyword(name) @@ -183,3 +184,17 @@ pub(crate) fn check_os_pathlib_two_arg_calls( }); } } + +pub(crate) fn has_unknown_keywords_or_starred_expr( + arguments: &ast::Arguments, + allowed: &[&str], +) -> bool { + if arguments.args.iter().any(Expr::is_starred_expr) { + return true; + } + + arguments.keywords.iter().any(|kw| match &kw.arg { + Some(arg) => !allowed.contains(&arg.as_str()), + None => true, + }) +} diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs index b1412707e9624..7c9c180fb62ea 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs @@ -2,6 +2,8 @@ pub(crate) use glob_rule::*; pub(crate) use invalid_pathlib_with_suffix::*; pub(crate) use os_chmod::*; pub(crate) use os_getcwd::*; +pub(crate) use os_makedirs::*; +pub(crate) use os_mkdir::*; pub(crate) use os_path_abspath::*; pub(crate) use os_path_basename::*; pub(crate) use os_path_dirname::*; @@ -30,6 +32,8 @@ mod glob_rule; mod invalid_pathlib_with_suffix; mod os_chmod; mod os_getcwd; +mod os_makedirs; +mod os_mkdir; mod os_path_abspath; mod os_path_basename; mod os_path_dirname; diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs new file mode 100644 index 0000000000000..c280d3ef77415 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs @@ -0,0 +1,152 @@ +use ruff_diagnostics::{Applicability, Edit, Fix}; +use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::{ArgOrKeyword, ExprCall}; +use ruff_text_size::Ranged; + +use crate::checkers::ast::Checker; +use crate::importer::ImportRequest; +use crate::preview::is_fix_os_makedirs_enabled; +use crate::rules::flake8_use_pathlib::helpers::{ + has_unknown_keywords_or_starred_expr, is_pathlib_path_call, +}; +use crate::{FixAvailability, Violation}; + +/// ## What it does +/// Checks for uses of `os.makedirs`. +/// +/// ## Why is this bad? +/// `pathlib` offers a high-level API for path manipulation, as compared to +/// the lower-level API offered by `os`. When possible, using `Path` object +/// methods such as `Path.mkdir(parents=True)` can improve readability over the +/// `os` module's counterparts (e.g., `os.makedirs()`. +/// +/// ## Examples +/// ```python +/// import os +/// +/// os.makedirs("./nested/directory/") +/// ``` +/// +/// Use instead: +/// ```python +/// from pathlib import Path +/// +/// Path("./nested/directory/").mkdir(parents=True) +/// ``` +/// +/// ## Known issues +/// While using `pathlib` can improve the readability and type safety of your code, +/// it can be less performant than the lower-level alternatives that work directly with strings, +/// especially on older versions of Python. +/// +/// ## Fix Safety +/// This rule's fix is marked as unsafe if the replacement would remove comments attached to the original expression. +/// +/// ## References +/// - [Python documentation: `Path.mkdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir) +/// - [Python documentation: `os.makedirs`](https://docs.python.org/3/library/os.html#os.makedirs) +/// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) +/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) +#[derive(ViolationMetadata)] +pub(crate) struct OsMakedirs; + +impl Violation for OsMakedirs { + const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; + + #[derive_message_formats] + fn message(&self) -> String { + "`os.makedirs()` should be replaced by `Path.mkdir(parents=True)`".to_string() + } + + fn fix_title(&self) -> Option { + Some("Replace with `Path(...).mkdir(parents=True)`".to_string()) + } +} + +/// PTH103 +pub(crate) fn os_makedirs(checker: &Checker, call: &ExprCall, segments: &[&str]) { + if segments != ["os", "makedirs"] { + return; + } + + let range = call.range(); + let mut diagnostic = checker.report_diagnostic(OsMakedirs, call.func.range()); + + let Some(name) = call.arguments.find_argument_value("name", 0) else { + return; + }; + + if !is_fix_os_makedirs_enabled(checker.settings()) { + return; + } + + // Signature as of Python 3.13 (https://docs.python.org/3/library/os.html#os.makedirs) + // ```text + // 0 1 2 + // os.makedirs(name, mode=0o777, exist_ok=False) + // ``` + // We should not offer autofixes if there are more arguments + // than in the original signature + if call.arguments.len() > 3 { + return; + } + // We should not offer autofixes if there are keyword arguments + // that don't match the original function signature + if has_unknown_keywords_or_starred_expr(&call.arguments, &["name", "mode", "exist_ok"]) { + return; + } + + diagnostic.try_set_fix(|| { + let (import_edit, binding) = checker.importer().get_or_import_symbol( + &ImportRequest::import("pathlib", "Path"), + call.start(), + checker.semantic(), + )?; + + let applicability = if checker.comment_ranges().intersects(range) { + Applicability::Unsafe + } else { + Applicability::Safe + }; + + let locator = checker.locator(); + + let name_code = locator.slice(name.range()); + + let mode = call.arguments.find_argument("mode", 1); + let exist_ok = call.arguments.find_argument("exist_ok", 2); + + let mkdir_args = match (mode, exist_ok) { + // Default to a keyword argument when alone. + (None, None) => "parents=True".to_string(), + // If either argument is missing, it's safe to add `parents` at the end. + (None, Some(arg)) | (Some(arg), None) => { + format!("{}, parents=True", locator.slice(arg)) + } + // If they're all positional, `parents` has to be positional too. + (Some(ArgOrKeyword::Arg(mode)), Some(ArgOrKeyword::Arg(exist_ok))) => { + format!("{}, True, {}", locator.slice(mode), locator.slice(exist_ok)) + } + // If either argument is a keyword, we can put `parents` at the end again. + (Some(mode), Some(exist_ok)) => format!( + "{}, {}, parents=True", + locator.slice(mode), + locator.slice(exist_ok) + ), + }; + + let replacement = if is_pathlib_path_call(checker, name) { + format!("{name_code}.mkdir({mkdir_args})") + } else { + format!("{binding}({name_code}).mkdir({mkdir_args})") + }; + + Ok(Fix::applicable_edits( + Edit::range_replacement(replacement, range), + [import_edit], + applicability, + )) + }); +} diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs new file mode 100644 index 0000000000000..754191910e5c9 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs @@ -0,0 +1,136 @@ +use ruff_diagnostics::{Applicability, Edit, Fix}; +use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::ExprCall; +use ruff_text_size::Ranged; + +use crate::checkers::ast::Checker; +use crate::importer::ImportRequest; +use crate::preview::is_fix_os_mkdir_enabled; +use crate::rules::flake8_use_pathlib::helpers::{ + has_unknown_keywords_or_starred_expr, is_keyword_only_argument_non_default, + is_pathlib_path_call, +}; +use crate::{FixAvailability, Violation}; + +/// ## What it does +/// Checks for uses of `os.mkdir`. +/// +/// ## Why is this bad? +/// `pathlib` offers a high-level API for path manipulation, as compared to +/// the lower-level API offered by `os`. When possible, using `Path` object +/// methods such as `Path.mkdir()` can improve readability over the `os` +/// module's counterparts (e.g., `os.mkdir()`). +/// +/// ## Examples +/// ```python +/// import os +/// +/// os.mkdir("./directory/") +/// ``` +/// +/// Use instead: +/// ```python +/// from pathlib import Path +/// +/// Path("./directory/").mkdir() +/// ``` +/// +/// ## Known issues +/// While using `pathlib` can improve the readability and type safety of your code, +/// it can be less performant than the lower-level alternatives that work directly with strings, +/// especially on older versions of Python. +/// +/// ## Fix Safety +/// This rule's fix is marked as unsafe if the replacement would remove comments attached to the original expression. +/// +/// ## References +/// - [Python documentation: `Path.mkdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir) +/// - [Python documentation: `os.mkdir`](https://docs.python.org/3/library/os.html#os.mkdir) +/// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) +/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) +#[derive(ViolationMetadata)] +pub(crate) struct OsMkdir; + +impl Violation for OsMkdir { + const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; + + #[derive_message_formats] + fn message(&self) -> String { + "`os.mkdir()` should be replaced by `Path.mkdir()`".to_string() + } + + fn fix_title(&self) -> Option { + Some("Replace with `Path(...).mkdir()`".to_string()) + } +} + +/// PTH102 +pub(crate) fn os_mkdir(checker: &Checker, call: &ExprCall, segments: &[&str]) { + if segments != ["os", "mkdir"] { + return; + } + // `dir_fd` is not supported by pathlib, so check if it's set to non-default values. + // Signature as of Python 3.13 (https://docs.python.org/3/library/os.html#os.mkdir) + // ```text + // 0 1 2 + // os.mkdir(path, mode=0o777, *, dir_fd=None) + // ``` + if is_keyword_only_argument_non_default(&call.arguments, "dir_fd") { + return; + } + + let range = call.range(); + let mut diagnostic = checker.report_diagnostic(OsMkdir, call.func.range()); + + let Some(path) = call.arguments.find_argument_value("path", 0) else { + return; + }; + + if !is_fix_os_mkdir_enabled(checker.settings()) { + return; + } + + if call.arguments.len() > 2 { + return; + } + + if has_unknown_keywords_or_starred_expr(&call.arguments, &["path", "mode"]) { + return; + } + + diagnostic.try_set_fix(|| { + let (import_edit, binding) = checker.importer().get_or_import_symbol( + &ImportRequest::import("pathlib", "Path"), + call.start(), + checker.semantic(), + )?; + + let applicability = if checker.comment_ranges().intersects(range) { + Applicability::Unsafe + } else { + Applicability::Safe + }; + + let path_code = checker.locator().slice(path.range()); + + let mkdir_args = call + .arguments + .find_argument_value("mode", 1) + .map(|expr| format!("mode={}", checker.locator().slice(expr.range()))) + .unwrap_or_default(); + + let replacement = if is_pathlib_path_call(checker, path) { + format!("{path_code}.mkdir({mkdir_args})") + } else { + format!("{binding}({path_code}).mkdir({mkdir_args})") + }; + + Ok(Fix::applicable_edits( + Edit::range_replacement(replacement, range), + [import_edit], + applicability, + )) + }); +} diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs index 65026a0108990..b35ecd77c1d24 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs @@ -8,8 +8,7 @@ use crate::rules::flake8_use_pathlib::helpers::{ use crate::rules::flake8_use_pathlib::{ rules::Glob, violations::{ - BuiltinOpen, Joiner, OsListdir, OsMakedirs, OsMkdir, OsPathJoin, OsPathSplitext, OsStat, - OsSymlink, PyPath, + BuiltinOpen, Joiner, OsListdir, OsPathJoin, OsPathSplitext, OsStat, OsSymlink, PyPath, }, }; @@ -20,21 +19,6 @@ pub(crate) fn replaceable_by_pathlib(checker: &Checker, call: &ExprCall) { let range = call.func.range(); match qualified_name.segments() { - // PTH102 - ["os", "makedirs"] => checker.report_diagnostic_if_enabled(OsMakedirs, range), - // PTH103 - ["os", "mkdir"] => { - // `dir_fd` is not supported by pathlib, so check if it's set to non-default values. - // Signature as of Python 3.13 (https://docs.python.org/3/library/os.html#os.mkdir) - // ```text - // 0 1 2 - // os.mkdir(path, mode=0o777, *, dir_fd=None) - // ``` - if is_keyword_only_argument_non_default(&call.arguments, "dir_fd") { - return; - } - checker.report_diagnostic_if_enabled(OsMkdir, range) - } // PTH116 ["os", "stat"] => { // `dir_fd` is not supported by pathlib, so check if it's set to non-default values. diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__full_name.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__full_name.py.snap index 7a22a5615dbcb..84900549de9d6 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__full_name.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__full_name.py.snap @@ -34,6 +34,7 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 10 | os.makedirs(p) 11 | os.rename(p) | +help: Replace with `Path(...).mkdir()` PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> full_name.py:10:1 @@ -45,6 +46,7 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 11 | os.rename(p) 12 | os.replace(p) | +help: Replace with `Path(...).mkdir(parents=True)` PTH104 `os.rename()` should be replaced by `Path.rename()` --> full_name.py:11:1 @@ -419,5 +421,77 @@ PTH109 `os.getcwd()` should be replaced by `Path.cwd()` 108 | os.getcwd() 109 | os.getcwdb() | ^^^^^^^^^^ +110 | +111 | os.mkdir(path="directory") | help: Replace with `Path.cwd()` + +PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` + --> full_name.py:111:1 + | +109 | os.getcwdb() +110 | +111 | os.mkdir(path="directory") + | ^^^^^^^^ +112 | +113 | os.mkdir( + | +help: Replace with `Path(...).mkdir()` + +PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` + --> full_name.py:113:1 + | +111 | os.mkdir(path="directory") +112 | +113 | os.mkdir( + | ^^^^^^^^ +114 | # comment 1 +115 | "directory", + | +help: Replace with `Path(...).mkdir()` + +PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:121:1 + | +119 | os.mkdir("directory", mode=0o777, dir_fd=1) +120 | +121 | os.makedirs("name", 0o777, exist_ok=False) + | ^^^^^^^^^^^ +122 | +123 | os.makedirs("name", 0o777, False) + | +help: Replace with `Path(...).mkdir(parents=True)` + +PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:123:1 + | +121 | os.makedirs("name", 0o777, exist_ok=False) +122 | +123 | os.makedirs("name", 0o777, False) + | ^^^^^^^^^^^ +124 | +125 | os.makedirs(name="name", mode=0o777, exist_ok=False) + | +help: Replace with `Path(...).mkdir(parents=True)` + +PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:125:1 + | +123 | os.makedirs("name", 0o777, False) +124 | +125 | os.makedirs(name="name", mode=0o777, exist_ok=False) + | ^^^^^^^^^^^ +126 | +127 | os.makedirs("name", unknown_kwarg=True) + | +help: Replace with `Path(...).mkdir(parents=True)` + +PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:127:1 + | +125 | os.makedirs(name="name", mode=0o777, exist_ok=False) +126 | +127 | os.makedirs("name", unknown_kwarg=True) + | ^^^^^^^^^^^ + | +help: Replace with `Path(...).mkdir(parents=True)` diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_as.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_as.py.snap index 3d94e4eb065d2..f2b4eeff44967 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_as.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_as.py.snap @@ -34,6 +34,7 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 10 | foo.makedirs(p) 11 | foo.rename(p) | +help: Replace with `Path(...).mkdir()` PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> import_as.py:10:1 @@ -45,6 +46,7 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 11 | foo.rename(p) 12 | foo.replace(p) | +help: Replace with `Path(...).mkdir(parents=True)` PTH104 `os.rename()` should be replaced by `Path.rename()` --> import_as.py:11:1 diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from.py.snap index 5e8b12f577f63..010c77965497d 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from.py.snap @@ -34,6 +34,7 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 12 | makedirs(p) 13 | rename(p) | +help: Replace with `Path(...).mkdir()` PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> import_from.py:12:1 @@ -45,6 +46,7 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 13 | rename(p) 14 | replace(p) | +help: Replace with `Path(...).mkdir(parents=True)` PTH104 `os.rename()` should be replaced by `Path.rename()` --> import_from.py:13:1 diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from_as.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from_as.py.snap index 7a85401333e42..14992042957b0 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from_as.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__import_from_as.py.snap @@ -34,6 +34,7 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 17 | xmakedirs(p) 18 | xrename(p) | +help: Replace with `Path(...).mkdir()` PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> import_from_as.py:17:1 @@ -45,6 +46,7 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 18 | xrename(p) 19 | xreplace(p) | +help: Replace with `Path(...).mkdir(parents=True)` PTH104 `os.rename()` should be replaced by `Path.rename()` --> import_from_as.py:18:1 diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap index e3a23ed180284..8ed53256005eb 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap @@ -38,7 +38,7 @@ PTH101 `os.chmod()` should be replaced by `Path.chmod()` | help: Replace with `Path(...).chmod(...)` -PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` +PTH102 [*] `os.mkdir()` should be replaced by `Path.mkdir()` --> full_name.py:9:7 | 7 | a = os.path.abspath(p) @@ -48,8 +48,25 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 10 | os.makedirs(p) 11 | os.rename(p) | +help: Replace with `Path(...).mkdir()` -PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` +ℹ Safe fix +1 1 | import os +2 2 | import os.path + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +6 7 | +7 8 | a = os.path.abspath(p) +8 9 | aa = os.chmod(p) +9 |-aaa = os.mkdir(p) + 10 |+aaa = pathlib.Path(p).mkdir() +10 11 | os.makedirs(p) +11 12 | os.rename(p) +12 13 | os.replace(p) + +PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> full_name.py:10:1 | 8 | aa = os.chmod(p) @@ -59,6 +76,24 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 11 | os.rename(p) 12 | os.replace(p) | +help: Replace with `Path(...).mkdir(parents=True)` + +ℹ Safe fix +1 1 | import os +2 2 | import os.path + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +-------------------------------------------------------------------------------- +7 8 | a = os.path.abspath(p) +8 9 | aa = os.chmod(p) +9 10 | aaa = os.mkdir(p) +10 |-os.makedirs(p) + 11 |+pathlib.Path(p).mkdir(parents=True) +11 12 | os.rename(p) +12 13 | os.replace(p) +13 14 | os.rmdir(p) PTH104 `os.rename()` should be replaced by `Path.rename()` --> full_name.py:11:1 @@ -645,6 +680,8 @@ help: Replace with `Path.cwd()` 108 |-os.getcwd() 109 |+pathlib.Path.cwd() 109 110 | os.getcwdb() +110 111 | +111 112 | os.mkdir(path="directory") PTH109 [*] `os.getcwd()` should be replaced by `Path.cwd()` --> full_name.py:109:1 @@ -652,6 +689,8 @@ PTH109 [*] `os.getcwd()` should be replaced by `Path.cwd()` 108 | os.getcwd() 109 | os.getcwdb() | ^^^^^^^^^^ +110 | +111 | os.mkdir(path="directory") | help: Replace with `Path.cwd()` @@ -668,3 +707,164 @@ help: Replace with `Path.cwd()` 108 109 | os.getcwd() 109 |-os.getcwdb() 110 |+pathlib.Path.cwd() +110 111 | +111 112 | os.mkdir(path="directory") +112 113 | + +PTH102 [*] `os.mkdir()` should be replaced by `Path.mkdir()` + --> full_name.py:111:1 + | +109 | os.getcwdb() +110 | +111 | os.mkdir(path="directory") + | ^^^^^^^^ +112 | +113 | os.mkdir( + | +help: Replace with `Path(...).mkdir()` + +ℹ Safe fix +1 1 | import os +2 2 | import os.path + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +-------------------------------------------------------------------------------- +108 109 | os.getcwd() +109 110 | os.getcwdb() +110 111 | +111 |-os.mkdir(path="directory") + 112 |+pathlib.Path("directory").mkdir() +112 113 | +113 114 | os.mkdir( +114 115 | # comment 1 + +PTH102 [*] `os.mkdir()` should be replaced by `Path.mkdir()` + --> full_name.py:113:1 + | +111 | os.mkdir(path="directory") +112 | +113 | os.mkdir( + | ^^^^^^^^ +114 | # comment 1 +115 | "directory", + | +help: Replace with `Path(...).mkdir()` + +ℹ Unsafe fix +1 1 | import os +2 2 | import os.path + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +-------------------------------------------------------------------------------- +110 111 | +111 112 | os.mkdir(path="directory") +112 113 | +113 |-os.mkdir( +114 |- # comment 1 +115 |- "directory", +116 |- mode=0o777 +117 |-) + 114 |+pathlib.Path("directory").mkdir(mode=0o777) +118 115 | +119 116 | os.mkdir("directory", mode=0o777, dir_fd=1) +120 117 | + +PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:121:1 + | +119 | os.mkdir("directory", mode=0o777, dir_fd=1) +120 | +121 | os.makedirs("name", 0o777, exist_ok=False) + | ^^^^^^^^^^^ +122 | +123 | os.makedirs("name", 0o777, False) + | +help: Replace with `Path(...).mkdir(parents=True)` + +ℹ Safe fix +1 1 | import os +2 2 | import os.path + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +-------------------------------------------------------------------------------- +118 119 | +119 120 | os.mkdir("directory", mode=0o777, dir_fd=1) +120 121 | +121 |-os.makedirs("name", 0o777, exist_ok=False) + 122 |+pathlib.Path("name").mkdir(0o777, exist_ok=False, parents=True) +122 123 | +123 124 | os.makedirs("name", 0o777, False) +124 125 | + +PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:123:1 + | +121 | os.makedirs("name", 0o777, exist_ok=False) +122 | +123 | os.makedirs("name", 0o777, False) + | ^^^^^^^^^^^ +124 | +125 | os.makedirs(name="name", mode=0o777, exist_ok=False) + | +help: Replace with `Path(...).mkdir(parents=True)` + +ℹ Safe fix +1 1 | import os +2 2 | import os.path + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +-------------------------------------------------------------------------------- +120 121 | +121 122 | os.makedirs("name", 0o777, exist_ok=False) +122 123 | +123 |-os.makedirs("name", 0o777, False) + 124 |+pathlib.Path("name").mkdir(0o777, True, False) +124 125 | +125 126 | os.makedirs(name="name", mode=0o777, exist_ok=False) +126 127 | + +PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:125:1 + | +123 | os.makedirs("name", 0o777, False) +124 | +125 | os.makedirs(name="name", mode=0o777, exist_ok=False) + | ^^^^^^^^^^^ +126 | +127 | os.makedirs("name", unknown_kwarg=True) + | +help: Replace with `Path(...).mkdir(parents=True)` + +ℹ Safe fix +1 1 | import os +2 2 | import os.path + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +-------------------------------------------------------------------------------- +122 123 | +123 124 | os.makedirs("name", 0o777, False) +124 125 | +125 |-os.makedirs(name="name", mode=0o777, exist_ok=False) + 126 |+pathlib.Path("name").mkdir(mode=0o777, exist_ok=False, parents=True) +126 127 | +127 128 | os.makedirs("name", unknown_kwarg=True) + +PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` + --> full_name.py:127:1 + | +125 | os.makedirs(name="name", mode=0o777, exist_ok=False) +126 | +127 | os.makedirs("name", unknown_kwarg=True) + | ^^^^^^^^^^^ + | +help: Replace with `Path(...).mkdir(parents=True)` diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap index 5a32aa5f53313..167f4ecd2c771 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap @@ -38,7 +38,7 @@ PTH101 `os.chmod()` should be replaced by `Path.chmod()` | help: Replace with `Path(...).chmod(...)` -PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` +PTH102 [*] `os.mkdir()` should be replaced by `Path.mkdir()` --> import_as.py:9:7 | 7 | a = foo_p.abspath(p) @@ -48,8 +48,25 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 10 | foo.makedirs(p) 11 | foo.rename(p) | +help: Replace with `Path(...).mkdir()` -PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` +ℹ Safe fix +1 1 | import os as foo +2 2 | import os.path as foo_p + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +6 7 | +7 8 | a = foo_p.abspath(p) +8 9 | aa = foo.chmod(p) +9 |-aaa = foo.mkdir(p) + 10 |+aaa = pathlib.Path(p).mkdir() +10 11 | foo.makedirs(p) +11 12 | foo.rename(p) +12 13 | foo.replace(p) + +PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> import_as.py:10:1 | 8 | aa = foo.chmod(p) @@ -59,6 +76,24 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 11 | foo.rename(p) 12 | foo.replace(p) | +help: Replace with `Path(...).mkdir(parents=True)` + +ℹ Safe fix +1 1 | import os as foo +2 2 | import os.path as foo_p + 3 |+import pathlib +3 4 | +4 5 | p = "/foo" +5 6 | q = "bar" +-------------------------------------------------------------------------------- +7 8 | a = foo_p.abspath(p) +8 9 | aa = foo.chmod(p) +9 10 | aaa = foo.mkdir(p) +10 |-foo.makedirs(p) + 11 |+pathlib.Path(p).mkdir(parents=True) +11 12 | foo.rename(p) +12 13 | foo.replace(p) +13 14 | foo.rmdir(p) PTH104 `os.rename()` should be replaced by `Path.rename()` --> import_as.py:11:1 diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap index 1d295095d3fec..9b1262c76c873 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap @@ -39,7 +39,7 @@ PTH101 `os.chmod()` should be replaced by `Path.chmod()` | help: Replace with `Path(...).chmod(...)` -PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` +PTH102 [*] `os.mkdir()` should be replaced by `Path.mkdir()` --> import_from.py:11:7 | 9 | a = abspath(p) @@ -49,8 +49,26 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 12 | makedirs(p) 13 | rename(p) | +help: Replace with `Path(...).mkdir()` -PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` +ℹ Safe fix +2 2 | from os import remove, unlink, getcwd, readlink, stat +3 3 | from os.path import abspath, exists, expanduser, isdir, isfile, islink +4 4 | from os.path import isabs, join, basename, dirname, samefile, splitext + 5 |+import pathlib +5 6 | +6 7 | p = "/foo" +7 8 | q = "bar" +8 9 | +9 10 | a = abspath(p) +10 11 | aa = chmod(p) +11 |-aaa = mkdir(p) + 12 |+aaa = pathlib.Path(p).mkdir() +12 13 | makedirs(p) +13 14 | rename(p) +14 15 | replace(p) + +PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> import_from.py:12:1 | 10 | aa = chmod(p) @@ -60,6 +78,25 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 13 | rename(p) 14 | replace(p) | +help: Replace with `Path(...).mkdir(parents=True)` + +ℹ Safe fix +2 2 | from os import remove, unlink, getcwd, readlink, stat +3 3 | from os.path import abspath, exists, expanduser, isdir, isfile, islink +4 4 | from os.path import isabs, join, basename, dirname, samefile, splitext + 5 |+import pathlib +5 6 | +6 7 | p = "/foo" +7 8 | q = "bar" +-------------------------------------------------------------------------------- +9 10 | a = abspath(p) +10 11 | aa = chmod(p) +11 12 | aaa = mkdir(p) +12 |-makedirs(p) + 13 |+pathlib.Path(p).mkdir(parents=True) +13 14 | rename(p) +14 15 | replace(p) +15 16 | rmdir(p) PTH104 `os.rename()` should be replaced by `Path.rename()` --> import_from.py:13:1 diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap index 1d59d9f30456e..c964f4b1234a5 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap @@ -39,7 +39,7 @@ PTH101 `os.chmod()` should be replaced by `Path.chmod()` | help: Replace with `Path(...).chmod(...)` -PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` +PTH102 [*] `os.mkdir()` should be replaced by `Path.mkdir()` --> import_from_as.py:16:7 | 14 | a = xabspath(p) @@ -49,8 +49,26 @@ PTH102 `os.mkdir()` should be replaced by `Path.mkdir()` 17 | xmakedirs(p) 18 | xrename(p) | +help: Replace with `Path(...).mkdir()` -PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` +ℹ Safe fix +7 7 | from os.path import isfile as xisfile, islink as xislink, isabs as xisabs +8 8 | from os.path import join as xjoin, basename as xbasename, dirname as xdirname +9 9 | from os.path import samefile as xsamefile, splitext as xsplitext + 10 |+import pathlib +10 11 | +11 12 | p = "/foo" +12 13 | q = "bar" +13 14 | +14 15 | a = xabspath(p) +15 16 | aa = xchmod(p) +16 |-aaa = xmkdir(p) + 17 |+aaa = pathlib.Path(p).mkdir() +17 18 | xmakedirs(p) +18 19 | xrename(p) +19 20 | xreplace(p) + +PTH103 [*] `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` --> import_from_as.py:17:1 | 15 | aa = xchmod(p) @@ -60,6 +78,25 @@ PTH103 `os.makedirs()` should be replaced by `Path.mkdir(parents=True)` 18 | xrename(p) 19 | xreplace(p) | +help: Replace with `Path(...).mkdir(parents=True)` + +ℹ Safe fix +7 7 | from os.path import isfile as xisfile, islink as xislink, isabs as xisabs +8 8 | from os.path import join as xjoin, basename as xbasename, dirname as xdirname +9 9 | from os.path import samefile as xsamefile, splitext as xsplitext + 10 |+import pathlib +10 11 | +11 12 | p = "/foo" +12 13 | q = "bar" +-------------------------------------------------------------------------------- +14 15 | a = xabspath(p) +15 16 | aa = xchmod(p) +16 17 | aaa = xmkdir(p) +17 |-xmakedirs(p) + 18 |+pathlib.Path(p).mkdir(parents=True) +18 19 | xrename(p) +19 20 | xreplace(p) +20 21 | xrmdir(p) PTH104 `os.rename()` should be replaced by `Path.rename()` --> import_from_as.py:18:1 diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs index e9d741973727d..7a5661aae2f11 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs @@ -2,96 +2,6 @@ use ruff_macros::{ViolationMetadata, derive_message_formats}; use crate::Violation; -/// ## What it does -/// Checks for uses of `os.makedirs`. -/// -/// ## Why is this bad? -/// `pathlib` offers a high-level API for path manipulation, as compared to -/// the lower-level API offered by `os`. When possible, using `Path` object -/// methods such as `Path.mkdir(parents=True)` can improve readability over the -/// `os` module's counterparts (e.g., `os.makedirs()`. -/// -/// ## Examples -/// ```python -/// import os -/// -/// os.makedirs("./nested/directory/") -/// ``` -/// -/// Use instead: -/// ```python -/// from pathlib import Path -/// -/// Path("./nested/directory/").mkdir(parents=True) -/// ``` -/// -/// ## Known issues -/// While using `pathlib` can improve the readability and type safety of your code, -/// it can be less performant than the lower-level alternatives that work directly with strings, -/// especially on older versions of Python. -/// -/// ## References -/// - [Python documentation: `Path.mkdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir) -/// - [Python documentation: `os.makedirs`](https://docs.python.org/3/library/os.html#os.makedirs) -/// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) -/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) -/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[derive(ViolationMetadata)] -pub(crate) struct OsMakedirs; - -impl Violation for OsMakedirs { - #[derive_message_formats] - fn message(&self) -> String { - "`os.makedirs()` should be replaced by `Path.mkdir(parents=True)`".to_string() - } -} - -/// ## What it does -/// Checks for uses of `os.mkdir`. -/// -/// ## Why is this bad? -/// `pathlib` offers a high-level API for path manipulation, as compared to -/// the lower-level API offered by `os`. When possible, using `Path` object -/// methods such as `Path.mkdir()` can improve readability over the `os` -/// module's counterparts (e.g., `os.mkdir()`). -/// -/// ## Examples -/// ```python -/// import os -/// -/// os.mkdir("./directory/") -/// ``` -/// -/// Use instead: -/// ```python -/// from pathlib import Path -/// -/// Path("./directory/").mkdir() -/// ``` -/// -/// ## Known issues -/// While using `pathlib` can improve the readability and type safety of your code, -/// it can be less performant than the lower-level alternatives that work directly with strings, -/// especially on older versions of Python. -/// -/// ## References -/// - [Python documentation: `Path.mkdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir) -/// - [Python documentation: `os.mkdir`](https://docs.python.org/3/library/os.html#os.mkdir) -/// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) -/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) -/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[derive(ViolationMetadata)] -pub(crate) struct OsMkdir; - -impl Violation for OsMkdir { - #[derive_message_formats] - fn message(&self) -> String { - "`os.mkdir()` should be replaced by `Path.mkdir()`".to_string() - } -} - /// ## What it does /// Checks for uses of `os.stat`. /// From 7b75aee21d45bb84e6bb4d747cd5715dd0d03c95 Mon Sep 17 00:00:00 2001 From: Igor Drokin <41319097+IDrokin117@users.noreply.github.com> Date: Wed, 20 Aug 2025 22:22:03 +0300 Subject: [PATCH 075/160] [`pyupgrade`] Avoid reporting `__future__` features as unnecessary when they are used (`UP010`) (#19769) ## Summary Resolves #19561 Fixes the [unnecessary-future-import (UP010)](https://docs.astral.sh/ruff/rules/unnecessary-future-import/) rule to correctly identify when imported __future__ modules are actually used in the code, preventing false positives. I assume there is no way to check usage in `analyze::statements`, because we don't have any usage bindings for imports. To determine unused imports, we have to fully scan the file to create bindings and then check usage, similar to [unused-import (F401)](https://docs.astral.sh/ruff/rules/unused-import/#unused-import-f401). So, `Rule::UnnecessaryFutureImport` was moved from the `analyze::statements` to the `analyze::deferred_scopes` stage. This caused the need to change the logic of future import handling to a bindings-based approach. Also, the diagnostic report was changed. Before ``` | 1 | from __future__ import nested_scopes, generators | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UP010 ``` after ``` | 1 | from __future__ import nested_scopes, generators | ^^^^^^^^^^^^^ UP010 ``` I believe this is the correct way, because `generators` may be used, but `nested_scopes` is not. ### Special case I've found out about some specific case. ```python from __future__ import nested_scopes nested_scopes = 1 ``` Here we can treat `nested_scopes` as an unused import because the variable `nested_scopes` shadows it and we can safely remove the future import (my fix does it). But [F401](https://docs.astral.sh/ruff/rules/unused-import/#unused-import-f401) not triggered for such case ([sandbox](https://play.ruff.rs/296d9c7e-0f02-4659-b0c0-78cc21f3de76)) ``` from foo import print_function print_function = 1 ``` In my mind, `print_function` here is an unused import and should be deleted (my IDE highlight it). What do you think? ## Test Plan Added test cases and snapshots: - Split test file into separate _0 and _1 files for appropriate checks. - Added test cases to verify fixes when future module are used. --------- Co-authored-by: Igor Drokin --- .../pyupgrade/{UP010.py => UP010_0.py} | 0 .../test/fixtures/pyupgrade/UP010_1.py | 18 +++ .../checkers/ast/analyze/deferred_scopes.rs | 9 +- .../src/checkers/ast/analyze/statement.rs | 7 - crates/ruff_linter/src/rules/pyupgrade/mod.rs | 3 +- .../rules/unnecessary_future_import.rs | 140 ++++++++++-------- ..._rules__pyupgrade__tests__UP010_0.py.snap} | 22 +-- ...__rules__pyupgrade__tests__UP010_1.py.snap | 99 +++++++++++++ 8 files changed, 215 insertions(+), 83 deletions(-) rename crates/ruff_linter/resources/test/fixtures/pyupgrade/{UP010.py => UP010_0.py} (100%) create mode 100644 crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010_1.py rename crates/ruff_linter/src/rules/pyupgrade/snapshots/{ruff_linter__rules__pyupgrade__tests__UP010.py.snap => ruff_linter__rules__pyupgrade__tests__UP010_0.py.snap} (96%) create mode 100644 crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010_1.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010_0.py similarity index 100% rename from crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010.py rename to crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010_0.py diff --git a/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010_1.py b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010_1.py new file mode 100644 index 0000000000000..33f9be894a626 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/pyupgrade/UP010_1.py @@ -0,0 +1,18 @@ +from __future__ import nested_scopes, generators +from __future__ import with_statement, unicode_literals + +from __future__ import absolute_import, division +from __future__ import generator_stop +from __future__ import print_function, nested_scopes, generator_stop + +print(with_statement) +generators = 1 + + +class Foo(): + + def boo(self): + print(division) + + +__all__ = ["print_function", "generator_stop"] diff --git a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs index 4971254acf8cd..2cf6ec15bba56 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/deferred_scopes.rs @@ -1,10 +1,11 @@ +use ruff_python_ast::PythonVersion; use ruff_python_semantic::{Binding, ScopeKind}; use crate::checkers::ast::Checker; use crate::codes::Rule; use crate::rules::{ flake8_builtins, flake8_pyi, flake8_type_checking, flake8_unused_arguments, pep8_naming, - pyflakes, pylint, ruff, + pyflakes, pylint, pyupgrade, ruff, }; /// Run lint rules over all deferred scopes in the [`SemanticModel`]. @@ -45,6 +46,7 @@ pub(crate) fn deferred_scopes(checker: &Checker) { Rule::UnusedStaticMethodArgument, Rule::UnusedUnpackedVariable, Rule::UnusedVariable, + Rule::UnnecessaryFutureImport, ]) { return; } @@ -224,6 +226,11 @@ pub(crate) fn deferred_scopes(checker: &Checker) { if checker.is_rule_enabled(Rule::UnusedImport) { pyflakes::rules::unused_import(checker, scope); } + if checker.is_rule_enabled(Rule::UnnecessaryFutureImport) { + if checker.target_version() >= PythonVersion::PY37 { + pyupgrade::rules::unnecessary_future_import(checker, scope); + } + } if checker.is_rule_enabled(Rule::ImportPrivateName) { pylint::rules::import_private_name(checker, scope); diff --git a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs index 0cfb3a3cc7bf8..164df3846a261 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/statement.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/statement.rs @@ -728,13 +728,6 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) { pylint::rules::non_ascii_module_import(checker, alias); } } - if checker.is_rule_enabled(Rule::UnnecessaryFutureImport) { - if checker.target_version() >= PythonVersion::PY37 { - if let Some("__future__") = module { - pyupgrade::rules::unnecessary_future_import(checker, stmt, names); - } - } - } if checker.is_rule_enabled(Rule::DeprecatedMockImport) { pyupgrade::rules::deprecated_mock_import(checker, stmt); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/mod.rs b/crates/ruff_linter/src/rules/pyupgrade/mod.rs index afc3f2c049388..763e9f34b7126 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/mod.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/mod.rs @@ -101,7 +101,8 @@ mod tests { #[test_case(Rule::UnnecessaryClassParentheses, Path::new("UP039.py"))] #[test_case(Rule::UnnecessaryDefaultTypeArgs, Path::new("UP043.py"))] #[test_case(Rule::UnnecessaryEncodeUTF8, Path::new("UP012.py"))] - #[test_case(Rule::UnnecessaryFutureImport, Path::new("UP010.py"))] + #[test_case(Rule::UnnecessaryFutureImport, Path::new("UP010_0.py"))] + #[test_case(Rule::UnnecessaryFutureImport, Path::new("UP010_1.py"))] #[test_case(Rule::UselessMetaclassType, Path::new("UP001.py"))] #[test_case(Rule::UselessObjectInheritance, Path::new("UP004.py"))] #[test_case(Rule::YieldInForLoop, Path::new("UP028_0.py"))] diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs index 1809cc3e1629d..51b8167172fc8 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_future_import.rs @@ -1,10 +1,11 @@ -use std::collections::BTreeSet; +use std::collections::{BTreeSet, HashMap}; -use itertools::Itertools; +use itertools::{Itertools, chain}; +use ruff_python_semantic::NodeId; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::{self as ast, Alias, Stmt, StmtRef}; -use ruff_python_semantic::NameImport; +use ruff_python_semantic::{NameImport, Scope}; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; @@ -111,68 +112,81 @@ pub(crate) fn is_import_required_by_isort( } /// UP010 -pub(crate) fn unnecessary_future_import(checker: &Checker, stmt: &Stmt, names: &[Alias]) { - let mut unused_imports: Vec<&Alias> = vec![]; - for alias in names { - if alias.asname.is_some() { - continue; - } - - if is_import_required_by_isort( - &checker.settings().isort.required_imports, - stmt.into(), - alias, - ) { - continue; - } - - if PY33_PLUS_REMOVE_FUTURES.contains(&alias.name.as_str()) - || PY37_PLUS_REMOVE_FUTURES.contains(&alias.name.as_str()) - { - unused_imports.push(alias); +pub(crate) fn unnecessary_future_import(checker: &Checker, scope: &Scope) { + let mut unused_imports: HashMap> = HashMap::new(); + for future_name in chain(PY33_PLUS_REMOVE_FUTURES, PY37_PLUS_REMOVE_FUTURES).unique() { + for binding_id in scope.get_all(future_name) { + let binding = checker.semantic().binding(binding_id); + if binding.kind.is_future_import() && binding.is_unused() { + let Some(node_id) = binding.source else { + continue; + }; + + let stmt = checker.semantic().statement(node_id); + if let Stmt::ImportFrom(ast::StmtImportFrom { names, .. }) = stmt { + let Some(alias) = names + .iter() + .find(|alias| alias.name.as_str() == binding.name(checker.source())) + else { + continue; + }; + + if alias.asname.is_some() { + continue; + } + + if is_import_required_by_isort( + &checker.settings().isort.required_imports, + stmt.into(), + alias, + ) { + continue; + } + unused_imports.entry(node_id).or_default().push(alias); + } + } } } - if unused_imports.is_empty() { - return; + for (node_id, unused_aliases) in unused_imports { + let mut diagnostic = checker.report_diagnostic( + UnnecessaryFutureImport { + names: unused_aliases + .iter() + .map(|alias| alias.name.to_string()) + .sorted() + .collect(), + }, + checker.semantic().statement(node_id).range(), + ); + + diagnostic.try_set_fix(|| { + let statement = checker.semantic().statement(node_id); + let parent = checker.semantic().parent_statement(node_id); + let edit = fix::edits::remove_unused_imports( + unused_aliases + .iter() + .map(|alias| &alias.name) + .map(ast::Identifier::as_str), + statement, + parent, + checker.locator(), + checker.stylist(), + checker.indexer(), + )?; + + let range = edit.range(); + let applicability = if checker.comment_ranges().intersects(range) { + Applicability::Unsafe + } else { + Applicability::Safe + }; + + Ok( + Fix::applicable_edit(edit, applicability).isolate(Checker::isolation( + checker.semantic().current_statement_parent_id(), + )), + ) + }); } - let mut diagnostic = checker.report_diagnostic( - UnnecessaryFutureImport { - names: unused_imports - .iter() - .map(|alias| alias.name.to_string()) - .sorted() - .collect(), - }, - stmt.range(), - ); - - diagnostic.try_set_fix(|| { - let statement = checker.semantic().current_statement(); - let parent = checker.semantic().current_statement_parent(); - let edit = fix::edits::remove_unused_imports( - unused_imports - .iter() - .map(|alias| &alias.name) - .map(ast::Identifier::as_str), - statement, - parent, - checker.locator(), - checker.stylist(), - checker.indexer(), - )?; - - let range = edit.range(); - let applicability = if checker.comment_ranges().intersects(range) { - Applicability::Unsafe - } else { - Applicability::Safe - }; - - Ok( - Fix::applicable_edit(edit, applicability).isolate(Checker::isolation( - checker.semantic().current_statement_parent_id(), - )), - ) - }); } diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010_0.py.snap similarity index 96% rename from crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010.py.snap rename to crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010_0.py.snap index 58c064522c19b..dc038f9c44c69 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010.py.snap +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010_0.py.snap @@ -2,7 +2,7 @@ source: crates/ruff_linter/src/rules/pyupgrade/mod.rs --- UP010 [*] Unnecessary `__future__` imports `generators`, `nested_scopes` for target Python version - --> UP010.py:1:1 + --> UP010_0.py:1:1 | 1 | from __future__ import nested_scopes, generators | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ help: Remove unnecessary `__future__` import 4 3 | from __future__ import generator_stop UP010 [*] Unnecessary `__future__` imports `unicode_literals`, `with_statement` for target Python version - --> UP010.py:2:1 + --> UP010_0.py:2:1 | 1 | from __future__ import nested_scopes, generators 2 | from __future__ import with_statement, unicode_literals @@ -36,7 +36,7 @@ help: Remove unnecessary `__future__` import 5 4 | from __future__ import print_function, generator_stop UP010 [*] Unnecessary `__future__` imports `absolute_import`, `division` for target Python version - --> UP010.py:3:1 + --> UP010_0.py:3:1 | 1 | from __future__ import nested_scopes, generators 2 | from __future__ import with_statement, unicode_literals @@ -56,7 +56,7 @@ help: Remove unnecessary `__future__` import 6 5 | from __future__ import invalid_module, generators UP010 [*] Unnecessary `__future__` import `generator_stop` for target Python version - --> UP010.py:4:1 + --> UP010_0.py:4:1 | 2 | from __future__ import with_statement, unicode_literals 3 | from __future__ import absolute_import, division @@ -77,7 +77,7 @@ help: Remove unnecessary `__future__` import 7 6 | UP010 [*] Unnecessary `__future__` imports `generator_stop`, `print_function` for target Python version - --> UP010.py:5:1 + --> UP010_0.py:5:1 | 3 | from __future__ import absolute_import, division 4 | from __future__ import generator_stop @@ -97,7 +97,7 @@ help: Remove unnecessary `__future__` import 8 7 | if True: UP010 [*] Unnecessary `__future__` import `generators` for target Python version - --> UP010.py:6:1 + --> UP010_0.py:6:1 | 4 | from __future__ import generator_stop 5 | from __future__ import print_function, generator_stop @@ -119,7 +119,7 @@ help: Remove unnecessary `__future__` import 9 9 | from __future__ import generator_stop UP010 [*] Unnecessary `__future__` import `generator_stop` for target Python version - --> UP010.py:9:5 + --> UP010_0.py:9:5 | 8 | if True: 9 | from __future__ import generator_stop @@ -138,7 +138,7 @@ help: Remove unnecessary `__future__` import 12 11 | if True: UP010 [*] Unnecessary `__future__` import `generators` for target Python version - --> UP010.py:10:5 + --> UP010_0.py:10:5 | 8 | if True: 9 | from __future__ import generator_stop @@ -159,7 +159,7 @@ help: Remove unnecessary `__future__` import 13 12 | from __future__ import generator_stop UP010 [*] Unnecessary `__future__` import `generator_stop` for target Python version - --> UP010.py:13:5 + --> UP010_0.py:13:5 | 12 | if True: 13 | from __future__ import generator_stop @@ -178,7 +178,7 @@ help: Remove unnecessary `__future__` import 15 14 | from __future__ import generators # comment UP010 [*] Unnecessary `__future__` import `generators` for target Python version - --> UP010.py:14:5 + --> UP010_0.py:14:5 | 12 | if True: 13 | from __future__ import generator_stop @@ -197,7 +197,7 @@ help: Remove unnecessary `__future__` import 15 15 | from __future__ import generators # comment UP010 [*] Unnecessary `__future__` import `generators` for target Python version - --> UP010.py:15:5 + --> UP010_0.py:15:5 | 13 | from __future__ import generator_stop 14 | from __future__ import invalid_module, generators diff --git a/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010_1.py.snap b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010_1.py.snap new file mode 100644 index 0000000000000..be0f0ce24dcff --- /dev/null +++ b/crates/ruff_linter/src/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP010_1.py.snap @@ -0,0 +1,99 @@ +--- +source: crates/ruff_linter/src/rules/pyupgrade/mod.rs +--- +UP010 [*] Unnecessary `__future__` imports `generators`, `nested_scopes` for target Python version + --> UP010_1.py:1:1 + | +1 | from __future__ import nested_scopes, generators + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 | from __future__ import with_statement, unicode_literals + | +help: Remove unnecessary `__future__` import + +ℹ Safe fix +1 |-from __future__ import nested_scopes, generators +2 1 | from __future__ import with_statement, unicode_literals +3 2 | +4 3 | from __future__ import absolute_import, division + +UP010 [*] Unnecessary `__future__` import `unicode_literals` for target Python version + --> UP010_1.py:2:1 + | +1 | from __future__ import nested_scopes, generators +2 | from __future__ import with_statement, unicode_literals + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +3 | +4 | from __future__ import absolute_import, division + | +help: Remove unnecessary `__future__` import + +ℹ Safe fix +1 1 | from __future__ import nested_scopes, generators +2 |-from __future__ import with_statement, unicode_literals + 2 |+from __future__ import with_statement +3 3 | +4 4 | from __future__ import absolute_import, division +5 5 | from __future__ import generator_stop + +UP010 [*] Unnecessary `__future__` import `absolute_import` for target Python version + --> UP010_1.py:4:1 + | +2 | from __future__ import with_statement, unicode_literals +3 | +4 | from __future__ import absolute_import, division + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +5 | from __future__ import generator_stop +6 | from __future__ import print_function, nested_scopes, generator_stop + | +help: Remove unnecessary `__future__` import + +ℹ Safe fix +1 1 | from __future__ import nested_scopes, generators +2 2 | from __future__ import with_statement, unicode_literals +3 3 | +4 |-from __future__ import absolute_import, division + 4 |+from __future__ import division +5 5 | from __future__ import generator_stop +6 6 | from __future__ import print_function, nested_scopes, generator_stop +7 7 | + +UP010 [*] Unnecessary `__future__` import `generator_stop` for target Python version + --> UP010_1.py:5:1 + | +4 | from __future__ import absolute_import, division +5 | from __future__ import generator_stop + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +6 | from __future__ import print_function, nested_scopes, generator_stop + | +help: Remove unnecessary `__future__` import + +ℹ Safe fix +2 2 | from __future__ import with_statement, unicode_literals +3 3 | +4 4 | from __future__ import absolute_import, division +5 |-from __future__ import generator_stop +6 5 | from __future__ import print_function, nested_scopes, generator_stop +7 6 | +8 7 | print(with_statement) + +UP010 [*] Unnecessary `__future__` import `nested_scopes` for target Python version + --> UP010_1.py:6:1 + | +4 | from __future__ import absolute_import, division +5 | from __future__ import generator_stop +6 | from __future__ import print_function, nested_scopes, generator_stop + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +7 | +8 | print(with_statement) + | +help: Remove unnecessary `__future__` import + +ℹ Safe fix +3 3 | +4 4 | from __future__ import absolute_import, division +5 5 | from __future__ import generator_stop +6 |-from __future__ import print_function, nested_scopes, generator_stop + 6 |+from __future__ import print_function, generator_stop +7 7 | +8 8 | print(with_statement) +9 9 | generators = 1 From 859475f017c3295ba2dbac144dcefdb2a2318250 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Wed, 20 Aug 2025 17:00:09 -0400 Subject: [PATCH 076/160] [ty] add docstrings to completions based on type (#20008) This is a fairly simple but effective way to add docstrings to like 95% of completions from initial experimentation. Fixes https://github.com/astral-sh/ty/issues/1036 Although ironically this approach *does not* work specifically for `print` and I haven't looked into why. --- crates/ty_ide/src/completion.rs | 34 +++++++++++++++---- crates/ty_ide/src/goto.rs | 22 ++++++++++++ .../src/server/api/requests/completion.rs | 9 +++-- crates/ty_wasm/src/lib.rs | 7 +++- playground/ty/src/Editor/Editor.tsx | 1 + 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/crates/ty_ide/src/completion.rs b/crates/ty_ide/src/completion.rs index dc7072dfd73a5..a52e0588b71a6 100644 --- a/crates/ty_ide/src/completion.rs +++ b/crates/ty_ide/src/completion.rs @@ -8,9 +8,11 @@ use ruff_text_size::{Ranged, TextRange, TextSize}; use ty_python_semantic::{Completion, NameKind, SemanticModel}; use crate::Db; +use crate::docstring::Docstring; use crate::find_node::covering_node; +use crate::goto::DefinitionsOrTargets; -pub fn completion(db: &dyn Db, file: File, offset: TextSize) -> Vec> { +pub fn completion(db: &dyn Db, file: File, offset: TextSize) -> Vec> { let parsed = parsed_module(db, file).load(db); let Some(target_token) = CompletionTargetTokens::find(&parsed, offset) else { @@ -40,6 +42,27 @@ pub fn completion(db: &dyn Db, file: File, offset: TextSize) -> Vec { + pub inner: Completion<'db>, + pub documentation: Option, +} +impl<'db> std::ops::Deref for DetailedCompletion<'db> { + type Target = Completion<'db>; + fn deref(&self) -> &Self::Target { + &self.inner + } } /// The kind of tokens identified under the cursor. @@ -478,9 +501,8 @@ fn compare_suggestions(c1: &Completion, c2: &Completion) -> Ordering { mod tests { use insta::assert_snapshot; use ruff_python_parser::{Mode, ParseOptions, TokenKind, Tokens}; - use ty_python_semantic::Completion; - use crate::completion; + use crate::completion::{DetailedCompletion, completion}; use crate::tests::{CursorTest, cursor_test}; use super::token_suffix_by_kinds; @@ -3022,14 +3044,14 @@ from os. ) } - fn completions_if(&self, predicate: impl Fn(&Completion) -> bool) -> String { + fn completions_if(&self, predicate: impl Fn(&DetailedCompletion) -> bool) -> String { self.completions_if_snapshot(predicate, |c| c.name.as_str().to_string()) } fn completions_if_snapshot( &self, - predicate: impl Fn(&Completion) -> bool, - snapshot: impl Fn(&Completion) -> String, + predicate: impl Fn(&DetailedCompletion) -> bool, + snapshot: impl Fn(&DetailedCompletion) -> String, ) -> String { let completions = completion(&self.db, self.cursor.file, self.cursor.offset); if completions.is_empty() { diff --git a/crates/ty_ide/src/goto.rs b/crates/ty_ide/src/goto.rs index 2047dce35ee34..52af38896b2c7 100644 --- a/crates/ty_ide/src/goto.rs +++ b/crates/ty_ide/src/goto.rs @@ -159,6 +159,28 @@ pub(crate) enum DefinitionsOrTargets<'db> { } impl<'db> DefinitionsOrTargets<'db> { + pub(crate) fn from_ty(db: &'db dyn crate::Db, ty: Type<'db>) -> Option { + let ty_def = ty.definition(db)?; + let resolved = match ty_def { + ty_python_semantic::types::TypeDefinition::Module(module) => { + ResolvedDefinition::Module(module.file(db)?) + } + ty_python_semantic::types::TypeDefinition::Class(definition) => { + ResolvedDefinition::Definition(definition) + } + ty_python_semantic::types::TypeDefinition::Function(definition) => { + ResolvedDefinition::Definition(definition) + } + ty_python_semantic::types::TypeDefinition::TypeVar(definition) => { + ResolvedDefinition::Definition(definition) + } + ty_python_semantic::types::TypeDefinition::TypeAlias(definition) => { + ResolvedDefinition::Definition(definition) + } + }; + Some(DefinitionsOrTargets::Definitions(vec![resolved])) + } + /// Get the "goto-declaration" interpretation of this definition /// /// In this case it basically returns exactly what was found. diff --git a/crates/ty_server/src/server/api/requests/completion.rs b/crates/ty_server/src/server/api/requests/completion.rs index 946a61e3f43ba..ee59532f9cb26 100644 --- a/crates/ty_server/src/server/api/requests/completion.rs +++ b/crates/ty_server/src/server/api/requests/completion.rs @@ -2,7 +2,9 @@ use std::borrow::Cow; use std::time::Instant; use lsp_types::request::Completion; -use lsp_types::{CompletionItem, CompletionItemKind, CompletionParams, CompletionResponse, Url}; +use lsp_types::{ + CompletionItem, CompletionItemKind, CompletionParams, CompletionResponse, Documentation, Url, +}; use ruff_db::source::{line_index, source_text}; use ty_ide::completion; use ty_project::ProjectDatabase; @@ -64,9 +66,12 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler { .map(|(i, comp)| { let kind = comp.kind(db).map(ty_kind_to_lsp_kind); CompletionItem { - label: comp.name.into(), + label: comp.inner.name.into(), kind, sort_text: Some(format!("{i:-max_index_len$}")), + documentation: comp + .documentation + .map(|docstring| Documentation::String(docstring.render_plaintext())), ..Default::default() } }) diff --git a/crates/ty_wasm/src/lib.rs b/crates/ty_wasm/src/lib.rs index 82fa82e4da1d9..ced09a516415f 100644 --- a/crates/ty_wasm/src/lib.rs +++ b/crates/ty_wasm/src/lib.rs @@ -421,7 +421,10 @@ impl Workspace { .into_iter() .map(|completion| Completion { kind: completion.kind(&self.db).map(CompletionKind::from), - name: completion.name.into(), + name: completion.inner.name.into(), + documentation: completion + .documentation + .map(|documentation| documentation.render_plaintext()), }) .collect()) } @@ -908,6 +911,8 @@ pub struct Completion { #[wasm_bindgen(getter_with_clone)] pub name: String, pub kind: Option, + #[wasm_bindgen(getter_with_clone)] + pub documentation: Option, } #[wasm_bindgen] diff --git a/playground/ty/src/Editor/Editor.tsx b/playground/ty/src/Editor/Editor.tsx index cc1020345fb9b..7fd9dbfcec68f 100644 --- a/playground/ty/src/Editor/Editor.tsx +++ b/playground/ty/src/Editor/Editor.tsx @@ -319,6 +319,7 @@ class PlaygroundServer ? CompletionItemKind.Variable : mapCompletionKind(completion.kind), insertText: completion.name, + documentation: completion.documentation, // TODO(micha): It's unclear why this field is required for monaco but not VS Code. // and omitting it works just fine? The LSP doesn't expose this information right now // which is why we go with undefined for now. From 99111961c05a92d2fac4f1b93e0b27eb391cf891 Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Thu, 21 Aug 2025 00:28:57 -0400 Subject: [PATCH 077/160] [ty] Add link for namespaces being partial (#20015) As requested --- .../resources/mdtest/import/partial_stub_packages.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md index b84faf4c8561f..a609c998b3e60 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md +++ b/crates/ty_python_semantic/resources/mdtest/import/partial_stub_packages.md @@ -426,7 +426,8 @@ reveal_type(Fake().fake) # revealed: Unknown ## Namespace stub with missing module -Namespace stubs are always partial. +Namespace stubs are always partial, as specified in: + This is a regression test for . From d43a3d34dda1c9d90114955ffb4dc8039c5ecfae Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Thu, 21 Aug 2025 11:43:11 +0530 Subject: [PATCH 078/160] [ty] Avoid unnecessary argument type expansion (#19999) ## Summary Part of: https://github.com/astral-sh/ty/issues/868 This PR adds a heuristic to avoid argument type expansion if it's going to eventually lead to no matching overload. This is done by checking whether the non-expandable argument types are assignable to the corresponding annotated parameter type. If one of them is not assignable to all of the remaining overloads, then argument type expansion isn't going to help. ## Test Plan Add mdtest that would otherwise take a long time because of the number of arguments that it would need to expand (30). --- .../resources/mdtest/call/overloads.md | 211 ++++++++++++++++++ .../src/types/call/arguments.rs | 24 +- .../ty_python_semantic/src/types/call/bind.rs | 43 ++++ 3 files changed, 277 insertions(+), 1 deletion(-) diff --git a/crates/ty_python_semantic/resources/mdtest/call/overloads.md b/crates/ty_python_semantic/resources/mdtest/call/overloads.md index ca447b6063e7e..d6fbf08b3a039 100644 --- a/crates/ty_python_semantic/resources/mdtest/call/overloads.md +++ b/crates/ty_python_semantic/resources/mdtest/call/overloads.md @@ -620,6 +620,217 @@ def _(ab: A | B, ac: A | C, cd: C | D): reveal_type(f(*(cd,))) # revealed: Unknown ``` +### Optimization: Avoid argument type expansion + +Argument type expansion could lead to exponential growth of the number of argument lists that needs +to be evaluated, so ty deploys some heuristics to prevent this from happening. + +Heuristic: If an argument type that cannot be expanded and cannot be assighned to any of the +remaining overloads before argument type expansion, then even with argument type expansion, it won't +lead to a successful evaluation of the call. + +`overloaded.pyi`: + +```pyi +from typing import overload + +class A: ... +class B: ... +class C: ... + +@overload +def f() -> None: ... +@overload +def f(**kwargs: int) -> C: ... +@overload +def f(x: A, /, **kwargs: int) -> A: ... +@overload +def f(x: B, /, **kwargs: int) -> B: ... + +class Foo: + @overload + def f(self) -> None: ... + @overload + def f(self, **kwargs: int) -> C: ... + @overload + def f(self, x: A, /, **kwargs: int) -> A: ... + @overload + def f(self, x: B, /, **kwargs: int) -> B: ... +``` + +```py +from overloaded import A, B, C, Foo, f +from typing_extensions import reveal_type + +def _(ab: A | B, a=1): + reveal_type(f(a1=a, a2=a, a3=a)) # revealed: C + reveal_type(f(A(), a1=a, a2=a, a3=a)) # revealed: A + reveal_type(f(B(), a1=a, a2=a, a3=a)) # revealed: B + + # Here, the arity check filters out the first and second overload, type checking fails on the + # remaining overloads, so ty moves on to argument type expansion. But, the first argument (`C`) + # isn't assignable to any of the remaining overloads (3 and 4), so there's no point in expanding + # the other 30 arguments of type `Unknown | Literal[1]` which would result in allocating a + # vector containing 2**30 argument lists after expanding all of the arguments. + reveal_type( + # error: [no-matching-overload] + # revealed: Unknown + f( + C(), + a1=a, + a2=a, + a3=a, + a4=a, + a5=a, + a6=a, + a7=a, + a8=a, + a9=a, + a10=a, + a11=a, + a12=a, + a13=a, + a14=a, + a15=a, + a16=a, + a17=a, + a18=a, + a19=a, + a20=a, + a21=a, + a22=a, + a23=a, + a24=a, + a25=a, + a26=a, + a27=a, + a28=a, + a29=a, + a30=a, + ) + ) + + # Here, the heuristics won't come into play because all arguments can be expanded but expanding + # the first argument resutls in a successful evaluation of the call, so there's no exponential + # growth of the number of argument lists. + reveal_type( + # revealed: A | B + f( + ab, + a1=a, + a2=a, + a3=a, + a4=a, + a5=a, + a6=a, + a7=a, + a8=a, + a9=a, + a10=a, + a11=a, + a12=a, + a13=a, + a14=a, + a15=a, + a16=a, + a17=a, + a18=a, + a19=a, + a20=a, + a21=a, + a22=a, + a23=a, + a24=a, + a25=a, + a26=a, + a27=a, + a28=a, + a29=a, + a30=a, + ) + ) + +def _(foo: Foo, ab: A | B, a=1): + reveal_type(foo.f(a1=a, a2=a, a3=a)) # revealed: C + reveal_type(foo.f(A(), a1=a, a2=a, a3=a)) # revealed: A + reveal_type(foo.f(B(), a1=a, a2=a, a3=a)) # revealed: B + + reveal_type( + # error: [no-matching-overload] + # revealed: Unknown + foo.f( + C(), + a1=a, + a2=a, + a3=a, + a4=a, + a5=a, + a6=a, + a7=a, + a8=a, + a9=a, + a10=a, + a11=a, + a12=a, + a13=a, + a14=a, + a15=a, + a16=a, + a17=a, + a18=a, + a19=a, + a20=a, + a21=a, + a22=a, + a23=a, + a24=a, + a25=a, + a26=a, + a27=a, + a28=a, + a29=a, + a30=a, + ) + ) + + reveal_type( + # revealed: A | B + foo.f( + ab, + a1=a, + a2=a, + a3=a, + a4=a, + a5=a, + a6=a, + a7=a, + a8=a, + a9=a, + a10=a, + a11=a, + a12=a, + a13=a, + a14=a, + a15=a, + a16=a, + a17=a, + a18=a, + a19=a, + a20=a, + a21=a, + a22=a, + a23=a, + a24=a, + a25=a, + a26=a, + a27=a, + a28=a, + a29=a, + a30=a, + ) + ) +``` + ## Filtering based on `Any` / `Unknown` This is the step 5 of the overload call evaluation algorithm which specifies that: diff --git a/crates/ty_python_semantic/src/types/call/arguments.rs b/crates/ty_python_semantic/src/types/call/arguments.rs index b200f3fc8af14..648b0cdab932a 100644 --- a/crates/ty_python_semantic/src/types/call/arguments.rs +++ b/crates/ty_python_semantic/src/types/call/arguments.rs @@ -5,7 +5,7 @@ use ruff_python_ast as ast; use crate::Db; use crate::types::KnownClass; -use crate::types::enums::enum_member_literals; +use crate::types::enums::{enum_member_literals, enum_metadata}; use crate::types::tuple::{Tuple, TupleLength, TupleType}; use super::Type; @@ -208,10 +208,32 @@ impl<'a, 'db> FromIterator<(Argument<'a>, Option>)> for CallArguments< } } +/// Returns `true` if the type can be expanded into its subtypes. +/// +/// In other words, it returns `true` if [`expand_type`] returns [`Some`] for the given type. +pub(crate) fn is_expandable_type<'db>(db: &'db dyn Db, ty: Type<'db>) -> bool { + match ty { + Type::NominalInstance(instance) => { + let class = instance.class(db); + class.is_known(db, KnownClass::Bool) + || instance.tuple_spec(db).is_some_and(|spec| match &*spec { + Tuple::Fixed(fixed_length_tuple) => fixed_length_tuple + .all_elements() + .any(|element| is_expandable_type(db, *element)), + Tuple::Variable(_) => false, + }) + || enum_metadata(db, class.class_literal(db).0).is_some() + } + Type::Union(_) => true, + _ => false, + } +} + /// Expands a type into its possible subtypes, if applicable. /// /// Returns [`None`] if the type cannot be expanded. fn expand_type<'db>(db: &'db dyn Db, ty: Type<'db>) -> Option>> { + // NOTE: Update `is_expandable_type` if this logic changes accordingly. match ty { Type::NominalInstance(instance) => { let class = instance.class(db); diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index d904e4c9ab455..da685d68ed909 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -16,6 +16,7 @@ use crate::Program; use crate::db::Db; use crate::dunder_all::dunder_all_names; use crate::place::{Boundness, Place}; +use crate::types::call::arguments::is_expandable_type; use crate::types::diagnostic::{ CALL_NON_CALLABLE, CONFLICTING_ARGUMENT_FORMS, INVALID_ARGUMENT_TYPE, MISSING_ARGUMENT, NO_MATCHING_OVERLOAD, PARAMETER_ALREADY_ASSIGNED, TOO_MANY_POSITIONAL_ARGUMENTS, @@ -1337,6 +1338,48 @@ impl<'db> CallableBinding<'db> { // for evaluating the expanded argument lists. snapshotter.restore(self, pre_evaluation_snapshot); + // At this point, there's at least one argument that can be expanded. + // + // This heuristic tries to detect if there's any need to perform argument type expansion or + // not by checking whether there are any non-expandable argument type that cannot be + // assigned to any of the remaining overloads. + // + // This heuristic needs to be applied after restoring the bindings state to the one before + // type checking as argument type expansion would evaluate it from that point on. + for (argument_index, (argument, argument_type)) in argument_types.iter().enumerate() { + // TODO: Remove `Keywords` once `**kwargs` support is added + if matches!(argument, Argument::Synthetic | Argument::Keywords) { + continue; + } + let Some(argument_type) = argument_type else { + continue; + }; + if is_expandable_type(db, argument_type) { + continue; + } + let mut is_argument_assignable_to_any_overload = false; + 'overload: for (_, overload) in self.matching_overloads() { + for parameter_index in &overload.argument_matches[argument_index].parameters { + let parameter_type = overload.signature.parameters()[*parameter_index] + .annotated_type() + .unwrap_or(Type::unknown()); + if argument_type.is_assignable_to(db, parameter_type) { + is_argument_assignable_to_any_overload = true; + break 'overload; + } + } + } + if !is_argument_assignable_to_any_overload { + tracing::debug!( + "Argument at {argument_index} (`{}`) is not assignable to any of the \ + remaining overloads, skipping argument type expansion", + argument_type.display(db) + ); + snapshotter.restore(self, post_evaluation_snapshot); + return; + } + } + for expanded_argument_lists in expansions { // This is the merged state of the bindings after evaluating all of the expanded // argument lists. This will be the final state to restore the bindings to if all of From a5cbca156ccba18900f95d5597db9ed2935a31d6 Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Thu, 21 Aug 2025 03:26:06 -0400 Subject: [PATCH 079/160] Fix rust feature activation (#20012) --- crates/ruff_diagnostics/Cargo.toml | 5 ++++- crates/ruff_source_file/Cargo.toml | 2 +- crates/ruff_workspace/Cargo.toml | 1 + crates/ty_project/Cargo.toml | 7 ++++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/crates/ruff_diagnostics/Cargo.toml b/crates/ruff_diagnostics/Cargo.toml index 810364a8441dc..b2241f7423c0b 100644 --- a/crates/ruff_diagnostics/Cargo.toml +++ b/crates/ruff_diagnostics/Cargo.toml @@ -14,8 +14,11 @@ license = { workspace = true } doctest = false [dependencies] -ruff_text_size = { workspace = true } +ruff_text_size = { workspace = true, features = ["get-size"] } get-size2 = { workspace = true } is-macro = { workspace = true } serde = { workspace = true, optional = true, features = [] } + +[features] +serde = ["dep:serde", "ruff_text_size/serde"] diff --git a/crates/ruff_source_file/Cargo.toml b/crates/ruff_source_file/Cargo.toml index ffc41ca462b74..33d28a449ee7a 100644 --- a/crates/ruff_source_file/Cargo.toml +++ b/crates/ruff_source_file/Cargo.toml @@ -22,7 +22,7 @@ serde = { workspace = true, optional = true } [dev-dependencies] [features] -get-size = ["dep:get-size2"] +get-size = ["dep:get-size2", "ruff_text_size/get-size"] serde = ["dep:serde", "ruff_text_size/serde"] [lints] diff --git a/crates/ruff_workspace/Cargo.toml b/crates/ruff_workspace/Cargo.toml index 7b075f0344fab..f3def3ee9b31d 100644 --- a/crates/ruff_workspace/Cargo.toml +++ b/crates/ruff_workspace/Cargo.toml @@ -64,6 +64,7 @@ default = [] schemars = [ "dep:schemars", "ruff_formatter/schemars", + "ruff_linter/schemars", "ruff_python_formatter/schemars", "ruff_python_semantic/schemars", ] diff --git a/crates/ty_project/Cargo.toml b/crates/ty_project/Cargo.toml index 29411de0d8824..6ccc1e494c0e6 100644 --- a/crates/ty_project/Cargo.toml +++ b/crates/ty_project/Cargo.toml @@ -51,7 +51,12 @@ insta = { workspace = true, features = ["redactions", "ron"] } [features] default = ["zstd"] deflate = ["ty_vendored/deflate"] -schemars = ["dep:schemars", "ruff_db/schemars", "ty_python_semantic/schemars"] +schemars = [ + "dep:schemars", + "ruff_db/schemars", + "ruff_python_ast/schemars", + "ty_python_semantic/schemars", +] zstd = ["ty_vendored/zstd"] format = ["ruff_python_formatter"] testing = [] From 045cba382ad4ba019146192d3124f99fe1deb752 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Thu, 21 Aug 2025 10:31:54 +0200 Subject: [PATCH 080/160] [ty] Use `dedent` in cursor tests (#20019) --- crates/ty_ide/src/document_symbols.rs | 14 +- crates/ty_ide/src/goto_declaration.rs | 322 ++++++++--------- crates/ty_ide/src/goto_references.rs | 4 +- crates/ty_ide/src/goto_type_definition.rs | 224 ++++++------ crates/ty_ide/src/hover.rs | 404 +++++++++++----------- crates/ty_ide/src/lib.rs | 5 +- crates/ty_ide/src/semantic_tokens.rs | 218 ++++++------ 7 files changed, 596 insertions(+), 595 deletions(-) diff --git a/crates/ty_ide/src/document_symbols.rs b/crates/ty_ide/src/document_symbols.rs index f3f1356f909c6..e9d5096c07047 100644 --- a/crates/ty_ide/src/document_symbols.rs +++ b/crates/ty_ide/src/document_symbols.rs @@ -198,7 +198,7 @@ def standalone_function(): 12 | typed_class_var: str = 'class_typed' 13 | annotated_class_var: float | ^^^^^^^^^^^^^^^^^^^ - 14 | + 14 | 15 | def __init__(self): | info: Field annotated_class_var @@ -207,7 +207,7 @@ def standalone_function(): --> main.py:15:9 | 13 | annotated_class_var: float - 14 | + 14 | 15 | def __init__(self): | ^^^^^^^^ 16 | self.instance_var = 0 @@ -218,7 +218,7 @@ def standalone_function(): --> main.py:18:9 | 16 | self.instance_var = 0 - 17 | + 17 | 18 | def public_method(self): | ^^^^^^^^^^^^^ 19 | return self.instance_var @@ -229,7 +229,7 @@ def standalone_function(): --> main.py:21:9 | 19 | return self.instance_var - 20 | + 20 | 21 | def _private_method(self): | ^^^^^^^^^^^^^^^ 22 | pass @@ -282,7 +282,7 @@ class OuterClass: 2 | class OuterClass: 3 | OUTER_CONSTANT = 100 | ^^^^^^^^^^^^^^ - 4 | + 4 | 5 | def outer_method(self): | info: Constant OUTER_CONSTANT @@ -291,7 +291,7 @@ class OuterClass: --> main.py:5:9 | 3 | OUTER_CONSTANT = 100 - 4 | + 4 | 5 | def outer_method(self): | ^^^^^^^^^^^^ 6 | return self.OUTER_CONSTANT @@ -302,7 +302,7 @@ class OuterClass: --> main.py:8:11 | 6 | return self.OUTER_CONSTANT - 7 | + 7 | 8 | class InnerClass: | ^^^^^^^^^^ 9 | def inner_method(self): diff --git a/crates/ty_ide/src/goto_declaration.rs b/crates/ty_ide/src/goto_declaration.rs index 52025ac6e248d..cdb2cd31edf4c 100644 --- a/crates/ty_ide/src/goto_declaration.rs +++ b/crates/ty_ide/src/goto_declaration.rs @@ -53,19 +53,19 @@ mod tests { assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:2:17 + --> main.py:2:5 | - 2 | def my_function(x, y): - | ^^^^^^^^^^^ - 3 | return x + y + 2 | def my_function(x, y): + | ^^^^^^^^^^^ + 3 | return x + y | info: Source - --> main.py:5:22 + --> main.py:5:10 | - 3 | return x + y + 3 | return x + y 4 | - 5 | result = my_function(1, 2) - | ^^^^^^^^^^^ + 5 | result = my_function(1, 2) + | ^^^^^^^^^^^ | "); } @@ -81,18 +81,18 @@ mod tests { assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:2:13 + --> main.py:2:1 | - 2 | x = 42 - | ^ - 3 | y = x + 2 | x = 42 + | ^ + 3 | y = x | info: Source - --> main.py:3:17 + --> main.py:3:5 | - 2 | x = 42 - 3 | y = x - | ^ + 2 | x = 42 + 3 | y = x + | ^ | "); } @@ -111,20 +111,20 @@ mod tests { assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:2:19 + --> main.py:2:7 | - 2 | class MyClass: - | ^^^^^^^ - 3 | def __init__(self): - 4 | pass + 2 | class MyClass: + | ^^^^^^^ + 3 | def __init__(self): + 4 | pass | info: Source - --> main.py:6:24 + --> main.py:6:12 | - 4 | pass + 4 | pass 5 | - 6 | instance = MyClass() - | ^^^^^^^ + 6 | instance = MyClass() + | ^^^^^^^ | "); } @@ -140,18 +140,18 @@ mod tests { assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:2:21 + --> main.py:2:9 | - 2 | def foo(param): - | ^^^^^ - 3 | return param * 2 + 2 | def foo(param): + | ^^^^^ + 3 | return param * 2 | info: Source - --> main.py:3:24 + --> main.py:3:12 | - 2 | def foo(param): - 3 | return param * 2 - | ^^^^^ + 2 | def foo(param): + 3 | return param * 2 + | ^^^^^ | "); } @@ -168,20 +168,20 @@ mod tests { assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:2:30 + --> main.py:2:18 | - 2 | def generic_func[T](value: T) -> T: - | ^ - 3 | v: T = value - 4 | return v + 2 | def generic_func[T](value: T) -> T: + | ^ + 3 | v: T = value + 4 | return v | info: Source - --> main.py:3:20 + --> main.py:3:8 | - 2 | def generic_func[T](value: T) -> T: - 3 | v: T = value - | ^ - 4 | return v + 2 | def generic_func[T](value: T) -> T: + 3 | v: T = value + | ^ + 4 | return v | "); } @@ -198,20 +198,20 @@ mod tests { assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:2:32 + --> main.py:2:20 | - 2 | class GenericClass[T]: - | ^ - 3 | def __init__(self, value: T): - 4 | self.value = value + 2 | class GenericClass[T]: + | ^ + 3 | def __init__(self, value: T): + 4 | self.value = value | info: Source - --> main.py:3:43 + --> main.py:3:31 | - 2 | class GenericClass[T]: - 3 | def __init__(self, value: T): - | ^ - 4 | self.value = value + 2 | class GenericClass[T]: + 3 | def __init__(self, value: T): + | ^ + 4 | self.value = value | "); } @@ -230,21 +230,21 @@ mod tests { assert_snapshot!(test.goto_declaration(), @r#" info[goto-declaration]: Declaration - --> main.py:2:13 + --> main.py:2:1 | - 2 | x = "outer" - | ^ - 3 | def outer_func(): - 4 | def inner_func(): + 2 | x = "outer" + | ^ + 3 | def outer_func(): + 4 | def inner_func(): | info: Source - --> main.py:5:28 + --> main.py:5:16 | - 3 | def outer_func(): - 4 | def inner_func(): - 5 | return x # Should find outer x - | ^ - 6 | return inner_func + 3 | def outer_func(): + 4 | def inner_func(): + 5 | return x # Should find outer x + | ^ + 6 | return inner_func | "#); } @@ -852,21 +852,21 @@ def another_helper(path): assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:4:21 + --> main.py:4:9 | - 2 | class C: - 3 | def __init__(self): - 4 | self.x: int = 1 - | ^^^^^^ + 2 | class C: + 3 | def __init__(self): + 4 | self.x: int = 1 + | ^^^^^^ 5 | - 6 | c = C() + 6 | c = C() | info: Source - --> main.py:7:19 + --> main.py:7:7 | - 6 | c = C() - 7 | y = c.x - | ^ + 6 | c = C() + 7 | y = c.x + | ^ | "); } @@ -890,21 +890,21 @@ def another_helper(path): assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:4:21 + --> main.py:4:9 | - 2 | class C: - 3 | def __init__(self): - 4 | self.x: int = 1 - | ^^^^^^ + 2 | class C: + 3 | def __init__(self): + 4 | self.x: int = 1 + | ^^^^^^ 5 | - 6 | class D: + 6 | class D: | info: Source - --> main.py:11:21 + --> main.py:11:9 | - 10 | d = D() - 11 | y = d.y.x - | ^ + 10 | d = D() + 11 | y = d.y.x + | ^ | "); } @@ -924,21 +924,21 @@ def another_helper(path): assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:4:21 + --> main.py:4:9 | - 2 | class C: - 3 | def __init__(self): - 4 | self.x = 1 - | ^^^^^^ + 2 | class C: + 3 | def __init__(self): + 4 | self.x = 1 + | ^^^^^^ 5 | - 6 | c = C() + 6 | c = C() | info: Source - --> main.py:7:19 + --> main.py:7:7 | - 6 | c = C() - 7 | y = c.x - | ^ + 6 | c = C() + 7 | y = c.x + | ^ | "); } @@ -958,19 +958,19 @@ def another_helper(path): assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:3:21 + --> main.py:3:9 | - 2 | class C: - 3 | def foo(self): - | ^^^ - 4 | return 42 + 2 | class C: + 3 | def foo(self): + | ^^^ + 4 | return 42 | info: Source - --> main.py:7:21 + --> main.py:7:9 | - 6 | c = C() - 7 | res = c.foo() - | ^^^ + 6 | c = C() + 7 | res = c.foo() + | ^^^ | "); } @@ -1036,7 +1036,7 @@ def outer(): 2 | def outer(): 3 | x = "outer_value" | ^ - 4 | + 4 | 5 | def inner(): | info: Source @@ -1046,7 +1046,7 @@ def outer(): 7 | x = "modified" 8 | return x # Should find the nonlocal x declaration in outer scope | ^ - 9 | + 9 | 10 | return inner | "#); @@ -1103,20 +1103,20 @@ def function(): assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:3:17 + --> main.py:3:5 | - 2 | class A: - 3 | x = 10 - | ^ + 2 | class A: + 3 | x = 10 + | ^ 4 | - 5 | class B(A): + 5 | class B(A): | info: Source - --> main.py:9:19 + --> main.py:9:7 | - 8 | b = B() - 9 | y = b.x - | ^ + 8 | b = B() + 9 | y = b.x + | ^ | "); } @@ -1140,19 +1140,19 @@ def function(): assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:7:21 + --> main.py:7:9 | - 6 | @property - 7 | def value(self): - | ^^^^^ - 8 | return self._value + 6 | @property + 7 | def value(self): + | ^^^^^ + 8 | return self._value | info: Source - --> main.py:11:15 + --> main.py:11:3 | - 10 | c = C() - 11 | c.value = 42 - | ^^^^^ + 10 | c = C() + 11 | c.value = 42 + | ^^^^^ | "); } @@ -1213,21 +1213,21 @@ def function(): assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:6:17 + --> main.py:6:5 | - 4 | class Drawable(Protocol): - 5 | def draw(self) -> None: ... - 6 | name: str - | ^^^^ + 4 | class Drawable(Protocol): + 5 | def draw(self) -> None: ... + 6 | name: str + | ^^^^ 7 | - 8 | def use_drawable(obj: Drawable): + 8 | def use_drawable(obj: Drawable): | info: Source - --> main.py:9:21 + --> main.py:9:9 | - 8 | def use_drawable(obj: Drawable): - 9 | obj.name - | ^^^^ + 8 | def use_drawable(obj: Drawable): + 9 | obj.name + | ^^^^ | "); } @@ -1252,14 +1252,14 @@ class MyClass: 2 | class MyClass: 3 | ClassType = int | ^^^^^^^^^ - 4 | + 4 | 5 | def generic_method[T](self, value: ClassType) -> T: | info: Source --> main.py:5:40 | 3 | ClassType = int - 4 | + 4 | 5 | def generic_method[T](self, value: ClassType) -> T: | ^^^^^^^^^ 6 | return value @@ -1280,19 +1280,19 @@ class MyClass: assert_snapshot!(test.goto_declaration(), @r" info[goto-declaration]: Declaration - --> main.py:2:32 + --> main.py:2:20 | - 2 | def my_function(x, y, z=10): - | ^ - 3 | return x + y + z + 2 | def my_function(x, y, z=10): + | ^ + 3 | return x + y + z | info: Source - --> main.py:5:37 + --> main.py:5:25 | - 3 | return x + y + z + 3 | return x + y + z 4 | - 5 | result = my_function(1, y=2, z=3) - | ^ + 5 | result = my_function(1, y=2, z=3) + | ^ | "); } @@ -1320,37 +1320,37 @@ class MyClass: // Should navigate to the parameter in both matching overloads assert_snapshot!(test.goto_declaration(), @r#" info[goto-declaration]: Declaration - --> main.py:5:36 + --> main.py:5:24 | - 4 | @overload - 5 | def process(data: str, format: str) -> str: ... - | ^^^^^^ + 4 | @overload + 5 | def process(data: str, format: str) -> str: ... + | ^^^^^^ 6 | - 7 | @overload + 7 | @overload | info: Source - --> main.py:14:39 + --> main.py:14:27 | - 13 | # Call the overloaded function - 14 | result = process("hello", format="json") - | ^^^^^^ + 13 | # Call the overloaded function + 14 | result = process("hello", format="json") + | ^^^^^^ | info[goto-declaration]: Declaration - --> main.py:8:36 + --> main.py:8:24 | - 7 | @overload - 8 | def process(data: int, format: int) -> int: ... - | ^^^^^^ + 7 | @overload + 8 | def process(data: int, format: int) -> int: ... + | ^^^^^^ 9 | - 10 | def process(data, format): + 10 | def process(data, format): | info: Source - --> main.py:14:39 + --> main.py:14:27 | - 13 | # Call the overloaded function - 14 | result = process("hello", format="json") - | ^^^^^^ + 13 | # Call the overloaded function + 14 | result = process("hello", format="json") + | ^^^^^^ | "#); } diff --git a/crates/ty_ide/src/goto_references.rs b/crates/ty_ide/src/goto_references.rs index 7860cfb169548..067ee19ad7ab5 100644 --- a/crates/ty_ide/src/goto_references.rs +++ b/crates/ty_ide/src/goto_references.rs @@ -786,7 +786,7 @@ class DataProcessor: 5 | def __init__(self): 6 | self.multiplier = func | ^^^^ - 7 | + 7 | 8 | def process(self, value): | @@ -834,7 +834,7 @@ def process_model(): 2 | class MyModel: 3 | attr = 42 | ^^^^ - 4 | + 4 | 5 | def get_attribute(self): | diff --git a/crates/ty_ide/src/goto_type_definition.rs b/crates/ty_ide/src/goto_type_definition.rs index 4d8f06f354577..4e9a3af4d7313 100644 --- a/crates/ty_ide/src/goto_type_definition.rs +++ b/crates/ty_ide/src/goto_type_definition.rs @@ -50,20 +50,20 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r" info[goto-type-definition]: Type definition - --> main.py:2:19 + --> main.py:2:7 | - 2 | class Test: ... - | ^^^^ + 2 | class Test: ... + | ^^^^ 3 | - 4 | ab = Test() + 4 | ab = Test() | info: Source - --> main.py:4:13 + --> main.py:4:1 | - 2 | class Test: ... + 2 | class Test: ... 3 | - 4 | ab = Test() - | ^^ + 4 | ab = Test() + | ^^ | "); } @@ -82,20 +82,20 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r" info[goto-type-definition]: Type definition - --> main.py:2:17 + --> main.py:2:5 | - 2 | def foo(a, b): ... - | ^^^ + 2 | def foo(a, b): ... + | ^^^ 3 | - 4 | ab = foo + 4 | ab = foo | info: Source - --> main.py:6:13 + --> main.py:6:1 | - 4 | ab = foo + 4 | ab = foo 5 | - 6 | ab - | ^^ + 6 | ab + | ^^ | "); } @@ -120,39 +120,39 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r" info[goto-type-definition]: Type definition - --> main.py:3:17 + --> main.py:3:5 | - 3 | def foo(a, b): ... - | ^^^ + 3 | def foo(a, b): ... + | ^^^ 4 | - 5 | def bar(a, b): ... + 5 | def bar(a, b): ... | info: Source - --> main.py:12:13 + --> main.py:12:1 | - 10 | a = bar + 10 | a = bar 11 | - 12 | a - | ^ + 12 | a + | ^ | info[goto-type-definition]: Type definition - --> main.py:5:17 + --> main.py:5:5 | - 3 | def foo(a, b): ... + 3 | def foo(a, b): ... 4 | - 5 | def bar(a, b): ... - | ^^^ + 5 | def bar(a, b): ... + | ^^^ 6 | - 7 | if random.choice(): + 7 | if random.choice(): | info: Source - --> main.py:12:13 + --> main.py:12:1 | - 10 | a = bar + 10 | a = bar 11 | - 12 | a - | ^ + 12 | a + | ^ | "); } @@ -177,12 +177,12 @@ mod tests { | ^^^^^^ | info: Source - --> main.py:4:13 + --> main.py:4:1 | - 2 | import lib + 2 | import lib 3 | - 4 | lib - | ^^^ + 4 | lib + | ^^^ | "); } @@ -197,7 +197,7 @@ mod tests { "#, ); - assert_snapshot!(test.goto_type_definition(), @r###" + assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition --> stdlib/builtins.pyi:901:7 | @@ -209,14 +209,14 @@ mod tests { 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source - --> main.py:4:13 + --> main.py:4:1 | - 2 | a: str = "test" + 2 | a: str = "test" 3 | - 4 | a - | ^ + 4 | a + | ^ | - "###); + "#); } #[test] fn goto_type_of_expression_with_literal_node() { @@ -226,7 +226,7 @@ mod tests { "#, ); - assert_snapshot!(test.goto_type_definition(), @r###" + assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition --> stdlib/builtins.pyi:901:7 | @@ -238,12 +238,12 @@ mod tests { 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source - --> main.py:2:22 + --> main.py:2:10 | - 2 | a: str = "test" - | ^^^^^^ + 2 | a: str = "test" + | ^^^^^^ | - "###); + "#); } #[test] @@ -256,16 +256,16 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r" info[goto-type-definition]: Type definition - --> main.py:2:24 + --> main.py:2:12 | - 2 | type Alias[T: int = bool] = list[T] - | ^ + 2 | type Alias[T: int = bool] = list[T] + | ^ | info: Source - --> main.py:2:46 + --> main.py:2:34 | - 2 | type Alias[T: int = bool] = list[T] - | ^ + 2 | type Alias[T: int = bool] = list[T] + | ^ | "); } @@ -312,22 +312,22 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> main.py:4:13 + --> main.py:4:1 | - 2 | from typing_extensions import TypeAliasType + 2 | from typing_extensions import TypeAliasType 3 | - 4 | Alias = TypeAliasType("Alias", tuple[int, int]) - | ^^^^^ + 4 | Alias = TypeAliasType("Alias", tuple[int, int]) + | ^^^^^ 5 | - 6 | Alias + 6 | Alias | info: Source - --> main.py:6:13 + --> main.py:6:1 | - 4 | Alias = TypeAliasType("Alias", tuple[int, int]) + 4 | Alias = TypeAliasType("Alias", tuple[int, int]) 5 | - 6 | Alias - | ^^^^^ + 6 | Alias + | ^^^^^ | "#); } @@ -342,7 +342,7 @@ mod tests { "#, ); - assert_snapshot!(test.goto_type_definition(), @r###" + assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition --> stdlib/builtins.pyi:901:7 | @@ -354,14 +354,14 @@ mod tests { 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source - --> main.py:4:18 + --> main.py:4:6 | - 2 | def test(a: str): ... + 2 | def test(a: str): ... 3 | - 4 | test(a= "123") - | ^ + 4 | test(a= "123") + | ^ | - "###); + "#); } #[test] @@ -389,12 +389,12 @@ mod tests { 339 | int(x, base=10) -> integer | info: Source - --> main.py:4:18 + --> main.py:4:6 | - 2 | def test(a: str): ... + 2 | def test(a: str): ... 3 | - 4 | test(a= 123) - | ^ + 4 | test(a= 123) + | ^ | "#); } @@ -442,7 +442,7 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r###" + assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition --> stdlib/builtins.pyi:901:7 | @@ -454,13 +454,13 @@ f(**kwargs) 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source - --> main.py:3:17 + --> main.py:3:5 | - 2 | def foo(a: str): - 3 | a - | ^ + 2 | def foo(a: str): + 3 | a + | ^ | - "###); + "#); } #[test] @@ -478,19 +478,19 @@ f(**kwargs) assert_snapshot!(test.goto_type_definition(), @r" info[goto-type-definition]: Type definition - --> main.py:2:19 + --> main.py:2:7 | - 2 | class X: - | ^ - 3 | def foo(a, b): ... + 2 | class X: + | ^ + 3 | def foo(a, b): ... | info: Source - --> main.py:7:13 + --> main.py:7:1 | - 5 | x = X() + 5 | x = X() 6 | - 7 | x.foo() - | ^ + 7 | x.foo() + | ^ | "); } @@ -507,20 +507,20 @@ f(**kwargs) assert_snapshot!(test.goto_type_definition(), @r" info[goto-type-definition]: Type definition - --> main.py:2:17 + --> main.py:2:5 | - 2 | def foo(a, b): ... - | ^^^ + 2 | def foo(a, b): ... + | ^^^ 3 | - 4 | foo() + 4 | foo() | info: Source - --> main.py:4:13 + --> main.py:4:1 | - 2 | def foo(a, b): ... + 2 | def foo(a, b): ... 3 | - 4 | foo() - | ^^^ + 4 | foo() + | ^^^ | "); } @@ -535,7 +535,7 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r###" + assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition --> stdlib/builtins.pyi:901:7 | @@ -547,14 +547,14 @@ f(**kwargs) 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source - --> main.py:4:27 + --> main.py:4:15 | - 2 | def foo(a: str | None, b): - 3 | if a is not None: - 4 | print(a) - | ^ + 2 | def foo(a: str | None, b): + 3 | if a is not None: + 4 | print(a) + | ^ | - "###); + "#); } #[test] @@ -566,7 +566,7 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r###" + assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition --> stdlib/types.pyi:922:11 | @@ -577,11 +577,11 @@ f(**kwargs) 923 | """The type of the None singleton.""" | info: Source - --> main.py:3:17 + --> main.py:3:5 | - 2 | def foo(a: str | None, b): - 3 | a - | ^ + 2 | def foo(a: str | None, b): + 3 | a + | ^ | info[goto-type-definition]: Type definition @@ -595,13 +595,13 @@ f(**kwargs) 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source - --> main.py:3:17 + --> main.py:3:5 | - 2 | def foo(a: str | None, b): - 3 | a - | ^ + 2 | def foo(a: str | None, b): + 3 | a + | ^ | - "###); + "#); } impl CursorTest { diff --git a/crates/ty_ide/src/hover.rs b/crates/ty_ide/src/hover.rs index 5480d73b5403f..90b64d911e117 100644 --- a/crates/ty_ide/src/hover.rs +++ b/crates/ty_ide/src/hover.rs @@ -174,14 +174,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:4:9 + --> main.py:4:1 | - 2 | a = 10 + 2 | a = 10 3 | - 4 | a - | ^- Cursor offset - | | - | source + 4 | a + | ^- Cursor offset + | | + | source | "); } @@ -233,15 +233,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:11:9 + --> main.py:11:1 | - 9 | return 0 + 9 | return 0 10 | - 11 | my_func(1, 2) - | ^^^^^-^ - | | | - | | Cursor offset - | source + 11 | my_func(1, 2) + | ^^^^^-^ + | | | + | | Cursor offset + | source | "); } @@ -291,14 +291,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:13 + --> main.py:2:5 | - 2 | def my_func(a, b): - | ^^^^^-^ - | | | - | | Cursor offset - | source - 3 | '''This is such a great func!! + 2 | def my_func(a, b): + | ^^^^^-^ + | | | + | | Cursor offset + | source + 3 | '''This is such a great func!! | "); } @@ -357,15 +357,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:24:9 + --> main.py:24:1 | - 22 | return 0 + 22 | return 0 23 | - 24 | MyClass - | ^^^^^-^ - | | | - | | Cursor offset - | source + 24 | MyClass + | ^^^^^-^ + | | | + | | Cursor offset + | source | "); } @@ -422,15 +422,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:15 + --> main.py:2:7 | - 2 | class MyClass: - | ^^^^^-^ - | | | - | | Cursor offset - | source - 3 | ''' - 4 | This is such a great class!! + 2 | class MyClass: + | ^^^^^-^ + | | | + | | Cursor offset + | source + 3 | ''' + 4 | This is such a great class!! | "); } @@ -489,15 +489,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:24:13 + --> main.py:24:5 | - 22 | return 0 + 22 | return 0 23 | - 24 | x = MyClass(0) - | ^^^^^-^ - | | | - | | Cursor offset - | source + 24 | x = MyClass(0) + | ^^^^^-^ + | | | + | | Cursor offset + | source | "); } @@ -563,14 +563,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:25:11 + --> main.py:25:3 | - 24 | x = MyClass(0) - 25 | x.my_method(2, 3) - | ^^^^^-^^^ - | | | - | | Cursor offset - | source + 24 | x = MyClass(0) + 25 | x.my_method(2, 3) + | ^^^^^-^^^ + | | | + | | Cursor offset + | source | "); } @@ -599,14 +599,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:10:13 + --> main.py:10:5 | - 9 | foo = Foo() - 10 | foo.a - | - - | | - | source - | Cursor offset + 9 | foo = Foo() + 10 | foo.a + | - + | | + | source + | Cursor offset | "); } @@ -635,14 +635,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:4:13 + --> main.py:4:1 | - 2 | def foo(a, b): ... + 2 | def foo(a, b): ... 3 | - 4 | foo - | ^^^- Cursor offset - | | - | source + 4 | foo + | ^^^- Cursor offset + | | + | source | "); } @@ -664,14 +664,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:3:17 + --> main.py:3:5 | - 2 | def foo(a: int, b: int, c: int): - 3 | a + b == c - | ^^^^^^^^-^ - | | | - | | Cursor offset - | source + 2 | def foo(a: int, b: int, c: int): + 3 | a + b == c + | ^^^^^^^^-^ + | | | + | | Cursor offset + | source | "); } @@ -701,15 +701,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:10:18 + --> main.py:10:6 | - 8 | return 0 + 8 | return 0 9 | - 10 | test(ab= 123) - | ^- - | || - | |Cursor offset - | source + 10 | test(ab= 123) + | ^- + | || + | |Cursor offset + | source | "); } @@ -736,14 +736,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:22 + --> main.py:2:10 | - 2 | def test(ab: int): - | ^- - | || - | |Cursor offset - | source - 3 | """my cool test + 2 | def test(ab: int): + | ^- + | || + | |Cursor offset + | source + 3 | """my cool test | "#); } @@ -778,14 +778,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:16:13 + --> main.py:16:1 | - 14 | a = bar + 14 | a = bar 15 | - 16 | a - | ^- Cursor offset - | | - | source + 16 | a + | ^- Cursor offset + | | + | source | "); } @@ -845,14 +845,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:19:13 + --> main.py:19:1 | - 17 | a = "hello" + 17 | a = "hello" 18 | - 19 | foo(a, 2) - | ^^^- Cursor offset - | | - | source + 19 | foo(a, 2) + | ^^^- Cursor offset + | | + | source | "#); } @@ -900,14 +900,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:19:13 + --> main.py:19:1 | - 17 | a = "hello" + 17 | a = "hello" 18 | - 19 | foo(a) - | ^^^- Cursor offset - | | - | source + 19 | foo(a) + | ^^^- Cursor offset + | | + | source | "#); } @@ -955,15 +955,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:4:13 + --> main.py:4:1 | - 2 | import lib + 2 | import lib 3 | - 4 | lib - | ^^- - | | | - | | Cursor offset - | source + 4 | lib + | ^^- + | | | + | | Cursor offset + | source | "); } @@ -1005,15 +1005,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:20 + --> main.py:2:8 | - 2 | import lib - | ^^- - | | | - | | Cursor offset - | source + 2 | import lib + | ^^- + | | | + | | Cursor offset + | source 3 | - 4 | lib + 4 | lib | "); } @@ -1027,7 +1027,7 @@ mod tests { ); // TODO: This should render T@Alias once we create GenericContexts for type alias scopes. - assert_snapshot!(test.hover(), @r###" + assert_snapshot!(test.hover(), @r" typing.TypeVar --------------------------------------------- ```python @@ -1035,14 +1035,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:46 + --> main.py:2:34 | - 2 | type Alias[T: int = bool] = list[T] - | ^- Cursor offset - | | - | source + 2 | type Alias[T: int = bool] = list[T] + | ^- Cursor offset + | | + | source | - "###); + "); } #[test] @@ -1061,12 +1061,12 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:53 + --> main.py:2:41 | - 2 | type Alias[**P = [int, str]] = Callable[P, int] - | ^- Cursor offset - | | - | source + 2 | type Alias[**P = [int, str]] = Callable[P, int] + | ^- Cursor offset + | | + | source | "); } @@ -1087,12 +1087,12 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:43 + --> main.py:2:31 | - 2 | type Alias[*Ts = ()] = tuple[*Ts] - | ^^- Cursor offset - | | - | source + 2 | type Alias[*Ts = ()] = tuple[*Ts] + | ^^- Cursor offset + | | + | source | "); } @@ -1113,12 +1113,12 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:2:13 + --> main.py:2:1 | - 2 | value = 1 - | ^^^^^- Cursor offset - | | - | source + 2 | value = 1 + | ^^^^^- Cursor offset + | | + | source | "); } @@ -1144,13 +1144,13 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:3:13 + --> main.py:3:1 | - 2 | value = 1 - 3 | value += 2 - | ^^^^^- Cursor offset - | | - | source + 2 | value = 1 + 3 | value += 2 + | ^^^^^- Cursor offset + | | + | source | "); } @@ -1174,14 +1174,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:5:15 + --> main.py:5:3 | - 3 | attr: int = 1 + 3 | attr: int = 1 4 | - 5 | C.attr = 2 - | ^^^^- Cursor offset - | | - | source + 5 | C.attr = 2 + | ^^^^- Cursor offset + | | + | source | "); } @@ -1207,14 +1207,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:5:15 + --> main.py:5:3 | - 3 | attr = 1 + 3 | attr = 1 4 | - 5 | C.attr += 2 - | ^^^^- Cursor offset - | | - | source + 5 | C.attr += 2 + | ^^^^- Cursor offset + | | + | source | "); } @@ -1236,13 +1236,13 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:3:13 + --> main.py:3:5 | - 2 | class Foo: - 3 | a: int - | ^- Cursor offset - | | - | source + 2 | class Foo: + 3 | a: int + | ^- Cursor offset + | | + | source | "); } @@ -1264,13 +1264,13 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:3:13 + --> main.py:3:5 | - 2 | class Foo: - 3 | a: int = 1 - | ^- Cursor offset - | | - | source + 2 | class Foo: + 3 | a: int = 1 + | ^- Cursor offset + | | + | source | "); } @@ -1293,14 +1293,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:4:22 + --> main.py:4:14 | - 2 | class Foo: - 3 | def __init__(self, a: int): - 4 | self.a: int = a - | ^- Cursor offset - | | - | source + 2 | class Foo: + 3 | def __init__(self, a: int): + 4 | self.a: int = a + | ^- Cursor offset + | | + | source | "); } @@ -1329,14 +1329,14 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:10:27 + --> main.py:10:15 | - 8 | ''' - 9 | if a is not None: - 10 | print(a) - | ^- Cursor offset - | | - | source + 8 | ''' + 9 | if a is not None: + 10 | print(a) + | ^- Cursor offset + | | + | source | "); } @@ -1407,15 +1407,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:5:9 + --> main.py:5:1 | - 3 | def ab(x: int, y: Callable[[int, int], Any], z: List[int]) -> int: ... + 3 | def ab(x: int, y: Callable[[int, int], Any], z: List[int]) -> int: ... 4 | - 5 | ab - | ^- - | || - | |Cursor offset - | source + 5 | ab + | ^- + | || + | |Cursor offset + | source | "); } @@ -1439,15 +1439,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:5:9 + --> main.py:5:1 | - 3 | ab: Tuple[Any, int, Callable[[int, int], Any]] = ... + 3 | ab: Tuple[Any, int, Callable[[int, int], Any]] = ... 4 | - 5 | ab - | ^- - | || - | |Cursor offset - | source + 5 | ab + | ^- + | || + | |Cursor offset + | source | "); } @@ -1471,15 +1471,15 @@ mod tests { ``` --------------------------------------------- info[hover]: Hovered content is - --> main.py:5:9 + --> main.py:5:1 | - 3 | ab: Callable[[int, int], Any] | None = ... + 3 | ab: Callable[[int, int], Any] | None = ... 4 | - 5 | ab - | ^- - | || - | |Cursor offset - | source + 5 | ab + | ^- + | || + | |Cursor offset + | source | "); } diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index 55e4a920f84a1..9395fb7533011 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -287,6 +287,7 @@ mod tests { use ruff_db::diagnostic::{Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig}; use ruff_db::files::{File, system_path_to_file}; use ruff_db::system::{DbWithWritableSystem, SystemPath, SystemPathBuf}; + use ruff_python_trivia::textwrap::dedent; use ruff_text_size::TextSize; use ty_project::ProjectMetadata; use ty_python_semantic::{ @@ -417,12 +418,12 @@ mod tests { pub(super) fn source( &mut self, path: impl Into, - contents: impl Into, + contents: impl AsRef, ) -> &mut CursorTestBuilder { const MARKER: &str = ""; let path = path.into(); - let contents = contents.into(); + let contents = dedent(contents.as_ref()).into_owned(); let Some(cursor_offset) = contents.find(MARKER) else { self.sources.push(Source { path, diff --git a/crates/ty_ide/src/semantic_tokens.rs b/crates/ty_ide/src/semantic_tokens.rs index 749671ad1813c..9b70b32e60223 100644 --- a/crates/ty_ide/src/semantic_tokens.rs +++ b/crates/ty_ide/src/semantic_tokens.rs @@ -1405,34 +1405,34 @@ u = List.__name__ # __name__ should be variable "MyClass" @ 89..96: Class [definition] "CONSTANT" @ 102..110: Variable [readonly] "42" @ 113..115: Number - "method" @ 129..135: Method [definition] - "self" @ 136..140: SelfParameter - "/"hello/"" @ 158..165: String - "property" @ 176..184: Decorator - "prop" @ 193..197: Method [definition] - "self" @ 198..202: SelfParameter - "self" @ 220..224: Variable - "CONSTANT" @ 225..233: Variable [readonly] - "obj" @ 235..238: Variable - "MyClass" @ 241..248: Class - "x" @ 286..287: Namespace - "os" @ 290..292: Namespace - "path" @ 293..297: Namespace - "y" @ 347..348: Method - "obj" @ 351..354: Variable - "method" @ 355..361: Method - "z" @ 413..414: Variable - "obj" @ 417..420: Variable - "CONSTANT" @ 421..429: Variable [readonly] - "w" @ 491..492: Variable - "obj" @ 495..498: Variable - "prop" @ 499..503: Variable - "v" @ 542..543: Function - "MyClass" @ 546..553: Class - "method" @ 554..560: Method - "u" @ 604..605: Variable - "List" @ 608..612: Variable - "__name__" @ 613..621: Variable + "method" @ 125..131: Method [definition] + "self" @ 132..136: SelfParameter + "/"hello/"" @ 154..161: String + "property" @ 168..176: Decorator + "prop" @ 185..189: Method [definition] + "self" @ 190..194: SelfParameter + "self" @ 212..216: Variable + "CONSTANT" @ 217..225: Variable [readonly] + "obj" @ 227..230: Variable + "MyClass" @ 233..240: Class + "x" @ 278..279: Namespace + "os" @ 282..284: Namespace + "path" @ 285..289: Namespace + "y" @ 339..340: Method + "obj" @ 343..346: Variable + "method" @ 347..353: Method + "z" @ 405..406: Variable + "obj" @ 409..412: Variable + "CONSTANT" @ 413..421: Variable [readonly] + "w" @ 483..484: Variable + "obj" @ 487..490: Variable + "prop" @ 491..495: Variable + "v" @ 534..535: Function + "MyClass" @ 538..545: Class + "method" @ 546..552: Method + "u" @ 596..597: Variable + "List" @ 600..604: Variable + "__name__" @ 605..613: Variable "#); } @@ -1456,14 +1456,14 @@ y = obj.unknown_attr # Should fall back to variable "MyClass" @ 7..14: Class [definition] "some_attr" @ 20..29: Variable "/"value/"" @ 32..39: String - "obj" @ 45..48: Variable - "MyClass" @ 51..58: Class - "x" @ 121..122: Variable - "obj" @ 125..128: Variable - "some_attr" @ 129..138: Variable - "y" @ 191..192: Variable - "obj" @ 195..198: Variable - "unknown_attr" @ 199..211: Variable + "obj" @ 41..44: Variable + "MyClass" @ 47..54: Class + "x" @ 117..118: Variable + "obj" @ 121..124: Variable + "some_attr" @ 125..134: Variable + "y" @ 187..188: Variable + "obj" @ 191..194: Variable + "unknown_attr" @ 195..207: Variable "#); } @@ -1497,20 +1497,20 @@ w = obj.A # Should not have readonly modifier (length == 1) "12" @ 72..74: Number "A" @ 79..80: Variable "1" @ 83..84: Number - "obj" @ 90..93: Variable - "MyClass" @ 96..103: Class - "x" @ 106..107: Variable - "obj" @ 110..113: Variable - "UPPER_CASE" @ 114..124: Variable [readonly] - "y" @ 160..161: Variable - "obj" @ 164..167: Variable - "lower_case" @ 168..178: Variable - "z" @ 220..221: Variable - "obj" @ 224..227: Variable - "MixedCase" @ 228..237: Variable - "w" @ 278..279: Variable - "obj" @ 282..285: Variable - "A" @ 286..287: Variable + "obj" @ 86..89: Variable + "MyClass" @ 92..99: Class + "x" @ 102..103: Variable + "obj" @ 106..109: Variable + "UPPER_CASE" @ 110..120: Variable [readonly] + "y" @ 156..157: Variable + "obj" @ 160..163: Variable + "lower_case" @ 164..174: Variable + "z" @ 216..217: Variable + "obj" @ 220..223: Variable + "MixedCase" @ 224..233: Variable + "w" @ 274..275: Variable + "obj" @ 278..281: Variable + "A" @ 282..283: Variable "#); } @@ -1636,7 +1636,7 @@ def test_function(param: int, other: MyClass) -> Optional[List[str]]: "List" @ 236..240: Variable "str" @ 241..244: Class "/"hello/"" @ 249..256: String - "None" @ 361..365: BuiltinConstant + "None" @ 357..361: BuiltinConstant "#); } @@ -1800,32 +1800,32 @@ class BoundedContainer[T: int, U = str]: "value1" @ 594..600: Parameter "U" @ 622..623: TypeParameter "value2" @ 626..632: Parameter - "get_first" @ 646..655: Method [definition] - "self" @ 656..660: SelfParameter - "T" @ 665..666: TypeParameter - "self" @ 683..687: Variable - "value1" @ 688..694: Variable - "get_second" @ 708..718: Method [definition] - "self" @ 719..723: SelfParameter - "U" @ 728..729: TypeParameter - "self" @ 746..750: Variable - "value2" @ 751..757: Variable - "BoundedContainer" @ 806..822: Class [definition] - "T" @ 823..824: TypeParameter [definition] - "int" @ 826..829: Class - "U" @ 831..832: TypeParameter [definition] - "str" @ 835..838: Class - "process" @ 849..856: Method [definition] - "self" @ 857..861: SelfParameter - "x" @ 863..864: Parameter - "T" @ 866..867: TypeParameter - "y" @ 869..870: Parameter - "U" @ 872..873: TypeParameter - "tuple" @ 878..883: Class - "T" @ 884..885: TypeParameter - "U" @ 887..888: TypeParameter - "x" @ 907..908: Parameter - "y" @ 910..911: Parameter + "get_first" @ 642..651: Method [definition] + "self" @ 652..656: SelfParameter + "T" @ 661..662: TypeParameter + "self" @ 679..683: Variable + "value1" @ 684..690: Variable + "get_second" @ 700..710: Method [definition] + "self" @ 711..715: SelfParameter + "U" @ 720..721: TypeParameter + "self" @ 738..742: Variable + "value2" @ 743..749: Variable + "BoundedContainer" @ 798..814: Class [definition] + "T" @ 815..816: TypeParameter [definition] + "int" @ 818..821: Class + "U" @ 823..824: TypeParameter [definition] + "str" @ 827..830: Class + "process" @ 841..848: Method [definition] + "self" @ 849..853: SelfParameter + "x" @ 855..856: Parameter + "T" @ 858..859: TypeParameter + "y" @ 861..862: Parameter + "U" @ 864..865: TypeParameter + "tuple" @ 870..875: Class + "T" @ 876..877: TypeParameter + "U" @ 879..880: TypeParameter + "x" @ 899..900: Parameter + "y" @ 902..903: Parameter "#); } @@ -2071,24 +2071,24 @@ def outer(): "/"outer_value/"" @ 63..76: String "z" @ 81..82: Variable "/"outer_local/"" @ 85..98: String - "inner" @ 112..117: Function [definition] - "x" @ 138..139: Variable - "z" @ 141..142: Variable - "y" @ 193..194: Variable - "x" @ 243..244: Variable - "/"modified/"" @ 247..257: String - "y" @ 266..267: Variable - "/"modified_global/"" @ 270..287: String - "z" @ 296..297: Variable - "/"modified_local/"" @ 300..316: String - "deeper" @ 338..344: Function [definition] - "x" @ 369..370: Variable - "y" @ 410..411: Variable - "x" @ 413..414: Variable - "x" @ 469..470: Variable - "y" @ 473..474: Variable - "deeper" @ 499..505: Function - "inner" @ 522..527: Function + "inner" @ 108..113: Function [definition] + "x" @ 134..135: Variable + "z" @ 137..138: Variable + "y" @ 189..190: Variable + "x" @ 239..240: Variable + "/"modified/"" @ 243..253: String + "y" @ 262..263: Variable + "/"modified_global/"" @ 266..283: String + "z" @ 292..293: Variable + "/"modified_local/"" @ 296..312: String + "deeper" @ 326..332: Function [definition] + "x" @ 357..358: Variable + "y" @ 398..399: Variable + "x" @ 401..402: Variable + "x" @ 457..458: Variable + "y" @ 461..462: Variable + "deeper" @ 479..485: Function + "inner" @ 498..503: Function "#); } @@ -2115,20 +2115,20 @@ def test(): "test" @ 34..38: Function [definition] "x" @ 53..54: Variable "y" @ 68..69: Variable - "a" @ 128..129: Variable - "b" @ 131..132: Variable - "c" @ 134..135: Variable - "d" @ 149..150: Variable - "e" @ 152..153: Variable - "f" @ 155..156: Variable - "x" @ 173..174: Variable - "y" @ 177..178: Variable - "a" @ 181..182: Variable - "b" @ 185..186: Variable - "c" @ 189..190: Variable - "d" @ 193..194: Variable - "e" @ 197..198: Variable - "f" @ 201..202: Variable + "a" @ 124..125: Variable + "b" @ 127..128: Variable + "c" @ 130..131: Variable + "d" @ 145..146: Variable + "e" @ 148..149: Variable + "f" @ 151..152: Variable + "x" @ 165..166: Variable + "y" @ 169..170: Variable + "a" @ 173..174: Variable + "b" @ 177..178: Variable + "c" @ 181..182: Variable + "d" @ 185..186: Variable + "e" @ 189..190: Variable + "f" @ 193..194: Variable "#); } From 14fe1228e72dca90db6b3dbb7e07f973d175ea0e Mon Sep 17 00:00:00 2001 From: Douglas Creager Date: Thu, 21 Aug 2025 09:30:09 -0400 Subject: [PATCH 081/160] [ty] Perform assignability etc checks using new `Constraints` trait (#19838) "Why would you do this? This looks like you just replaced `bool` with an overly complex trait" Yes that's correct! This should be a no-op refactoring. It replaces all of the logic in our assignability, subtyping, equivalence, and disjointness methods to work over an arbitrary `Constraints` trait instead of only working on `bool`. The methods that `Constraints` provides looks very much like what we get from `bool`. But soon we will add a new impl of this trait, and some new methods, that let us express "fuzzy" constraints that aren't always true or false. (In particular, a constraint will express the upper and lower bounds of the allowed specializations of a typevar.) Even once we have that, most of the operations that we perform on constraint sets will be the usual boolean operations, just on sets. (`false` becomes empty/never; `true` becomes universe/always; `or` becomes union; `and` becomes intersection; `not` becomes negation.) So it's helpful to have this separate PR to refactor how we invoke those operations without introducing the new functionality yet. Note that we also have translations of `Option::is_some_and` and `is_none_or`, and of `Iterator::any` and `all`, and that the `and`, `or`, `when_any`, and `when_all` methods are meant to short-circuit, just like the corresponding boolean operations. For constraint sets, that depends on being able to implement the `is_always` and `is_never` trait methods. --------- Co-authored-by: Carl Meyer Co-authored-by: Alex Waygood --- .../mdtest/generics/pep695/variables.md | 11 + crates/ty_python_semantic/src/types.rs | 669 +++++++++++------- crates/ty_python_semantic/src/types/class.rs | 92 ++- .../src/types/class_base.rs | 5 +- .../src/types/constraints.rs | 184 +++++ crates/ty_python_semantic/src/types/cyclic.rs | 12 +- .../ty_python_semantic/src/types/function.rs | 30 +- .../ty_python_semantic/src/types/generics.rs | 64 +- .../ty_python_semantic/src/types/instance.rs | 93 ++- .../src/types/protocol_class.rs | 64 +- .../src/types/signatures.rs | 177 +++-- .../src/types/subclass_of.rs | 32 +- crates/ty_python_semantic/src/types/tuple.rs | 297 +++++--- 13 files changed, 1138 insertions(+), 592 deletions(-) create mode 100644 crates/ty_python_semantic/src/types/constraints.rs diff --git a/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md b/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md index ebf69f7e4e87d..3064be79d6af6 100644 --- a/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md +++ b/crates/ty_python_semantic/resources/mdtest/generics/pep695/variables.md @@ -327,6 +327,17 @@ def union[T: Base, U: (Base, Unrelated)](t: T, u: U) -> None: static_assert(is_subtype_of(U, U | None)) ``` +A bound or constrained typevar in a union with a dynamic type is assignable to the typevar: + +```py +def union_with_dynamic[T: Base, U: (Base, Unrelated)](t: T, u: U) -> None: + static_assert(is_assignable_to(T | Any, T)) + static_assert(is_assignable_to(U | Any, U)) + + static_assert(not is_subtype_of(T | Any, T)) + static_assert(not is_subtype_of(U | Any, U)) +``` + And an intersection of a typevar with another type is always a subtype of the TypeVar: ```py diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 1afe7cd844560..f20412c07396b 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -39,6 +39,9 @@ use crate::suppression::check_suppressions; use crate::types::call::{Binding, Bindings, CallArguments, CallableBinding}; use crate::types::class::{CodeGeneratorKind, Field}; pub(crate) use crate::types::class_base::ClassBase; +use crate::types::constraints::{ + Constraints, IteratorConstraintsExtension, OptionConstraintsExtension, +}; use crate::types::context::{LintDiagnosticGuard, LintDiagnosticGuardBuilder}; use crate::types::diagnostic::{INVALID_AWAIT, INVALID_TYPE_FORM, UNSUPPORTED_BOOL_CONVERSION}; pub use crate::types::display::DisplaySettings; @@ -73,6 +76,7 @@ mod builder; mod call; mod class; mod class_base; +mod constraints; mod context; mod cyclic; mod diagnostic; @@ -176,14 +180,14 @@ fn definition_expression_type<'db>( pub(crate) type ApplyTypeMappingVisitor<'db> = TypeTransformer<'db, TypeMapping<'db, 'db>>; /// A [`PairVisitor`] that is used in `has_relation_to` methods. -pub(crate) type HasRelationToVisitor<'db> = PairVisitor<'db, TypeRelation>; +pub(crate) type HasRelationToVisitor<'db, C> = PairVisitor<'db, TypeRelation, C>; /// A [`PairVisitor`] that is used in `is_disjoint_from` methods. -pub(crate) type IsDisjointVisitor<'db> = PairVisitor<'db, IsDisjoint>; +pub(crate) type IsDisjointVisitor<'db, C> = PairVisitor<'db, IsDisjoint, C>; pub(crate) struct IsDisjoint; /// A [`PairVisitor`] that is used in `is_equivalent` methods. -pub(crate) type IsEquivalentVisitor<'db> = PairVisitor<'db, IsEquivalent>; +pub(crate) type IsEquivalentVisitor<'db, C> = PairVisitor<'db, IsEquivalent, C>; pub(crate) struct IsEquivalent; /// A [`TypeTransformer`] that is used in `normalized` methods. @@ -1080,7 +1084,7 @@ impl<'db> Type<'db> { /// - Converts class-based protocols into synthesized protocols #[must_use] pub(crate) fn normalized(self, db: &'db dyn Db) -> Self { - self.normalized_impl(db, &TypeTransformer::default()) + self.normalized_impl(db, &NormalizedVisitor::default()) } #[must_use] @@ -1328,6 +1332,10 @@ impl<'db> Type<'db> { /// intersection simplification dependent on the order in which elements are added), so we do /// not use this more general definition of subtyping. pub(crate) fn is_subtype_of(self, db: &'db dyn Db, target: Type<'db>) -> bool { + self.when_subtype_of(db, target) + } + + fn when_subtype_of>(self, db: &'db dyn Db, target: Type<'db>) -> C { self.has_relation_to(db, target, TypeRelation::Subtyping) } @@ -1335,40 +1343,58 @@ impl<'db> Type<'db> { /// /// [assignable to]: https://typing.python.org/en/latest/spec/concepts.html#the-assignable-to-or-consistent-subtyping-relation pub(crate) fn is_assignable_to(self, db: &'db dyn Db, target: Type<'db>) -> bool { + self.when_assignable_to(db, target) + } + + fn when_assignable_to>(self, db: &'db dyn Db, target: Type<'db>) -> C { self.has_relation_to(db, target, TypeRelation::Assignability) } - fn has_relation_to(self, db: &'db dyn Db, target: Type<'db>, relation: TypeRelation) -> bool { - self.has_relation_to_impl(db, target, relation, &PairVisitor::new(true)) + fn has_relation_to>( + self, + db: &'db dyn Db, + target: Type<'db>, + relation: TypeRelation, + ) -> C { + self.has_relation_to_impl( + db, + target, + relation, + &HasRelationToVisitor::new(C::always_satisfiable(db)), + ) } - fn has_relation_to_impl( + fn has_relation_to_impl>( self, db: &'db dyn Db, target: Type<'db>, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { // Subtyping implies assignability, so if subtyping is reflexive and the two types are // equal, it is both a subtype and assignable. Assignability is always reflexive. // // Note that we could do a full equivalence check here, but that would be both expensive // and unnecessary. This early return is only an optimisation. if (relation.is_assignability() || self.subtyping_is_always_reflexive()) && self == target { - return true; + return C::always_satisfiable(db); } match (self, target) { // Everything is a subtype of `object`. - (_, Type::NominalInstance(instance)) if instance.is_object(db) => true, + (_, Type::NominalInstance(instance)) if instance.is_object(db) => { + C::always_satisfiable(db) + } // `Never` is the bottom type, the empty set. // It is a subtype of all other types. - (Type::Never, _) => true, + (Type::Never, _) => C::always_satisfiable(db), // Dynamic is only a subtype of `object` and only a supertype of `Never`; both were // handled above. It's always assignable, though. - (Type::Dynamic(_), _) | (_, Type::Dynamic(_)) => relation.is_assignability(), + (Type::Dynamic(_), _) | (_, Type::Dynamic(_)) => { + C::from_bool(db, relation.is_assignability()) + } (Type::TypeAlias(self_alias), _) => visitor.visit((self, target), || { self_alias @@ -1386,12 +1412,14 @@ impl<'db> Type<'db> { (Type::KnownInstance(KnownInstanceType::Field(field)), right) if relation.is_assignability() => { - field.default_type(db).has_relation_to(db, right, relation) + field + .default_type(db) + .has_relation_to_impl(db, right, relation, visitor) } (Type::TypedDict(_), _) | (_, Type::TypedDict(_)) => { // TODO: Implement assignability and subtyping for TypedDict - relation.is_assignability() + C::from_bool(db, relation.is_assignability()) } // In general, a TypeVar `T` is not a subtype of a type `S` unless one of the two conditions is satisfied: @@ -1405,17 +1433,17 @@ impl<'db> Type<'db> { (Type::NonInferableTypeVar(_), Type::Union(union)) if union.elements(db).contains(&self) => { - true + C::always_satisfiable(db) } (Type::Intersection(intersection), Type::NonInferableTypeVar(_)) if intersection.positive(db).contains(&target) => { - true + C::always_satisfiable(db) } (Type::Intersection(intersection), Type::NonInferableTypeVar(_)) if intersection.negative(db).contains(&target) => { - false + C::always_satisfiable(db) } // Two identical typevars must always solve to the same type, so they are always @@ -1426,7 +1454,7 @@ impl<'db> Type<'db> { ( Type::NonInferableTypeVar(lhs_bound_typevar), Type::NonInferableTypeVar(rhs_bound_typevar), - ) if lhs_bound_typevar == rhs_bound_typevar => true, + ) if lhs_bound_typevar == rhs_bound_typevar => C::always_satisfiable(db), // A fully static typevar is a subtype of its upper bound, and to something similar to // the union of its constraints. An unbound, unconstrained, fully static typevar has an @@ -1440,7 +1468,7 @@ impl<'db> Type<'db> { bound.has_relation_to_impl(db, target, relation, visitor) } Some(TypeVarBoundOrConstraints::Constraints(constraints)) => { - constraints.elements(db).iter().all(|constraint| { + constraints.elements(db).iter().when_all(db, |constraint| { constraint.has_relation_to_impl(db, target, relation, visitor) }) } @@ -1451,69 +1479,79 @@ impl<'db> Type<'db> { // might be specialized to any one of them. However, the constraints do not have to be // disjoint, which means an lhs type might be a subtype of all of the constraints. (_, Type::NonInferableTypeVar(bound_typevar)) - if bound_typevar + if !bound_typevar .typevar(db) .constraints(db) - .is_some_and(|constraints| { - constraints.iter().all(|constraint| { + .when_some_and(db, |constraints| { + constraints.iter().when_all(db, |constraint| { self.has_relation_to_impl(db, *constraint, relation, visitor) }) - }) => + }) + .is_never_satisfied(db) => { - true + // TODO: The repetition here isn't great, but we really need the fallthrough logic, + // where this arm only engages if it returns true (or in the world of constraints, + // not false). Once we're using real constraint sets instead of bool, we should be + // able to simplify the typevar logic. + bound_typevar + .typevar(db) + .constraints(db) + .when_some_and(db, |constraints| { + constraints.iter().when_all(db, |constraint| { + self.has_relation_to_impl(db, *constraint, relation, visitor) + }) + }) } // `Never` is the bottom type, the empty set. // Other than one unlikely edge case (TypeVars bound to `Never`), // no other type is a subtype of or assignable to `Never`. - (_, Type::Never) => false, + (_, Type::Never) => C::unsatisfiable(db), - (Type::Union(union), _) => union - .elements(db) - .iter() - .all(|&elem_ty| elem_ty.has_relation_to_impl(db, target, relation, visitor)), + (Type::Union(union), _) => union.elements(db).iter().when_all(db, |&elem_ty| { + elem_ty.has_relation_to_impl(db, target, relation, visitor) + }), - (_, Type::Union(union)) => union - .elements(db) - .iter() - .any(|&elem_ty| self.has_relation_to_impl(db, elem_ty, relation, visitor)), + (_, Type::Union(union)) => union.elements(db).iter().when_any(db, |&elem_ty| { + self.has_relation_to_impl(db, elem_ty, relation, visitor) + }), // If both sides are intersections we need to handle the right side first // (A & B & C) is a subtype of (A & B) because the left is a subtype of both A and B, // but none of A, B, or C is a subtype of (A & B). - (_, Type::Intersection(intersection)) => { - intersection - .positive(db) - .iter() - .all(|&pos_ty| self.has_relation_to_impl(db, pos_ty, relation, visitor)) - && intersection + (_, Type::Intersection(intersection)) => (intersection.positive(db).iter()) + .when_all(db, |&pos_ty| { + self.has_relation_to_impl(db, pos_ty, relation, visitor) + }) + .and(db, || { + intersection .negative(db) .iter() - .all(|&neg_ty| self.is_disjoint_from(db, neg_ty)) + .when_all(db, |&neg_ty| self.when_disjoint_from(db, neg_ty)) + }), + (Type::Intersection(intersection), _) => { + intersection.positive(db).iter().when_any(db, |&elem_ty| { + elem_ty.has_relation_to_impl(db, target, relation, visitor) + }) } - (Type::Intersection(intersection), _) => intersection - .positive(db) - .iter() - .any(|&elem_ty| elem_ty.has_relation_to_impl(db, target, relation, visitor)), - // Other than the special cases checked above, no other types are a subtype of a // typevar, since there's no guarantee what type the typevar will be specialized to. // (If the typevar is bounded, it might be specialized to a smaller type than the // bound. This is true even if the bound is a final class, since the typevar can still // be specialized to `Never`.) - (_, Type::NonInferableTypeVar(_)) => false, + (_, Type::NonInferableTypeVar(_)) => C::unsatisfiable(db), // TODO: Infer specializations here - (Type::TypeVar(_), _) | (_, Type::TypeVar(_)) => false, + (Type::TypeVar(_), _) | (_, Type::TypeVar(_)) => C::unsatisfiable(db), // Note that the definition of `Type::AlwaysFalsy` depends on the return value of `__bool__`. // If `__bool__` always returns True or False, it can be treated as a subtype of `AlwaysTruthy` or `AlwaysFalsy`, respectively. - (left, Type::AlwaysFalsy) => left.bool(db).is_always_false(), - (left, Type::AlwaysTruthy) => left.bool(db).is_always_true(), + (left, Type::AlwaysFalsy) => C::from_bool(db, left.bool(db).is_always_false()), + (left, Type::AlwaysTruthy) => C::from_bool(db, left.bool(db).is_always_true()), // Currently, the only supertype of `AlwaysFalsy` and `AlwaysTruthy` is the universal set (object instance). (Type::AlwaysFalsy | Type::AlwaysTruthy, _) => { - target.is_equivalent_to(db, Type::object(db)) + target.when_equivalent_to(db, Type::object(db)) } // These clauses handle type variants that include function literals. A function @@ -1522,13 +1560,13 @@ impl<'db> Type<'db> { // applied to the signature. Different specializations of the same function literal are // only subtypes of each other if they result in the same signature. (Type::FunctionLiteral(self_function), Type::FunctionLiteral(target_function)) => { - self_function.has_relation_to(db, target_function, relation) + self_function.has_relation_to_impl(db, target_function, relation, visitor) } (Type::BoundMethod(self_method), Type::BoundMethod(target_method)) => { - self_method.has_relation_to(db, target_method, relation) + self_method.has_relation_to_impl(db, target_method, relation, visitor) } (Type::MethodWrapper(self_method), Type::MethodWrapper(target_method)) => { - self_method.has_relation_to(db, target_method, relation) + self_method.has_relation_to_impl(db, target_method, relation, visitor) } // No literal type is a subtype of any other literal type, unless they are the same @@ -1550,36 +1588,39 @@ impl<'db> Type<'db> { | Type::FunctionLiteral(_) | Type::ModuleLiteral(_) | Type::EnumLiteral(_), - ) => false, + ) => C::unsatisfiable(db), (Type::Callable(self_callable), Type::Callable(other_callable)) => { - self_callable.has_relation_to(db, other_callable, relation) + self_callable.has_relation_to_impl(db, other_callable, relation, visitor) } - (_, Type::Callable(_)) => self.into_callable(db).is_some_and(|callable| { + (_, Type::Callable(_)) => self.into_callable(db).when_some_and(db, |callable| { callable.has_relation_to_impl(db, target, relation, visitor) }), (Type::ProtocolInstance(left), Type::ProtocolInstance(right)) => { - left.has_relation_to(db, right, relation) + left.has_relation_to_impl(db, right, relation, visitor) } // A protocol instance can never be a subtype of a nominal type, with the *sole* exception of `object`. - (Type::ProtocolInstance(_), _) => false, + (Type::ProtocolInstance(_), _) => C::unsatisfiable(db), (_, Type::ProtocolInstance(protocol)) => { - self.satisfies_protocol(db, protocol, relation) + self.satisfies_protocol(db, protocol, relation, visitor) } // All `StringLiteral` types are a subtype of `LiteralString`. - (Type::StringLiteral(_), Type::LiteralString) => true, + (Type::StringLiteral(_), Type::LiteralString) => C::always_satisfiable(db), // An instance is a subtype of an enum literal, if it is an instance of the enum class // and the enum has only one member. (Type::NominalInstance(_), Type::EnumLiteral(target_enum_literal)) => { if target_enum_literal.enum_class_instance(db) != self { - return false; + return C::unsatisfiable(db); } - is_single_member_enum(db, target_enum_literal.enum_class(db)) + C::from_bool( + db, + is_single_member_enum(db, target_enum_literal.enum_class(db)), + ) } // Except for the special `LiteralString` case above, @@ -1594,7 +1635,7 @@ impl<'db> Type<'db> { | Type::ModuleLiteral(_) | Type::EnumLiteral(_), _, - ) => (self.literal_fallback_instance(db)).is_some_and(|instance| { + ) => (self.literal_fallback_instance(db)).when_some_and(db, |instance| { instance.has_relation_to_impl(db, target, relation, visitor) }), @@ -1602,7 +1643,7 @@ impl<'db> Type<'db> { // so it also, for now, just delegates to its instance fallback. (Type::FunctionLiteral(_), _) => KnownClass::FunctionType .to_instance(db) - .has_relation_to(db, target, relation), + .has_relation_to_impl(db, target, relation, visitor), // The same reasoning applies for these special callable types: (Type::BoundMethod(_), _) => KnownClass::MethodType @@ -1617,23 +1658,21 @@ impl<'db> Type<'db> { (Type::DataclassDecorator(_) | Type::DataclassTransformer(_), _) => { // TODO: Implement subtyping using an equivalent `Callable` type. - false + C::unsatisfiable(db) } // `TypeIs` is invariant. - (Type::TypeIs(left), Type::TypeIs(right)) => { - left.return_type(db).has_relation_to_impl( - db, - right.return_type(db), - relation, - visitor, - ) && right.return_type(db).has_relation_to_impl( - db, - left.return_type(db), - relation, - visitor, - ) - } + (Type::TypeIs(left), Type::TypeIs(right)) => left + .return_type(db) + .has_relation_to_impl(db, right.return_type(db), relation, visitor) + .and(db, || { + right.return_type(db).has_relation_to_impl( + db, + left.return_type(db), + relation, + visitor, + ) + }), // `TypeIs[T]` is a subtype of `bool`. (Type::TypeIs(_), _) => KnownClass::Bool @@ -1641,18 +1680,15 @@ impl<'db> Type<'db> { .has_relation_to_impl(db, target, relation, visitor), // Function-like callables are subtypes of `FunctionType` - (Type::Callable(callable), _) - if callable.is_function_like(db) - && KnownClass::FunctionType - .to_instance(db) - .has_relation_to_impl(db, target, relation, visitor) => - { - true + (Type::Callable(callable), _) if callable.is_function_like(db) => { + KnownClass::FunctionType + .to_instance(db) + .has_relation_to_impl(db, target, relation, visitor) } - (Type::Callable(_), _) => false, + (Type::Callable(_), _) => C::unsatisfiable(db), - (Type::BoundSuper(_), Type::BoundSuper(_)) => self.is_equivalent_to(db, target), + (Type::BoundSuper(_), Type::BoundSuper(_)) => self.when_equivalent_to(db, target), (Type::BoundSuper(_), _) => KnownClass::Super .to_instance(db) .has_relation_to_impl(db, target, relation, visitor), @@ -1670,7 +1706,7 @@ impl<'db> Type<'db> { visitor, ) }) - .unwrap_or(relation.is_assignability()), + .unwrap_or_else(|| C::from_bool(db, relation.is_assignability())), (Type::GenericAlias(alias), Type::SubclassOf(target_subclass_ty)) => target_subclass_ty .subclass_of() .into_class() @@ -1682,7 +1718,7 @@ impl<'db> Type<'db> { visitor, ) }) - .unwrap_or(relation.is_assignability()), + .unwrap_or_else(|| C::from_bool(db, relation.is_assignability())), // This branch asks: given two types `type[T]` and `type[S]`, is `type[T]` a subtype of `type[S]`? (Type::SubclassOf(self_subclass_ty), Type::SubclassOf(target_subclass_ty)) => { @@ -1704,13 +1740,16 @@ impl<'db> Type<'db> { KnownClass::Type .to_instance(db) .has_relation_to_impl(db, other, relation, visitor) - || (relation.is_assignability() - && other.has_relation_to_impl( - db, - KnownClass::Type.to_instance(db), - relation, - visitor, - )) + .or(db, || { + C::from_bool(db, relation.is_assignability()).and(db, || { + other.has_relation_to_impl( + db, + KnownClass::Type.to_instance(db), + relation, + visitor, + ) + }) + }) } // Any `type[...]` type is assignable to `type[Any]` @@ -1765,7 +1804,7 @@ impl<'db> Type<'db> { // Other than the special cases enumerated above, `Instance` types and typevars are // never subtypes of any other variants - (Type::NominalInstance(_) | Type::NonInferableTypeVar(_), _) => false, + (Type::NominalInstance(_) | Type::NonInferableTypeVar(_), _) => C::unsatisfiable(db), } } @@ -1782,27 +1821,37 @@ impl<'db> Type<'db> { /// /// [equivalent to]: https://typing.python.org/en/latest/spec/glossary.html#term-equivalent pub(crate) fn is_equivalent_to(self, db: &'db dyn Db, other: Type<'db>) -> bool { - self.is_equivalent_to_impl(db, other, &PairVisitor::new(true)) + self.when_equivalent_to(db, other) + } + + fn when_equivalent_to>(self, db: &'db dyn Db, other: Type<'db>) -> C { + self.is_equivalent_to_impl( + db, + other, + &IsEquivalentVisitor::new(C::always_satisfiable(db)), + ) } - pub(crate) fn is_equivalent_to_impl( + pub(crate) fn is_equivalent_to_impl>( self, db: &'db dyn Db, other: Type<'db>, - visitor: &IsEquivalentVisitor<'db>, - ) -> bool { + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { if self == other { - return true; + return C::always_satisfiable(db); } match (self, other) { - (Type::Dynamic(_), Type::Dynamic(_)) => true, + (Type::Dynamic(_), Type::Dynamic(_)) => C::always_satisfiable(db), (Type::SubclassOf(first), Type::SubclassOf(second)) => { match (first.subclass_of(), second.subclass_of()) { - (first, second) if first == second => true, - (SubclassOfInner::Dynamic(_), SubclassOfInner::Dynamic(_)) => true, - _ => false, + (first, second) if first == second => C::always_satisfiable(db), + (SubclassOfInner::Dynamic(_), SubclassOfInner::Dynamic(_)) => { + C::always_satisfiable(db) + } + _ => C::unsatisfiable(db), } } @@ -1821,45 +1870,49 @@ impl<'db> Type<'db> { } (Type::NominalInstance(first), Type::NominalInstance(second)) => { - first.is_equivalent_to(db, second) + first.is_equivalent_to_impl(db, second, visitor) } - (Type::Union(first), Type::Union(second)) => first.is_equivalent_to(db, second), + (Type::Union(first), Type::Union(second)) => { + first.is_equivalent_to_impl(db, second, visitor) + } (Type::Intersection(first), Type::Intersection(second)) => { - first.is_equivalent_to(db, second) + first.is_equivalent_to_impl(db, second, visitor) } (Type::FunctionLiteral(self_function), Type::FunctionLiteral(target_function)) => { - self_function.is_equivalent_to(db, target_function) + self_function.is_equivalent_to_impl(db, target_function, visitor) } (Type::BoundMethod(self_method), Type::BoundMethod(target_method)) => { - self_method.is_equivalent_to(db, target_method) + self_method.is_equivalent_to_impl(db, target_method, visitor) } (Type::MethodWrapper(self_method), Type::MethodWrapper(target_method)) => { - self_method.is_equivalent_to(db, target_method) + self_method.is_equivalent_to_impl(db, target_method, visitor) + } + (Type::Callable(first), Type::Callable(second)) => { + first.is_equivalent_to_impl(db, second, visitor) } - (Type::Callable(first), Type::Callable(second)) => first.is_equivalent_to(db, second), (Type::ProtocolInstance(first), Type::ProtocolInstance(second)) => { - first.is_equivalent_to(db, second) + first.is_equivalent_to_impl(db, second, visitor) } (Type::ProtocolInstance(protocol), nominal @ Type::NominalInstance(n)) | (nominal @ Type::NominalInstance(n), Type::ProtocolInstance(protocol)) => { - n.is_object(db) && protocol.normalized(db) == nominal + C::from_bool(db, n.is_object(db) && protocol.normalized(db) == nominal) } // An instance of an enum class is equivalent to an enum literal of that class, // if that enum has only has one member. (Type::NominalInstance(instance), Type::EnumLiteral(literal)) | (Type::EnumLiteral(literal), Type::NominalInstance(instance)) => { if literal.enum_class_instance(db) != Type::NominalInstance(instance) { - return false; + return C::unsatisfiable(db); } let class_literal = instance.class(db).class_literal(db).0; - is_single_member_enum(db, class_literal) + C::from_bool(db, is_single_member_enum(db, class_literal)) } - _ => false, + _ => C::unsatisfiable(db), } } @@ -1868,40 +1921,44 @@ impl<'db> Type<'db> { /// Note: This function aims to have no false positives, but might return /// wrong `false` answers in some cases. pub(crate) fn is_disjoint_from(self, db: &'db dyn Db, other: Type<'db>) -> bool { - self.is_disjoint_from_impl(db, other, &PairVisitor::new(false)) + self.when_disjoint_from(db, other) + } + + fn when_disjoint_from>(self, db: &'db dyn Db, other: Type<'db>) -> C { + self.is_disjoint_from_impl(db, other, &IsDisjointVisitor::new(C::unsatisfiable(db))) } - pub(crate) fn is_disjoint_from_impl( + pub(crate) fn is_disjoint_from_impl>( self, db: &'db dyn Db, other: Type<'db>, - visitor: &IsDisjointVisitor<'db>, - ) -> bool { - fn any_protocol_members_absent_or_disjoint<'db>( + visitor: &IsDisjointVisitor<'db, C>, + ) -> C { + fn any_protocol_members_absent_or_disjoint<'db, C: Constraints<'db>>( db: &'db dyn Db, protocol: ProtocolInstanceType<'db>, other: Type<'db>, - visitor: &IsDisjointVisitor<'db>, - ) -> bool { - protocol.interface(db).members(db).any(|member| { + visitor: &IsDisjointVisitor<'db, C>, + ) -> C { + protocol.interface(db).members(db).when_any(db, |member| { other .member(db, member.name()) .place .ignore_possibly_unbound() - .is_none_or(|attribute_type| { + .when_none_or(db, |attribute_type| { member.has_disjoint_type_from(db, attribute_type, visitor) }) }) } match (self, other) { - (Type::Never, _) | (_, Type::Never) => true, + (Type::Never, _) | (_, Type::Never) => C::always_satisfiable(db), - (Type::Dynamic(_), _) | (_, Type::Dynamic(_)) => false, + (Type::Dynamic(_), _) | (_, Type::Dynamic(_)) => C::unsatisfiable(db), (Type::TypedDict(_), _) | (_, Type::TypedDict(_)) => { // TODO: Implement disjointness for TypedDict - false + C::unsatisfiable(db) } (Type::TypeAlias(alias), _) => { @@ -1922,44 +1979,44 @@ impl<'db> Type<'db> { // be specialized to the same type. (This is an important difference between typevars // and `Any`!) Different typevars might be disjoint, depending on their bounds and // constraints, which are handled below. - (Type::NonInferableTypeVar(self_bound_typevar), Type::NonInferableTypeVar(other_bound_typevar)) - if self_bound_typevar == other_bound_typevar => - { - false - } + ( + Type::NonInferableTypeVar(self_bound_typevar), + Type::NonInferableTypeVar(other_bound_typevar), + ) if self_bound_typevar == other_bound_typevar => C::unsatisfiable(db), (tvar @ Type::NonInferableTypeVar(_), Type::Intersection(intersection)) | (Type::Intersection(intersection), tvar @ Type::NonInferableTypeVar(_)) if intersection.negative(db).contains(&tvar) => { - true + C::always_satisfiable(db) } // An unbounded typevar is never disjoint from any other type, since it might be // specialized to any type. A bounded typevar is not disjoint from its bound, and is // only disjoint from other types if its bound is. A constrained typevar is disjoint // from a type if all of its constraints are. - (Type::NonInferableTypeVar(bound_typevar), other) | (other, Type::NonInferableTypeVar(bound_typevar)) => { + (Type::NonInferableTypeVar(bound_typevar), other) + | (other, Type::NonInferableTypeVar(bound_typevar)) => { match bound_typevar.typevar(db).bound_or_constraints(db) { - None => false, + None => C::unsatisfiable(db), Some(TypeVarBoundOrConstraints::UpperBound(bound)) => { bound.is_disjoint_from_impl(db, other, visitor) } - Some(TypeVarBoundOrConstraints::Constraints(constraints)) => constraints - .elements(db) - .iter() - .all(|constraint| constraint.is_disjoint_from_impl(db, other, visitor)), + Some(TypeVarBoundOrConstraints::Constraints(constraints)) => { + constraints.elements(db).iter().when_all(db, |constraint| { + constraint.is_disjoint_from_impl(db, other, visitor) + }) + } } } // TODO: Infer specializations here - (Type::TypeVar(_), _) - | (_, Type::TypeVar(_)) => false, + (Type::TypeVar(_), _) | (_, Type::TypeVar(_)) => C::unsatisfiable(db), (Type::Union(union), other) | (other, Type::Union(union)) => union .elements(db) .iter() - .all(|e| e.is_disjoint_from_impl(db, other, visitor)), + .when_all(db, |e| e.is_disjoint_from_impl(db, other, visitor)), // If we have two intersections, we test the positive elements of each one against the other intersection // Negative elements need a positive element on the other side in order to be disjoint. @@ -1968,11 +2025,13 @@ impl<'db> Type<'db> { self_intersection .positive(db) .iter() - .any(|p| p.is_disjoint_from_impl(db, other, visitor)) - || other_intersection - .positive(db) - .iter() - .any(|p: &Type<'_>| p.is_disjoint_from_impl(db, self, visitor)) + .when_any(db, |p| p.is_disjoint_from_impl(db, other, visitor)) + .or(db, || { + other_intersection + .positive(db) + .iter() + .when_any(db, |p| p.is_disjoint_from_impl(db, self, visitor)) + }) } (Type::Intersection(intersection), other) @@ -1980,12 +2039,14 @@ impl<'db> Type<'db> { intersection .positive(db) .iter() - .any(|p| p.is_disjoint_from_impl(db, other, visitor)) + .when_any(db, |p| p.is_disjoint_from_impl(db, other, visitor)) // A & B & Not[C] is disjoint from C - || intersection - .negative(db) - .iter() - .any(|&neg_ty| other.is_subtype_of(db, neg_ty)) + .or(db, || { + intersection + .negative(db) + .iter() + .when_any(db, |&neg_ty| other.when_subtype_of(db, neg_ty)) + }) } // any single-valued type is disjoint from another single-valued type @@ -2019,7 +2080,7 @@ impl<'db> Type<'db> { | Type::GenericAlias(..) | Type::SpecialForm(..) | Type::KnownInstance(..)), - ) => left != right, + ) => C::from_bool(db, left != right), ( Type::SubclassOf(_), @@ -2048,16 +2109,16 @@ impl<'db> Type<'db> { | Type::WrapperDescriptor(..) | Type::ModuleLiteral(..), Type::SubclassOf(_), - ) => true, + ) => C::always_satisfiable(db), (Type::AlwaysTruthy, ty) | (ty, Type::AlwaysTruthy) => { // `Truthiness::Ambiguous` may include `AlwaysTrue` as a subset, so it's not guaranteed to be disjoint. // Thus, they are only disjoint if `ty.bool() == AlwaysFalse`. - ty.bool(db).is_always_false() + C::from_bool(db, ty.bool(db).is_always_false()) } (Type::AlwaysFalsy, ty) | (ty, Type::AlwaysFalsy) => { // Similarly, they are only disjoint if `ty.bool() == AlwaysTrue`. - ty.bool(db).is_always_true() + C::from_bool(db, ty.bool(db).is_always_true()) } (Type::ProtocolInstance(left), Type::ProtocolInstance(right)) => { @@ -2065,15 +2126,27 @@ impl<'db> Type<'db> { } (Type::ProtocolInstance(protocol), Type::SpecialForm(special_form)) - | (Type::SpecialForm(special_form), Type::ProtocolInstance(protocol)) => visitor.visit((self, other), || { - any_protocol_members_absent_or_disjoint(db, protocol, special_form.instance_fallback(db), visitor) - }), - + | (Type::SpecialForm(special_form), Type::ProtocolInstance(protocol)) => { + visitor.visit((self, other), || { + any_protocol_members_absent_or_disjoint( + db, + protocol, + special_form.instance_fallback(db), + visitor, + ) + }) + } (Type::ProtocolInstance(protocol), Type::KnownInstance(known_instance)) - | (Type::KnownInstance(known_instance), Type::ProtocolInstance(protocol)) => visitor.visit((self, other), || { - any_protocol_members_absent_or_disjoint(db, protocol, known_instance.instance_fallback(db), visitor) - }), + | (Type::KnownInstance(known_instance), Type::ProtocolInstance(protocol)) => visitor + .visit((self, other), || { + any_protocol_members_absent_or_disjoint( + db, + protocol, + known_instance.instance_fallback(db), + visitor, + ) + }), // The absence of a protocol member on one of these types guarantees // that the type will be disjoint from the protocol, @@ -2112,8 +2185,7 @@ impl<'db> Type<'db> { | Type::ModuleLiteral(..) | Type::GenericAlias(..) | Type::IntLiteral(..) - | Type::EnumLiteral(..) - ), + | Type::EnumLiteral(..)), Type::ProtocolInstance(protocol), ) | ( @@ -2128,55 +2200,65 @@ impl<'db> Type<'db> { | Type::GenericAlias(..) | Type::IntLiteral(..) | Type::EnumLiteral(..)), - ) => visitor.visit((self, other), || any_protocol_members_absent_or_disjoint(db, protocol, ty, visitor)), + ) => visitor.visit((self, other), || { + any_protocol_members_absent_or_disjoint(db, protocol, ty, visitor) + }), // This is the same as the branch above -- // once guard patterns are stabilised, it could be unified with that branch // () (Type::ProtocolInstance(protocol), nominal @ Type::NominalInstance(n)) | (nominal @ Type::NominalInstance(n), Type::ProtocolInstance(protocol)) - if n.class(db).is_final(db) => visitor.visit((self, other), || + if n.class(db).is_final(db) => { - any_protocol_members_absent_or_disjoint(db, protocol, nominal, visitor) - }), + visitor.visit((self, other), || { + any_protocol_members_absent_or_disjoint(db, protocol, nominal, visitor) + }) + } (Type::ProtocolInstance(protocol), other) | (other, Type::ProtocolInstance(protocol)) => visitor.visit((self, other), || { - protocol.interface(db).members(db).any(|member| { - matches!( - other.member(db, member.name()).place, - Place::Type(attribute_type, _) if member.has_disjoint_type_from(db, attribute_type, visitor) - ) + protocol.interface(db).members(db).when_any(db, |member| { + match other.member(db, member.name()).place { + Place::Type(attribute_type, _) => { + member.has_disjoint_type_from(db, attribute_type, visitor) + } + Place::Unbound => C::unsatisfiable(db), + } }) }), (Type::SubclassOf(subclass_of_ty), Type::ClassLiteral(class_b)) | (Type::ClassLiteral(class_b), Type::SubclassOf(subclass_of_ty)) => { match subclass_of_ty.subclass_of() { - SubclassOfInner::Dynamic(_) => false, - SubclassOfInner::Class(class_a) => !class_b.is_subclass_of(db, None, class_a), + SubclassOfInner::Dynamic(_) => C::unsatisfiable(db), + SubclassOfInner::Class(class_a) => { + class_b.when_subclass_of::(db, None, class_a).negate(db) + } } } (Type::SubclassOf(subclass_of_ty), Type::GenericAlias(alias_b)) | (Type::GenericAlias(alias_b), Type::SubclassOf(subclass_of_ty)) => { match subclass_of_ty.subclass_of() { - SubclassOfInner::Dynamic(_) => false, - SubclassOfInner::Class(class_a) => { - !ClassType::from(alias_b).is_subclass_of(db, class_a) - } + SubclassOfInner::Dynamic(_) => C::unsatisfiable(db), + SubclassOfInner::Class(class_a) => ClassType::from(alias_b) + .when_subclass_of::(db, class_a) + .negate(db), } } - (Type::SubclassOf(left), Type::SubclassOf(right)) => left.is_disjoint_from_impl(db, right), + (Type::SubclassOf(left), Type::SubclassOf(right)) => { + left.is_disjoint_from_impl(db, right, visitor) + } // for `type[Any]`/`type[Unknown]`/`type[Todo]`, we know the type cannot be any larger than `type`, // so although the type is dynamic we can still determine disjointedness in some situations (Type::SubclassOf(subclass_of_ty), other) | (other, Type::SubclassOf(subclass_of_ty)) => match subclass_of_ty.subclass_of() { - SubclassOfInner::Dynamic(_) => { - KnownClass::Type.to_instance(db).is_disjoint_from_impl(db, other, visitor) - } + SubclassOfInner::Dynamic(_) => KnownClass::Type + .to_instance(db) + .is_disjoint_from_impl(db, other, visitor), SubclassOfInner::Class(class) => class .metaclass_instance_type(db) .is_disjoint_from_impl(db, other, visitor), @@ -2184,78 +2266,93 @@ impl<'db> Type<'db> { (Type::SpecialForm(special_form), Type::NominalInstance(instance)) | (Type::NominalInstance(instance), Type::SpecialForm(special_form)) => { - !special_form.is_instance_of(db, instance.class(db)) + C::from_bool(db, !special_form.is_instance_of(db, instance.class(db))) } (Type::KnownInstance(known_instance), Type::NominalInstance(instance)) | (Type::NominalInstance(instance), Type::KnownInstance(known_instance)) => { - !known_instance.is_instance_of(db, instance.class(db)) + C::from_bool(db, !known_instance.is_instance_of(db, instance.class(db))) } (Type::BooleanLiteral(..) | Type::TypeIs(_), Type::NominalInstance(instance)) | (Type::NominalInstance(instance), Type::BooleanLiteral(..) | Type::TypeIs(_)) => { // A `Type::BooleanLiteral()` must be an instance of exactly `bool` // (it cannot be an instance of a `bool` subclass) - !KnownClass::Bool.is_subclass_of(db, instance.class(db)) + KnownClass::Bool + .when_subclass_of::(db, instance.class(db)) + .negate(db) } (Type::BooleanLiteral(..) | Type::TypeIs(_), _) - | (_, Type::BooleanLiteral(..) | Type::TypeIs(_)) => true, + | (_, Type::BooleanLiteral(..) | Type::TypeIs(_)) => C::always_satisfiable(db), (Type::IntLiteral(..), Type::NominalInstance(instance)) | (Type::NominalInstance(instance), Type::IntLiteral(..)) => { // A `Type::IntLiteral()` must be an instance of exactly `int` // (it cannot be an instance of an `int` subclass) - !KnownClass::Int.is_subclass_of(db, instance.class(db)) + KnownClass::Int + .when_subclass_of::(db, instance.class(db)) + .negate(db) } - (Type::IntLiteral(..), _) | (_, Type::IntLiteral(..)) => true, + (Type::IntLiteral(..), _) | (_, Type::IntLiteral(..)) => C::always_satisfiable(db), (Type::StringLiteral(..), Type::LiteralString) - | (Type::LiteralString, Type::StringLiteral(..)) => false, + | (Type::LiteralString, Type::StringLiteral(..)) => C::unsatisfiable(db), (Type::StringLiteral(..) | Type::LiteralString, Type::NominalInstance(instance)) | (Type::NominalInstance(instance), Type::StringLiteral(..) | Type::LiteralString) => { // A `Type::StringLiteral()` or a `Type::LiteralString` must be an instance of exactly `str` // (it cannot be an instance of a `str` subclass) - !KnownClass::Str.is_subclass_of(db, instance.class(db)) + KnownClass::Str + .when_subclass_of::(db, instance.class(db)) + .negate(db) } - (Type::LiteralString, Type::LiteralString) => false, - (Type::LiteralString, _) | (_, Type::LiteralString) => true, + (Type::LiteralString, Type::LiteralString) => C::unsatisfiable(db), + (Type::LiteralString, _) | (_, Type::LiteralString) => C::always_satisfiable(db), (Type::BytesLiteral(..), Type::NominalInstance(instance)) | (Type::NominalInstance(instance), Type::BytesLiteral(..)) => { // A `Type::BytesLiteral()` must be an instance of exactly `bytes` // (it cannot be an instance of a `bytes` subclass) - !KnownClass::Bytes.is_subclass_of(db, instance.class(db)) + KnownClass::Bytes + .when_subclass_of::(db, instance.class(db)) + .negate(db) } - (Type::EnumLiteral(enum_literal), instance@Type::NominalInstance(_)) - | (instance@Type::NominalInstance(_), Type::EnumLiteral(enum_literal)) => { - !enum_literal.enum_class_instance(db).is_subtype_of(db, instance) + (Type::EnumLiteral(enum_literal), instance @ Type::NominalInstance(_)) + | (instance @ Type::NominalInstance(_), Type::EnumLiteral(enum_literal)) => { + enum_literal + .enum_class_instance(db) + .when_subtype_of::(db, instance) + .negate(db) } - (Type::EnumLiteral(..), _) | (_, Type::EnumLiteral(..)) => true, + (Type::EnumLiteral(..), _) | (_, Type::EnumLiteral(..)) => C::always_satisfiable(db), // A class-literal type `X` is always disjoint from an instance type `Y`, // unless the type expressing "all instances of `Z`" is a subtype of of `Y`, // where `Z` is `X`'s metaclass. (Type::ClassLiteral(class), instance @ Type::NominalInstance(_)) - | (instance @ Type::NominalInstance(_), Type::ClassLiteral(class)) => !class + | (instance @ Type::NominalInstance(_), Type::ClassLiteral(class)) => class .metaclass_instance_type(db) - .is_subtype_of(db, instance), + .when_subtype_of::(db, instance) + .negate(db), (Type::GenericAlias(alias), instance @ Type::NominalInstance(_)) | (instance @ Type::NominalInstance(_), Type::GenericAlias(alias)) => { - !ClassType::from(alias) + ClassType::from(alias) .metaclass_instance_type(db) - .is_subtype_of(db, instance) + .when_subtype_of::(db, instance) + .negate(db) } (Type::FunctionLiteral(..), Type::NominalInstance(instance)) | (Type::NominalInstance(instance), Type::FunctionLiteral(..)) => { // A `Type::FunctionLiteral()` must be an instance of exactly `types.FunctionType` // (it cannot be an instance of a `types.FunctionType` subclass) - !KnownClass::FunctionType.is_subclass_of(db, instance.class(db)) + KnownClass::FunctionType + .when_subclass_of::(db, instance.class(db)) + .negate(db) } (Type::BoundMethod(_), other) | (other, Type::BoundMethod(_)) => KnownClass::MethodType @@ -2279,7 +2376,7 @@ impl<'db> Type<'db> { // No two callable types are ever disjoint because // `(*args: object, **kwargs: object) -> Never` is a subtype of all fully static // callable types. - false + C::unsatisfiable(db) } (Type::Callable(_), Type::StringLiteral(_) | Type::BytesLiteral(_)) @@ -2287,7 +2384,7 @@ impl<'db> Type<'db> { // A callable type is disjoint from other literal types. For example, // `Type::StringLiteral` must be an instance of exactly `str`, not a subclass // of `str`, and `str` is not callable. The same applies to other literal types. - true + C::always_satisfiable(db) } (Type::Callable(_), Type::SpecialForm(special_form)) @@ -2296,7 +2393,7 @@ impl<'db> Type<'db> { // that are callable (like TypedDict and collection constructors). // Most special forms are type constructors/annotations (like `typing.Literal`, // `typing.Union`, etc.) that are subscripted, not called. - !special_form.is_callable() + C::from_bool(db, !special_form.is_callable()) } ( @@ -2314,8 +2411,10 @@ impl<'db> Type<'db> { ) .place .ignore_possibly_unbound() - .is_none_or(|dunder_call| { - !dunder_call.is_assignable_to(db, CallableType::unknown(db)) + .when_none_or(db, |dunder_call| { + dunder_call + .when_assignable_to::(db, CallableType::unknown(db)) + .negate(db) }), ( @@ -2327,7 +2426,7 @@ impl<'db> Type<'db> { Type::Callable(_) | Type::DataclassDecorator(_) | Type::DataclassTransformer(_), ) => { // TODO: Implement disjointness for general callable type with other types - false + C::unsatisfiable(db) } (Type::ModuleLiteral(..), other @ Type::NominalInstance(..)) @@ -2346,7 +2445,9 @@ impl<'db> Type<'db> { .is_disjoint_from_impl(db, other, visitor) } - (Type::BoundSuper(_), Type::BoundSuper(_)) => !self.is_equivalent_to(db, other), + (Type::BoundSuper(_), Type::BoundSuper(_)) => { + self.when_equivalent_to::(db, other).negate(db) + } (Type::BoundSuper(_), other) | (other, Type::BoundSuper(_)) => KnownClass::Super .to_instance(db) .is_disjoint_from_impl(db, other, visitor), @@ -5841,7 +5942,7 @@ impl<'db> Type<'db> { db: &'db dyn Db, type_mapping: &TypeMapping<'a, 'db>, ) -> Type<'db> { - self.apply_type_mapping_impl(db, type_mapping, &TypeTransformer::default()) + self.apply_type_mapping_impl(db, type_mapping, &ApplyTypeMappingVisitor::default()) } fn apply_type_mapping_impl<'a>( @@ -8614,23 +8715,42 @@ impl<'db> BoundMethodType<'db> { ) } - fn has_relation_to(self, db: &'db dyn Db, other: Self, relation: TypeRelation) -> bool { + fn has_relation_to_impl>( + self, + db: &'db dyn Db, + other: Self, + relation: TypeRelation, + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { // A bound method is a typically a subtype of itself. However, we must explicitly verify // the subtyping of the underlying function signatures (since they might be specialized // differently), and of the bound self parameter (taking care that parameters, including a // bound self parameter, are contravariant.) self.function(db) - .has_relation_to(db, other.function(db), relation) - && other - .self_instance(db) - .has_relation_to(db, self.self_instance(db), relation) + .has_relation_to_impl(db, other.function(db), relation, visitor) + .and(db, || { + other.self_instance(db).has_relation_to_impl( + db, + self.self_instance(db), + relation, + visitor, + ) + }) } - fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { - self.function(db).is_equivalent_to(db, other.function(db)) - && other - .self_instance(db) - .is_equivalent_to(db, self.self_instance(db)) + fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { + self.function(db) + .is_equivalent_to_impl(db, other.function(db), visitor) + .and(db, || { + other + .self_instance(db) + .is_equivalent_to_impl(db, self.self_instance(db), visitor) + }) } } @@ -8752,26 +8872,37 @@ impl<'db> CallableType<'db> { /// Check whether this callable type has the given relation to another callable type. /// /// See [`Type::is_subtype_of`] and [`Type::is_assignable_to`] for more details. - fn has_relation_to(self, db: &'db dyn Db, other: Self, relation: TypeRelation) -> bool { + fn has_relation_to_impl>( + self, + db: &'db dyn Db, + other: Self, + relation: TypeRelation, + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { if other.is_function_like(db) && !self.is_function_like(db) { - return false; + return C::unsatisfiable(db); } self.signatures(db) - .has_relation_to(db, other.signatures(db), relation) + .has_relation_to_impl(db, other.signatures(db), relation, visitor) } /// Check whether this callable type is equivalent to another callable type. /// /// See [`Type::is_equivalent_to`] for more details. - fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { + fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { if self == other { - return true; + return C::always_satisfiable(db); } - self.is_function_like(db) == other.is_function_like(db) - && self - .signatures(db) - .is_equivalent_to(db, other.signatures(db)) + C::from_bool(db, self.is_function_like(db) == other.is_function_like(db)).and(db, || { + self.signatures(db) + .is_equivalent_to_impl(db, other.signatures(db), visitor) + }) } } @@ -8821,22 +8952,28 @@ pub(super) fn walk_method_wrapper_type<'db, V: visitor::TypeVisitor<'db> + ?Size } impl<'db> MethodWrapperKind<'db> { - fn has_relation_to(self, db: &'db dyn Db, other: Self, relation: TypeRelation) -> bool { + fn has_relation_to_impl>( + self, + db: &'db dyn Db, + other: Self, + relation: TypeRelation, + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match (self, other) { ( MethodWrapperKind::FunctionTypeDunderGet(self_function), MethodWrapperKind::FunctionTypeDunderGet(other_function), - ) => self_function.has_relation_to(db, other_function, relation), + ) => self_function.has_relation_to_impl(db, other_function, relation, visitor), ( MethodWrapperKind::FunctionTypeDunderCall(self_function), MethodWrapperKind::FunctionTypeDunderCall(other_function), - ) => self_function.has_relation_to(db, other_function, relation), + ) => self_function.has_relation_to_impl(db, other_function, relation, visitor), (MethodWrapperKind::PropertyDunderGet(_), MethodWrapperKind::PropertyDunderGet(_)) | (MethodWrapperKind::PropertyDunderSet(_), MethodWrapperKind::PropertyDunderSet(_)) | (MethodWrapperKind::StrStartswith(_), MethodWrapperKind::StrStartswith(_)) => { - self == other + C::from_bool(db, self == other) } ( @@ -8850,26 +8987,31 @@ impl<'db> MethodWrapperKind<'db> { | MethodWrapperKind::PropertyDunderGet(_) | MethodWrapperKind::PropertyDunderSet(_) | MethodWrapperKind::StrStartswith(_), - ) => false, + ) => C::unsatisfiable(db), } } - fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { + fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { match (self, other) { ( MethodWrapperKind::FunctionTypeDunderGet(self_function), MethodWrapperKind::FunctionTypeDunderGet(other_function), - ) => self_function.is_equivalent_to(db, other_function), + ) => self_function.is_equivalent_to_impl(db, other_function, visitor), ( MethodWrapperKind::FunctionTypeDunderCall(self_function), MethodWrapperKind::FunctionTypeDunderCall(other_function), - ) => self_function.is_equivalent_to(db, other_function), + ) => self_function.is_equivalent_to_impl(db, other_function, visitor), (MethodWrapperKind::PropertyDunderGet(_), MethodWrapperKind::PropertyDunderGet(_)) | (MethodWrapperKind::PropertyDunderSet(_), MethodWrapperKind::PropertyDunderSet(_)) | (MethodWrapperKind::StrStartswith(_), MethodWrapperKind::StrStartswith(_)) => { - self == other + C::from_bool(db, self == other) } ( @@ -8883,7 +9025,7 @@ impl<'db> MethodWrapperKind<'db> { | MethodWrapperKind::PropertyDunderGet(_) | MethodWrapperKind::PropertyDunderSet(_) | MethodWrapperKind::StrStartswith(_), - ) => false, + ) => C::unsatisfiable(db), } } @@ -9371,7 +9513,7 @@ impl<'db> UnionType<'db> { /// See [`Type::normalized`] for more details. #[must_use] pub(crate) fn normalized(self, db: &'db dyn Db) -> Self { - self.normalized_impl(db, &TypeTransformer::default()) + self.normalized_impl(db, &NormalizedVisitor::default()) } pub(crate) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { @@ -9384,26 +9526,30 @@ impl<'db> UnionType<'db> { UnionType::new(db, new_elements.into_boxed_slice()) } - /// Return `true` if `self` represents the exact same sets of possible runtime objects as `other` - pub(crate) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { + pub(crate) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + _visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { if self == other { - return true; + return C::always_satisfiable(db); } let self_elements = self.elements(db); let other_elements = other.elements(db); if self_elements.len() != other_elements.len() { - return false; + return C::unsatisfiable(db); } let sorted_self = self.normalized(db); if sorted_self == other { - return true; + return C::always_satisfiable(db); } - sorted_self == other.normalized(db) + C::from_bool(db, sorted_self == other.normalized(db)) } } @@ -9445,7 +9591,7 @@ impl<'db> IntersectionType<'db> { /// See [`Type::normalized`] for more details. #[must_use] pub(crate) fn normalized(self, db: &'db dyn Db) -> Self { - self.normalized_impl(db, &TypeTransformer::default()) + self.normalized_impl(db, &NormalizedVisitor::default()) } pub(crate) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { @@ -9471,32 +9617,37 @@ impl<'db> IntersectionType<'db> { } /// Return `true` if `self` represents exactly the same set of possible runtime objects as `other` - pub(crate) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { + pub(crate) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + _visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { if self == other { - return true; + return C::always_satisfiable(db); } let self_positive = self.positive(db); let other_positive = other.positive(db); if self_positive.len() != other_positive.len() { - return false; + return C::unsatisfiable(db); } let self_negative = self.negative(db); let other_negative = other.negative(db); if self_negative.len() != other_negative.len() { - return false; + return C::unsatisfiable(db); } let sorted_self = self.normalized(db); if sorted_self == other { - return true; + return C::always_satisfiable(db); } - sorted_self == other.normalized(db) + C::from_bool(db, sorted_self == other.normalized(db)) } /// Returns an iterator over the positive elements of the intersection. If diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 49ef66960acee..12a38594cb718 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -18,6 +18,7 @@ use crate::semantic_index::{ BindingWithConstraints, DeclarationWithConstraint, SemanticIndex, attribute_declarations, attribute_scopes, }; +use crate::types::constraints::{Constraints, IteratorConstraintsExtension}; use crate::types::context::InferContext; use crate::types::diagnostic::{INVALID_LEGACY_TYPE_VARIABLE, INVALID_TYPE_ALIAS_TYPE}; use crate::types::enums::enum_metadata; @@ -28,10 +29,10 @@ use crate::types::signatures::{CallableSignature, Parameter, Parameters, Signatu use crate::types::tuple::{TupleSpec, TupleType}; use crate::types::{ ApplyTypeMappingVisitor, BareTypeAliasType, Binding, BoundSuperError, BoundSuperType, - CallableType, DataclassParams, DeprecatedInstance, HasRelationToVisitor, KnownInstanceType, - NormalizedVisitor, PropertyInstanceType, StringLiteralType, TypeAliasType, TypeMapping, - TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, VarianceInferable, - declaration_type, infer_definition_types, todo_type, + CallableType, DataclassParams, DeprecatedInstance, HasRelationToVisitor, IsEquivalentVisitor, + KnownInstanceType, NormalizedVisitor, PropertyInstanceType, StringLiteralType, TypeAliasType, + TypeMapping, TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, + VarianceInferable, declaration_type, infer_definition_types, todo_type, }; use crate::{ Db, FxIndexMap, FxOrderSet, Program, @@ -49,7 +50,7 @@ use crate::{ }, types::{ CallArguments, CallError, CallErrorKind, MetaclassCandidate, UnionBuilder, UnionType, - cyclic::PairVisitor, definition_expression_type, + definition_expression_type, }, }; use indexmap::IndexSet; @@ -536,64 +537,88 @@ impl<'db> ClassType<'db> { /// Return `true` if `other` is present in this class's MRO. pub(super) fn is_subclass_of(self, db: &'db dyn Db, other: ClassType<'db>) -> bool { - self.has_relation_to_impl(db, other, TypeRelation::Subtyping, &PairVisitor::new(true)) + self.when_subclass_of(db, other) } - pub(super) fn has_relation_to_impl( + pub(super) fn when_subclass_of>( + self, + db: &'db dyn Db, + other: ClassType<'db>, + ) -> C { + self.has_relation_to_impl( + db, + other, + TypeRelation::Subtyping, + &HasRelationToVisitor::new(C::always_satisfiable(db)), + ) + } + + pub(super) fn has_relation_to_impl>( self, db: &'db dyn Db, other: Self, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { - self.iter_mro(db).any(|base| { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { + self.iter_mro(db).when_any(db, |base| { match base { ClassBase::Dynamic(_) => match relation { - TypeRelation::Subtyping => other.is_object(db), - TypeRelation::Assignability => !other.is_final(db), + TypeRelation::Subtyping => C::from_bool(db, other.is_object(db)), + TypeRelation::Assignability => C::from_bool(db, !other.is_final(db)), }, // Protocol and Generic are not represented by a ClassType. - ClassBase::Protocol | ClassBase::Generic => false, + ClassBase::Protocol | ClassBase::Generic => C::unsatisfiable(db), ClassBase::Class(base) => match (base, other) { - (ClassType::NonGeneric(base), ClassType::NonGeneric(other)) => base == other, + (ClassType::NonGeneric(base), ClassType::NonGeneric(other)) => { + C::from_bool(db, base == other) + } (ClassType::Generic(base), ClassType::Generic(other)) => { - base.origin(db) == other.origin(db) - && base.specialization(db).has_relation_to_impl( + C::from_bool(db, base.origin(db) == other.origin(db)).and(db, || { + base.specialization(db).has_relation_to_impl( db, other.specialization(db), relation, visitor, ) + }) } (ClassType::Generic(_), ClassType::NonGeneric(_)) - | (ClassType::NonGeneric(_), ClassType::Generic(_)) => false, + | (ClassType::NonGeneric(_), ClassType::Generic(_)) => C::unsatisfiable(db), }, ClassBase::TypedDict => { // TODO: Implement subclassing and assignability for TypedDicts. - true + C::always_satisfiable(db) } } }) } - pub(super) fn is_equivalent_to(self, db: &'db dyn Db, other: ClassType<'db>) -> bool { + pub(super) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: ClassType<'db>, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { if self == other { - return true; + return C::always_satisfiable(db); } match (self, other) { // A non-generic class is never equivalent to a generic class. // Two non-generic classes are only equivalent if they are equal (handled above). - (ClassType::NonGeneric(_), _) | (_, ClassType::NonGeneric(_)) => false, + (ClassType::NonGeneric(_), _) | (_, ClassType::NonGeneric(_)) => C::unsatisfiable(db), (ClassType::Generic(this), ClassType::Generic(other)) => { - this.origin(db) == other.origin(db) - && this - .specialization(db) - .is_equivalent_to(db, other.specialization(db)) + C::from_bool(db, this.origin(db) == other.origin(db)).and(db, || { + this.specialization(db).is_equivalent_to_impl( + db, + other.specialization(db), + visitor, + ) + }) } } } @@ -1613,6 +1638,15 @@ impl<'db> ClassLiteral<'db> { .contains(&ClassBase::Class(other)) } + pub(super) fn when_subclass_of>( + self, + db: &'db dyn Db, + specialization: Option>, + other: ClassType<'db>, + ) -> C { + C::from_bool(db, self.is_subclass_of(db, specialization, other)) + } + /// Return `true` if this class constitutes a typed dict specification (inherits from /// `typing.TypedDict`, either directly or indirectly). #[salsa::tracked( @@ -4186,6 +4220,14 @@ impl KnownClass { .is_ok_and(|class| class.is_subclass_of(db, None, other)) } + pub(super) fn when_subclass_of<'db, C: Constraints<'db>>( + self, + db: &'db dyn Db, + other: ClassType<'db>, + ) -> C { + C::from_bool(db, self.is_subclass_of(db, other)) + } + /// Return the module in which we should look up the definition for this class fn canonical_module(self, db: &dyn Db) -> KnownModule { match self { diff --git a/crates/ty_python_semantic/src/types/class_base.rs b/crates/ty_python_semantic/src/types/class_base.rs index e8a5fd1e41e8f..2d05ca04cebce 100644 --- a/crates/ty_python_semantic/src/types/class_base.rs +++ b/crates/ty_python_semantic/src/types/class_base.rs @@ -3,8 +3,7 @@ use crate::types::generics::Specialization; use crate::types::tuple::TupleType; use crate::types::{ ApplyTypeMappingVisitor, ClassLiteral, ClassType, DynamicType, KnownClass, KnownInstanceType, - MroError, MroIterator, NormalizedVisitor, SpecialFormType, Type, TypeMapping, TypeTransformer, - todo_type, + MroError, MroIterator, NormalizedVisitor, SpecialFormType, Type, TypeMapping, todo_type, }; /// Enumeration of the possible kinds of types we allow in class bases. @@ -292,7 +291,7 @@ impl<'db> ClassBase<'db> { self.apply_type_mapping_impl( db, &TypeMapping::Specialization(specialization), - &TypeTransformer::default(), + &ApplyTypeMappingVisitor::default(), ) } else { self diff --git a/crates/ty_python_semantic/src/types/constraints.rs b/crates/ty_python_semantic/src/types/constraints.rs new file mode 100644 index 0000000000000..ddf003adf3f31 --- /dev/null +++ b/crates/ty_python_semantic/src/types/constraints.rs @@ -0,0 +1,184 @@ +//! Constraints under which type properties hold +//! +//! For "concrete" types (which contain no type variables), type properties like assignability have +//! simple answers: one type is either assignable to another type, or it isn't. (The _rules_ for +//! comparing two particular concrete types can be rather complex, but the _answer_ is a simple +//! "yes" or "no".) +//! +//! These properties are more complex when type variables are involved, because there are (usually) +//! many different concrete types that a typevar can be specialized to, and the type property might +//! hold for some specializations, but not for others. That means that for types that include +//! typevars, "Is this type assignable to another?" no longer makes sense as a question. The better +//! question is: "Under what constraints is this type assignable to another?". +//! +//! This module provides the machinery for representing the "under what constraints" part of that +//! question. An individual constraint restricts the specialization of a single typevar to be within a +//! particular lower and upper bound. You can then build up more complex constraint sets using +//! union, intersection, and negation operations (just like types themselves). +//! +//! NOTE: This module is currently in a transitional state: we've added a trait that our constraint +//! set implementations will conform to, and updated all of our type property implementations to +//! work on any impl of that trait. But the only impl we have right now is `bool`, which means that +//! we are still not tracking the full detail as promised in the description above. (`bool` is a +//! perfectly fine impl, but it can generate false positives when you have to break down a +//! particular assignability check into subchecks: each subcheck might say "yes", but technically +//! under conflicting constraints, which a single `bool` can't track.) Soon we will add a proper +//! constraint set implementation, and the `bool` impl of the trait (and possibly the trait itself) +//! will go away. + +use crate::Db; + +/// Encodes the constraints under which a type property (e.g. assignability) holds. +pub(crate) trait Constraints<'db>: Clone + Sized { + /// Returns a constraint set that never holds + fn unsatisfiable(db: &'db dyn Db) -> Self; + + /// Returns a constraint set that always holds + fn always_satisfiable(db: &'db dyn Db) -> Self; + + /// Returns whether this constraint set never holds + fn is_never_satisfied(&self, db: &'db dyn Db) -> bool; + + /// Returns whether this constraint set always holds + fn is_always_satisfied(&self, db: &'db dyn Db) -> bool; + + /// Updates this constraint set to hold the union of itself and another constraint set. + fn union(&mut self, db: &'db dyn Db, other: Self) -> &Self; + + /// Updates this constraint set to hold the intersection of itself and another constraint set. + fn intersect(&mut self, db: &'db dyn Db, other: Self) -> &Self; + + /// Returns the negation of this constraint set. + fn negate(self, db: &'db dyn Db) -> Self; + + /// Returns a constraint set representing a boolean condition. + fn from_bool(db: &'db dyn Db, b: bool) -> Self { + if b { + Self::always_satisfiable(db) + } else { + Self::unsatisfiable(db) + } + } + + /// Returns the intersection of this constraint set and another. The other constraint set is + /// provided as a thunk, to implement short-circuiting: the thunk is not forced if the + /// constraint set is already saturated. + fn and(mut self, db: &'db dyn Db, other: impl FnOnce() -> Self) -> Self { + if !self.is_never_satisfied(db) { + self.intersect(db, other()); + } + self + } + + /// Returns the union of this constraint set and another. The other constraint set is provided + /// as a thunk, to implement short-circuiting: the thunk is not forced if the constraint set is + /// already saturated. + fn or(mut self, db: &'db dyn Db, other: impl FnOnce() -> Self) -> Self { + if !self.is_always_satisfied(db) { + self.union(db, other()); + } + self + } +} + +impl<'db> Constraints<'db> for bool { + fn unsatisfiable(_db: &'db dyn Db) -> Self { + false + } + + fn always_satisfiable(_db: &'db dyn Db) -> Self { + true + } + + fn is_never_satisfied(&self, _db: &'db dyn Db) -> bool { + !*self + } + + fn is_always_satisfied(&self, _db: &'db dyn Db) -> bool { + *self + } + + fn union(&mut self, _db: &'db dyn Db, other: Self) -> &Self { + *self = *self || other; + self + } + + fn intersect(&mut self, _db: &'db dyn Db, other: Self) -> &Self { + *self = *self && other; + self + } + + fn negate(self, _db: &'db dyn Db) -> Self { + !self + } +} + +/// An extension trait for building constraint sets from [`Option`] values. +pub(crate) trait OptionConstraintsExtension { + /// Returns [`always_satisfiable`][Constraints::always_satisfiable] if the option is `None`; + /// otherwise applies a function to determine under what constraints the value inside of it + /// holds. + fn when_none_or<'db, C: Constraints<'db>>(self, db: &'db dyn Db, f: impl FnOnce(T) -> C) -> C; + + /// Returns [`unsatisfiable`][Constraints::unsatisfiable] if the option is `None`; otherwise + /// applies a function to determine under what constraints the value inside of it holds. + fn when_some_and<'db, C: Constraints<'db>>(self, db: &'db dyn Db, f: impl FnOnce(T) -> C) -> C; +} + +impl OptionConstraintsExtension for Option { + fn when_none_or<'db, C: Constraints<'db>>(self, db: &'db dyn Db, f: impl FnOnce(T) -> C) -> C { + match self { + Some(value) => f(value), + None => C::always_satisfiable(db), + } + } + + fn when_some_and<'db, C: Constraints<'db>>(self, db: &'db dyn Db, f: impl FnOnce(T) -> C) -> C { + match self { + Some(value) => f(value), + None => C::unsatisfiable(db), + } + } +} + +/// An extension trait for building constraint sets from an [`Iterator`]. +pub(crate) trait IteratorConstraintsExtension { + /// Returns the constraints under which any element of the iterator holds. + /// + /// This method short-circuits; if we encounter any element that + /// [`is_always_satisfied`][Constraints::is_always_satisfied] true, then the overall result + /// must be as well, and we stop consuming elements from the iterator. + fn when_any<'db, C: Constraints<'db>>(self, db: &'db dyn Db, f: impl FnMut(T) -> C) -> C; + + /// Returns the constraints under which every element of the iterator holds. + /// + /// This method short-circuits; if we encounter any element that + /// [`is_never_satisfied`][Constraints::is_never_satisfied] true, then the overall result must + /// be as well, and we stop consuming elements from the iterator. + fn when_all<'db, C: Constraints<'db>>(self, db: &'db dyn Db, f: impl FnMut(T) -> C) -> C; +} + +impl IteratorConstraintsExtension for I +where + I: Iterator, +{ + fn when_any<'db, C: Constraints<'db>>(self, db: &'db dyn Db, mut f: impl FnMut(T) -> C) -> C { + let mut result = C::unsatisfiable(db); + for child in self { + if result.union(db, f(child)).is_always_satisfied(db) { + return result; + } + } + result + } + + fn when_all<'db, C: Constraints<'db>>(self, db: &'db dyn Db, mut f: impl FnMut(T) -> C) -> C { + let mut result = C::always_satisfiable(db); + for child in self { + if result.intersect(db, f(child)).is_never_satisfied(db) { + return result; + } + } + result + } +} diff --git a/crates/ty_python_semantic/src/types/cyclic.rs b/crates/ty_python_semantic/src/types/cyclic.rs index 27a201143b54a..979be6ae58bce 100644 --- a/crates/ty_python_semantic/src/types/cyclic.rs +++ b/crates/ty_python_semantic/src/types/cyclic.rs @@ -41,7 +41,7 @@ impl Default for TypeTransformer<'_, Tag> { } } -pub(crate) type PairVisitor<'db, Tag> = CycleDetector, Type<'db>), bool>; +pub(crate) type PairVisitor<'db, Tag, C> = CycleDetector, Type<'db>), C>; #[derive(Debug)] pub(crate) struct CycleDetector { @@ -63,7 +63,7 @@ pub(crate) struct CycleDetector { _tag: PhantomData, } -impl CycleDetector { +impl CycleDetector { pub(crate) fn new(fallback: R) -> Self { CycleDetector { seen: RefCell::new(FxIndexSet::default()), @@ -75,17 +75,17 @@ impl CycleDetector { pub(crate) fn visit(&self, item: T, func: impl FnOnce() -> R) -> R { if let Some(val) = self.cache.borrow().get(&item) { - return *val; + return val.clone(); } // We hit a cycle - if !self.seen.borrow_mut().insert(item) { - return self.fallback; + if !self.seen.borrow_mut().insert(item.clone()) { + return self.fallback.clone(); } let ret = func(); self.seen.borrow_mut().pop(); - self.cache.borrow_mut().insert(item, ret); + self.cache.borrow_mut().insert(item, ret.clone()); ret } diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 9a9c10ef75c30..dde034efc4587 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -65,6 +65,7 @@ use crate::semantic_index::definition::Definition; use crate::semantic_index::scope::ScopeId; use crate::semantic_index::semantic_index; use crate::types::call::{Binding, CallArguments}; +use crate::types::constraints::Constraints; use crate::types::context::InferContext; use crate::types::diagnostic::{ REDUNDANT_CAST, STATIC_ASSERT_ERROR, TYPE_ASSERTION_FAILURE, @@ -77,8 +78,9 @@ use crate::types::signatures::{CallableSignature, Signature}; use crate::types::visitor::any_over_type; use crate::types::{ BoundMethodType, BoundTypeVarInstance, CallableType, ClassBase, ClassLiteral, ClassType, - DeprecatedInstance, DynamicType, KnownClass, NormalizedVisitor, Truthiness, Type, TypeMapping, - TypeRelation, TypeTransformer, UnionBuilder, all_members, walk_type_mapping, + DeprecatedInstance, DynamicType, HasRelationToVisitor, IsEquivalentVisitor, KnownClass, + NormalizedVisitor, Truthiness, Type, TypeMapping, TypeRelation, UnionBuilder, all_members, + walk_type_mapping, }; use crate::{Db, FxOrderSet, ModuleName, resolve_module}; @@ -858,15 +860,16 @@ impl<'db> FunctionType<'db> { BoundMethodType::new(db, self, self_instance) } - pub(crate) fn has_relation_to( + pub(crate) fn has_relation_to_impl>( self, db: &'db dyn Db, other: Self, relation: TypeRelation, - ) -> bool { + _visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match relation { - TypeRelation::Subtyping => self.is_subtype_of(db, other), - TypeRelation::Assignability => self.is_assignable_to(db, other), + TypeRelation::Subtyping => C::from_bool(db, self.is_subtype_of(db, other)), + TypeRelation::Assignability => C::from_bool(db, self.is_assignable_to(db, other)), } } @@ -895,16 +898,21 @@ impl<'db> FunctionType<'db> { && self.signature(db).is_assignable_to(db, other.signature(db)) } - pub(crate) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { + pub(crate) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { if self.normalized(db) == other.normalized(db) { - return true; + return C::always_satisfiable(db); } if self.literal(db) != other.literal(db) { - return false; + return C::unsatisfiable(db); } let self_signature = self.signature(db); let other_signature = other.signature(db); - self_signature.is_equivalent_to(db, other_signature) + self_signature.is_equivalent_to_impl(db, other_signature, visitor) } pub(crate) fn find_legacy_typevars( @@ -920,7 +928,7 @@ impl<'db> FunctionType<'db> { } pub(crate) fn normalized(self, db: &'db dyn Db) -> Self { - self.normalized_impl(db, &TypeTransformer::default()) + self.normalized_impl(db, &NormalizedVisitor::default()) } pub(crate) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index 049b953949445..2a686ef80a4f5 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -9,13 +9,14 @@ use crate::semantic_index::definition::Definition; use crate::semantic_index::scope::{FileScopeId, NodeWithScopeKind}; use crate::types::class::ClassType; use crate::types::class_base::ClassBase; +use crate::types::constraints::Constraints; use crate::types::infer::infer_definition_types; use crate::types::instance::{Protocol, ProtocolInstanceType}; use crate::types::signatures::{Parameter, Parameters, Signature}; use crate::types::tuple::{TupleSpec, TupleType, walk_tuple_type}; use crate::types::{ - ApplyTypeMappingVisitor, BoundTypeVarInstance, HasRelationToVisitor, KnownClass, - KnownInstanceType, NormalizedVisitor, Type, TypeMapping, TypeRelation, TypeTransformer, + ApplyTypeMappingVisitor, BoundTypeVarInstance, HasRelationToVisitor, IsEquivalentVisitor, + KnownClass, KnownInstanceType, NormalizedVisitor, Type, TypeMapping, TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarVariance, UnionType, binding_type, declaration_type, }; @@ -471,7 +472,7 @@ impl<'db> Specialization<'db> { db: &'db dyn Db, type_mapping: &TypeMapping<'a, 'db>, ) -> Self { - self.apply_type_mapping_impl(db, type_mapping, &TypeTransformer::default()) + self.apply_type_mapping_impl(db, type_mapping, &ApplyTypeMappingVisitor::default()) } pub(crate) fn apply_type_mapping_impl<'a>( @@ -560,16 +561,16 @@ impl<'db> Specialization<'db> { Specialization::new(db, self.generic_context(db), types, tuple_inner) } - pub(crate) fn has_relation_to_impl( + pub(crate) fn has_relation_to_impl>( self, db: &'db dyn Db, other: Self, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { let generic_context = self.generic_context(db); if generic_context != other.generic_context(db) { - return false; + return C::unsatisfiable(db); } if let (Some(self_tuple), Some(other_tuple)) = (self.tuple_inner(db), other.tuple_inner(db)) @@ -577,6 +578,7 @@ impl<'db> Specialization<'db> { return self_tuple.has_relation_to_impl(db, other_tuple, relation, visitor); } + let mut result = C::always_satisfiable(db); for ((bound_typevar, self_type), other_type) in (generic_context.variables(db).into_iter()) .zip(self.types(db)) .zip(other.types(db)) @@ -584,7 +586,7 @@ impl<'db> Specialization<'db> { if self_type.is_dynamic() || other_type.is_dynamic() { match relation { TypeRelation::Assignability => continue, - TypeRelation::Subtyping => return false, + TypeRelation::Subtyping => return C::unsatisfiable(db), } } @@ -596,11 +598,12 @@ impl<'db> Specialization<'db> { // - bivariant: skip, can't make subtyping/assignability false let compatible = match bound_typevar.variance(db) { TypeVarVariance::Invariant => match relation { - TypeRelation::Subtyping => self_type.is_equivalent_to(db, *other_type), - TypeRelation::Assignability => { + TypeRelation::Subtyping => self_type.when_equivalent_to(db, *other_type), + TypeRelation::Assignability => C::from_bool( + db, self_type.is_assignable_to(db, *other_type) - && other_type.is_assignable_to(db, *self_type) - } + && other_type.is_assignable_to(db, *self_type), + ), }, TypeVarVariance::Covariant => { self_type.has_relation_to_impl(db, *other_type, relation, visitor) @@ -608,22 +611,28 @@ impl<'db> Specialization<'db> { TypeVarVariance::Contravariant => { other_type.has_relation_to_impl(db, *self_type, relation, visitor) } - TypeVarVariance::Bivariant => true, + TypeVarVariance::Bivariant => C::always_satisfiable(db), }; - if !compatible { - return false; + if result.intersect(db, compatible).is_never_satisfied(db) { + return result; } } - true + result } - pub(crate) fn is_equivalent_to(self, db: &'db dyn Db, other: Specialization<'db>) -> bool { + pub(crate) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Specialization<'db>, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { let generic_context = self.generic_context(db); if generic_context != other.generic_context(db) { - return false; + return C::unsatisfiable(db); } + let mut result = C::always_satisfiable(db); for ((bound_typevar, self_type), other_type) in (generic_context.variables(db).into_iter()) .zip(self.types(db)) .zip(other.types(db)) @@ -637,25 +646,28 @@ impl<'db> Specialization<'db> { let compatible = match bound_typevar.variance(db) { TypeVarVariance::Invariant | TypeVarVariance::Covariant - | TypeVarVariance::Contravariant => self_type.is_equivalent_to(db, *other_type), - TypeVarVariance::Bivariant => true, + | TypeVarVariance::Contravariant => { + self_type.is_equivalent_to_impl(db, *other_type, visitor) + } + TypeVarVariance::Bivariant => C::always_satisfiable(db), }; - if !compatible { - return false; + if result.intersect(db, compatible).is_never_satisfied(db) { + return result; } } match (self.tuple_inner(db), other.tuple_inner(db)) { - (Some(_), None) | (None, Some(_)) => return false, + (Some(_), None) | (None, Some(_)) => return C::unsatisfiable(db), (None, None) => {} (Some(self_tuple), Some(other_tuple)) => { - if !self_tuple.is_equivalent_to(db, other_tuple) { - return false; + let compatible = self_tuple.is_equivalent_to_impl(db, other_tuple, visitor); + if result.intersect(db, compatible).is_never_satisfied(db) { + return result; } } } - true + result } pub(crate) fn find_legacy_typevars( diff --git a/crates/ty_python_semantic/src/types/instance.rs b/crates/ty_python_semantic/src/types/instance.rs index eb6978af2232a..8c3cdbb786468 100644 --- a/crates/ty_python_semantic/src/types/instance.rs +++ b/crates/ty_python_semantic/src/types/instance.rs @@ -7,12 +7,13 @@ use super::protocol_class::ProtocolInterface; use super::{BoundTypeVarInstance, ClassType, KnownClass, SubclassOfType, Type, TypeVarVariance}; use crate::place::PlaceAndQualifiers; use crate::semantic_index::definition::Definition; +use crate::types::constraints::{Constraints, IteratorConstraintsExtension}; use crate::types::enums::is_single_member_enum; use crate::types::protocol_class::walk_protocol_interface; use crate::types::tuple::{TupleSpec, TupleType}; use crate::types::{ ApplyTypeMappingVisitor, ClassBase, DynamicType, HasRelationToVisitor, IsDisjointVisitor, - NormalizedVisitor, TypeMapping, TypeRelation, TypeTransformer, VarianceInferable, + IsEquivalentVisitor, NormalizedVisitor, TypeMapping, TypeRelation, VarianceInferable, }; use crate::{Db, FxOrderSet}; @@ -92,23 +93,26 @@ impl<'db> Type<'db> { SynthesizedProtocolType::new( db, ProtocolInterface::with_property_members(db, members), - &TypeTransformer::default(), + &NormalizedVisitor::default(), ), )) } /// Return `true` if `self` conforms to the interface described by `protocol`. - pub(super) fn satisfies_protocol( + pub(super) fn satisfies_protocol>( self, db: &'db dyn Db, protocol: ProtocolInstanceType<'db>, relation: TypeRelation, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { protocol .inner .interface(db) .members(db) - .all(|member| member.is_satisfied_by(db, self, relation)) + .when_all(db, |member| { + member.is_satisfied_by(db, self, relation, visitor) + }) } } @@ -264,13 +268,13 @@ impl<'db> NominalInstanceType<'db> { } } - pub(super) fn has_relation_to_impl( + pub(super) fn has_relation_to_impl>( self, db: &'db dyn Db, other: Self, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match (self.0, other.0) { ( NominalInstanceInner::ExactTuple(tuple1), @@ -282,35 +286,45 @@ impl<'db> NominalInstanceType<'db> { } } - pub(super) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { + pub(super) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { match (self.0, other.0) { ( NominalInstanceInner::ExactTuple(tuple1), NominalInstanceInner::ExactTuple(tuple2), - ) => tuple1.is_equivalent_to(db, tuple2), + ) => tuple1.is_equivalent_to_impl(db, tuple2, visitor), (NominalInstanceInner::NonTuple(class1), NominalInstanceInner::NonTuple(class2)) => { - class1.is_equivalent_to(db, class2) + class1.is_equivalent_to_impl(db, class2, visitor) } - _ => false, + _ => C::unsatisfiable(db), } } - pub(super) fn is_disjoint_from_impl( + pub(super) fn is_disjoint_from_impl>( self, db: &'db dyn Db, other: Self, - visitor: &IsDisjointVisitor<'db>, - ) -> bool { + visitor: &IsDisjointVisitor<'db, C>, + ) -> C { + let mut result = C::unsatisfiable(db); if let Some(self_spec) = self.tuple_spec(db) { if let Some(other_spec) = other.tuple_spec(db) { - if self_spec.is_disjoint_from_impl(db, &other_spec, visitor) { - return true; + let compatible = self_spec.is_disjoint_from_impl(db, &other_spec, visitor); + if result.union(db, compatible).is_always_satisfied(db) { + return result; } } } - !self - .class(db) - .could_coexist_in_mro_with(db, other.class(db)) + result.or(db, || { + C::from_bool( + db, + !(self.class(db)).could_coexist_in_mro_with(db, other.class(db)), + ) + }) } pub(super) fn is_singleton(self, db: &'db dyn Db) -> bool { @@ -479,7 +493,7 @@ impl<'db> ProtocolInstanceType<'db> { /// /// See [`Type::normalized`] for more details. pub(super) fn normalized(self, db: &'db dyn Db) -> Type<'db> { - self.normalized_impl(db, &TypeTransformer::default()) + self.normalized_impl(db, &NormalizedVisitor::default()) } /// Return a "normalized" version of this `Protocol` type. @@ -491,7 +505,12 @@ impl<'db> ProtocolInstanceType<'db> { visitor: &NormalizedVisitor<'db>, ) -> Type<'db> { let object = Type::object(db); - if object.satisfies_protocol(db, self, TypeRelation::Subtyping) { + if object.satisfies_protocol( + db, + self, + TypeRelation::Subtyping, + &HasRelationToVisitor::new(true), + ) { return object; } match self.inner { @@ -505,30 +524,36 @@ impl<'db> ProtocolInstanceType<'db> { /// Return `true` if this protocol type has the given type relation to the protocol `other`. /// /// TODO: consider the types of the members as well as their existence - pub(super) fn has_relation_to( + pub(super) fn has_relation_to_impl>( self, db: &'db dyn Db, other: Self, _relation: TypeRelation, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { other .inner .interface(db) - .is_sub_interface_of(db, self.inner.interface(db)) + .is_sub_interface_of(db, self.inner.interface(db), visitor) } /// Return `true` if this protocol type is equivalent to the protocol `other`. /// /// TODO: consider the types of the members as well as their existence - pub(super) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { + pub(super) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + _visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { if self == other { - return true; + return C::always_satisfiable(db); } let self_normalized = self.normalized(db); if self_normalized == Type::ProtocolInstance(other) { - return true; + return C::always_satisfiable(db); } - self_normalized == other.normalized(db) + C::from_bool(db, self_normalized == other.normalized(db)) } /// Return `true` if this protocol type is disjoint from the protocol `other`. @@ -536,13 +561,13 @@ impl<'db> ProtocolInstanceType<'db> { /// TODO: a protocol `X` is disjoint from a protocol `Y` if `X` and `Y` /// have a member with the same name but disjoint types #[expect(clippy::unused_self)] - pub(super) fn is_disjoint_from_impl( + pub(super) fn is_disjoint_from_impl>( self, - _db: &'db dyn Db, + db: &'db dyn Db, _other: Self, - _visitor: &IsDisjointVisitor<'db>, - ) -> bool { - false + _visitor: &IsDisjointVisitor<'db, C>, + ) -> C { + C::unsatisfiable(db) } pub(crate) fn instance_member(self, db: &'db dyn Db, name: &str) -> PlaceAndQualifiers<'db> { diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index d910bdc1ce2ed..6bb6a16ac4027 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -16,9 +16,10 @@ use crate::{ place::{Boundness, Place, PlaceAndQualifiers, place_from_bindings, place_from_declarations}, semantic_index::{definition::Definition, use_def_map}, types::{ - BoundTypeVarInstance, CallableType, ClassBase, ClassLiteral, IsDisjointVisitor, - KnownFunction, NormalizedVisitor, PropertyInstanceType, Signature, Type, TypeMapping, - TypeQualifiers, TypeRelation, TypeTransformer, VarianceInferable, + BoundTypeVarInstance, CallableType, ClassBase, ClassLiteral, HasRelationToVisitor, + IsDisjointVisitor, KnownFunction, NormalizedVisitor, PropertyInstanceType, Signature, Type, + TypeMapping, TypeQualifiers, TypeRelation, VarianceInferable, + constraints::{Constraints, IteratorConstraintsExtension}, signatures::{Parameter, Parameters}, }, }; @@ -219,10 +220,17 @@ impl<'db> ProtocolInterface<'db> { /// Return `true` if if all members on `self` are also members of `other`. /// /// TODO: this method should consider the types of the members as well as their names. - pub(super) fn is_sub_interface_of(self, db: &'db dyn Db, other: Self) -> bool { - self.inner(db) - .keys() - .all(|member_name| other.inner(db).contains_key(member_name)) + pub(super) fn is_sub_interface_of>( + self, + db: &'db dyn Db, + other: Self, + _visitor: &HasRelationToVisitor<'db, C>, + ) -> C { + // TODO: This could just return a bool as written, but this form is what will be needed to + // combine the constraints when we do assignability checks on each member. + self.inner(db).keys().when_all(db, |member_name| { + C::from_bool(db, other.inner(db).contains_key(member_name)) + }) } pub(super) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { @@ -318,7 +326,7 @@ pub(super) struct ProtocolMemberData<'db> { impl<'db> ProtocolMemberData<'db> { fn normalized(&self, db: &'db dyn Db) -> Self { - self.normalized_impl(db, &TypeTransformer::default()) + self.normalized_impl(db, &NormalizedVisitor::default()) } fn normalized_impl(&self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { @@ -504,46 +512,56 @@ impl<'a, 'db> ProtocolMember<'a, 'db> { } } - pub(super) fn has_disjoint_type_from( + pub(super) fn has_disjoint_type_from>( &self, db: &'db dyn Db, other: Type<'db>, - visitor: &IsDisjointVisitor<'db>, - ) -> bool { + visitor: &IsDisjointVisitor<'db, C>, + ) -> C { match &self.kind { // TODO: implement disjointness for property/method members as well as attribute members - ProtocolMemberKind::Property(_) | ProtocolMemberKind::Method(_) => false, + ProtocolMemberKind::Property(_) | ProtocolMemberKind::Method(_) => C::unsatisfiable(db), ProtocolMemberKind::Other(ty) => ty.is_disjoint_from_impl(db, other, visitor), } } /// Return `true` if `other` contains an attribute/method/property that satisfies /// the part of the interface defined by this protocol member. - pub(super) fn is_satisfied_by( + pub(super) fn is_satisfied_by>( &self, db: &'db dyn Db, other: Type<'db>, relation: TypeRelation, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match &self.kind { // TODO: consider the types of the attribute on `other` for method members - ProtocolMemberKind::Method(_) => matches!( - other.to_meta_type(db).member(db, self.name).place, - Place::Type(_, Boundness::Bound) + ProtocolMemberKind::Method(_) => C::from_bool( + db, + matches!( + other.to_meta_type(db).member(db, self.name).place, + Place::Type(_, Boundness::Bound) + ), ), // TODO: consider the types of the attribute on `other` for property members - ProtocolMemberKind::Property(_) => matches!( - other.member(db, self.name).place, - Place::Type(_, Boundness::Bound) + ProtocolMemberKind::Property(_) => C::from_bool( + db, + matches!( + other.member(db, self.name).place, + Place::Type(_, Boundness::Bound) + ), ), ProtocolMemberKind::Other(member_type) => { let Place::Type(attribute_type, Boundness::Bound) = other.member(db, self.name).place else { - return false; + return C::unsatisfiable(db); }; - member_type.has_relation_to(db, attribute_type, relation) - && attribute_type.has_relation_to(db, *member_type, relation) + member_type + .has_relation_to_impl(db, attribute_type, relation, visitor) + .and(db, || { + attribute_type.has_relation_to_impl(db, *member_type, relation, visitor) + }) } } } diff --git a/crates/ty_python_semantic/src/types/signatures.rs b/crates/ty_python_semantic/src/types/signatures.rs index 4c80c375717e3..478b75b057134 100644 --- a/crates/ty_python_semantic/src/types/signatures.rs +++ b/crates/ty_python_semantic/src/types/signatures.rs @@ -17,10 +17,11 @@ use smallvec::{SmallVec, smallvec_inline}; use super::{DynamicType, Type, TypeVarVariance, definition_expression_type}; use crate::semantic_index::definition::Definition; +use crate::types::constraints::{Constraints, IteratorConstraintsExtension}; use crate::types::generics::{GenericContext, walk_generic_context}; use crate::types::{ - BindingContext, BoundTypeVarInstance, KnownClass, NormalizedVisitor, TypeMapping, TypeRelation, - VarianceInferable, todo_type, + BindingContext, BoundTypeVarInstance, HasRelationToVisitor, IsEquivalentVisitor, KnownClass, + NormalizedVisitor, TypeMapping, TypeRelation, VarianceInferable, todo_type, }; use crate::{Db, FxOrderSet}; use ruff_python_ast::{self as ast, name::Name}; @@ -112,27 +113,19 @@ impl<'db> CallableSignature<'db> { } } - pub(crate) fn has_relation_to( - &self, - db: &'db dyn Db, - other: &Self, - relation: TypeRelation, - ) -> bool { - match relation { - TypeRelation::Subtyping => self.is_subtype_of(db, other), - TypeRelation::Assignability => self.is_assignable_to(db, other), - } - } - /// Check whether this callable type is a subtype of another callable type. /// /// See [`Type::is_subtype_of`] for more details. pub(crate) fn is_subtype_of(&self, db: &'db dyn Db, other: &Self) -> bool { - Self::has_relation_to_impl( + self.is_subtype_of_impl(db, other) + } + + fn is_subtype_of_impl>(&self, db: &'db dyn Db, other: &Self) -> C { + self.has_relation_to_impl( db, - &self.overloads, - &other.overloads, + other, TypeRelation::Subtyping, + &HasRelationToVisitor::new(C::always_satisfiable(db)), ) } @@ -140,55 +133,69 @@ impl<'db> CallableSignature<'db> { /// /// See [`Type::is_assignable_to`] for more details. pub(crate) fn is_assignable_to(&self, db: &'db dyn Db, other: &Self) -> bool { - Self::has_relation_to_impl( + self.has_relation_to_impl( db, - &self.overloads, - &other.overloads, + other, TypeRelation::Assignability, + &HasRelationToVisitor::new(true), ) } + pub(crate) fn has_relation_to_impl>( + &self, + db: &'db dyn Db, + other: &Self, + relation: TypeRelation, + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { + Self::has_relation_to_inner(db, &self.overloads, &other.overloads, relation, visitor) + } + /// Implementation of subtyping and assignability between two, possible overloaded, callable /// types. - fn has_relation_to_impl( + fn has_relation_to_inner>( db: &'db dyn Db, self_signatures: &[Signature<'db>], other_signatures: &[Signature<'db>], relation: TypeRelation, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match (self_signatures, other_signatures) { ([self_signature], [other_signature]) => { // Base case: both callable types contain a single signature. - self_signature.has_relation_to(db, other_signature, relation) + self_signature.has_relation_to_impl(db, other_signature, relation, visitor) } // `self` is possibly overloaded while `other` is definitely not overloaded. - (_, [_]) => self_signatures.iter().any(|self_signature| { - Self::has_relation_to_impl( + (_, [_]) => self_signatures.iter().when_any(db, |self_signature| { + Self::has_relation_to_inner( db, std::slice::from_ref(self_signature), other_signatures, relation, + visitor, ) }), // `self` is definitely not overloaded while `other` is possibly overloaded. - ([_], _) => other_signatures.iter().all(|other_signature| { - Self::has_relation_to_impl( + ([_], _) => other_signatures.iter().when_all(db, |other_signature| { + Self::has_relation_to_inner( db, self_signatures, std::slice::from_ref(other_signature), relation, + visitor, ) }), // `self` is definitely overloaded while `other` is possibly overloaded. - (_, _) => other_signatures.iter().all(|other_signature| { - Self::has_relation_to_impl( + (_, _) => other_signatures.iter().when_all(db, |other_signature| { + Self::has_relation_to_inner( db, self_signatures, std::slice::from_ref(other_signature), relation, + visitor, ) }), } @@ -197,18 +204,24 @@ impl<'db> CallableSignature<'db> { /// Check whether this callable type is equivalent to another callable type. /// /// See [`Type::is_equivalent_to`] for more details. - pub(crate) fn is_equivalent_to(&self, db: &'db dyn Db, other: &Self) -> bool { + pub(crate) fn is_equivalent_to_impl>( + &self, + db: &'db dyn Db, + other: &Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { match (self.overloads.as_slice(), other.overloads.as_slice()) { ([self_signature], [other_signature]) => { // Common case: both callable types contain a single signature, use the custom // equivalence check instead of delegating it to the subtype check. - self_signature.is_equivalent_to(db, other_signature) + self_signature.is_equivalent_to_impl(db, other_signature, visitor) } (_, _) => { if self == other { - return true; + return C::always_satisfiable(db); } - self.is_subtype_of(db, other) && other.is_subtype_of(db, self) + self.is_subtype_of_impl::(db, other) + .and(db, || other.is_subtype_of_impl(db, self)) } } } @@ -498,23 +511,31 @@ impl<'db> Signature<'db> { /// Return `true` if `self` has exactly the same set of possible static materializations as /// `other` (if `self` represents the same set of possible sets of possible runtime objects as /// `other`). - pub(crate) fn is_equivalent_to(&self, db: &'db dyn Db, other: &Signature<'db>) -> bool { - let check_types = |self_type: Option>, other_type: Option>| { - self_type - .unwrap_or(Type::unknown()) - .is_equivalent_to(db, other_type.unwrap_or(Type::unknown())) + pub(crate) fn is_equivalent_to_impl>( + &self, + db: &'db dyn Db, + other: &Signature<'db>, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { + let mut result = C::always_satisfiable(db); + let mut check_types = |self_type: Option>, other_type: Option>| { + let self_type = self_type.unwrap_or(Type::unknown()); + let other_type = other_type.unwrap_or(Type::unknown()); + !result + .intersect(db, self_type.is_equivalent_to_impl(db, other_type, visitor)) + .is_never_satisfied(db) }; if self.parameters.is_gradual() != other.parameters.is_gradual() { - return false; + return C::unsatisfiable(db); } if self.parameters.len() != other.parameters.len() { - return false; + return C::unsatisfiable(db); } if !check_types(self.return_ty, other.return_ty) { - return false; + return result; } for (self_parameter, other_parameter) in self.parameters.iter().zip(&other.parameters) { @@ -558,27 +579,28 @@ impl<'db> Signature<'db> { (ParameterKind::KeywordVariadic { .. }, ParameterKind::KeywordVariadic { .. }) => {} - _ => return false, + _ => return C::unsatisfiable(db), } if !check_types( self_parameter.annotated_type(), other_parameter.annotated_type(), ) { - return false; + return result; } } - true + result } /// Implementation of subtyping and assignability for signature. - fn has_relation_to( + fn has_relation_to_impl>( &self, db: &'db dyn Db, other: &Signature<'db>, relation: TypeRelation, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { /// A helper struct to zip two slices of parameters together that provides control over the /// two iterators individually. It also keeps track of the current parameter in each /// iterator. @@ -640,17 +662,18 @@ impl<'db> Signature<'db> { } } - let check_types = |type1: Option>, type2: Option>| { - type1.unwrap_or(Type::unknown()).has_relation_to( - db, - type2.unwrap_or(Type::unknown()), - relation, - ) + let mut result = C::always_satisfiable(db); + let mut check_types = |type1: Option>, type2: Option>| { + let type1 = type1.unwrap_or(Type::unknown()); + let type2 = type2.unwrap_or(Type::unknown()); + !result + .intersect(db, type1.has_relation_to_impl(db, type2, relation, visitor)) + .is_never_satisfied(db) }; // Return types are covariant. if !check_types(self.return_ty, other.return_ty) { - return false; + return result; } // A gradual parameter list is a supertype of the "bottom" parameter list (*args: object, @@ -665,13 +688,13 @@ impl<'db> Signature<'db> { .keyword_variadic() .is_some_and(|(_, param)| param.annotated_type().is_some_and(|ty| ty.is_object(db))) { - return true; + return C::always_satisfiable(db); } // If either of the parameter lists is gradual (`...`), then it is assignable to and from // any other parameter list, but not a subtype or supertype of any other parameter list. if self.parameters.is_gradual() || other.parameters.is_gradual() { - return relation.is_assignability(); + return C::from_bool(db, relation.is_assignability()); } let mut parameters = ParametersZip { @@ -689,7 +712,7 @@ impl<'db> Signature<'db> { let Some(next_parameter) = parameters.next() else { // All parameters have been checked or both the parameter lists were empty. In // either case, `self` is a subtype of `other`. - return true; + return result; }; match next_parameter { @@ -709,7 +732,7 @@ impl<'db> Signature<'db> { // `other`, then the non-variadic parameters in `self` must have a default // value. if default_type.is_none() { - return false; + return C::unsatisfiable(db); } } ParameterKind::Variadic { .. } | ParameterKind::KeywordVariadic { .. } => { @@ -721,7 +744,7 @@ impl<'db> Signature<'db> { EitherOrBoth::Right(_) => { // If there are more parameters in `other` than in `self`, then `self` is not a // subtype of `other`. - return false; + return C::unsatisfiable(db); } EitherOrBoth::Both(self_parameter, other_parameter) => { @@ -741,13 +764,13 @@ impl<'db> Signature<'db> { }, ) => { if self_default.is_none() && other_default.is_some() { - return false; + return C::unsatisfiable(db); } if !check_types( other_parameter.annotated_type(), self_parameter.annotated_type(), ) { - return false; + return result; } } @@ -762,17 +785,17 @@ impl<'db> Signature<'db> { }, ) => { if self_name != other_name { - return false; + return C::unsatisfiable(db); } // The following checks are the same as positional-only parameters. if self_default.is_none() && other_default.is_some() { - return false; + return C::unsatisfiable(db); } if !check_types( other_parameter.annotated_type(), self_parameter.annotated_type(), ) { - return false; + return result; } } @@ -785,7 +808,7 @@ impl<'db> Signature<'db> { other_parameter.annotated_type(), self_parameter.annotated_type(), ) { - return false; + return result; } if matches!( @@ -825,7 +848,7 @@ impl<'db> Signature<'db> { other_parameter.annotated_type(), self_parameter.annotated_type(), ) { - return false; + return result; } parameters.next_other(); } @@ -836,7 +859,7 @@ impl<'db> Signature<'db> { other_parameter.annotated_type(), self_parameter.annotated_type(), ) { - return false; + return result; } } @@ -851,7 +874,7 @@ impl<'db> Signature<'db> { break; } - _ => return false, + _ => return C::unsatisfiable(db), } } } @@ -885,7 +908,7 @@ impl<'db> Signature<'db> { // previous loop. They cannot be matched against any parameter in `other` which // only contains keyword-only and keyword-variadic parameters so the subtype // relation is invalid. - return false; + return C::unsatisfiable(db); } ParameterKind::Variadic { .. } => {} } @@ -912,13 +935,13 @@ impl<'db> Signature<'db> { .. } => { if self_default.is_none() && other_default.is_some() { - return false; + return C::unsatisfiable(db); } if !check_types( other_parameter.annotated_type(), self_parameter.annotated_type(), ) { - return false; + return result; } } _ => unreachable!( @@ -930,25 +953,25 @@ impl<'db> Signature<'db> { other_parameter.annotated_type(), self_keyword_variadic_type, ) { - return false; + return result; } } else { - return false; + return C::unsatisfiable(db); } } ParameterKind::KeywordVariadic { .. } => { let Some(self_keyword_variadic_type) = self_keyword_variadic else { // For a `self <: other` relationship, if `other` has a keyword variadic // parameter, `self` must also have a keyword variadic parameter. - return false; + return C::unsatisfiable(db); }; if !check_types(other_parameter.annotated_type(), self_keyword_variadic_type) { - return false; + return result; } } _ => { // This can only occur in case of a syntax error. - return false; + return C::unsatisfiable(db); } } } @@ -957,11 +980,11 @@ impl<'db> Signature<'db> { // optional otherwise the subtype relation is invalid. for (_, self_parameter) in self_keywords { if self_parameter.default_type().is_none() { - return false; + return C::unsatisfiable(db); } } - true + result } /// Create a new signature with the given definition. diff --git a/crates/ty_python_semantic/src/types/subclass_of.rs b/crates/ty_python_semantic/src/types/subclass_of.rs index eeb329436360e..38f399ae5613a 100644 --- a/crates/ty_python_semantic/src/types/subclass_of.rs +++ b/crates/ty_python_semantic/src/types/subclass_of.rs @@ -2,11 +2,12 @@ use ruff_python_ast::name::Name; use crate::place::PlaceAndQualifiers; use crate::semantic_index::definition::Definition; +use crate::types::constraints::Constraints; use crate::types::variance::VarianceInferable; use crate::types::{ ApplyTypeMappingVisitor, BindingContext, BoundTypeVarInstance, ClassType, DynamicType, - HasRelationToVisitor, KnownClass, MemberLookupPolicy, NormalizedVisitor, Type, TypeMapping, - TypeRelation, TypeVarInstance, + HasRelationToVisitor, IsDisjointVisitor, KnownClass, MemberLookupPolicy, NormalizedVisitor, + Type, TypeMapping, TypeRelation, TypeVarInstance, }; use crate::{Db, FxOrderSet}; @@ -159,21 +160,23 @@ impl<'db> SubclassOfType<'db> { } /// Return `true` if `self` has a certain relation to `other`. - pub(crate) fn has_relation_to_impl( + pub(crate) fn has_relation_to_impl>( self, db: &'db dyn Db, other: SubclassOfType<'db>, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match (self.subclass_of, other.subclass_of) { (SubclassOfInner::Dynamic(_), SubclassOfInner::Dynamic(_)) => { - relation.is_assignability() + C::from_bool(db, relation.is_assignability()) } (SubclassOfInner::Dynamic(_), SubclassOfInner::Class(other_class)) => { - other_class.is_object(db) || relation.is_assignability() + C::from_bool(db, other_class.is_object(db) || relation.is_assignability()) + } + (SubclassOfInner::Class(_), SubclassOfInner::Dynamic(_)) => { + C::from_bool(db, relation.is_assignability()) } - (SubclassOfInner::Class(_), SubclassOfInner::Dynamic(_)) => relation.is_assignability(), // For example, `type[bool]` describes all possible runtime subclasses of the class `bool`, // and `type[int]` describes all possible runtime subclasses of the class `int`. @@ -187,11 +190,18 @@ impl<'db> SubclassOfType<'db> { /// Return` true` if `self` is a disjoint type from `other`. /// /// See [`Type::is_disjoint_from`] for more details. - pub(crate) fn is_disjoint_from_impl(self, db: &'db dyn Db, other: Self) -> bool { + pub(crate) fn is_disjoint_from_impl>( + self, + db: &'db dyn Db, + other: Self, + _visitor: &IsDisjointVisitor<'db, C>, + ) -> C { match (self.subclass_of, other.subclass_of) { - (SubclassOfInner::Dynamic(_), _) | (_, SubclassOfInner::Dynamic(_)) => false, + (SubclassOfInner::Dynamic(_), _) | (_, SubclassOfInner::Dynamic(_)) => { + C::unsatisfiable(db) + } (SubclassOfInner::Class(self_class), SubclassOfInner::Class(other_class)) => { - !self_class.could_coexist_in_mro_with(db, other_class) + C::from_bool(db, !self_class.could_coexist_in_mro_with(db, other_class)) } } } diff --git a/crates/ty_python_semantic/src/types/tuple.rs b/crates/ty_python_semantic/src/types/tuple.rs index 6058b4e49a0d9..35de11013de42 100644 --- a/crates/ty_python_semantic/src/types/tuple.rs +++ b/crates/ty_python_semantic/src/types/tuple.rs @@ -24,9 +24,11 @@ use itertools::{Either, EitherOrBoth, Itertools}; use crate::semantic_index::definition::Definition; use crate::types::Truthiness; use crate::types::class::{ClassType, KnownClass}; +use crate::types::constraints::{Constraints, IteratorConstraintsExtension}; use crate::types::{ ApplyTypeMappingVisitor, BoundTypeVarInstance, HasRelationToVisitor, IsDisjointVisitor, - NormalizedVisitor, Type, TypeMapping, TypeRelation, TypeVarVariance, UnionBuilder, UnionType, + IsEquivalentVisitor, NormalizedVisitor, Type, TypeMapping, TypeRelation, TypeVarVariance, + UnionBuilder, UnionType, }; use crate::util::subscript::{Nth, OutOfBoundsError, PyIndex, PySlice, StepSizeZeroError}; use crate::{Db, FxOrderSet, Program}; @@ -254,19 +256,25 @@ impl<'db> TupleType<'db> { .find_legacy_typevars(db, binding_context, typevars); } - pub(crate) fn has_relation_to_impl( + pub(crate) fn has_relation_to_impl>( self, db: &'db dyn Db, other: Self, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { self.tuple(db) .has_relation_to_impl(db, other.tuple(db), relation, visitor) } - pub(crate) fn is_equivalent_to(self, db: &'db dyn Db, other: Self) -> bool { - self.tuple(db).is_equivalent_to(db, other.tuple(db)) + pub(crate) fn is_equivalent_to_impl>( + self, + db: &'db dyn Db, + other: Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { + self.tuple(db) + .is_equivalent_to_impl(db, other.tuple(db), visitor) } pub(crate) fn is_single_valued(self, db: &'db dyn Db) -> bool { @@ -409,56 +417,76 @@ impl<'db> FixedLengthTuple> { } } - fn has_relation_to_impl( + fn has_relation_to_impl>( &self, db: &'db dyn Db, other: &Tuple>, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match other { - Tuple::Fixed(other) => { - self.0.len() == other.0.len() - && (self.0.iter()).zip(&other.0).all(|(self_ty, other_ty)| { - self_ty.has_relation_to_impl(db, *other_ty, relation, visitor) - }) - } + Tuple::Fixed(other) => C::from_bool(db, self.0.len() == other.0.len()).and(db, || { + (self.0.iter().zip(&other.0)).when_all(db, |(self_ty, other_ty)| { + self_ty.has_relation_to_impl(db, *other_ty, relation, visitor) + }) + }), Tuple::Variable(other) => { // This tuple must have enough elements to match up with the other tuple's prefix // and suffix, and each of those elements must pairwise satisfy the relation. + let mut result = C::always_satisfiable(db); let mut self_iter = self.0.iter(); for other_ty in &other.prefix { let Some(self_ty) = self_iter.next() else { - return false; + return C::unsatisfiable(db); }; - if !self_ty.has_relation_to_impl(db, *other_ty, relation, visitor) { - return false; + let element_constraints = + self_ty.has_relation_to_impl(db, *other_ty, relation, visitor); + if result + .intersect(db, element_constraints) + .is_never_satisfied(db) + { + return result; } } for other_ty in other.suffix.iter().rev() { let Some(self_ty) = self_iter.next_back() else { - return false; + return C::unsatisfiable(db); }; - if !self_ty.has_relation_to_impl(db, *other_ty, relation, visitor) { - return false; + let element_constraints = + self_ty.has_relation_to_impl(db, *other_ty, relation, visitor); + if result + .intersect(db, element_constraints) + .is_never_satisfied(db) + { + return result; } } // In addition, any remaining elements in this tuple must satisfy the // variable-length portion of the other tuple. - self_iter.all(|self_ty| { - self_ty.has_relation_to_impl(db, other.variable, relation, visitor) + result.and(db, || { + self_iter.when_all(db, |self_ty| { + self_ty.has_relation_to_impl(db, other.variable, relation, visitor) + }) }) } } } - fn is_equivalent_to(&self, db: &'db dyn Db, other: &Self) -> bool { - self.0.len() == other.0.len() - && (self.0.iter()) + fn is_equivalent_to_impl>( + &self, + db: &'db dyn Db, + other: &Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { + C::from_bool(db, self.0.len() == other.0.len()).and(db, || { + (self.0.iter()) .zip(&other.0) - .all(|(self_ty, other_ty)| self_ty.is_equivalent_to(db, *other_ty)) + .when_all(db, |(self_ty, other_ty)| { + self_ty.is_equivalent_to_impl(db, *other_ty, visitor) + }) + }) } fn is_single_valued(&self, db: &'db dyn Db) -> bool { @@ -717,13 +745,13 @@ impl<'db> VariableLengthTuple> { } } - fn has_relation_to_impl( + fn has_relation_to_impl>( &self, db: &'db dyn Db, other: &Tuple>, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match other { Tuple::Fixed(other) => { // The `...` length specifier of a variable-length tuple type is interpreted @@ -738,32 +766,43 @@ impl<'db> VariableLengthTuple> { // length. if relation == TypeRelation::Subtyping || !matches!(self.variable, Type::Dynamic(_)) { - return false; + return C::unsatisfiable(db); } // In addition, the other tuple must have enough elements to match up with this // tuple's prefix and suffix, and each of those elements must pairwise satisfy the // relation. + let mut result = C::always_satisfiable(db); let mut other_iter = other.elements().copied(); for self_ty in self.prenormalized_prefix_elements(db, None) { let Some(other_ty) = other_iter.next() else { - return false; + return C::unsatisfiable(db); }; - if !self_ty.has_relation_to_impl(db, other_ty, relation, visitor) { - return false; + let element_constraints = + self_ty.has_relation_to_impl(db, other_ty, relation, visitor); + if result + .intersect(db, element_constraints) + .is_never_satisfied(db) + { + return result; } } let suffix: Vec<_> = self.prenormalized_suffix_elements(db, None).collect(); for self_ty in suffix.iter().rev() { let Some(other_ty) = other_iter.next_back() else { - return false; + return C::unsatisfiable(db); }; - if !self_ty.has_relation_to_impl(db, other_ty, relation, visitor) { - return false; + let element_constraints = + self_ty.has_relation_to_impl(db, other_ty, relation, visitor); + if result + .intersect(db, element_constraints) + .is_never_satisfied(db) + { + return result; } } - true + result } Tuple::Variable(other) => { @@ -781,12 +820,13 @@ impl<'db> VariableLengthTuple> { // The overlapping parts of the prefixes and suffixes must satisfy the relation. // Any remaining parts must satisfy the relation with the other tuple's // variable-length part. - if !self - .prenormalized_prefix_elements(db, self_prenormalize_variable) + let mut result = C::always_satisfiable(db); + let pairwise = (self.prenormalized_prefix_elements(db, self_prenormalize_variable)) .zip_longest( other.prenormalized_prefix_elements(db, other_prenormalize_variable), - ) - .all(|pair| match pair { + ); + for pair in pairwise { + let pair_constraints = match pair { EitherOrBoth::Both(self_ty, other_ty) => { self_ty.has_relation_to_impl(db, other_ty, relation, visitor) } @@ -796,11 +836,15 @@ impl<'db> VariableLengthTuple> { EitherOrBoth::Right(_) => { // The rhs has a required element that the lhs is not guaranteed to // provide. - false + return C::unsatisfiable(db); } - }) - { - return false; + }; + if result + .intersect(db, pair_constraints) + .is_never_satisfied(db) + { + return result; + } } let self_suffix: Vec<_> = self @@ -809,9 +853,9 @@ impl<'db> VariableLengthTuple> { let other_suffix: Vec<_> = other .prenormalized_suffix_elements(db, other_prenormalize_variable) .collect(); - if !(self_suffix.iter().rev()) - .zip_longest(other_suffix.iter().rev()) - .all(|pair| match pair { + let pairwise = (self_suffix.iter().rev()).zip_longest(other_suffix.iter().rev()); + for pair in pairwise { + let pair_constraints = match pair { EitherOrBoth::Both(self_ty, other_ty) => { self_ty.has_relation_to_impl(db, *other_ty, relation, visitor) } @@ -821,34 +865,54 @@ impl<'db> VariableLengthTuple> { EitherOrBoth::Right(_) => { // The rhs has a required element that the lhs is not guaranteed to // provide. - false + return C::unsatisfiable(db); } - }) - { - return false; + }; + if result + .intersect(db, pair_constraints) + .is_never_satisfied(db) + { + return result; + } } // And lastly, the variable-length portions must satisfy the relation. - self.variable - .has_relation_to_impl(db, other.variable, relation, visitor) + result.and(db, || { + self.variable + .has_relation_to_impl(db, other.variable, relation, visitor) + }) } } } - fn is_equivalent_to(&self, db: &'db dyn Db, other: &Self) -> bool { - self.variable.is_equivalent_to(db, other.variable) - && (self.prenormalized_prefix_elements(db, None)) - .zip_longest(other.prenormalized_prefix_elements(db, None)) - .all(|pair| match pair { - EitherOrBoth::Both(self_ty, other_ty) => self_ty.is_equivalent_to(db, other_ty), - EitherOrBoth::Left(_) | EitherOrBoth::Right(_) => false, - }) - && (self.prenormalized_suffix_elements(db, None)) - .zip_longest(other.prenormalized_suffix_elements(db, None)) - .all(|pair| match pair { - EitherOrBoth::Both(self_ty, other_ty) => self_ty.is_equivalent_to(db, other_ty), - EitherOrBoth::Left(_) | EitherOrBoth::Right(_) => false, - }) + fn is_equivalent_to_impl>( + &self, + db: &'db dyn Db, + other: &Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { + self.variable + .is_equivalent_to_impl(db, other.variable, visitor) + .and(db, || { + (self.prenormalized_prefix_elements(db, None)) + .zip_longest(other.prenormalized_prefix_elements(db, None)) + .when_all(db, |pair| match pair { + EitherOrBoth::Both(self_ty, other_ty) => { + self_ty.is_equivalent_to_impl(db, other_ty, visitor) + } + EitherOrBoth::Left(_) | EitherOrBoth::Right(_) => C::unsatisfiable(db), + }) + }) + .and(db, || { + (self.prenormalized_suffix_elements(db, None)) + .zip_longest(other.prenormalized_suffix_elements(db, None)) + .when_all(db, |pair| match pair { + EitherOrBoth::Both(self_ty, other_ty) => { + self_ty.is_equivalent_to_impl(db, other_ty, visitor) + } + EitherOrBoth::Left(_) | EitherOrBoth::Right(_) => C::unsatisfiable(db), + }) + }) } } @@ -1027,13 +1091,13 @@ impl<'db> Tuple> { } } - fn has_relation_to_impl( + fn has_relation_to_impl>( &self, db: &'db dyn Db, other: &Self, relation: TypeRelation, - visitor: &HasRelationToVisitor<'db>, - ) -> bool { + visitor: &HasRelationToVisitor<'db, C>, + ) -> C { match self { Tuple::Fixed(self_tuple) => { self_tuple.has_relation_to_impl(db, other, relation, visitor) @@ -1044,96 +1108,95 @@ impl<'db> Tuple> { } } - fn is_equivalent_to(&self, db: &'db dyn Db, other: &Self) -> bool { + fn is_equivalent_to_impl>( + &self, + db: &'db dyn Db, + other: &Self, + visitor: &IsEquivalentVisitor<'db, C>, + ) -> C { match (self, other) { (Tuple::Fixed(self_tuple), Tuple::Fixed(other_tuple)) => { - self_tuple.is_equivalent_to(db, other_tuple) + self_tuple.is_equivalent_to_impl(db, other_tuple, visitor) } (Tuple::Variable(self_tuple), Tuple::Variable(other_tuple)) => { - self_tuple.is_equivalent_to(db, other_tuple) + self_tuple.is_equivalent_to_impl(db, other_tuple, visitor) + } + (Tuple::Fixed(_), Tuple::Variable(_)) | (Tuple::Variable(_), Tuple::Fixed(_)) => { + C::unsatisfiable(db) } - (Tuple::Fixed(_), Tuple::Variable(_)) | (Tuple::Variable(_), Tuple::Fixed(_)) => false, } } - pub(super) fn is_disjoint_from_impl( + pub(super) fn is_disjoint_from_impl>( &self, db: &'db dyn Db, other: &Self, - visitor: &IsDisjointVisitor<'db>, - ) -> bool { + visitor: &IsDisjointVisitor<'db, C>, + ) -> C { // Two tuples with an incompatible number of required elements must always be disjoint. let (self_min, self_max) = self.len().size_hint(); let (other_min, other_max) = other.len().size_hint(); if self_max.is_some_and(|max| max < other_min) { - return true; + return C::always_satisfiable(db); } if other_max.is_some_and(|max| max < self_min) { - return true; + return C::always_satisfiable(db); } // If any of the required elements are pairwise disjoint, the tuples are disjoint as well. #[allow(clippy::items_after_statements)] - fn any_disjoint<'s, 'db>( + fn any_disjoint<'s, 'db, C: Constraints<'db>>( db: &'db dyn Db, a: impl IntoIterator>, b: impl IntoIterator>, - visitor: &IsDisjointVisitor<'db>, - ) -> bool + visitor: &IsDisjointVisitor<'db, C>, + ) -> C where 'db: 's, { - a.into_iter().zip(b).any(|(self_element, other_element)| { + (a.into_iter().zip(b)).when_any(db, |(self_element, other_element)| { self_element.is_disjoint_from_impl(db, *other_element, visitor) }) } match (self, other) { (Tuple::Fixed(self_tuple), Tuple::Fixed(other_tuple)) => { - if any_disjoint(db, self_tuple.elements(), other_tuple.elements(), visitor) { - return true; - } + any_disjoint(db, self_tuple.elements(), other_tuple.elements(), visitor) } - (Tuple::Variable(self_tuple), Tuple::Variable(other_tuple)) => { - if any_disjoint( - db, - self_tuple.prefix_elements(), - other_tuple.prefix_elements(), - visitor, - ) { - return true; - } - if any_disjoint( + // Note that we don't compare the variable-length portions; two pure homogeneous tuples + // `tuple[A, ...]` and `tuple[B, ...]` can never be disjoint even if A and B are + // disjoint, because `tuple[()]` would be assignable to both. + (Tuple::Variable(self_tuple), Tuple::Variable(other_tuple)) => any_disjoint( + db, + self_tuple.prefix_elements(), + other_tuple.prefix_elements(), + visitor, + ) + .or(db, || { + any_disjoint( db, self_tuple.suffix_elements().rev(), other_tuple.suffix_elements().rev(), visitor, - ) { - return true; - } - } + ) + }), (Tuple::Fixed(fixed), Tuple::Variable(variable)) | (Tuple::Variable(variable), Tuple::Fixed(fixed)) => { - if any_disjoint(db, fixed.elements(), variable.prefix_elements(), visitor) { - return true; - } - if any_disjoint( + any_disjoint(db, fixed.elements(), variable.prefix_elements(), visitor).or( db, - fixed.elements().rev(), - variable.suffix_elements().rev(), - visitor, - ) { - return true; - } + || { + any_disjoint( + db, + fixed.elements().rev(), + variable.suffix_elements().rev(), + visitor, + ) + }, + ) } } - - // Two pure homogeneous tuples `tuple[A, ...]` and `tuple[B, ...]` can never be - // disjoint even if A and B are disjoint, because `tuple[()]` would be assignable to - // both. - false } pub(crate) fn is_single_valued(&self, db: &'db dyn Db) -> bool { From 692be72f5aff65bfea504504c54d82112657c98a Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Thu, 21 Aug 2025 09:47:00 -0400 Subject: [PATCH 082/160] Move diff rendering to `ruff_db` (#20006) Summary -- This is a preparatory PR in support of #19919. It moves our `Diff` rendering code from `ruff_linter` to `ruff_db`, where we have direct access to the `DiagnosticStylesheet` used by our other diagnostic rendering code. As shown by the tests, this shouldn't cause any visible changes. The colors aren't exactly the same, as I note in a TODO comment, but I don't think there's any existing way to see those, even in tests. The `Diff` implementation is mostly unchanged. I just switched from a Ruff-specific `SourceFile` to a `DiagnosticSource` (removing an `expect_ruff_source_file` call) and updated the `LineStyle` struct and other styling calls to use `fmt_styled` and our existing stylesheet. In support of these changes, I added three styles to our stylesheet: `insertion` and `deletion` for the corresponding diff operations, and `underline`, which apparently we _can_ use, as I hoped on Discord. This isn't supported in all terminals, though. It worked in ghostty but not in st for me. I moved the `calculate_print_width` function from the now-deleted `diff.rs` to a method on `OneIndexed`, where it was available everywhere we needed it. I'm not sure if that's desirable, or if my other changes to the function are either (using `ilog10` instead of a loop). This does make it `const` and slightly simplifies things in my opinion, but I'm happy to revert it if preferred. I also inlined a version of `show_nonprinting` from the `ShowNonprinting` trait in `ruff_linter`: https://github.com/astral-sh/ruff/blob/f4be05a83be770c8c9781088508275170396b411/crates/ruff_linter/src/text_helpers.rs#L3-L5 This trait is now only used in `source_kind.rs`, so I'm not sure it's worth having the trait or the macro-generated implementation (which is only called once). This is obviously closely related to our unprintable character handling in diagnostic rendering, but the usage seems different enough not to try to combine them. https://github.com/astral-sh/ruff/blob/f4be05a83be770c8c9781088508275170396b411/crates/ruff_db/src/diagnostic/render.rs#L990-L998 We could also move the trait to another crate where we can use it in `ruff_db` instead of inlining here, of course. Finally, this PR makes `TextEmitter` a very thin wrapper around a `DisplayDiagnosticsConfig`. It's still used in a few places, though, unlike the other emitters we've replaced, so I figured it was worth keeping around. It's a pretty nice API for setting all of the options on the config and then passing that along to a `DisplayDiagnostics`. Test Plan -- Existing snapshot tests with diffs --- Cargo.lock | 1 + crates/ruff_db/Cargo.toml | 1 + crates/ruff_db/src/diagnostic/mod.rs | 13 ++ crates/ruff_db/src/diagnostic/render/full.rs | 199 ++++++++++++++++- crates/ruff_db/src/diagnostic/stylesheet.rs | 9 + crates/ruff_linter/src/message/diff.rs | 202 ------------------ crates/ruff_linter/src/message/grouped.rs | 13 +- crates/ruff_linter/src/message/mod.rs | 1 - crates/ruff_linter/src/message/text.rs | 26 +-- crates/ruff_source_file/src/line_index.rs | 27 +++ .../src/server/api/requests/completion.rs | 4 +- 11 files changed, 266 insertions(+), 230 deletions(-) delete mode 100644 crates/ruff_linter/src/message/diff.rs diff --git a/Cargo.lock b/Cargo.lock index 768c871516c16..72a90b18ea7b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2886,6 +2886,7 @@ dependencies = [ "schemars", "serde", "serde_json", + "similar", "tempfile", "thiserror 2.0.12", "tracing", diff --git a/crates/ruff_db/Cargo.toml b/crates/ruff_db/Cargo.toml index f3df7fac70a09..40eb42ec8f949 100644 --- a/crates/ruff_db/Cargo.toml +++ b/crates/ruff_db/Cargo.toml @@ -40,6 +40,7 @@ salsa = { workspace = true } schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } +similar = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true } tracing-subscriber = { workspace = true, optional = true } diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index 53b4247adccae..db6befc9aa1f2 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -1294,6 +1294,10 @@ pub struct DisplayDiagnosticConfig { hide_severity: bool, /// Whether to show the availability of a fix in a diagnostic. show_fix_status: bool, + /// Whether to show the diff for an available fix after the main diagnostic. + /// + /// This currently only applies to `DiagnosticFormat::Full`. + show_fix_diff: bool, /// The lowest applicability that should be shown when reporting diagnostics. fix_applicability: Applicability, } @@ -1341,6 +1345,14 @@ impl DisplayDiagnosticConfig { } } + /// Whether to show a diff for an available fix after the main diagnostic. + pub fn show_fix_diff(self, yes: bool) -> DisplayDiagnosticConfig { + DisplayDiagnosticConfig { + show_fix_diff: yes, + ..self + } + } + /// Set the lowest fix applicability that should be shown. /// /// In other words, an applicability of `Safe` (the default) would suppress showing fixes or fix @@ -1364,6 +1376,7 @@ impl Default for DisplayDiagnosticConfig { preview: false, hide_severity: false, show_fix_status: false, + show_fix_diff: false, fix_applicability: Applicability::Safe, } } diff --git a/crates/ruff_db/src/diagnostic/render/full.rs b/crates/ruff_db/src/diagnostic/render/full.rs index 0eee73e543b62..951b812562b60 100644 --- a/crates/ruff_db/src/diagnostic/render/full.rs +++ b/crates/ruff_db/src/diagnostic/render/full.rs @@ -1,7 +1,17 @@ +use std::borrow::Cow; +use std::num::NonZeroUsize; + +use anstyle::Style; +use similar::{ChangeTag, TextDiff}; + use ruff_annotate_snippets::Renderer as AnnotateRenderer; +use ruff_diagnostics::{Applicability, Fix}; +use ruff_source_file::OneIndexed; +use ruff_text_size::{Ranged, TextRange, TextSize}; use crate::diagnostic::render::{FileResolver, Resolved}; -use crate::diagnostic::{Diagnostic, DisplayDiagnosticConfig, stylesheet::DiagnosticStylesheet}; +use crate::diagnostic::stylesheet::{DiagnosticStylesheet, fmt_styled}; +use crate::diagnostic::{Diagnostic, DiagnosticSource, DisplayDiagnosticConfig}; pub(super) struct FullRenderer<'a> { resolver: &'a dyn FileResolver, @@ -48,12 +58,199 @@ impl<'a> FullRenderer<'a> { writeln!(f, "{}", renderer.render(diag.to_annotate()))?; } writeln!(f)?; + + if self.config.show_fix_diff { + if let Some(diff) = Diff::from_diagnostic(diag, &stylesheet, self.resolver) { + writeln!(f, "{diff}")?; + } + } + } + + Ok(()) + } +} + +/// Renders a diff that shows the code fixes. +/// +/// The implementation isn't fully fledged out and only used by tests. Before using in production, try +/// * Improve layout +/// * Replace tabs with spaces for a consistent experience across terminals +/// * Replace zero-width whitespaces +/// * Print a simpler diff if only a single line has changed +/// * Compute the diff from the `Edit` because diff calculation is expensive. +struct Diff<'a> { + fix: &'a Fix, + diagnostic_source: DiagnosticSource, + stylesheet: &'a DiagnosticStylesheet, +} + +impl<'a> Diff<'a> { + fn from_diagnostic( + diagnostic: &'a Diagnostic, + stylesheet: &'a DiagnosticStylesheet, + resolver: &'a dyn FileResolver, + ) -> Option> { + Some(Diff { + fix: diagnostic.fix()?, + diagnostic_source: diagnostic + .primary_span_ref()? + .file + .diagnostic_source(resolver), + stylesheet, + }) + } +} + +impl std::fmt::Display for Diff<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let source_code = self.diagnostic_source.as_source_code(); + let source_text = source_code.text(); + + // TODO(dhruvmanila): Add support for Notebook cells once it's user-facing + let mut output = String::with_capacity(source_text.len()); + let mut last_end = TextSize::default(); + + for edit in self.fix.edits() { + output.push_str(source_code.slice(TextRange::new(last_end, edit.start()))); + output.push_str(edit.content().unwrap_or_default()); + last_end = edit.end(); + } + + output.push_str(&source_text[usize::from(last_end)..]); + + let diff = TextDiff::from_lines(source_text, &output); + + let message = match self.fix.applicability() { + // TODO(zanieb): Adjust this messaging once it's user-facing + Applicability::Safe => "Safe fix", + Applicability::Unsafe => "Unsafe fix", + Applicability::DisplayOnly => "Display-only fix", + }; + + // TODO(brent) `stylesheet.separator` is cyan rather than blue, as we had before. I think + // we're getting rid of this soon anyway, so I didn't think it was worth adding another + // style to the stylesheet temporarily. The color doesn't appear at all in the snapshot + // tests, which is the only place these are currently used. + writeln!(f, "ℹ {}", fmt_styled(message, self.stylesheet.separator))?; + + let (largest_old, largest_new) = diff + .ops() + .last() + .map(|op| (op.old_range().start, op.new_range().start)) + .unwrap_or_default(); + + let digit_with = OneIndexed::from_zero_indexed(largest_new.max(largest_old)).digits(); + + for (idx, group) in diff.grouped_ops(3).iter().enumerate() { + if idx > 0 { + writeln!(f, "{:-^1$}", "-", 80)?; + } + for op in group { + for change in diff.iter_inline_changes(op) { + let sign = match change.tag() { + ChangeTag::Delete => "-", + ChangeTag::Insert => "+", + ChangeTag::Equal => " ", + }; + + let line_style = LineStyle::from(change.tag(), self.stylesheet); + + let old_index = change.old_index().map(OneIndexed::from_zero_indexed); + let new_index = change.new_index().map(OneIndexed::from_zero_indexed); + + write!( + f, + "{} {} |{}", + Line { + index: old_index, + width: digit_with + }, + Line { + index: new_index, + width: digit_with + }, + fmt_styled(line_style.apply_to(sign), self.stylesheet.emphasis), + )?; + + for (emphasized, value) in change.iter_strings_lossy() { + let value = show_nonprinting(&value); + if emphasized { + write!( + f, + "{}", + fmt_styled(line_style.apply_to(&value), self.stylesheet.underline) + )?; + } else { + write!(f, "{}", line_style.apply_to(&value))?; + } + } + if change.missing_newline() { + writeln!(f)?; + } + } + } } Ok(()) } } +struct LineStyle { + style: Style, +} + +impl LineStyle { + fn apply_to(&self, input: &str) -> impl std::fmt::Display { + fmt_styled(input, self.style) + } + + fn from(value: ChangeTag, stylesheet: &DiagnosticStylesheet) -> LineStyle { + match value { + ChangeTag::Equal => LineStyle { + style: stylesheet.none, + }, + ChangeTag::Delete => LineStyle { + style: stylesheet.deletion, + }, + ChangeTag::Insert => LineStyle { + style: stylesheet.insertion, + }, + } + } +} + +struct Line { + index: Option, + width: NonZeroUsize, +} + +impl std::fmt::Display for Line { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + match self.index { + None => { + for _ in 0..self.width.get() { + f.write_str(" ")?; + } + Ok(()) + } + Some(idx) => write!(f, "{: Cow<'_, str> { + if s.find(['\x07', '\x08', '\x1b', '\x7f']).is_some() { + Cow::Owned( + s.replace('\x07', "␇") + .replace('\x08', "␈") + .replace('\x1b', "␛") + .replace('\x7f', "␡"), + ) + } else { + Cow::Borrowed(s) + } +} + #[cfg(test)] mod tests { use ruff_diagnostics::Applicability; diff --git a/crates/ruff_db/src/diagnostic/stylesheet.rs b/crates/ruff_db/src/diagnostic/stylesheet.rs index 50be7ee41ce65..bba985ead3c58 100644 --- a/crates/ruff_db/src/diagnostic/stylesheet.rs +++ b/crates/ruff_db/src/diagnostic/stylesheet.rs @@ -40,9 +40,12 @@ pub struct DiagnosticStylesheet { pub(crate) help: Style, pub(crate) line_no: Style, pub(crate) emphasis: Style, + pub(crate) underline: Style, pub(crate) none: Style, pub(crate) separator: Style, pub(crate) secondary_code: Style, + pub(crate) insertion: Style, + pub(crate) deletion: Style, } impl Default for DiagnosticStylesheet { @@ -63,9 +66,12 @@ impl DiagnosticStylesheet { help: AnsiColor::BrightCyan.on_default().effects(Effects::BOLD), line_no: bright_blue.effects(Effects::BOLD), emphasis: Style::new().effects(Effects::BOLD), + underline: Style::new().effects(Effects::UNDERLINE), none: Style::new(), separator: AnsiColor::Cyan.on_default(), secondary_code: AnsiColor::Red.on_default().effects(Effects::BOLD), + insertion: AnsiColor::Green.on_default(), + deletion: AnsiColor::Red.on_default(), } } @@ -78,9 +84,12 @@ impl DiagnosticStylesheet { help: Style::new(), line_no: Style::new(), emphasis: Style::new(), + underline: Style::new(), none: Style::new(), separator: Style::new(), secondary_code: Style::new(), + insertion: Style::new(), + deletion: Style::new(), } } } diff --git a/crates/ruff_linter/src/message/diff.rs b/crates/ruff_linter/src/message/diff.rs deleted file mode 100644 index 437fc0a83033d..0000000000000 --- a/crates/ruff_linter/src/message/diff.rs +++ /dev/null @@ -1,202 +0,0 @@ -use std::fmt::{Display, Formatter}; -use std::num::NonZeroUsize; - -use colored::{Color, ColoredString, Colorize, Styles}; -use similar::{ChangeTag, TextDiff}; - -use ruff_db::diagnostic::Diagnostic; -use ruff_source_file::{OneIndexed, SourceFile}; -use ruff_text_size::{Ranged, TextRange, TextSize}; - -use crate::text_helpers::ShowNonprinting; -use crate::{Applicability, Fix}; - -/// Renders a diff that shows the code fixes. -/// -/// The implementation isn't fully fledged out and only used by tests. Before using in production, try -/// * Improve layout -/// * Replace tabs with spaces for a consistent experience across terminals -/// * Replace zero-width whitespaces -/// * Print a simpler diff if only a single line has changed -/// * Compute the diff from the [`Edit`] because diff calculation is expensive. -pub(super) struct Diff<'a> { - fix: &'a Fix, - source_code: &'a SourceFile, -} - -impl<'a> Diff<'a> { - pub(crate) fn from_message(message: &'a Diagnostic) -> Option> { - message.fix().map(|fix| Diff { - source_code: message.expect_ruff_source_file(), - fix, - }) - } -} - -impl Display for Diff<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { - // TODO(dhruvmanila): Add support for Notebook cells once it's user-facing - let mut output = String::with_capacity(self.source_code.source_text().len()); - let mut last_end = TextSize::default(); - - for edit in self.fix.edits() { - output.push_str( - self.source_code - .slice(TextRange::new(last_end, edit.start())), - ); - output.push_str(edit.content().unwrap_or_default()); - last_end = edit.end(); - } - - output.push_str(&self.source_code.source_text()[usize::from(last_end)..]); - - let diff = TextDiff::from_lines(self.source_code.source_text(), &output); - - let message = match self.fix.applicability() { - // TODO(zanieb): Adjust this messaging once it's user-facing - Applicability::Safe => "Safe fix", - Applicability::Unsafe => "Unsafe fix", - Applicability::DisplayOnly => "Display-only fix", - }; - writeln!(f, "ℹ {}", message.blue())?; - - let (largest_old, largest_new) = diff - .ops() - .last() - .map(|op| (op.old_range().start, op.new_range().start)) - .unwrap_or_default(); - - let digit_with = - calculate_print_width(OneIndexed::from_zero_indexed(largest_new.max(largest_old))); - - for (idx, group) in diff.grouped_ops(3).iter().enumerate() { - if idx > 0 { - writeln!(f, "{:-^1$}", "-", 80)?; - } - for op in group { - for change in diff.iter_inline_changes(op) { - let sign = match change.tag() { - ChangeTag::Delete => "-", - ChangeTag::Insert => "+", - ChangeTag::Equal => " ", - }; - - let line_style = LineStyle::from(change.tag()); - - let old_index = change.old_index().map(OneIndexed::from_zero_indexed); - let new_index = change.new_index().map(OneIndexed::from_zero_indexed); - - write!( - f, - "{} {} |{}", - Line { - index: old_index, - width: digit_with - }, - Line { - index: new_index, - width: digit_with - }, - line_style.apply_to(sign).bold() - )?; - - for (emphasized, value) in change.iter_strings_lossy() { - let value = value.show_nonprinting(); - if emphasized { - write!(f, "{}", line_style.apply_to(&value).underline().on_black())?; - } else { - write!(f, "{}", line_style.apply_to(&value))?; - } - } - if change.missing_newline() { - writeln!(f)?; - } - } - } - } - - Ok(()) - } -} - -struct LineStyle { - fgcolor: Option, - style: Option, -} - -impl LineStyle { - fn apply_to(&self, input: &str) -> ColoredString { - let mut colored = ColoredString::from(input); - if let Some(color) = self.fgcolor { - colored = colored.color(color); - } - - if let Some(style) = self.style { - match style { - Styles::Clear => colored.clear(), - Styles::Bold => colored.bold(), - Styles::Dimmed => colored.dimmed(), - Styles::Underline => colored.underline(), - Styles::Reversed => colored.reversed(), - Styles::Italic => colored.italic(), - Styles::Blink => colored.blink(), - Styles::Hidden => colored.hidden(), - Styles::Strikethrough => colored.strikethrough(), - } - } else { - colored - } - } -} - -impl From for LineStyle { - fn from(value: ChangeTag) -> Self { - match value { - ChangeTag::Equal => LineStyle { - fgcolor: None, - style: Some(Styles::Dimmed), - }, - ChangeTag::Delete => LineStyle { - fgcolor: Some(Color::Red), - style: None, - }, - ChangeTag::Insert => LineStyle { - fgcolor: Some(Color::Green), - style: None, - }, - } - } -} - -struct Line { - index: Option, - width: NonZeroUsize, -} - -impl Display for Line { - fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { - match self.index { - None => { - for _ in 0..self.width.get() { - f.write_str(" ")?; - } - Ok(()) - } - Some(idx) => write!(f, "{: NonZeroUsize { - const TEN: OneIndexed = OneIndexed::from_zero_indexed(9); - - let mut width = OneIndexed::ONE; - - while value >= TEN { - value = OneIndexed::new(value.get() / 10).unwrap_or(OneIndexed::MIN); - width = width.checked_add(1).unwrap(); - } - - width -} diff --git a/crates/ruff_linter/src/message/grouped.rs b/crates/ruff_linter/src/message/grouped.rs index 0a7de26b2dde6..1733d94b2be12 100644 --- a/crates/ruff_linter/src/message/grouped.rs +++ b/crates/ruff_linter/src/message/grouped.rs @@ -10,7 +10,6 @@ use ruff_notebook::NotebookIndex; use ruff_source_file::{LineColumn, OneIndexed}; use crate::fs::relativize_path; -use crate::message::diff::calculate_print_width; use crate::message::{Emitter, EmitterContext}; use crate::settings::types::UnsafeFixes; @@ -53,8 +52,8 @@ impl Emitter for GroupedEmitter { max_column_length = max_column_length.max(message.start_location.column); } - let row_length = calculate_print_width(max_row_length); - let column_length = calculate_print_width(max_column_length); + let row_length = max_row_length.digits(); + let column_length = max_column_length.digits(); // Print the filename. writeln!(writer, "{}:", relativize_path(&*filename).underline())?; @@ -131,8 +130,7 @@ impl Display for DisplayGroupedMessage<'_> { write!( f, " {row_padding}", - row_padding = " " - .repeat(self.row_length.get() - calculate_print_width(start_location.line).get()) + row_padding = " ".repeat(self.row_length.get() - start_location.line.digits().get()) )?; // Check if we're working on a jupyter notebook and translate positions with cell accordingly @@ -159,9 +157,8 @@ impl Display for DisplayGroupedMessage<'_> { f, "{row}{sep}{col}{col_padding} {code_and_body}", sep = ":".cyan(), - col_padding = " ".repeat( - self.column_length.get() - calculate_print_width(start_location.column).get() - ), + col_padding = + " ".repeat(self.column_length.get() - start_location.column.digits().get()), code_and_body = RuleCodeAndBody { message, show_fix_status: self.show_fix_status, diff --git a/crates/ruff_linter/src/message/mod.rs b/crates/ruff_linter/src/message/mod.rs index b6328c686b3ed..1918575a2b933 100644 --- a/crates/ruff_linter/src/message/mod.rs +++ b/crates/ruff_linter/src/message/mod.rs @@ -21,7 +21,6 @@ pub use text::TextEmitter; use crate::Fix; use crate::registry::Rule; -mod diff; mod github; mod gitlab; mod grouped; diff --git a/crates/ruff_linter/src/message/text.rs b/crates/ruff_linter/src/message/text.rs index 610a7a750c1c0..1e47c7e25881b 100644 --- a/crates/ruff_linter/src/message/text.rs +++ b/crates/ruff_linter/src/message/text.rs @@ -1,23 +1,19 @@ use std::io::Write; -use ruff_db::diagnostic::{Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig}; +use ruff_db::diagnostic::{ + Diagnostic, DiagnosticFormat, DisplayDiagnosticConfig, DisplayDiagnostics, +}; -use crate::message::diff::Diff; use crate::message::{Emitter, EmitterContext}; use crate::settings::types::UnsafeFixes; pub struct TextEmitter { - /// Whether to show the diff of a fix, for diagnostics that have a fix. - /// - /// Note that this is not currently exposed in the CLI (#7352) and is only used in tests. - show_fix_diff: bool, config: DisplayDiagnosticConfig, } impl Default for TextEmitter { fn default() -> Self { Self { - show_fix_diff: false, config: DisplayDiagnosticConfig::default() .format(DiagnosticFormat::Concise) .hide_severity(true) @@ -35,7 +31,7 @@ impl TextEmitter { #[must_use] pub fn with_show_fix_diff(mut self, show_fix_diff: bool) -> Self { - self.show_fix_diff = show_fix_diff; + self.config = self.config.show_fix_diff(show_fix_diff); self } @@ -77,15 +73,11 @@ impl Emitter for TextEmitter { diagnostics: &[Diagnostic], context: &EmitterContext, ) -> anyhow::Result<()> { - for message in diagnostics { - write!(writer, "{}", message.display(context, &self.config))?; - - if self.show_fix_diff { - if let Some(diff) = Diff::from_message(message) { - writeln!(writer, "{diff}")?; - } - } - } + write!( + writer, + "{}", + DisplayDiagnostics::new(context, &self.config, diagnostics) + )?; Ok(()) } diff --git a/crates/ruff_source_file/src/line_index.rs b/crates/ruff_source_file/src/line_index.rs index 1f04aef2401ce..4adb9d17b784a 100644 --- a/crates/ruff_source_file/src/line_index.rs +++ b/crates/ruff_source_file/src/line_index.rs @@ -622,6 +622,33 @@ impl OneIndexed { pub fn checked_sub(self, rhs: Self) -> Option { self.0.get().checked_sub(rhs.get()).and_then(Self::new) } + + /// Calculate the number of digits in `self`. + /// + /// This is primarily intended for computing the length of the string representation for + /// formatted printing. + /// + /// # Examples + /// + /// ``` + /// use ruff_source_file::OneIndexed; + /// + /// let one = OneIndexed::new(1).unwrap(); + /// assert_eq!(one.digits().get(), 1); + /// + /// let hundred = OneIndexed::new(100).unwrap(); + /// assert_eq!(hundred.digits().get(), 3); + /// + /// let thousand = OneIndexed::new(1000).unwrap(); + /// assert_eq!(thousand.digits().get(), 4); + /// ``` + pub const fn digits(self) -> NonZeroUsize { + // Safety: the 1+ ensures this is always non-zero, and + // `usize::MAX.ilog10()` << `usize::MAX`, so the result is always safe + // to cast to a usize, even though it's returned as a u32 + // (u64::MAX.ilog10() is 19). + NonZeroUsize::new(1 + self.0.get().ilog10() as usize).unwrap() + } } impl Default for OneIndexed { diff --git a/crates/ty_server/src/server/api/requests/completion.rs b/crates/ty_server/src/server/api/requests/completion.rs index ee59532f9cb26..214c04582fae0 100644 --- a/crates/ty_server/src/server/api/requests/completion.rs +++ b/crates/ty_server/src/server/api/requests/completion.rs @@ -6,6 +6,7 @@ use lsp_types::{ CompletionItem, CompletionItemKind, CompletionParams, CompletionResponse, Documentation, Url, }; use ruff_db::source::{line_index, source_text}; +use ruff_source_file::OneIndexed; use ty_ide::completion; use ty_project::ProjectDatabase; use ty_python_semantic::CompletionKind; @@ -59,7 +60,8 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler { return Ok(None); } - let max_index_len = completions.len().saturating_sub(1).to_string().len(); + // Safety: we just checked that completions is not empty. + let max_index_len = OneIndexed::new(completions.len()).unwrap().digits().get(); let items: Vec = completions .into_iter() .enumerate() From 5931a5207de19583484e53b5b5d9583690f22f6e Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 21 Aug 2025 13:22:47 -0400 Subject: [PATCH 083/160] [ty] Stop running every mdtest twice This was an accidental oversight introduced in commit 468eb37d7572acaa354c0159875157ffceb9d447. --- crates/ty_test/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/ty_test/src/lib.rs b/crates/ty_test/src/lib.rs index e5938eddc1c38..878282235d919 100644 --- a/crates/ty_test/src/lib.rs +++ b/crates/ty_test/src/lib.rs @@ -78,7 +78,7 @@ pub fn run( println!("\n{}\n", test.name().bold().underline()); } - if let Err(failures) = run_test(&mut db, relative_fixture_path, snapshot_path, &test) { + if let Err(failures) = failures { let md_index = LineIndex::from_source_text(&source); for test_failures in failures { @@ -105,7 +105,7 @@ pub fn run( } } } - if let Err(inconsistencies) = run_module_resolution_consistency_test(&db) { + if let Err(inconsistencies) = inconsistencies { any_failures = true; for inconsistency in inconsistencies { match output_format { From c68ff8d90b57e2fc525d905527c1e9e0919802b0 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 21 Aug 2025 13:09:31 -0500 Subject: [PATCH 084/160] Bump 0.12.10 (#20025) --- CHANGELOG.md | 24 ++++++++++++++++++++++++ Cargo.lock | 6 +++--- README.md | 6 +++--- crates/ruff/Cargo.toml | 2 +- crates/ruff_linter/Cargo.toml | 2 +- crates/ruff_wasm/Cargo.toml | 2 +- docs/integrations.md | 8 ++++---- docs/tutorial.md | 2 +- pyproject.toml | 2 +- scripts/benchmarks/pyproject.toml | 2 +- 10 files changed, 40 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9952e0f66bd5..8772a86039a20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,29 @@ # Changelog +## 0.12.10 + +### Preview features + +- \[`flake8-simplify`\] Implement fix for `maxsplit` without separator (`SIM905`) ([#19851](https://github.com/astral-sh/ruff/pull/19851)) +- \[`flake8-use-pathlib`\] Add fixes for `PTH102` and `PTH103` ([#19514](https://github.com/astral-sh/ruff/pull/19514)) + +### Bug fixes + +- \[`isort`\] Handle multiple continuation lines after module docstring (`I002`) ([#19818](https://github.com/astral-sh/ruff/pull/19818)) +- \[`pyupgrade`\] Avoid reporting `__future__` features as unnecessary when they are used (`UP010`) ([#19769](https://github.com/astral-sh/ruff/pull/19769)) +- \[`pyupgrade`\] Handle nested `Optional`s (`UP045`) ([#19770](https://github.com/astral-sh/ruff/pull/19770)) + +### Rule changes + +- \[`pycodestyle`\] Make `E731` fix unsafe instead of display-only for class assignments ([#19700](https://github.com/astral-sh/ruff/pull/19700)) +- \[`pyflakes`\] Add secondary annotation showing previous definition (`F811`) ([#19900](https://github.com/astral-sh/ruff/pull/19900)) + +### Documentation + +- Fix description of global config file discovery strategy ([#19188](https://github.com/astral-sh/ruff/pull/19188)) +- Update outdated links to ([#19992](https://github.com/astral-sh/ruff/pull/19992)) +- \[`flake8-annotations`\] Remove unused import in example (`ANN401`) ([#20000](https://github.com/astral-sh/ruff/pull/20000)) + ## 0.12.9 ### Preview features diff --git a/Cargo.lock b/Cargo.lock index 72a90b18ea7b6..55388f373f912 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2743,7 +2743,7 @@ dependencies = [ [[package]] name = "ruff" -version = "0.12.9" +version = "0.12.10" dependencies = [ "anyhow", "argfile", @@ -2997,7 +2997,7 @@ dependencies = [ [[package]] name = "ruff_linter" -version = "0.12.9" +version = "0.12.10" dependencies = [ "aho-corasick", "anyhow", @@ -3336,7 +3336,7 @@ dependencies = [ [[package]] name = "ruff_wasm" -version = "0.12.9" +version = "0.12.10" dependencies = [ "console_error_panic_hook", "console_log", diff --git a/README.md b/README.md index cca5dbe09c348..b18b8307b42a9 100644 --- a/README.md +++ b/README.md @@ -148,8 +148,8 @@ curl -LsSf https://astral.sh/ruff/install.sh | sh powershell -c "irm https://astral.sh/ruff/install.ps1 | iex" # For a specific version. -curl -LsSf https://astral.sh/ruff/0.12.9/install.sh | sh -powershell -c "irm https://astral.sh/ruff/0.12.9/install.ps1 | iex" +curl -LsSf https://astral.sh/ruff/0.12.10/install.sh | sh +powershell -c "irm https://astral.sh/ruff/0.12.10/install.ps1 | iex" ``` You can also install Ruff via [Homebrew](https://formulae.brew.sh/formula/ruff), [Conda](https://anaconda.org/conda-forge/ruff), @@ -182,7 +182,7 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com/) hook via [`ruff ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.9 + rev: v0.12.10 hooks: # Run the linter. - id: ruff-check diff --git a/crates/ruff/Cargo.toml b/crates/ruff/Cargo.toml index 20b44648a333b..dd57a997078ff 100644 --- a/crates/ruff/Cargo.toml +++ b/crates/ruff/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruff" -version = "0.12.9" +version = "0.12.10" publish = true authors = { workspace = true } edition = { workspace = true } diff --git a/crates/ruff_linter/Cargo.toml b/crates/ruff_linter/Cargo.toml index aef2004ab57c7..50dfb754e612a 100644 --- a/crates/ruff_linter/Cargo.toml +++ b/crates/ruff_linter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruff_linter" -version = "0.12.9" +version = "0.12.10" publish = false authors = { workspace = true } edition = { workspace = true } diff --git a/crates/ruff_wasm/Cargo.toml b/crates/ruff_wasm/Cargo.toml index 9b6c0ed914a36..59224e461ae16 100644 --- a/crates/ruff_wasm/Cargo.toml +++ b/crates/ruff_wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruff_wasm" -version = "0.12.9" +version = "0.12.10" publish = false authors = { workspace = true } edition = { workspace = true } diff --git a/docs/integrations.md b/docs/integrations.md index f6b2d10d4dd08..ef431f2d911b9 100644 --- a/docs/integrations.md +++ b/docs/integrations.md @@ -80,7 +80,7 @@ You can add the following configuration to `.gitlab-ci.yml` to run a `ruff forma stage: build interruptible: true image: - name: ghcr.io/astral-sh/ruff:0.12.9-alpine + name: ghcr.io/astral-sh/ruff:0.12.10-alpine before_script: - cd $CI_PROJECT_DIR - ruff --version @@ -106,7 +106,7 @@ Ruff can be used as a [pre-commit](https://pre-commit.com) hook via [`ruff-pre-c ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.9 + rev: v0.12.10 hooks: # Run the linter. - id: ruff-check @@ -119,7 +119,7 @@ To enable lint fixes, add the `--fix` argument to the lint hook: ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.9 + rev: v0.12.10 hooks: # Run the linter. - id: ruff-check @@ -133,7 +133,7 @@ To avoid running on Jupyter Notebooks, remove `jupyter` from the list of allowed ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.9 + rev: v0.12.10 hooks: # Run the linter. - id: ruff-check diff --git a/docs/tutorial.md b/docs/tutorial.md index c111be14f3b57..56f119bac325b 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -369,7 +369,7 @@ This tutorial has focused on Ruff's command-line interface, but Ruff can also be ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.9 + rev: v0.12.10 hooks: # Run the linter. - id: ruff diff --git a/pyproject.toml b/pyproject.toml index 3af299d9ee227..499a0dac08bdb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "ruff" -version = "0.12.9" +version = "0.12.10" description = "An extremely fast Python linter and code formatter, written in Rust." authors = [{ name = "Astral Software Inc.", email = "hey@astral.sh" }] readme = "README.md" diff --git a/scripts/benchmarks/pyproject.toml b/scripts/benchmarks/pyproject.toml index 5ad99debbc56d..839e01432114f 100644 --- a/scripts/benchmarks/pyproject.toml +++ b/scripts/benchmarks/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "scripts" -version = "0.12.9" +version = "0.12.10" description = "" authors = ["Charles Marsh "] From fc5321e0007fb96de01b51682d9374247a9dfe5c Mon Sep 17 00:00:00 2001 From: Aria Desires Date: Thu, 21 Aug 2025 16:19:52 -0400 Subject: [PATCH 085/160] [ty] fix GotoTargets for keyword args in nested function calls (#20013) While implementing similar logic for initializers I noticed that this code appeared to be walking the ancestors in the wrong direction, and so if you have nested function calls it would always grab the outermost one instead of the closest-ancestor. The four copies of the test are because there's something really evil in our caching that can't seem to be demonstrated in our cursor testing framework, which I'm filing a followup for. --- crates/ty_ide/src/find_node.rs | 8 +- crates/ty_ide/src/goto_definition.rs | 152 +++++++++++++++++++++++++++ crates/ty_ide/src/selection_range.rs | 3 +- 3 files changed, 158 insertions(+), 5 deletions(-) diff --git a/crates/ty_ide/src/find_node.rs b/crates/ty_ide/src/find_node.rs index a56be5f7b957e..74c1de060bd87 100644 --- a/crates/ty_ide/src/find_node.rs +++ b/crates/ty_ide/src/find_node.rs @@ -116,10 +116,10 @@ impl<'a> CoveringNode<'a> { Ok(self) } - /// Returns an iterator over the ancestor nodes, starting from the root - /// and ending with the covering node. - pub(crate) fn ancestors(&self) -> impl Iterator> + '_ { - self.nodes.iter().copied() + /// Returns an iterator over the ancestor nodes, starting with the node itself + /// and walking towards the root. + pub(crate) fn ancestors(&self) -> impl DoubleEndedIterator> + '_ { + self.nodes.iter().copied().rev() } /// Finds the index of the node that fully covers the range and diff --git a/crates/ty_ide/src/goto_definition.rs b/crates/ty_ide/src/goto_definition.rs index aaa02cd2a231f..3c5edac5ec670 100644 --- a/crates/ty_ide/src/goto_definition.rs +++ b/crates/ty_ide/src/goto_definition.rs @@ -630,6 +630,158 @@ class MyClass: ... "); } + /// goto-definition on a nested call using a keyword arg where both funcs have that arg name + /// + /// In this case they ultimately have different signatures. + #[test] + fn goto_definition_nested_keyword_arg1() { + let test = CursorTest::builder() + .source( + "main.py", + r#" +def my_func(ab, y, z = None): ... +def my_other_func(ab, y): ... + +my_other_func(my_func(ab=5, y=2), 0) +my_func(my_other_func(ab=5, y=2), 0) +"#, + ) + .build(); + + assert_snapshot!(test.goto_definition(), @r" + info[goto-definition]: Definition + --> main.py:2:13 + | + 2 | def my_func(ab, y, z = None): ... + | ^^ + 3 | def my_other_func(ab, y): ... + | + info: Source + --> main.py:5:23 + | + 3 | def my_other_func(ab, y): ... + 4 | + 5 | my_other_func(my_func(ab=5, y=2), 0) + | ^^ + 6 | my_func(my_other_func(ab=5, y=2), 0) + | + "); + } + + /// goto-definition on a nested call using a keyword arg where both funcs have that arg name + /// + /// In this case they ultimately have different signatures. + #[test] + fn goto_definition_nested_keyword_arg2() { + let test = CursorTest::builder() + .source( + "main.py", + r#" +def my_func(ab, y, z = None): ... +def my_other_func(ab, y): ... + +my_other_func(my_func(ab=5, y=2), 0) +my_func(my_other_func(ab=5, y=2), 0) +"#, + ) + .build(); + + assert_snapshot!(test.goto_definition(), @r" + info[goto-definition]: Definition + --> main.py:3:19 + | + 2 | def my_func(ab, y, z = None): ... + 3 | def my_other_func(ab, y): ... + | ^^ + 4 | + 5 | my_other_func(my_func(ab=5, y=2), 0) + | + info: Source + --> main.py:6:23 + | + 5 | my_other_func(my_func(ab=5, y=2), 0) + 6 | my_func(my_other_func(ab=5, y=2), 0) + | ^^ + | + "); + } + + /// goto-definition on a nested call using a keyword arg where both funcs have that arg name + /// + /// In this case they have identical signatures. + #[test] + fn goto_definition_nested_keyword_arg3() { + let test = CursorTest::builder() + .source( + "main.py", + r#" +def my_func(ab, y): ... +def my_other_func(ab, y): ... + +my_other_func(my_func(ab=5, y=2), 0) +my_func(my_other_func(ab=5, y=2), 0) +"#, + ) + .build(); + + assert_snapshot!(test.goto_definition(), @r" + info[goto-definition]: Definition + --> main.py:2:13 + | + 2 | def my_func(ab, y): ... + | ^^ + 3 | def my_other_func(ab, y): ... + | + info: Source + --> main.py:5:23 + | + 3 | def my_other_func(ab, y): ... + 4 | + 5 | my_other_func(my_func(ab=5, y=2), 0) + | ^^ + 6 | my_func(my_other_func(ab=5, y=2), 0) + | + "); + } + + /// goto-definition on a nested call using a keyword arg where both funcs have that arg name + /// + /// In this case they have identical signatures. + #[test] + fn goto_definition_nested_keyword_arg4() { + let test = CursorTest::builder() + .source( + "main.py", + r#" +def my_func(ab, y): ... +def my_other_func(ab, y): ... + +my_other_func(my_func(ab=5, y=2), 0) +my_func(my_other_func(ab=5, y=2), 0) +"#, + ) + .build(); + + assert_snapshot!(test.goto_definition(), @r" + info[goto-definition]: Definition + --> main.py:3:19 + | + 2 | def my_func(ab, y): ... + 3 | def my_other_func(ab, y): ... + | ^^ + 4 | + 5 | my_other_func(my_func(ab=5, y=2), 0) + | + info: Source + --> main.py:6:23 + | + 5 | my_other_func(my_func(ab=5, y=2), 0) + 6 | my_func(my_other_func(ab=5, y=2), 0) + | ^^ + | + "); + } + impl CursorTest { fn goto_definition(&self) -> String { let Some(targets) = goto_definition(&self.db, self.cursor.file, self.cursor.offset) diff --git a/crates/ty_ide/src/selection_range.rs b/crates/ty_ide/src/selection_range.rs index 9603ff39e7fee..139b8d433cb70 100644 --- a/crates/ty_ide/src/selection_range.rs +++ b/crates/ty_ide/src/selection_range.rs @@ -14,7 +14,8 @@ pub fn selection_range(db: &dyn Db, file: File, offset: TextSize) -> Vec Date: Thu, 21 Aug 2025 22:36:40 +0200 Subject: [PATCH 086/160] [ty] Fix incorrect docstring in call signature completion (#20021) ## Summary This PR fixes https://github.com/astral-sh/ty/issues/1071 The core issue is that `CallableType` is a salsa interned but `Signature` (which `CallableType` stores) ignores the `Definition` in its `Eq` and `Hash` implementation. This PR tries to simplest fix by removing the custom `Eq` and `Hash` implementation. The main downside of this fix is that it can increase memory usage because `CallableType`s that are equal except for their `Definition` are now interned separately. The alternative is to remove `Definition` from `CallableType` and instead, call `bindings` directly on the callee (call_expression.func). However, this would require addressing the TODO here https://github.com/astral-sh/ruff/blob/39ee71c2a57bd6c51482430ba8bfe3728b4ca443/crates/ty_python_semantic/src/types.rs#L4582-L4586 This might probably be worth addressing anyway, but is the more involved fix. That's why I opted for removing the custom `Eq` implementation. We already "ignore" the definition during normalization, thank's to Alex's work in https://github.com/astral-sh/ruff/pull/19615 ## Test Plan https://github.com/user-attachments/assets/248d1cb1-12fd-4441-adab-b7e0866d23eb --- .../src/types/signatures.rs | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/crates/ty_python_semantic/src/types/signatures.rs b/crates/ty_python_semantic/src/types/signatures.rs index 478b75b057134..061c9b513d76e 100644 --- a/crates/ty_python_semantic/src/types/signatures.rs +++ b/crates/ty_python_semantic/src/types/signatures.rs @@ -247,7 +247,7 @@ impl<'db> VarianceInferable<'db> for &CallableSignature<'db> { } /// The signature of one of the overloads of a callable. -#[derive(Clone, Debug, salsa::Update, get_size2::GetSize)] +#[derive(Clone, Debug, salsa::Update, get_size2::GetSize, PartialEq, Eq, Hash)] pub struct Signature<'db> { /// The generic context for this overload, if it is generic. pub(crate) generic_context: Option>, @@ -993,28 +993,6 @@ impl<'db> Signature<'db> { } } -// Manual implementations of PartialEq, Eq, and Hash that exclude the definition field -// since the definition is not relevant for type equality/equivalence -impl PartialEq for Signature<'_> { - fn eq(&self, other: &Self) -> bool { - self.generic_context == other.generic_context - && self.inherited_generic_context == other.inherited_generic_context - && self.parameters == other.parameters - && self.return_ty == other.return_ty - } -} - -impl Eq for Signature<'_> {} - -impl std::hash::Hash for Signature<'_> { - fn hash(&self, state: &mut H) { - self.generic_context.hash(state); - self.inherited_generic_context.hash(state); - self.parameters.hash(state); - self.return_ty.hash(state); - } -} - impl<'db> VarianceInferable<'db> for &Signature<'db> { fn variance_of(self, db: &'db dyn Db, typevar: BoundTypeVarInstance<'db>) -> TypeVarVariance { tracing::debug!( From f82025d9196a872d94dce99e4ee84932b29af1ec Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 21 Aug 2025 22:00:44 +0100 Subject: [PATCH 087/160] [ty] Improve diagnostics for bad calls to functions (#20022) --- .../mdtest/diagnostics/missing_argument.md | 37 ++++++ .../diagnostics/too_many_positionals.md | 37 ++++++ .../mdtest/diagnostics/unknown_argument.md | 37 ++++++ ...\200\246_-_Syntax_(142fa2948c3c6cf1).snap" | 10 ++ ...-_Calls_to_methods_(4b3b8695d519a02).snap" | 2 +- ...nthetic_arguments_(4c09844bbbf47741).snap" | 2 +- ...t_dia\342\200\246_(f0811e84fcea1085).snap" | 117 ++++++++++++++++++ ...onal-\342\200\246_(eafa522239b42502).snap" | 117 ++++++++++++++++++ ...t_dia\342\200\246_(f419c2a8e2ce2412).snap" | 117 ++++++++++++++++++ .../ty_python_semantic/src/types/call/bind.rs | 39 +++++- 10 files changed, 511 insertions(+), 4 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/diagnostics/missing_argument.md create mode 100644 crates/ty_python_semantic/resources/mdtest/diagnostics/too_many_positionals.md create mode 100644 crates/ty_python_semantic/resources/mdtest/diagnostics/unknown_argument.md create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/missing_argument.md_-_Missing_argument_dia\342\200\246_(f0811e84fcea1085).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/too_many_positionals\342\200\246_-_too-many-positional-\342\200\246_(eafa522239b42502).snap" create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/unknown_argument.md_-_Unknown_argument_dia\342\200\246_(f419c2a8e2ce2412).snap" diff --git a/crates/ty_python_semantic/resources/mdtest/diagnostics/missing_argument.md b/crates/ty_python_semantic/resources/mdtest/diagnostics/missing_argument.md new file mode 100644 index 0000000000000..24a6e552b26bb --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/diagnostics/missing_argument.md @@ -0,0 +1,37 @@ +# Missing argument diagnostics + + + +If a non-union callable is called with a required parameter missing, we add a subdiagnostic showing +where the parameter was defined. We don't do this for unions as we currently emit a separate +diagnostic for each element of the union; having a sub-diagnostic for each element would probably be +too verbose for it to be worth it. + +`module.py`: + +```py +def f(a, b=42): ... +def g(a, b): ... + +class Foo: + def method(self, a): ... +``` + +`main.py`: + +```py +from module import f, g, Foo + +f() # error: [missing-argument] + +def coinflip() -> bool: + return True + +h = f if coinflip() else g + +# error: [missing-argument] +# error: [missing-argument] +h(b=56) + +Foo().method() # error: [missing-argument] +``` diff --git a/crates/ty_python_semantic/resources/mdtest/diagnostics/too_many_positionals.md b/crates/ty_python_semantic/resources/mdtest/diagnostics/too_many_positionals.md new file mode 100644 index 0000000000000..07eebd1c8cebc --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/diagnostics/too_many_positionals.md @@ -0,0 +1,37 @@ +# too-many-positional-arguments diagnostics + + + +If a non-union callable is called with too many positional arguments, we add a subdiagnostic showing +where the callable was defined. We don't do this for unions as we currently emit a separate +diagnostic for each element of the union; having a sub-diagnostic for each element would probably be +too verbose for it to be worth it. + +`module.py`: + +```py +def f(a, b=42): ... +def g(a, b): ... + +class Foo: + def method(self, a): ... +``` + +`main.py`: + +```py +from module import f, g, Foo + +f(1, 2, 3) # error: [too-many-positional-arguments] + +def coinflip() -> bool: + return True + +h = f if coinflip() else g + +# error: [too-many-positional-arguments] +# error: [too-many-positional-arguments] +h(1, 2, 3) + +Foo().method(1, 2) # error: [too-many-positional-arguments] +``` diff --git a/crates/ty_python_semantic/resources/mdtest/diagnostics/unknown_argument.md b/crates/ty_python_semantic/resources/mdtest/diagnostics/unknown_argument.md new file mode 100644 index 0000000000000..5e709233ecc49 --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/diagnostics/unknown_argument.md @@ -0,0 +1,37 @@ +# Unknown argument diagnostics + + + +If a non-union callable is called with a parameter that doesn't match any parameter from the +signature, we add a subdiagnostic showing where the callable was defined. We don't do this for +unions as we currently emit a separate diagnostic for each element of the union; having a +sub-diagnostic for each element would probably be too verbose for it to be worth it. + +`module.py`: + +```py +def f(a, b, c=42): ... +def g(a, b): ... + +class Foo: + def method(self, a, b): ... +``` + +`main.py`: + +```py +from module import f, g, Foo + +f(a=1, b=2, c=3, d=42) # error: [unknown-argument] + +def coinflip() -> bool: + return True + +h = f if coinflip() else g + +# error: [unknown-argument] +# error: [unknown-argument] +h(a=1, b=2, d=42) + +Foo().method(a=1, b=2, c=3) # error: [unknown-argument] +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" index ac29feddc9329..1a32df61af990 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" @@ -90,6 +90,16 @@ error[missing-argument]: No argument provided for required parameter `arg` of bo | ^^^^^^^^^^^^^^ 7 | from typing_extensions import deprecated | +info: Parameter declared here + --> stdlib/typing_extensions.pyi:967:28 + | +965 | stacklevel: int +966 | def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... +967 | def __call__(self, arg: _T, /) -> _T: ... + | ^^^^^^^ +968 | +969 | @final + | info: rule `missing-argument` is enabled by default ``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Calls_to_methods_(4b3b8695d519a02).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Calls_to_methods_(4b3b8695d519a02).snap" index e0483e581db39..a02a98d39125b 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Calls_to_methods_(4b3b8695d519a02).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Calls_to_methods_(4b3b8695d519a02).snap" @@ -30,7 +30,7 @@ error[invalid-argument-type]: Argument to bound method `square` is incorrect 6 | c.square("hello") # error: [invalid-argument-type] | ^^^^^^^ Expected `int`, found `Literal["hello"]` | -info: Function defined here +info: Method defined here --> src/mdtest_snippet.py:2:9 | 1 | class C: diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Tests_for_a_variety_\342\200\246_-_Synthetic_arguments_(4c09844bbbf47741).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Tests_for_a_variety_\342\200\246_-_Synthetic_arguments_(4c09844bbbf47741).snap" index a21d9085a59bb..5864211fc9101 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Tests_for_a_variety_\342\200\246_-_Synthetic_arguments_(4c09844bbbf47741).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_argument_typ\342\200\246_-_Invalid_argument_typ\342\200\246_-_Tests_for_a_variety_\342\200\246_-_Synthetic_arguments_(4c09844bbbf47741).snap" @@ -30,7 +30,7 @@ error[invalid-argument-type]: Argument to bound method `__call__` is incorrect 6 | c("wrong") # error: [invalid-argument-type] | ^^^^^^^ Expected `int`, found `Literal["wrong"]` | -info: Function defined here +info: Method defined here --> src/mdtest_snippet.py:2:9 | 1 | class C: diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/missing_argument.md_-_Missing_argument_dia\342\200\246_(f0811e84fcea1085).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/missing_argument.md_-_Missing_argument_dia\342\200\246_(f0811e84fcea1085).snap" new file mode 100644 index 0000000000000..5311a64551099 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/missing_argument.md_-_Missing_argument_dia\342\200\246_(f0811e84fcea1085).snap" @@ -0,0 +1,117 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: missing_argument.md - Missing argument diagnostics +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/missing_argument.md +--- + +# Python source files + +## module.py + +``` +1 | def f(a, b=42): ... +2 | def g(a, b): ... +3 | +4 | class Foo: +5 | def method(self, a): ... +``` + +## main.py + +``` + 1 | from module import f, g, Foo + 2 | + 3 | f() # error: [missing-argument] + 4 | + 5 | def coinflip() -> bool: + 6 | return True + 7 | + 8 | h = f if coinflip() else g + 9 | +10 | # error: [missing-argument] +11 | # error: [missing-argument] +12 | h(b=56) +13 | +14 | Foo().method() # error: [missing-argument] +``` + +# Diagnostics + +``` +error[missing-argument]: No argument provided for required parameter `a` of function `f` + --> src/main.py:3:1 + | +1 | from module import f, g, Foo +2 | +3 | f() # error: [missing-argument] + | ^^^ +4 | +5 | def coinflip() -> bool: + | +info: Parameter declared here + --> src/module.py:1:7 + | +1 | def f(a, b=42): ... + | ^ +2 | def g(a, b): ... + | +info: rule `missing-argument` is enabled by default + +``` + +``` +error[missing-argument]: No argument provided for required parameter `a` of function `f` + --> src/main.py:12:1 + | +10 | # error: [missing-argument] +11 | # error: [missing-argument] +12 | h(b=56) + | ^^^^^^^ +13 | +14 | Foo().method() # error: [missing-argument] + | +info: Union variant `def f(a, b=Literal[42]) -> Unknown` is incompatible with this call site +info: Attempted to call union type `(def f(a, b=Literal[42]) -> Unknown) | (def g(a, b) -> Unknown)` +info: rule `missing-argument` is enabled by default + +``` + +``` +error[missing-argument]: No argument provided for required parameter `a` of function `g` + --> src/main.py:12:1 + | +10 | # error: [missing-argument] +11 | # error: [missing-argument] +12 | h(b=56) + | ^^^^^^^ +13 | +14 | Foo().method() # error: [missing-argument] + | +info: Union variant `def g(a, b) -> Unknown` is incompatible with this call site +info: Attempted to call union type `(def f(a, b=Literal[42]) -> Unknown) | (def g(a, b) -> Unknown)` +info: rule `missing-argument` is enabled by default + +``` + +``` +error[missing-argument]: No argument provided for required parameter `a` of bound method `method` + --> src/main.py:14:1 + | +12 | h(b=56) +13 | +14 | Foo().method() # error: [missing-argument] + | ^^^^^^^^^^^^^^ + | +info: Parameter declared here + --> src/module.py:5:22 + | +4 | class Foo: +5 | def method(self, a): ... + | ^ + | +info: rule `missing-argument` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/too_many_positionals\342\200\246_-_too-many-positional-\342\200\246_(eafa522239b42502).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/too_many_positionals\342\200\246_-_too-many-positional-\342\200\246_(eafa522239b42502).snap" new file mode 100644 index 0000000000000..85d54b772bd8d --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/too_many_positionals\342\200\246_-_too-many-positional-\342\200\246_(eafa522239b42502).snap" @@ -0,0 +1,117 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: too_many_positionals.md - too-many-positional-arguments diagnostics +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/too_many_positionals.md +--- + +# Python source files + +## module.py + +``` +1 | def f(a, b=42): ... +2 | def g(a, b): ... +3 | +4 | class Foo: +5 | def method(self, a): ... +``` + +## main.py + +``` + 1 | from module import f, g, Foo + 2 | + 3 | f(1, 2, 3) # error: [too-many-positional-arguments] + 4 | + 5 | def coinflip() -> bool: + 6 | return True + 7 | + 8 | h = f if coinflip() else g + 9 | +10 | # error: [too-many-positional-arguments] +11 | # error: [too-many-positional-arguments] +12 | h(1, 2, 3) +13 | +14 | Foo().method(1, 2) # error: [too-many-positional-arguments] +``` + +# Diagnostics + +``` +error[too-many-positional-arguments]: Too many positional arguments to function `f`: expected 2, got 3 + --> src/main.py:3:9 + | +1 | from module import f, g, Foo +2 | +3 | f(1, 2, 3) # error: [too-many-positional-arguments] + | ^ +4 | +5 | def coinflip() -> bool: + | +info: Function signature here + --> src/module.py:1:5 + | +1 | def f(a, b=42): ... + | ^^^^^^^^^^ +2 | def g(a, b): ... + | +info: rule `too-many-positional-arguments` is enabled by default + +``` + +``` +error[too-many-positional-arguments]: Too many positional arguments to function `f`: expected 2, got 3 + --> src/main.py:12:9 + | +10 | # error: [too-many-positional-arguments] +11 | # error: [too-many-positional-arguments] +12 | h(1, 2, 3) + | ^ +13 | +14 | Foo().method(1, 2) # error: [too-many-positional-arguments] + | +info: Union variant `def f(a, b=Literal[42]) -> Unknown` is incompatible with this call site +info: Attempted to call union type `(def f(a, b=Literal[42]) -> Unknown) | (def g(a, b) -> Unknown)` +info: rule `too-many-positional-arguments` is enabled by default + +``` + +``` +error[too-many-positional-arguments]: Too many positional arguments to function `g`: expected 2, got 3 + --> src/main.py:12:9 + | +10 | # error: [too-many-positional-arguments] +11 | # error: [too-many-positional-arguments] +12 | h(1, 2, 3) + | ^ +13 | +14 | Foo().method(1, 2) # error: [too-many-positional-arguments] + | +info: Union variant `def g(a, b) -> Unknown` is incompatible with this call site +info: Attempted to call union type `(def f(a, b=Literal[42]) -> Unknown) | (def g(a, b) -> Unknown)` +info: rule `too-many-positional-arguments` is enabled by default + +``` + +``` +error[too-many-positional-arguments]: Too many positional arguments to bound method `method`: expected 2, got 3 + --> src/main.py:14:17 + | +12 | h(1, 2, 3) +13 | +14 | Foo().method(1, 2) # error: [too-many-positional-arguments] + | ^ + | +info: Method signature here + --> src/module.py:5:9 + | +4 | class Foo: +5 | def method(self, a): ... + | ^^^^^^^^^^^^^^^ + | +info: rule `too-many-positional-arguments` is enabled by default + +``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/unknown_argument.md_-_Unknown_argument_dia\342\200\246_(f419c2a8e2ce2412).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/unknown_argument.md_-_Unknown_argument_dia\342\200\246_(f419c2a8e2ce2412).snap" new file mode 100644 index 0000000000000..e311271fe83ec --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/unknown_argument.md_-_Unknown_argument_dia\342\200\246_(f419c2a8e2ce2412).snap" @@ -0,0 +1,117 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: unknown_argument.md - Unknown argument diagnostics +mdtest path: crates/ty_python_semantic/resources/mdtest/diagnostics/unknown_argument.md +--- + +# Python source files + +## module.py + +``` +1 | def f(a, b, c=42): ... +2 | def g(a, b): ... +3 | +4 | class Foo: +5 | def method(self, a, b): ... +``` + +## main.py + +``` + 1 | from module import f, g, Foo + 2 | + 3 | f(a=1, b=2, c=3, d=42) # error: [unknown-argument] + 4 | + 5 | def coinflip() -> bool: + 6 | return True + 7 | + 8 | h = f if coinflip() else g + 9 | +10 | # error: [unknown-argument] +11 | # error: [unknown-argument] +12 | h(a=1, b=2, d=42) +13 | +14 | Foo().method(a=1, b=2, c=3) # error: [unknown-argument] +``` + +# Diagnostics + +``` +error[unknown-argument]: Argument `d` does not match any known parameter of function `f` + --> src/main.py:3:18 + | +1 | from module import f, g, Foo +2 | +3 | f(a=1, b=2, c=3, d=42) # error: [unknown-argument] + | ^^^^ +4 | +5 | def coinflip() -> bool: + | +info: Function signature here + --> src/module.py:1:5 + | +1 | def f(a, b, c=42): ... + | ^^^^^^^^^^^^^ +2 | def g(a, b): ... + | +info: rule `unknown-argument` is enabled by default + +``` + +``` +error[unknown-argument]: Argument `d` does not match any known parameter of function `f` + --> src/main.py:12:13 + | +10 | # error: [unknown-argument] +11 | # error: [unknown-argument] +12 | h(a=1, b=2, d=42) + | ^^^^ +13 | +14 | Foo().method(a=1, b=2, c=3) # error: [unknown-argument] + | +info: Union variant `def f(a, b, c=Literal[42]) -> Unknown` is incompatible with this call site +info: Attempted to call union type `(def f(a, b, c=Literal[42]) -> Unknown) | (def g(a, b) -> Unknown)` +info: rule `unknown-argument` is enabled by default + +``` + +``` +error[unknown-argument]: Argument `d` does not match any known parameter of function `g` + --> src/main.py:12:13 + | +10 | # error: [unknown-argument] +11 | # error: [unknown-argument] +12 | h(a=1, b=2, d=42) + | ^^^^ +13 | +14 | Foo().method(a=1, b=2, c=3) # error: [unknown-argument] + | +info: Union variant `def g(a, b) -> Unknown` is incompatible with this call site +info: Attempted to call union type `(def f(a, b, c=Literal[42]) -> Unknown) | (def g(a, b) -> Unknown)` +info: rule `unknown-argument` is enabled by default + +``` + +``` +error[unknown-argument]: Argument `c` does not match any known parameter of bound method `method` + --> src/main.py:14:24 + | +12 | h(a=1, b=2, d=42) +13 | +14 | Foo().method(a=1, b=2, c=3) # error: [unknown-argument] + | ^^^ + | +info: Method signature here + --> src/module.py:5:9 + | +4 | class Foo: +5 | def method(self, a, b): ... + | ^^^^^^^^^^^^^^^^^^ + | +info: rule `unknown-argument` is enabled by default + +``` diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index da685d68ed909..8d728840d9b45 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -2759,6 +2759,12 @@ impl<'db> BindingError<'db> { union_diag: Option<&UnionDiagnostic<'_, '_>>, matching_overload: Option<&MatchingOverloadLiteral<'_>>, ) { + let callable_kind = match callable_ty { + Type::FunctionLiteral(_) => "Function", + Type::BoundMethod(_) => "Method", + _ => "Callable", + }; + match self { Self::InvalidArgumentType { parameter, @@ -2831,8 +2837,10 @@ impl<'db> BindingError<'db> { } else if let Some((name_span, parameter_span)) = callable_ty.parameter_span(context.db(), Some(parameter.index)) { - let mut sub = - SubDiagnostic::new(SubDiagnosticSeverity::Info, "Function defined here"); + let mut sub = SubDiagnostic::new( + SubDiagnosticSeverity::Info, + format_args!("{callable_kind} defined here"), + ); sub.annotate(Annotation::primary(name_span)); sub.annotate( Annotation::secondary(parameter_span).message("Parameter declared here"), @@ -2863,6 +2871,13 @@ impl<'db> BindingError<'db> { )); if let Some(union_diag) = union_diag { union_diag.add_union_context(context.db(), &mut diag); + } else if let Some(spans) = callable_ty.function_spans(context.db()) { + let mut sub = SubDiagnostic::new( + SubDiagnosticSeverity::Info, + format_args!("{callable_kind} signature here"), + ); + sub.annotate(Annotation::primary(spans.signature)); + diag.sub(sub); } } } @@ -2880,6 +2895,19 @@ impl<'db> BindingError<'db> { )); if let Some(union_diag) = union_diag { union_diag.add_union_context(context.db(), &mut diag); + } else { + let span = callable_ty.parameter_span( + context.db(), + (parameters.0.len() == 1).then(|| parameters.0[0].index), + ); + if let Some((_, parameter_span)) = span { + let mut sub = SubDiagnostic::new( + SubDiagnosticSeverity::Info, + format_args!("Parameter{s} declared here"), + ); + sub.annotate(Annotation::primary(parameter_span)); + diag.sub(sub); + } } } } @@ -2900,6 +2928,13 @@ impl<'db> BindingError<'db> { )); if let Some(union_diag) = union_diag { union_diag.add_union_context(context.db(), &mut diag); + } else if let Some(spans) = callable_ty.function_spans(context.db()) { + let mut sub = SubDiagnostic::new( + SubDiagnosticSeverity::Info, + format_args!("{callable_kind} signature here"), + ); + sub.annotate(Annotation::primary(spans.signature)); + diag.sub(sub); } } } From 7a44ea680e55f10af6e566eb5d9928244f79edd1 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Aug 2025 21:32:48 +0000 Subject: [PATCH 088/160] [ty] Sync vendored typeshed stubs (#20031) Co-authored-by: typeshedbot <> Co-authored-by: Alex Waygood --- ...\200\246_-_Syntax_(142fa2948c3c6cf1).snap" | 12 +- crates/ty_python_semantic/src/types/infer.rs | 17 +- .../src/types/special_form.rs | 3 +- .../vendor/typeshed/source_commit.txt | 2 +- .../vendor/typeshed/stdlib/_ast.pyi | 10 +- .../vendor/typeshed/stdlib/_blake2.pyi | 18 +- .../typeshed/stdlib/_collections_abc.pyi | 1 + .../vendor/typeshed/stdlib/_compat_pickle.pyi | 18 +- .../vendor/typeshed/stdlib/_ctypes.pyi | 22 +- .../vendor/typeshed/stdlib/_curses.pyi | 528 +++++++++--------- .../vendor/typeshed/stdlib/_curses_panel.pyi | 6 +- .../vendor/typeshed/stdlib/_dbm.pyi | 4 +- .../stdlib/_frozen_importlib_external.pyi | 38 +- .../vendor/typeshed/stdlib/_interpreters.pyi | 33 +- .../vendor/typeshed/stdlib/_lzma.pyi | 4 +- .../vendor/typeshed/stdlib/_msi.pyi | 78 +-- .../vendor/typeshed/stdlib/_thread.pyi | 2 +- .../typeshed/stdlib/_threading_local.pyi | 2 + .../typeshed/stdlib/_typeshed/__init__.pyi | 12 +- .../vendor/typeshed/stdlib/_winapi.pyi | 30 +- .../vendor/typeshed/stdlib/abc.pyi | 6 +- .../vendor/typeshed/stdlib/annotationlib.pyi | 2 +- .../vendor/typeshed/stdlib/argparse.pyi | 2 +- .../vendor/typeshed/stdlib/ast.pyi | 30 +- .../vendor/typeshed/stdlib/asyncio/events.pyi | 14 +- .../typeshed/stdlib/asyncio/protocols.pyi | 6 + .../typeshed/stdlib/asyncio/runners.pyi | 2 +- .../vendor/typeshed/stdlib/asyncio/tasks.pyi | 8 +- .../typeshed/stdlib/asyncio/transports.pyi | 8 + .../vendor/typeshed/stdlib/asyncio/trsock.pyi | 1 + .../typeshed/stdlib/asyncio/unix_events.pyi | 12 +- .../typeshed/stdlib/asyncio/windows_utils.pyi | 4 +- .../vendor/typeshed/stdlib/calendar.pyi | 38 +- .../vendor/typeshed/stdlib/colorsys.pyi | 8 +- .../stdlib/concurrent/futures/_base.pyi | 3 +- .../stdlib/concurrent/futures/process.pyi | 6 +- .../vendor/typeshed/stdlib/contextlib.pyi | 2 + .../typeshed/stdlib/ctypes/__init__.pyi | 13 +- .../vendor/typeshed/stdlib/ctypes/_endian.pyi | 4 + .../stdlib/ctypes/macholib/__init__.pyi | 4 +- .../typeshed/stdlib/ctypes/wintypes.pyi | 4 +- .../typeshed/stdlib/curses/__init__.pyi | 8 +- .../vendor/typeshed/stdlib/curses/ascii.pyi | 76 +-- .../vendor/typeshed/stdlib/dataclasses.pyi | 36 +- .../vendor/typeshed/stdlib/dis.pyi | 4 +- .../vendor/typeshed/stdlib/doctest.pyi | 34 +- .../stdlib/email/_header_value_parser.pyi | 2 +- .../vendor/typeshed/stdlib/email/charset.pyi | 13 +- .../vendor/typeshed/stdlib/enum.pyi | 16 +- .../vendor/typeshed/stdlib/errno.pyi | 405 +++++++------- .../vendor/typeshed/stdlib/filecmp.pyi | 2 +- .../vendor/typeshed/stdlib/fractions.pyi | 1 + .../vendor/typeshed/stdlib/functools.pyi | 2 +- .../vendor/typeshed/stdlib/glob.pyi | 8 +- .../vendor/typeshed/stdlib/hmac.pyi | 1 + .../vendor/typeshed/stdlib/html/entities.pyi | 10 +- .../vendor/typeshed/stdlib/http/client.pyi | 146 ++--- .../vendor/typeshed/stdlib/http/server.pyi | 101 +++- .../vendor/typeshed/stdlib/imp.pyi | 24 +- .../vendor/typeshed/stdlib/importlib/abc.pyi | 4 +- .../stdlib/importlib/metadata/__init__.pyi | 1 + .../vendor/typeshed/stdlib/inspect.pyi | 3 + .../vendor/typeshed/stdlib/ipaddress.pyi | 6 + .../typeshed/stdlib/logging/__init__.pyi | 8 +- .../vendor/typeshed/stdlib/logging/config.pyi | 6 +- .../typeshed/stdlib/logging/handlers.pyi | 12 +- .../typeshed/stdlib/msilib/__init__.pyi | 30 +- .../vendor/typeshed/stdlib/msilib/schema.pyi | 3 +- .../typeshed/stdlib/msilib/sequence.pyi | 13 +- .../vendor/typeshed/stdlib/msilib/text.pyi | 7 +- .../vendor/typeshed/stdlib/msvcrt.pyi | 8 +- .../stdlib/multiprocessing/managers.pyi | 1 + .../typeshed/stdlib/multiprocessing/util.pyi | 2 +- .../vendor/typeshed/stdlib/nturl2path.pyi | 4 +- .../vendor/typeshed/stdlib/numbers.pyi | 5 + .../vendor/typeshed/stdlib/opcode.pyi | 32 +- .../vendor/typeshed/stdlib/os/__init__.pyi | 371 ++++++------ .../vendor/typeshed/stdlib/ossaudiodev.pyi | 227 ++++---- .../typeshed/stdlib/pathlib/__init__.pyi | 41 +- .../vendor/typeshed/stdlib/pdb.pyi | 2 +- .../vendor/typeshed/stdlib/pickle.pyi | 148 ++--- .../vendor/typeshed/stdlib/pickletools.pyi | 15 +- .../vendor/typeshed/stdlib/platform.pyi | 2 +- .../vendor/typeshed/stdlib/plistlib.pyi | 6 +- .../vendor/typeshed/stdlib/poplib.pyi | 2 +- .../vendor/typeshed/stdlib/pydoc.pyi | 6 +- .../typeshed/stdlib/pydoc_data/topics.pyi | 4 +- .../vendor/typeshed/stdlib/resource.pyi | 41 +- .../vendor/typeshed/stdlib/select.pyi | 134 ++--- .../vendor/typeshed/stdlib/selectors.pyi | 6 +- .../vendor/typeshed/stdlib/smtplib.pyi | 14 +- .../vendor/typeshed/stdlib/socket.pyi | 155 ++--- .../vendor/typeshed/stdlib/sqlite3/dbapi2.pyi | 17 +- .../vendor/typeshed/stdlib/sre_compile.pyi | 4 +- .../vendor/typeshed/stdlib/sre_parse.pyi | 30 +- .../vendor/typeshed/stdlib/ssl.pyi | 4 +- .../vendor/typeshed/stdlib/statistics.pyi | 1 + .../typeshed/stdlib/string/__init__.pyi | 20 +- .../vendor/typeshed/stdlib/stringprep.pyi | 16 +- .../vendor/typeshed/stdlib/sunau.pyi | 30 +- .../vendor/typeshed/stdlib/symbol.pyi | 188 ++++--- .../vendor/typeshed/stdlib/symtable.pyi | 10 +- .../vendor/typeshed/stdlib/sys/__init__.pyi | 2 +- .../typeshed/stdlib/sys/_monitoring.pyi | 10 +- .../vendor/typeshed/stdlib/tarfile.pyi | 8 +- .../vendor/typeshed/stdlib/telnetlib.pyi | 158 +++--- .../vendor/typeshed/stdlib/tempfile.pyi | 4 +- .../vendor/typeshed/stdlib/threading.pyi | 20 +- .../vendor/typeshed/stdlib/time.pyi | 26 +- .../typeshed/stdlib/tkinter/__init__.pyi | 127 +++-- .../typeshed/stdlib/tkinter/messagebox.pyi | 6 +- .../vendor/typeshed/stdlib/tokenize.pyi | 74 +-- .../vendor/typeshed/stdlib/tomllib.pyi | 2 +- .../vendor/typeshed/stdlib/traceback.pyi | 19 +- .../vendor/typeshed/stdlib/tracemalloc.pyi | 5 + .../vendor/typeshed/stdlib/types.pyi | 2 +- .../vendor/typeshed/stdlib/typing.pyi | 55 +- .../typeshed/stdlib/typing_extensions.pyi | 9 +- .../vendor/typeshed/stdlib/unicodedata.pyi | 4 +- .../typeshed/stdlib/unittest/loader.pyi | 53 +- .../vendor/typeshed/stdlib/unittest/main.pyi | 7 +- .../vendor/typeshed/stdlib/unittest/mock.pyi | 10 +- .../vendor/typeshed/stdlib/unittest/util.pyi | 12 +- .../vendor/typeshed/stdlib/urllib/parse.pyi | 28 +- .../vendor/typeshed/stdlib/uuid.pyi | 1 + .../vendor/typeshed/stdlib/venv/__init__.pyi | 3 +- .../vendor/typeshed/stdlib/wave.pyi | 34 +- .../vendor/typeshed/stdlib/weakref.pyi | 3 + .../vendor/typeshed/stdlib/webbrowser.pyi | 38 +- .../vendor/typeshed/stdlib/winreg.pyi | 14 +- .../typeshed/stdlib/wsgiref/headers.pyi | 4 +- .../typeshed/stdlib/wsgiref/simple_server.pyi | 8 +- .../typeshed/stdlib/xml/dom/NodeFilter.pyi | 34 +- .../typeshed/stdlib/xml/dom/__init__.pyi | 33 +- .../typeshed/stdlib/xml/dom/expatbuilder.pyi | 21 +- .../typeshed/stdlib/xml/dom/minicompat.pyi | 2 + .../typeshed/stdlib/xml/dom/minidom.pyi | 26 + .../typeshed/stdlib/xml/dom/pulldom.pyi | 2 +- .../typeshed/stdlib/xml/dom/xmlbuilder.pyi | 24 +- .../stdlib/xml/etree/ElementInclude.pyi | 7 +- .../typeshed/stdlib/xml/etree/ElementPath.pyi | 6 +- .../typeshed/stdlib/xml/etree/ElementTree.pyi | 12 +- .../typeshed/stdlib/xml/sax/__init__.pyi | 4 +- .../typeshed/stdlib/xml/sax/expatreader.pyi | 4 +- .../typeshed/stdlib/xml/sax/handler.pyi | 32 +- .../typeshed/stdlib/zipfile/__init__.pyi | 31 +- .../typeshed/stdlib/zipfile/_path/glob.pyi | 6 +- 147 files changed, 2491 insertions(+), 2044 deletions(-) diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" index 1a32df61af990..8d387415ba731 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" @@ -91,14 +91,14 @@ error[missing-argument]: No argument provided for required parameter `arg` of bo 7 | from typing_extensions import deprecated | info: Parameter declared here - --> stdlib/typing_extensions.pyi:967:28 + --> stdlib/typing_extensions.pyi:973:28 | -965 | stacklevel: int -966 | def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... -967 | def __call__(self, arg: _T, /) -> _T: ... +971 | stacklevel: int +972 | def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... +973 | def __call__(self, arg: _T, /) -> _T: ... | ^^^^^^^ -968 | -969 | @final +974 | +975 | @final | info: rule `missing-argument` is enabled by default diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 07f82a732949c..5d3b21cc7edd2 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -4680,20 +4680,11 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } // Handle various singletons. - if let Type::NominalInstance(instance) = declared.inner_type() { - if instance - .class(self.db()) - .is_known(self.db(), KnownClass::SpecialForm) + if let Some(name_expr) = target.as_name_expr() { + if let Some(special_form) = + SpecialFormType::try_from_file_and_name(self.db(), self.file(), &name_expr.id) { - if let Some(name_expr) = target.as_name_expr() { - if let Some(special_form) = SpecialFormType::try_from_file_and_name( - self.db(), - self.file(), - &name_expr.id, - ) { - declared.inner = Type::SpecialForm(special_form); - } - } + declared.inner = Type::SpecialForm(special_form); } } diff --git a/crates/ty_python_semantic/src/types/special_form.rs b/crates/ty_python_semantic/src/types/special_form.rs index f0dd81b150cdf..3683283dfab0a 100644 --- a/crates/ty_python_semantic/src/types/special_form.rs +++ b/crates/ty_python_semantic/src/types/special_form.rs @@ -154,9 +154,10 @@ impl SpecialFormType { | Self::Intersection | Self::CallableTypeOf | Self::Protocol // actually `_ProtocolMeta` at runtime but this is what typeshed says - | Self::Generic // actually `type` at runtime but this is what typeshed says | Self::ReadOnly => KnownClass::SpecialForm, + Self::Generic => KnownClass::Type, + Self::List | Self::Dict | Self::DefaultDict diff --git a/crates/ty_vendored/vendor/typeshed/source_commit.txt b/crates/ty_vendored/vendor/typeshed/source_commit.txt index b09efe98fe9b4..9d77d588f91cb 100644 --- a/crates/ty_vendored/vendor/typeshed/source_commit.txt +++ b/crates/ty_vendored/vendor/typeshed/source_commit.txt @@ -1 +1 @@ -893b9a760deb3be64d13c748318e95a752230961 +f32d9f08bde8e42a3a35c050839d0275979eb3af diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_ast.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_ast.pyi index 00c6b357f7d80..d8d5a1829991e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_ast.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_ast.pyi @@ -108,7 +108,7 @@ from ast import ( unaryop as unaryop, withitem as withitem, ) -from typing import Literal +from typing import Final if sys.version_info >= (3, 12): from ast import ( @@ -137,9 +137,9 @@ if sys.version_info >= (3, 10): pattern as pattern, ) -PyCF_ALLOW_TOP_LEVEL_AWAIT: Literal[8192] -PyCF_ONLY_AST: Literal[1024] -PyCF_TYPE_COMMENTS: Literal[4096] +PyCF_ALLOW_TOP_LEVEL_AWAIT: Final = 8192 +PyCF_ONLY_AST: Final = 1024 +PyCF_TYPE_COMMENTS: Final = 4096 if sys.version_info >= (3, 13): - PyCF_OPTIMIZED_AST: Literal[33792] + PyCF_OPTIMIZED_AST: Final = 33792 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi index efaacea60a3f1..cf2872da70623 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi @@ -1,17 +1,17 @@ """_blake2b provides BLAKE2b for hashlib""" from _typeshed import ReadableBuffer -from typing import ClassVar, final +from typing import ClassVar, Final, final from typing_extensions import Self -BLAKE2B_MAX_DIGEST_SIZE: int = 64 -BLAKE2B_MAX_KEY_SIZE: int = 64 -BLAKE2B_PERSON_SIZE: int = 16 -BLAKE2B_SALT_SIZE: int = 16 -BLAKE2S_MAX_DIGEST_SIZE: int = 32 -BLAKE2S_MAX_KEY_SIZE: int = 32 -BLAKE2S_PERSON_SIZE: int = 8 -BLAKE2S_SALT_SIZE: int = 8 +BLAKE2B_MAX_DIGEST_SIZE: Final = 64 +BLAKE2B_MAX_KEY_SIZE: Final = 64 +BLAKE2B_PERSON_SIZE: Final = 16 +BLAKE2B_SALT_SIZE: Final = 16 +BLAKE2S_MAX_DIGEST_SIZE: Final = 32 +BLAKE2S_MAX_KEY_SIZE: Final = 32 +BLAKE2S_PERSON_SIZE: Final = 8 +BLAKE2S_SALT_SIZE: Final = 8 @final class blake2b: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_collections_abc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_collections_abc.pyi index 23199e713c52e..28bfd10ae5ef5 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_collections_abc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_collections_abc.pyi @@ -116,5 +116,6 @@ class dict_items(ItemsView[_KT_co, _VT_co]): # undocumented if sys.version_info >= (3, 12): @runtime_checkable class Buffer(Protocol): + __slots__ = () @abstractmethod def __buffer__(self, flags: int, /) -> memoryview: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_compat_pickle.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_compat_pickle.pyi index 50fb22442cc92..32c0b542d9913 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_compat_pickle.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_compat_pickle.pyi @@ -1,8 +1,10 @@ -IMPORT_MAPPING: dict[str, str] -NAME_MAPPING: dict[tuple[str, str], tuple[str, str]] -PYTHON2_EXCEPTIONS: tuple[str, ...] -MULTIPROCESSING_EXCEPTIONS: tuple[str, ...] -REVERSE_IMPORT_MAPPING: dict[str, str] -REVERSE_NAME_MAPPING: dict[tuple[str, str], tuple[str, str]] -PYTHON3_OSERROR_EXCEPTIONS: tuple[str, ...] -PYTHON3_IMPORTERROR_EXCEPTIONS: tuple[str, ...] +from typing import Final + +IMPORT_MAPPING: Final[dict[str, str]] +NAME_MAPPING: Final[dict[tuple[str, str], tuple[str, str]]] +PYTHON2_EXCEPTIONS: Final[tuple[str, ...]] +MULTIPROCESSING_EXCEPTIONS: Final[tuple[str, ...]] +REVERSE_IMPORT_MAPPING: Final[dict[str, str]] +REVERSE_NAME_MAPPING: Final[dict[tuple[str, str], tuple[str, str]]] +PYTHON3_OSERROR_EXCEPTIONS: Final[tuple[str, ...]] +PYTHON3_IMPORTERROR_EXCEPTIONS: Final[tuple[str, ...]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi index ba3f209bef962..2d7c2dc307f7a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_ctypes.pyi @@ -7,24 +7,24 @@ from abc import abstractmethod from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence from ctypes import CDLL, ArgumentError as ArgumentError, c_void_p from types import GenericAlias -from typing import Any, ClassVar, Generic, TypeVar, final, overload, type_check_only +from typing import Any, ClassVar, Final, Generic, TypeVar, final, overload, type_check_only from typing_extensions import Self, TypeAlias _T = TypeVar("_T") _CT = TypeVar("_CT", bound=_CData) -FUNCFLAG_CDECL: int -FUNCFLAG_PYTHONAPI: int -FUNCFLAG_USE_ERRNO: int -FUNCFLAG_USE_LASTERROR: int -RTLD_GLOBAL: int -RTLD_LOCAL: int +FUNCFLAG_CDECL: Final = 0x1 +FUNCFLAG_PYTHONAPI: Final = 0x4 +FUNCFLAG_USE_ERRNO: Final = 0x8 +FUNCFLAG_USE_LASTERROR: Final = 0x10 +RTLD_GLOBAL: Final[int] +RTLD_LOCAL: Final[int] if sys.version_info >= (3, 11): - CTYPES_MAX_ARGCOUNT: int + CTYPES_MAX_ARGCOUNT: Final[int] if sys.version_info >= (3, 12): - SIZEOF_TIME_T: int + SIZEOF_TIME_T: Final[int] if sys.platform == "win32": # Description, Source, HelpFile, HelpContext, scode @@ -41,8 +41,8 @@ if sys.platform == "win32": def CopyComPointer(src: _PointerLike, dst: _PointerLike | _CArgObject) -> int: """CopyComPointer(src, dst) -> HRESULT value""" - FUNCFLAG_HRESULT: int - FUNCFLAG_STDCALL: int + FUNCFLAG_HRESULT: Final = 0x2 + FUNCFLAG_STDCALL: Final = 0x0 def FormatError(code: int = ...) -> str: """FormatError([integer]) -> string diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi index f7421fad650ce..c5bf3a717a2ef 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadOnlyBuffer, SupportsRead, SupportsWrite from curses import _ncurses_version -from typing import Any, final, overload +from typing import Any, Final, final, overload from typing_extensions import TypeAlias # NOTE: This module is ordinarily only available on Unix, but the windows-curses @@ -11,270 +11,270 @@ from typing_extensions import TypeAlias _ChType: TypeAlias = str | bytes | int # ACS codes are only initialized after initscr is called -ACS_BBSS: int -ACS_BLOCK: int -ACS_BOARD: int -ACS_BSBS: int -ACS_BSSB: int -ACS_BSSS: int -ACS_BTEE: int -ACS_BULLET: int -ACS_CKBOARD: int -ACS_DARROW: int -ACS_DEGREE: int -ACS_DIAMOND: int -ACS_GEQUAL: int -ACS_HLINE: int -ACS_LANTERN: int -ACS_LARROW: int -ACS_LEQUAL: int -ACS_LLCORNER: int -ACS_LRCORNER: int -ACS_LTEE: int -ACS_NEQUAL: int -ACS_PI: int -ACS_PLMINUS: int -ACS_PLUS: int -ACS_RARROW: int -ACS_RTEE: int -ACS_S1: int -ACS_S3: int -ACS_S7: int -ACS_S9: int -ACS_SBBS: int -ACS_SBSB: int -ACS_SBSS: int -ACS_SSBB: int -ACS_SSBS: int -ACS_SSSB: int -ACS_SSSS: int -ACS_STERLING: int -ACS_TTEE: int -ACS_UARROW: int -ACS_ULCORNER: int -ACS_URCORNER: int -ACS_VLINE: int -ALL_MOUSE_EVENTS: int -A_ALTCHARSET: int -A_ATTRIBUTES: int -A_BLINK: int -A_BOLD: int -A_CHARTEXT: int -A_COLOR: int -A_DIM: int -A_HORIZONTAL: int -A_INVIS: int -A_ITALIC: int -A_LEFT: int -A_LOW: int -A_NORMAL: int -A_PROTECT: int -A_REVERSE: int -A_RIGHT: int -A_STANDOUT: int -A_TOP: int -A_UNDERLINE: int -A_VERTICAL: int -BUTTON1_CLICKED: int -BUTTON1_DOUBLE_CLICKED: int -BUTTON1_PRESSED: int -BUTTON1_RELEASED: int -BUTTON1_TRIPLE_CLICKED: int -BUTTON2_CLICKED: int -BUTTON2_DOUBLE_CLICKED: int -BUTTON2_PRESSED: int -BUTTON2_RELEASED: int -BUTTON2_TRIPLE_CLICKED: int -BUTTON3_CLICKED: int -BUTTON3_DOUBLE_CLICKED: int -BUTTON3_PRESSED: int -BUTTON3_RELEASED: int -BUTTON3_TRIPLE_CLICKED: int -BUTTON4_CLICKED: int -BUTTON4_DOUBLE_CLICKED: int -BUTTON4_PRESSED: int -BUTTON4_RELEASED: int -BUTTON4_TRIPLE_CLICKED: int +ACS_BBSS: Final[int] +ACS_BLOCK: Final[int] +ACS_BOARD: Final[int] +ACS_BSBS: Final[int] +ACS_BSSB: Final[int] +ACS_BSSS: Final[int] +ACS_BTEE: Final[int] +ACS_BULLET: Final[int] +ACS_CKBOARD: Final[int] +ACS_DARROW: Final[int] +ACS_DEGREE: Final[int] +ACS_DIAMOND: Final[int] +ACS_GEQUAL: Final[int] +ACS_HLINE: Final[int] +ACS_LANTERN: Final[int] +ACS_LARROW: Final[int] +ACS_LEQUAL: Final[int] +ACS_LLCORNER: Final[int] +ACS_LRCORNER: Final[int] +ACS_LTEE: Final[int] +ACS_NEQUAL: Final[int] +ACS_PI: Final[int] +ACS_PLMINUS: Final[int] +ACS_PLUS: Final[int] +ACS_RARROW: Final[int] +ACS_RTEE: Final[int] +ACS_S1: Final[int] +ACS_S3: Final[int] +ACS_S7: Final[int] +ACS_S9: Final[int] +ACS_SBBS: Final[int] +ACS_SBSB: Final[int] +ACS_SBSS: Final[int] +ACS_SSBB: Final[int] +ACS_SSBS: Final[int] +ACS_SSSB: Final[int] +ACS_SSSS: Final[int] +ACS_STERLING: Final[int] +ACS_TTEE: Final[int] +ACS_UARROW: Final[int] +ACS_ULCORNER: Final[int] +ACS_URCORNER: Final[int] +ACS_VLINE: Final[int] +ALL_MOUSE_EVENTS: Final[int] +A_ALTCHARSET: Final[int] +A_ATTRIBUTES: Final[int] +A_BLINK: Final[int] +A_BOLD: Final[int] +A_CHARTEXT: Final[int] +A_COLOR: Final[int] +A_DIM: Final[int] +A_HORIZONTAL: Final[int] +A_INVIS: Final[int] +A_ITALIC: Final[int] +A_LEFT: Final[int] +A_LOW: Final[int] +A_NORMAL: Final[int] +A_PROTECT: Final[int] +A_REVERSE: Final[int] +A_RIGHT: Final[int] +A_STANDOUT: Final[int] +A_TOP: Final[int] +A_UNDERLINE: Final[int] +A_VERTICAL: Final[int] +BUTTON1_CLICKED: Final[int] +BUTTON1_DOUBLE_CLICKED: Final[int] +BUTTON1_PRESSED: Final[int] +BUTTON1_RELEASED: Final[int] +BUTTON1_TRIPLE_CLICKED: Final[int] +BUTTON2_CLICKED: Final[int] +BUTTON2_DOUBLE_CLICKED: Final[int] +BUTTON2_PRESSED: Final[int] +BUTTON2_RELEASED: Final[int] +BUTTON2_TRIPLE_CLICKED: Final[int] +BUTTON3_CLICKED: Final[int] +BUTTON3_DOUBLE_CLICKED: Final[int] +BUTTON3_PRESSED: Final[int] +BUTTON3_RELEASED: Final[int] +BUTTON3_TRIPLE_CLICKED: Final[int] +BUTTON4_CLICKED: Final[int] +BUTTON4_DOUBLE_CLICKED: Final[int] +BUTTON4_PRESSED: Final[int] +BUTTON4_RELEASED: Final[int] +BUTTON4_TRIPLE_CLICKED: Final[int] # Darwin ncurses doesn't provide BUTTON5_* constants prior to 3.12.10 and 3.13.3 if sys.version_info >= (3, 10): if sys.version_info >= (3, 12) or sys.platform != "darwin": - BUTTON5_PRESSED: int - BUTTON5_RELEASED: int - BUTTON5_CLICKED: int - BUTTON5_DOUBLE_CLICKED: int - BUTTON5_TRIPLE_CLICKED: int -BUTTON_ALT: int -BUTTON_CTRL: int -BUTTON_SHIFT: int -COLOR_BLACK: int -COLOR_BLUE: int -COLOR_CYAN: int -COLOR_GREEN: int -COLOR_MAGENTA: int -COLOR_RED: int -COLOR_WHITE: int -COLOR_YELLOW: int -ERR: int -KEY_A1: int -KEY_A3: int -KEY_B2: int -KEY_BACKSPACE: int -KEY_BEG: int -KEY_BREAK: int -KEY_BTAB: int -KEY_C1: int -KEY_C3: int -KEY_CANCEL: int -KEY_CATAB: int -KEY_CLEAR: int -KEY_CLOSE: int -KEY_COMMAND: int -KEY_COPY: int -KEY_CREATE: int -KEY_CTAB: int -KEY_DC: int -KEY_DL: int -KEY_DOWN: int -KEY_EIC: int -KEY_END: int -KEY_ENTER: int -KEY_EOL: int -KEY_EOS: int -KEY_EXIT: int -KEY_F0: int -KEY_F1: int -KEY_F10: int -KEY_F11: int -KEY_F12: int -KEY_F13: int -KEY_F14: int -KEY_F15: int -KEY_F16: int -KEY_F17: int -KEY_F18: int -KEY_F19: int -KEY_F2: int -KEY_F20: int -KEY_F21: int -KEY_F22: int -KEY_F23: int -KEY_F24: int -KEY_F25: int -KEY_F26: int -KEY_F27: int -KEY_F28: int -KEY_F29: int -KEY_F3: int -KEY_F30: int -KEY_F31: int -KEY_F32: int -KEY_F33: int -KEY_F34: int -KEY_F35: int -KEY_F36: int -KEY_F37: int -KEY_F38: int -KEY_F39: int -KEY_F4: int -KEY_F40: int -KEY_F41: int -KEY_F42: int -KEY_F43: int -KEY_F44: int -KEY_F45: int -KEY_F46: int -KEY_F47: int -KEY_F48: int -KEY_F49: int -KEY_F5: int -KEY_F50: int -KEY_F51: int -KEY_F52: int -KEY_F53: int -KEY_F54: int -KEY_F55: int -KEY_F56: int -KEY_F57: int -KEY_F58: int -KEY_F59: int -KEY_F6: int -KEY_F60: int -KEY_F61: int -KEY_F62: int -KEY_F63: int -KEY_F7: int -KEY_F8: int -KEY_F9: int -KEY_FIND: int -KEY_HELP: int -KEY_HOME: int -KEY_IC: int -KEY_IL: int -KEY_LEFT: int -KEY_LL: int -KEY_MARK: int -KEY_MAX: int -KEY_MESSAGE: int -KEY_MIN: int -KEY_MOUSE: int -KEY_MOVE: int -KEY_NEXT: int -KEY_NPAGE: int -KEY_OPEN: int -KEY_OPTIONS: int -KEY_PPAGE: int -KEY_PREVIOUS: int -KEY_PRINT: int -KEY_REDO: int -KEY_REFERENCE: int -KEY_REFRESH: int -KEY_REPLACE: int -KEY_RESET: int -KEY_RESIZE: int -KEY_RESTART: int -KEY_RESUME: int -KEY_RIGHT: int -KEY_SAVE: int -KEY_SBEG: int -KEY_SCANCEL: int -KEY_SCOMMAND: int -KEY_SCOPY: int -KEY_SCREATE: int -KEY_SDC: int -KEY_SDL: int -KEY_SELECT: int -KEY_SEND: int -KEY_SEOL: int -KEY_SEXIT: int -KEY_SF: int -KEY_SFIND: int -KEY_SHELP: int -KEY_SHOME: int -KEY_SIC: int -KEY_SLEFT: int -KEY_SMESSAGE: int -KEY_SMOVE: int -KEY_SNEXT: int -KEY_SOPTIONS: int -KEY_SPREVIOUS: int -KEY_SPRINT: int -KEY_SR: int -KEY_SREDO: int -KEY_SREPLACE: int -KEY_SRESET: int -KEY_SRIGHT: int -KEY_SRSUME: int -KEY_SSAVE: int -KEY_SSUSPEND: int -KEY_STAB: int -KEY_SUNDO: int -KEY_SUSPEND: int -KEY_UNDO: int -KEY_UP: int -OK: int -REPORT_MOUSE_POSITION: int + BUTTON5_PRESSED: Final[int] + BUTTON5_RELEASED: Final[int] + BUTTON5_CLICKED: Final[int] + BUTTON5_DOUBLE_CLICKED: Final[int] + BUTTON5_TRIPLE_CLICKED: Final[int] +BUTTON_ALT: Final[int] +BUTTON_CTRL: Final[int] +BUTTON_SHIFT: Final[int] +COLOR_BLACK: Final[int] +COLOR_BLUE: Final[int] +COLOR_CYAN: Final[int] +COLOR_GREEN: Final[int] +COLOR_MAGENTA: Final[int] +COLOR_RED: Final[int] +COLOR_WHITE: Final[int] +COLOR_YELLOW: Final[int] +ERR: Final[int] +KEY_A1: Final[int] +KEY_A3: Final[int] +KEY_B2: Final[int] +KEY_BACKSPACE: Final[int] +KEY_BEG: Final[int] +KEY_BREAK: Final[int] +KEY_BTAB: Final[int] +KEY_C1: Final[int] +KEY_C3: Final[int] +KEY_CANCEL: Final[int] +KEY_CATAB: Final[int] +KEY_CLEAR: Final[int] +KEY_CLOSE: Final[int] +KEY_COMMAND: Final[int] +KEY_COPY: Final[int] +KEY_CREATE: Final[int] +KEY_CTAB: Final[int] +KEY_DC: Final[int] +KEY_DL: Final[int] +KEY_DOWN: Final[int] +KEY_EIC: Final[int] +KEY_END: Final[int] +KEY_ENTER: Final[int] +KEY_EOL: Final[int] +KEY_EOS: Final[int] +KEY_EXIT: Final[int] +KEY_F0: Final[int] +KEY_F1: Final[int] +KEY_F10: Final[int] +KEY_F11: Final[int] +KEY_F12: Final[int] +KEY_F13: Final[int] +KEY_F14: Final[int] +KEY_F15: Final[int] +KEY_F16: Final[int] +KEY_F17: Final[int] +KEY_F18: Final[int] +KEY_F19: Final[int] +KEY_F2: Final[int] +KEY_F20: Final[int] +KEY_F21: Final[int] +KEY_F22: Final[int] +KEY_F23: Final[int] +KEY_F24: Final[int] +KEY_F25: Final[int] +KEY_F26: Final[int] +KEY_F27: Final[int] +KEY_F28: Final[int] +KEY_F29: Final[int] +KEY_F3: Final[int] +KEY_F30: Final[int] +KEY_F31: Final[int] +KEY_F32: Final[int] +KEY_F33: Final[int] +KEY_F34: Final[int] +KEY_F35: Final[int] +KEY_F36: Final[int] +KEY_F37: Final[int] +KEY_F38: Final[int] +KEY_F39: Final[int] +KEY_F4: Final[int] +KEY_F40: Final[int] +KEY_F41: Final[int] +KEY_F42: Final[int] +KEY_F43: Final[int] +KEY_F44: Final[int] +KEY_F45: Final[int] +KEY_F46: Final[int] +KEY_F47: Final[int] +KEY_F48: Final[int] +KEY_F49: Final[int] +KEY_F5: Final[int] +KEY_F50: Final[int] +KEY_F51: Final[int] +KEY_F52: Final[int] +KEY_F53: Final[int] +KEY_F54: Final[int] +KEY_F55: Final[int] +KEY_F56: Final[int] +KEY_F57: Final[int] +KEY_F58: Final[int] +KEY_F59: Final[int] +KEY_F6: Final[int] +KEY_F60: Final[int] +KEY_F61: Final[int] +KEY_F62: Final[int] +KEY_F63: Final[int] +KEY_F7: Final[int] +KEY_F8: Final[int] +KEY_F9: Final[int] +KEY_FIND: Final[int] +KEY_HELP: Final[int] +KEY_HOME: Final[int] +KEY_IC: Final[int] +KEY_IL: Final[int] +KEY_LEFT: Final[int] +KEY_LL: Final[int] +KEY_MARK: Final[int] +KEY_MAX: Final[int] +KEY_MESSAGE: Final[int] +KEY_MIN: Final[int] +KEY_MOUSE: Final[int] +KEY_MOVE: Final[int] +KEY_NEXT: Final[int] +KEY_NPAGE: Final[int] +KEY_OPEN: Final[int] +KEY_OPTIONS: Final[int] +KEY_PPAGE: Final[int] +KEY_PREVIOUS: Final[int] +KEY_PRINT: Final[int] +KEY_REDO: Final[int] +KEY_REFERENCE: Final[int] +KEY_REFRESH: Final[int] +KEY_REPLACE: Final[int] +KEY_RESET: Final[int] +KEY_RESIZE: Final[int] +KEY_RESTART: Final[int] +KEY_RESUME: Final[int] +KEY_RIGHT: Final[int] +KEY_SAVE: Final[int] +KEY_SBEG: Final[int] +KEY_SCANCEL: Final[int] +KEY_SCOMMAND: Final[int] +KEY_SCOPY: Final[int] +KEY_SCREATE: Final[int] +KEY_SDC: Final[int] +KEY_SDL: Final[int] +KEY_SELECT: Final[int] +KEY_SEND: Final[int] +KEY_SEOL: Final[int] +KEY_SEXIT: Final[int] +KEY_SF: Final[int] +KEY_SFIND: Final[int] +KEY_SHELP: Final[int] +KEY_SHOME: Final[int] +KEY_SIC: Final[int] +KEY_SLEFT: Final[int] +KEY_SMESSAGE: Final[int] +KEY_SMOVE: Final[int] +KEY_SNEXT: Final[int] +KEY_SOPTIONS: Final[int] +KEY_SPREVIOUS: Final[int] +KEY_SPRINT: Final[int] +KEY_SR: Final[int] +KEY_SREDO: Final[int] +KEY_SREPLACE: Final[int] +KEY_SRESET: Final[int] +KEY_SRIGHT: Final[int] +KEY_SRSUME: Final[int] +KEY_SSAVE: Final[int] +KEY_SSUSPEND: Final[int] +KEY_STAB: Final[int] +KEY_SUNDO: Final[int] +KEY_SUSPEND: Final[int] +KEY_UNDO: Final[int] +KEY_UP: Final[int] +OK: Final[int] +REPORT_MOUSE_POSITION: Final[int] _C_API: Any -version: bytes +version: Final[bytes] def baudrate() -> int: """Return the output speed of the terminal in bits per second.""" @@ -947,7 +947,7 @@ class window: # undocumented def attrset(self, attr: int, /) -> None: """Set the "background" set of attributes.""" - def bkgd(self, ch: _ChType, attr: int = ..., /) -> None: + def bkgd(self, ch: _ChType, attr: int = 0, /) -> None: """Set the background property of the window. ch @@ -956,7 +956,7 @@ class window: # undocumented Background attributes. """ - def bkgdset(self, ch: _ChType, attr: int = ..., /) -> None: + def bkgdset(self, ch: _ChType, attr: int = 0, /) -> None: """Set the window's background. ch @@ -1085,7 +1085,7 @@ class window: # undocumented @overload def derwin(self, nlines: int, ncols: int, begin_y: int, begin_x: int) -> window: ... - def echochar(self, ch: _ChType, attr: int = ..., /) -> None: + def echochar(self, ch: _ChType, attr: int = 0, /) -> None: """Add character ch with attribute attr, and refresh. ch diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_curses_panel.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_curses_panel.pyi index 708dda319173a..39c877ed5816b 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_curses_panel.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_curses_panel.pyi @@ -1,8 +1,8 @@ from _curses import window -from typing import final +from typing import Final, final -__version__: str -version: str +__version__: Final[str] +version: Final[str] class error(Exception): ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi index 070398f7947e5..b9165094ffe3a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi @@ -1,7 +1,7 @@ import sys from _typeshed import ReadOnlyBuffer, StrOrBytesPath from types import TracebackType -from typing import TypeVar, final, overload, type_check_only +from typing import Final, TypeVar, final, overload, type_check_only from typing_extensions import Self, TypeAlias if sys.platform != "win32": @@ -10,7 +10,7 @@ if sys.platform != "win32": _ValueType: TypeAlias = str | ReadOnlyBuffer class error(OSError): ... - library: str + library: Final[str] # Actual typename dbm, not exposed by the implementation @final diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi index 8986a981e9ffa..bd0291a7fe512 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_frozen_importlib_external.pyi @@ -18,7 +18,7 @@ from _typeshed.importlib import LoaderProtocol from collections.abc import Callable, Iterable, Iterator, Mapping, MutableSequence, Sequence from importlib.machinery import ModuleSpec from importlib.metadata import DistributionFinder, PathDistribution -from typing import Any, Literal +from typing import Any, Final, Literal from typing_extensions import Self, deprecated if sys.version_info >= (3, 10): @@ -33,7 +33,7 @@ else: path_sep: Literal["/"] path_sep_tuple: tuple[Literal["/"]] -MAGIC_NUMBER: bytes +MAGIC_NUMBER: Final[bytes] def cache_from_source(path: StrPath, debug_override: bool | None = None, *, optimization: Any | None = None) -> str: """Given the path to a .py file, return the path to its .pyc file. @@ -89,7 +89,7 @@ def spec_from_file_location( """ @deprecated( - "Deprecated as of Python 3.6: Use site configuration instead. " + "Deprecated since Python 3.6. Use site configuration instead. " "Future versions of Python may not enable this finder by default." ) class WindowsRegistryFinder(importlib.abc.MetaPathFinder): @@ -167,11 +167,11 @@ class PathFinder(importlib.abc.MetaPathFinder): """ -SOURCE_SUFFIXES: list[str] -DEBUG_BYTECODE_SUFFIXES: list[str] -OPTIMIZED_BYTECODE_SUFFIXES: list[str] -BYTECODE_SUFFIXES: list[str] -EXTENSION_SUFFIXES: list[str] +SOURCE_SUFFIXES: Final[list[str]] +DEBUG_BYTECODE_SUFFIXES: Final = [".pyc"] +OPTIMIZED_BYTECODE_SUFFIXES: Final = [".pyc"] +BYTECODE_SUFFIXES: Final = [".pyc"] +EXTENSION_SUFFIXES: Final[list[str]] class FileFinder(importlib.abc.PathEntryFinder): """File-based finder. @@ -365,7 +365,7 @@ if sys.version_info >= (3, 11): """Use default semantics for module creation.""" def exec_module(self, module: types.ModuleType) -> None: ... - @deprecated("load_module() is deprecated; use exec_module() instead") + @deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `exec_module()` instead.") def load_module(self, fullname: str) -> types.ModuleType: """Load a namespace module. @@ -400,14 +400,15 @@ else: """Use default semantics for module creation.""" def exec_module(self, module: types.ModuleType) -> None: ... - @deprecated("load_module() is deprecated; use exec_module() instead") - def load_module(self, fullname: str) -> types.ModuleType: - """Load a namespace module. + if sys.version_info >= (3, 10): + @deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `exec_module()` instead.") + def load_module(self, fullname: str) -> types.ModuleType: + """Load a namespace module. - This method is deprecated. Use exec_module() instead. + This method is deprecated. Use exec_module() instead. + + """ - """ - if sys.version_info >= (3, 10): @staticmethod @deprecated( "Deprecated since Python 3.4; removed in Python 3.12. " @@ -422,6 +423,13 @@ else: def get_resource_reader(self, module: types.ModuleType) -> importlib.readers.NamespaceReader: ... else: + def load_module(self, fullname: str) -> types.ModuleType: + """Load a namespace module. + + This method is deprecated. Use exec_module() instead. + + """ + @classmethod @deprecated( "Deprecated since Python 3.4; removed in Python 3.12. " diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi index be2e5f184c86a..7bbf2a42d4fe0 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi @@ -4,7 +4,7 @@ The 'interpreters' module provides a more convenient interface. import types from collections.abc import Callable -from typing import Any, Final, Literal, SupportsIndex, TypeVar +from typing import Any, Final, Literal, SupportsIndex, TypeVar, overload from typing_extensions import TypeAlias _R = TypeVar("_R") @@ -60,19 +60,19 @@ def destroy(id: SupportsIndex, *, restrict: bool = False) -> None: So does an unrecognized ID. """ -def list_all(*, require_ready: bool) -> list[tuple[int, int]]: +def list_all(*, require_ready: bool = False) -> list[tuple[int, _Whence]]: """list_all() -> [(ID, whence)] Return a list containing the ID of every existing interpreter. """ -def get_current() -> tuple[int, int]: +def get_current() -> tuple[int, _Whence]: """get_current() -> (ID, whence) Return the ID of current interpreter. """ -def get_main() -> tuple[int, int]: +def get_main() -> tuple[int, _Whence]: """get_main() -> (ID, whence) Return the ID of main interpreter. @@ -97,11 +97,7 @@ def whence(id: SupportsIndex) -> _Whence: """ def exec( - id: SupportsIndex, - code: str | types.CodeType | Callable[[], object], - shared: _SharedDict | None = None, - *, - restrict: bool = False, + id: SupportsIndex, code: str | types.CodeType | Callable[[], object], shared: _SharedDict = {}, *, restrict: bool = False ) -> None | types.SimpleNamespace: """exec(id, code, shared=None, *, restrict=False) @@ -123,9 +119,10 @@ def exec( def call( id: SupportsIndex, callable: Callable[..., _R], - args: tuple[Any, ...] | None = None, - kwargs: dict[str, Any] | None = None, + args: tuple[Any, ...] = (), + kwargs: dict[str, Any] = {}, *, + preserve_exc: bool = False, restrict: bool = False, ) -> tuple[_R, types.SimpleNamespace]: """call(id, callable, args=None, kwargs=None, *, restrict=False) @@ -135,11 +132,7 @@ def call( """ def run_string( - id: SupportsIndex, - script: str | types.CodeType | Callable[[], object], - shared: _SharedDict | None = None, - *, - restrict: bool = False, + id: SupportsIndex, script: str | types.CodeType | Callable[[], object], shared: _SharedDict = {}, *, restrict: bool = False ) -> None: """run_string(id, script, shared=None, *, restrict=False) @@ -149,7 +142,7 @@ def run_string( """ def run_func( - id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: _SharedDict | None = None, *, restrict: bool = False + id: SupportsIndex, func: types.CodeType | Callable[[], object], shared: _SharedDict = {}, *, restrict: bool = False ) -> None: """run_func(id, func, shared=None, *, restrict=False) @@ -175,7 +168,8 @@ def is_shareable(obj: object) -> bool: False otherwise. """ -def capture_exception(exc: BaseException | None = None) -> types.SimpleNamespace: +@overload +def capture_exception(exc: BaseException) -> types.SimpleNamespace: """capture_exception(exc=None) -> types.SimpleNamespace Return a snapshot of an exception. If "exc" is None @@ -184,6 +178,9 @@ def capture_exception(exc: BaseException | None = None) -> types.SimpleNamespace The returned snapshot is the same as what _interpreters.exec() returns. """ +@overload +def capture_exception(exc: None = None) -> types.SimpleNamespace | None: ... + _Whence: TypeAlias = Literal[0, 1, 2, 3, 4, 5] WHENCE_UNKNOWN: Final = 0 WHENCE_RUNTIME: Final = 1 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi index b3b9746cbd395..a91a3608710ec 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi @@ -16,7 +16,7 @@ CHECK_CRC64: Final = 4 CHECK_SHA256: Final = 10 CHECK_ID_MAX: Final = 15 CHECK_UNKNOWN: Final = 16 -FILTER_LZMA1: int # v big number +FILTER_LZMA1: Final[int] # v big number FILTER_LZMA2: Final = 33 FILTER_DELTA: Final = 3 FILTER_X86: Final = 4 @@ -33,7 +33,7 @@ MF_BT4: Final = 20 MODE_FAST: Final = 1 MODE_NORMAL: Final = 2 PRESET_DEFAULT: Final = 6 -PRESET_EXTREME: int # v big number +PRESET_EXTREME: Final[int] # v big number @final class LZMADecompressor: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi index b828147122bd5..353942a5296cf 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_msi.pyi @@ -1,7 +1,7 @@ """Documentation""" import sys -from typing import type_check_only +from typing import Final, type_check_only if sys.platform == "win32": class MSIError(Exception): ... @@ -81,42 +81,42 @@ if sys.platform == "win32": count the number of fields of the record """ - MSICOLINFO_NAMES: int - MSICOLINFO_TYPES: int - MSIDBOPEN_CREATE: int - MSIDBOPEN_CREATEDIRECT: int - MSIDBOPEN_DIRECT: int - MSIDBOPEN_PATCHFILE: int - MSIDBOPEN_READONLY: int - MSIDBOPEN_TRANSACT: int - MSIMODIFY_ASSIGN: int - MSIMODIFY_DELETE: int - MSIMODIFY_INSERT: int - MSIMODIFY_INSERT_TEMPORARY: int - MSIMODIFY_MERGE: int - MSIMODIFY_REFRESH: int - MSIMODIFY_REPLACE: int - MSIMODIFY_SEEK: int - MSIMODIFY_UPDATE: int - MSIMODIFY_VALIDATE: int - MSIMODIFY_VALIDATE_DELETE: int - MSIMODIFY_VALIDATE_FIELD: int - MSIMODIFY_VALIDATE_NEW: int + MSICOLINFO_NAMES: Final[int] + MSICOLINFO_TYPES: Final[int] + MSIDBOPEN_CREATE: Final[int] + MSIDBOPEN_CREATEDIRECT: Final[int] + MSIDBOPEN_DIRECT: Final[int] + MSIDBOPEN_PATCHFILE: Final[int] + MSIDBOPEN_READONLY: Final[int] + MSIDBOPEN_TRANSACT: Final[int] + MSIMODIFY_ASSIGN: Final[int] + MSIMODIFY_DELETE: Final[int] + MSIMODIFY_INSERT: Final[int] + MSIMODIFY_INSERT_TEMPORARY: Final[int] + MSIMODIFY_MERGE: Final[int] + MSIMODIFY_REFRESH: Final[int] + MSIMODIFY_REPLACE: Final[int] + MSIMODIFY_SEEK: Final[int] + MSIMODIFY_UPDATE: Final[int] + MSIMODIFY_VALIDATE: Final[int] + MSIMODIFY_VALIDATE_DELETE: Final[int] + MSIMODIFY_VALIDATE_FIELD: Final[int] + MSIMODIFY_VALIDATE_NEW: Final[int] - PID_APPNAME: int - PID_AUTHOR: int - PID_CHARCOUNT: int - PID_CODEPAGE: int - PID_COMMENTS: int - PID_CREATE_DTM: int - PID_KEYWORDS: int - PID_LASTAUTHOR: int - PID_LASTPRINTED: int - PID_LASTSAVE_DTM: int - PID_PAGECOUNT: int - PID_REVNUMBER: int - PID_SECURITY: int - PID_SUBJECT: int - PID_TEMPLATE: int - PID_TITLE: int - PID_WORDCOUNT: int + PID_APPNAME: Final[int] + PID_AUTHOR: Final[int] + PID_CHARCOUNT: Final[int] + PID_CODEPAGE: Final[int] + PID_COMMENTS: Final[int] + PID_CREATE_DTM: Final[int] + PID_KEYWORDS: Final[int] + PID_LASTAUTHOR: Final[int] + PID_LASTPRINTED: Final[int] + PID_LASTSAVE_DTM: Final[int] + PID_PAGECOUNT: Final[int] + PID_REVNUMBER: Final[int] + PID_SECURITY: Final[int] + PID_SUBJECT: Final[int] + PID_TEMPLATE: Final[int] + PID_TITLE: Final[int] + PID_WORDCOUNT: Final[int] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi index 9fafbaaf2e951..86cd3ae0a87e2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi @@ -315,7 +315,7 @@ def stack_size(size: int = 0, /) -> int: the suggested approach in the absence of more specific information). """ -TIMEOUT_MAX: float +TIMEOUT_MAX: Final[float] def get_native_id() -> int: # only available on some platforms """Return a non-negative integer identifying the thread as reported diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_threading_local.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_threading_local.pyi index 34f70e80bd04a..fcf88de1bbc57 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_threading_local.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_threading_local.pyi @@ -17,6 +17,7 @@ _LocalDict: TypeAlias = dict[Any, Any] class _localimpl: """A class managing thread-local dicts""" + __slots__ = ("key", "dicts", "localargs", "locallock", "__weakref__") key: str dicts: dict[int, tuple[ReferenceType[Any], _LocalDict]] # Keep localargs in sync with the *args, **kwargs annotation on local.__new__ @@ -31,6 +32,7 @@ class _localimpl: """Create a new dict for the current thread, and return it.""" class local: + __slots__ = ("_local__impl", "__dict__") def __new__(cls, /, *args: Any, **kw: Any) -> Self: ... def __getattribute__(self, name: str) -> Any: ... def __setattr__(self, name: str, value: Any) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi index 98a369dfc5893..2cfd8173afd1b 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi @@ -3,7 +3,7 @@ # See the README.md file in this directory for more information. import sys -from collections.abc import Awaitable, Callable, Iterable, Sequence, Set as AbstractSet, Sized +from collections.abc import Awaitable, Callable, Iterable, Iterator, Sequence, Set as AbstractSet, Sized from dataclasses import Field from os import PathLike from types import FrameType, TracebackType @@ -275,6 +275,16 @@ class SupportsWrite(Protocol[_T_contra]): class SupportsFlush(Protocol): def flush(self) -> object: ... +# Suitable for dictionary view objects +class Viewable(Protocol[_T_co]): + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T_co]: ... + +class SupportsGetItemViewable(Protocol[_KT, _VT_co]): + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_KT]: ... + def __getitem__(self, key: _KT, /) -> _VT_co: ... + # Unfortunately PEP 688 does not allow us to distinguish read-only # from writable buffers. We use these aliases for readability for now. # Perhaps a future extension of the buffer protocol will allow us to diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi index 14140f58a76d6..0880f7404b635 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_winapi.pyi @@ -128,21 +128,21 @@ if sys.platform == "win32": WAIT_TIMEOUT: Final = 258 if sys.version_info >= (3, 10): - LOCALE_NAME_INVARIANT: str - LOCALE_NAME_MAX_LENGTH: int - LOCALE_NAME_SYSTEM_DEFAULT: str - LOCALE_NAME_USER_DEFAULT: str | None - - LCMAP_FULLWIDTH: int - LCMAP_HALFWIDTH: int - LCMAP_HIRAGANA: int - LCMAP_KATAKANA: int - LCMAP_LINGUISTIC_CASING: int - LCMAP_LOWERCASE: int - LCMAP_SIMPLIFIED_CHINESE: int - LCMAP_TITLECASE: int - LCMAP_TRADITIONAL_CHINESE: int - LCMAP_UPPERCASE: int + LOCALE_NAME_INVARIANT: Final[str] + LOCALE_NAME_MAX_LENGTH: Final[int] + LOCALE_NAME_SYSTEM_DEFAULT: Final[str] + LOCALE_NAME_USER_DEFAULT: Final[str | None] + + LCMAP_FULLWIDTH: Final[int] + LCMAP_HALFWIDTH: Final[int] + LCMAP_HIRAGANA: Final[int] + LCMAP_KATAKANA: Final[int] + LCMAP_LINGUISTIC_CASING: Final[int] + LCMAP_LOWERCASE: Final[int] + LCMAP_SIMPLIFIED_CHINESE: Final[int] + LCMAP_TITLECASE: Final[int] + LCMAP_TRADITIONAL_CHINESE: Final[int] + LCMAP_UPPERCASE: Final[int] if sys.version_info >= (3, 12): COPYFILE2_CALLBACK_CHUNK_STARTED: Final = 1 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/abc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/abc.pyi index 3a03460bb033c..04202fae9444c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/abc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/abc.pyi @@ -70,7 +70,7 @@ def abstractmethod(funcobj: _FuncT) -> _FuncT: ... """ -@deprecated("Use 'classmethod' with 'abstractmethod' instead") +@deprecated("Deprecated since Python 3.3. Use `@classmethod` stacked on top of `@abstractmethod` instead.") class abstractclassmethod(classmethod[_T, _P, _R_co]): """A decorator indicating abstract classmethods. @@ -87,7 +87,7 @@ class abstractclassmethod(classmethod[_T, _P, _R_co]): __isabstractmethod__: Literal[True] def __init__(self, callable: Callable[Concatenate[type[_T], _P], _R_co]) -> None: ... -@deprecated("Use 'staticmethod' with 'abstractmethod' instead") +@deprecated("Deprecated since Python 3.3. Use `@staticmethod` stacked on top of `@abstractmethod` instead.") class abstractstaticmethod(staticmethod[_P, _R_co]): """A decorator indicating abstract staticmethods. @@ -104,7 +104,7 @@ class abstractstaticmethod(staticmethod[_P, _R_co]): __isabstractmethod__: Literal[True] def __init__(self, callable: Callable[_P, _R_co]) -> None: ... -@deprecated("Use 'property' with 'abstractmethod' instead") +@deprecated("Deprecated since Python 3.3. Use `@property` stacked on top of `@abstractmethod` instead.") class abstractproperty(property): """A decorator indicating abstract properties. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi index 31ab9be8af060..2c02c4c8a44c8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi @@ -83,7 +83,7 @@ if sys.version_info >= (3, 14): owner: object = None, format: Format = Format.VALUE, # noqa: Y011 ) -> AnnotationForm: ... - @deprecated("Use ForwardRef.evaluate() or typing.evaluate_forward_ref() instead.") + @deprecated("Use `ForwardRef.evaluate()` or `typing.evaluate_forward_ref()` instead.") def _evaluate( self, globalns: dict[str, Any] | None, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi index 6d73c8ffcd903..c2fff6022532a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi @@ -669,7 +669,7 @@ class Namespace(_AttributeHolder): __hash__: ClassVar[None] # type: ignore[assignment] if sys.version_info >= (3, 14): - @deprecated("Deprecated in Python 3.14; Simply open files after parsing arguments") + @deprecated("Deprecated since Python 3.14. Open files after parsing arguments instead.") class FileType: """Deprecated factory for creating file object types diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi index 0f66829027d90..1771edd5a251a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi @@ -1332,20 +1332,20 @@ class Constant(expr): if sys.version_info < (3, 14): # Aliases for value, for backwards compatibility @property - @deprecated("Will be removed in Python 3.14. Use `value` instead.") + @deprecated("Removed in Python 3.14. Use `value` instead.") def n(self) -> _ConstantValue: """Deprecated. Use value instead.""" @n.setter - @deprecated("Will be removed in Python 3.14. Use `value` instead.") + @deprecated("Removed in Python 3.14. Use `value` instead.") def n(self, value: _ConstantValue) -> None: ... @property - @deprecated("Will be removed in Python 3.14. Use `value` instead.") + @deprecated("Removed in Python 3.14. Use `value` instead.") def s(self) -> _ConstantValue: """Deprecated. Use value instead.""" @s.setter - @deprecated("Will be removed in Python 3.14. Use `value` instead.") + @deprecated("Removed in Python 3.14. Use `value` instead.") def s(self, value: _ConstantValue) -> None: ... def __init__(self, value: _ConstantValue, kind: str | None = None, **kwargs: Unpack[_Attributes]) -> None: ... @@ -1467,7 +1467,7 @@ class Slice(expr): ) -> Self: """Return a copy of the AST node with new values for the specified fields.""" -@deprecated("Deprecated since Python 3.9. Use ast.Tuple instead.") +@deprecated("Deprecated since Python 3.9. Use `ast.Tuple` instead.") class ExtSlice(slice): """Deprecated AST node class. Use ast.Tuple instead.""" @@ -2134,31 +2134,31 @@ else: def __init__(cls, *args: Unused) -> None: ... if sys.version_info < (3, 14): - @deprecated("Replaced by ast.Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Num(Constant, metaclass=_ABC): """Deprecated AST node class. Use ast.Constant instead""" def __new__(cls, n: complex, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] - @deprecated("Replaced by ast.Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Str(Constant, metaclass=_ABC): """Deprecated AST node class. Use ast.Constant instead""" def __new__(cls, s: str, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] - @deprecated("Replaced by ast.Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Bytes(Constant, metaclass=_ABC): """Deprecated AST node class. Use ast.Constant instead""" def __new__(cls, s: bytes, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] - @deprecated("Replaced by ast.Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class NameConstant(Constant, metaclass=_ABC): """Deprecated AST node class. Use ast.Constant instead""" def __new__(cls, value: _ConstantValue, kind: str | None, **kwargs: Unpack[_Attributes]) -> Constant: ... # type: ignore[misc] # pyright: ignore[reportInconsistentConstructor] - @deprecated("Replaced by ast.Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `ast.Constant` instead.") class Ellipsis(Constant, metaclass=_ABC): """Deprecated AST node class. Use ast.Constant instead""" @@ -2605,15 +2605,15 @@ class NodeVisitor: def visit_Param(self, node: Param) -> Any: ... if sys.version_info < (3, 14): - @deprecated("Replaced by visit_Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `visit_Constant` instead.") def visit_Num(self, node: Num) -> Any: ... # type: ignore[deprecated] - @deprecated("Replaced by visit_Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `visit_Constant` instead.") def visit_Str(self, node: Str) -> Any: ... # type: ignore[deprecated] - @deprecated("Replaced by visit_Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `visit_Constant` instead.") def visit_Bytes(self, node: Bytes) -> Any: ... # type: ignore[deprecated] - @deprecated("Replaced by visit_Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `visit_Constant` instead.") def visit_NameConstant(self, node: NameConstant) -> Any: ... # type: ignore[deprecated] - @deprecated("Replaced by visit_Constant; removed in Python 3.14") + @deprecated("Removed in Python 3.14. Use `visit_Constant` instead.") def visit_Ellipsis(self, node: Ellipsis) -> Any: ... # type: ignore[deprecated] class NodeTransformer(NodeVisitor): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi index de3e1dec92d2e..1ce38b5f07419 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi @@ -77,6 +77,7 @@ class _TaskFactory(Protocol): class Handle: """Object returned by callback registration methods.""" + __slots__ = ("_callback", "_args", "_cancelled", "_loop", "_source_traceback", "_repr", "__weakref__", "_context") _cancelled: bool _args: Sequence[Any] def __init__( @@ -91,6 +92,7 @@ class Handle: class TimerHandle(Handle): """Object returned by timed callback registration methods.""" + __slots__ = ["_scheduled", "_when"] def __init__( self, when: float, @@ -968,10 +970,10 @@ class _AbstractEventLoopPolicy: if sys.version_info < (3, 14): if sys.version_info >= (3, 12): @abstractmethod - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") def get_child_watcher(self) -> AbstractChildWatcher: ... @abstractmethod - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") def set_child_watcher(self, watcher: AbstractChildWatcher) -> None: ... else: @abstractmethod @@ -1052,9 +1054,9 @@ if sys.version_info >= (3, 14): If policy is None, the default policy is restored. """ - @deprecated("Deprecated as of Python 3.14; will be removed in Python 3.16") + @deprecated("Deprecated since Python 3.14; will be removed in Python 3.16.") def get_event_loop_policy() -> _AbstractEventLoopPolicy: ... - @deprecated("Deprecated as of Python 3.14; will be removed in Python 3.16") + @deprecated("Deprecated since Python 3.14; will be removed in Python 3.16.") def set_event_loop_policy(policy: _AbstractEventLoopPolicy | None) -> None: ... else: @@ -1075,11 +1077,11 @@ def new_event_loop() -> AbstractEventLoop: if sys.version_info < (3, 14): if sys.version_info >= (3, 12): - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") def get_child_watcher() -> AbstractChildWatcher: """Equivalent to calling get_event_loop_policy().get_child_watcher().""" - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") def set_child_watcher(watcher: AbstractChildWatcher) -> None: """Equivalent to calling get_event_loop_policy().set_child_watcher(watcher). diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/protocols.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/protocols.pyi index c5833d683e3cc..bd2e9c1118cf3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/protocols.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/protocols.pyi @@ -17,6 +17,7 @@ class BaseProtocol: write-only transport like write pipe """ + __slots__ = () def connection_made(self, transport: transports.BaseTransport) -> None: """Called when a connection is made. @@ -87,6 +88,8 @@ class Protocol(BaseProtocol): * CL: connection_lost() """ + # Need annotation or mypy will complain about 'Cannot determine type of "__slots__" in base class' + __slots__: tuple[()] = () def data_received(self, data: bytes) -> None: """Called when some data is received. @@ -125,6 +128,7 @@ class BufferedProtocol(BaseProtocol): * CL: connection_lost() """ + __slots__ = () def get_buffer(self, sizehint: int) -> ReadableBuffer: """Called to allocate a new receive buffer. @@ -154,6 +158,7 @@ class BufferedProtocol(BaseProtocol): class DatagramProtocol(BaseProtocol): """Interface for datagram protocol.""" + __slots__ = () def connection_made(self, transport: transports.DatagramTransport) -> None: # type: ignore[override] """Called when a connection is made. @@ -177,6 +182,7 @@ class DatagramProtocol(BaseProtocol): class SubprocessProtocol(BaseProtocol): """Interface for protocol for subprocess calls.""" + __slots__: tuple[()] = () def pipe_data_received(self, fd: int, data: bytes) -> None: """Called when the subprocess writes data into stdout/stderr pipe. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/runners.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/runners.pyi index 1b7a4d48943ad..25698e14a64e1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/runners.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/runners.pyi @@ -56,7 +56,7 @@ if sys.version_info >= (3, 11): if sys.version_info >= (3, 12): def run( - main: Coroutine[Any, Any, _T], *, debug: bool | None = ..., loop_factory: Callable[[], AbstractEventLoop] | None = ... + main: Coroutine[Any, Any, _T], *, debug: bool | None = None, loop_factory: Callable[[], AbstractEventLoop] | None = None ) -> _T: """Execute the coroutine and return the result. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi index ebe927041ae0a..61563b419a9cf 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/tasks.pyi @@ -10,7 +10,7 @@ from _asyncio import ( _unregister_task as _unregister_task, ) from collections.abc import AsyncIterator, Awaitable, Coroutine, Generator, Iterable, Iterator -from typing import Any, Literal, Protocol, TypeVar, overload, type_check_only +from typing import Any, Final, Literal, Protocol, TypeVar, overload, type_check_only from typing_extensions import TypeAlias from . import _CoroutineLike @@ -84,9 +84,9 @@ else: _TaskYieldType: TypeAlias = Future[object] | None -FIRST_COMPLETED = concurrent.futures.FIRST_COMPLETED -FIRST_EXCEPTION = concurrent.futures.FIRST_EXCEPTION -ALL_COMPLETED = concurrent.futures.ALL_COMPLETED +FIRST_COMPLETED: Final = concurrent.futures.FIRST_COMPLETED +FIRST_EXCEPTION: Final = concurrent.futures.FIRST_EXCEPTION +ALL_COMPLETED: Final = concurrent.futures.ALL_COMPLETED if sys.version_info >= (3, 13): @type_check_only diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/transports.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/transports.pyi index 4473bacc6217d..5b2f7d12489c2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/transports.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/transports.pyi @@ -12,6 +12,7 @@ __all__ = ("BaseTransport", "ReadTransport", "WriteTransport", "Transport", "Dat class BaseTransport: """Base class for transports.""" + __slots__ = ("_extra",) def __init__(self, extra: Mapping[str, Any] | None = None) -> None: ... def get_extra_info(self, name: str, default: Any = None) -> Any: """Get optional transport information.""" @@ -37,6 +38,7 @@ class BaseTransport: class ReadTransport(BaseTransport): """Interface for read-only transports.""" + __slots__ = () def is_reading(self) -> bool: """Return True if the transport is receiving.""" @@ -57,6 +59,7 @@ class ReadTransport(BaseTransport): class WriteTransport(BaseTransport): """Interface for write-only transports.""" + __slots__ = () def set_write_buffer_limits(self, high: int | None = None, low: int | None = None) -> None: """Set the high- and low-water limits for write flow control. @@ -140,9 +143,12 @@ class Transport(ReadTransport, WriteTransport): except writelines(), which calls write() in a loop. """ + __slots__ = () + class DatagramTransport(BaseTransport): """Interface for datagram (UDP) transports.""" + __slots__ = () def sendto(self, data: bytes | bytearray | memoryview, addr: _Address | None = None) -> None: """Send data to the transport. @@ -163,6 +169,7 @@ class DatagramTransport(BaseTransport): """ class SubprocessTransport(BaseTransport): + __slots__ = () def get_pid(self) -> int: """Get subprocess id.""" @@ -223,4 +230,5 @@ class _FlowControlMixin(Transport): resume_writing() may be called. """ + __slots__ = ("_loop", "_protocol_paused", "_high_water", "_low_water") def __init__(self, extra: Mapping[str, Any] | None = None, loop: AbstractEventLoop | None = None) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi index c78f931c8555e..a1f5b209cfc2f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi @@ -21,6 +21,7 @@ class TransportSocket: operations (like "socket.close()") are banned. """ + __slots__ = ("_sock",) def __init__(self, sock: socket.socket) -> None: ... @property def family(self) -> int: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/unix_events.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/unix_events.pyi index a03ff6cfac5f5..679f2e6734780 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/unix_events.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/unix_events.pyi @@ -50,7 +50,7 @@ if sys.platform != "win32": # So, it is special cased. if sys.version_info < (3, 14): if sys.version_info >= (3, 12): - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") class AbstractChildWatcher: """Abstract base class for monitoring child processes. @@ -228,7 +228,7 @@ if sys.platform != "win32": def is_active(self) -> bool: ... def attach_loop(self, loop: events.AbstractEventLoop | None) -> None: ... - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") class SafeChildWatcher(BaseChildWatcher): """'Safe' child watcher implementation. @@ -249,7 +249,7 @@ if sys.platform != "win32": ) -> None: ... def remove_child_handler(self, pid: int) -> bool: ... - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") class FastChildWatcher(BaseChildWatcher): """'Fast' child watcher implementation. @@ -348,14 +348,14 @@ if sys.platform != "win32": """UNIX event loop policy with a watcher for child processes.""" if sys.version_info >= (3, 12): - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") def get_child_watcher(self) -> AbstractChildWatcher: """Get the watcher for child processes. If not yet set, a ThreadedChildWatcher object is automatically created. """ - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") def set_child_watcher(self, watcher: AbstractChildWatcher | None) -> None: """Set the watcher for child processes.""" else: @@ -380,7 +380,7 @@ if sys.platform != "win32": if sys.version_info < (3, 14): if sys.version_info >= (3, 12): - @deprecated("Deprecated as of Python 3.12; will be removed in Python 3.14") + @deprecated("Deprecated since Python 3.12; removed in Python 3.14.") class MultiLoopChildWatcher(AbstractChildWatcher): """A watcher that doesn't require running loop in the main thread. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi index 31cb9b899e34a..41bd0da716310 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi @@ -11,8 +11,8 @@ if sys.platform == "win32": __all__ = ("pipe", "Popen", "PIPE", "PipeHandle") BUFSIZE: Final = 8192 - PIPE = subprocess.PIPE - STDOUT = subprocess.STDOUT + PIPE: Final = subprocess.PIPE + STDOUT: Final = subprocess.STDOUT def pipe(*, duplex: bool = False, overlapped: tuple[bool, bool] = (True, True), bufsize: int = 8192) -> tuple[int, int]: """Like os.pipe() but with overlapped support and using handles not fds.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/calendar.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/calendar.pyi index 2c5dd4ae6f5eb..3b2aa61ceb873 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/calendar.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/calendar.pyi @@ -380,18 +380,18 @@ if sys.version_info >= (3, 12): NOVEMBER = 11 DECEMBER = 12 - JANUARY = Month.JANUARY - FEBRUARY = Month.FEBRUARY - MARCH = Month.MARCH - APRIL = Month.APRIL - MAY = Month.MAY - JUNE = Month.JUNE - JULY = Month.JULY - AUGUST = Month.AUGUST - SEPTEMBER = Month.SEPTEMBER - OCTOBER = Month.OCTOBER - NOVEMBER = Month.NOVEMBER - DECEMBER = Month.DECEMBER + JANUARY: Final = Month.JANUARY + FEBRUARY: Final = Month.FEBRUARY + MARCH: Final = Month.MARCH + APRIL: Final = Month.APRIL + MAY: Final = Month.MAY + JUNE: Final = Month.JUNE + JULY: Final = Month.JULY + AUGUST: Final = Month.AUGUST + SEPTEMBER: Final = Month.SEPTEMBER + OCTOBER: Final = Month.OCTOBER + NOVEMBER: Final = Month.NOVEMBER + DECEMBER: Final = Month.DECEMBER class Day(enum.IntEnum): MONDAY = 0 @@ -402,13 +402,13 @@ if sys.version_info >= (3, 12): SATURDAY = 5 SUNDAY = 6 - MONDAY = Day.MONDAY - TUESDAY = Day.TUESDAY - WEDNESDAY = Day.WEDNESDAY - THURSDAY = Day.THURSDAY - FRIDAY = Day.FRIDAY - SATURDAY = Day.SATURDAY - SUNDAY = Day.SUNDAY + MONDAY: Final = Day.MONDAY + TUESDAY: Final = Day.TUESDAY + WEDNESDAY: Final = Day.WEDNESDAY + THURSDAY: Final = Day.THURSDAY + FRIDAY: Final = Day.FRIDAY + SATURDAY: Final = Day.SATURDAY + SUNDAY: Final = Day.SUNDAY else: MONDAY: Final = 0 TUESDAY: Final = 1 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/colorsys.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/colorsys.pyi index 8aaab8b0ea179..9e674165b9551 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/colorsys.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/colorsys.pyi @@ -16,6 +16,8 @@ HLS: Hue, Luminance, Saturation HSV: Hue, Saturation, Value """ +from typing import Final + __all__ = ["rgb_to_yiq", "yiq_to_rgb", "rgb_to_hls", "hls_to_rgb", "rgb_to_hsv", "hsv_to_rgb"] def rgb_to_yiq(r: float, g: float, b: float) -> tuple[float, float, float]: ... @@ -26,6 +28,6 @@ def rgb_to_hsv(r: float, g: float, b: float) -> tuple[float, float, float]: ... def hsv_to_rgb(h: float, s: float, v: float) -> tuple[float, float, float]: ... # TODO: undocumented -ONE_SIXTH: float -ONE_THIRD: float -TWO_THIRD: float +ONE_SIXTH: Final[float] +ONE_THIRD: Final[float] +TWO_THIRD: Final[float] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi index 40a0525266eee..a1ab245dd8432 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/_base.pyi @@ -15,8 +15,7 @@ RUNNING: Final = "RUNNING" CANCELLED: Final = "CANCELLED" CANCELLED_AND_NOTIFIED: Final = "CANCELLED_AND_NOTIFIED" FINISHED: Final = "FINISHED" -_FUTURE_STATES: list[str] -_STATE_TO_DESCRIPTION_MAP: dict[str, str] +_STATE_TO_DESCRIPTION_MAP: Final[dict[str, str]] LOGGER: Logger class Error(Exception): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/process.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/process.pyi index d02bd6758495d..0264ceba46f4b 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/process.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/futures/process.pyi @@ -47,7 +47,7 @@ from multiprocessing.context import BaseContext, Process from multiprocessing.queues import Queue, SimpleQueue from threading import Lock, Semaphore, Thread from types import TracebackType -from typing import Any, Generic, TypeVar, overload +from typing import Any, Final, Generic, TypeVar, overload from typing_extensions import TypeVarTuple, Unpack from weakref import ref @@ -70,9 +70,9 @@ class _ThreadWakeup: def _python_exit() -> None: ... -EXTRA_QUEUED_CALLS: int +EXTRA_QUEUED_CALLS: Final = 1 -_MAX_WINDOWS_WORKERS: int +_MAX_WINDOWS_WORKERS: Final = 61 class _RemoteTraceback(Exception): tb: str diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/contextlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/contextlib.pyi index 1a1bb2c69c8fe..2b05511c33c9f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/contextlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/contextlib.pyi @@ -51,6 +51,7 @@ _CM_EF = TypeVar("_CM_EF", bound=AbstractContextManager[Any, Any] | _ExitFunc) class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] """An abstract base class for context managers.""" + __slots__ = () def __enter__(self) -> _T_co: """Return `self` upon entering the runtime context.""" @@ -67,6 +68,7 @@ class AbstractContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[m class AbstractAsyncContextManager(ABC, Protocol[_T_co, _ExitT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] """An abstract base class for asynchronous context managers.""" + __slots__ = () async def __aenter__(self) -> _T_co: """Return `self` upon entering the runtime context.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/__init__.pyi index 2d30ef8b6a276..9d488e29da7c7 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/__init__.pyi @@ -28,7 +28,7 @@ from _ctypes import ( from _typeshed import StrPath from ctypes._endian import BigEndianStructure as BigEndianStructure, LittleEndianStructure as LittleEndianStructure from types import GenericAlias -from typing import Any, ClassVar, Generic, Literal, TypeVar, overload, type_check_only +from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias, deprecated if sys.platform == "win32": @@ -69,7 +69,7 @@ if sys.version_info >= (3, 14): else: from _ctypes import POINTER as POINTER, pointer as pointer -DEFAULT_MODE: int +DEFAULT_MODE: Final[int] class ArgumentError(Exception): ... @@ -231,8 +231,13 @@ def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_w create_unicode_buffer(aString, anInteger) -> character array """ -@deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15") -def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ... +if sys.version_info >= (3, 13): + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ... + +else: + def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ... + def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... # Soft Deprecated, no plans to remove if sys.platform == "win32": diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/_endian.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/_endian.pyi index b6a581499172b..007fd7d3296c1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/_endian.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/_endian.pyi @@ -6,6 +6,8 @@ from ctypes import Structure, Union class BigEndianStructure(Structure): """Structure with big endian byte order""" + __slots__ = () + class LittleEndianStructure(Structure): """Structure base class""" @@ -14,5 +16,7 @@ if sys.version_info >= (3, 11): class BigEndianUnion(Union): """Union with big endian byte order""" + __slots__ = () + class LittleEndianUnion(Union): """Union base class""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/macholib/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/macholib/__init__.pyi index 106c61e635c50..0d240b1f70c6d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/macholib/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/macholib/__init__.pyi @@ -6,4 +6,6 @@ See the relevant header files in /usr/include/mach-o And also Apple's documentation. """ -__version__: str +from typing import Final + +__version__: Final[str] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/wintypes.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/wintypes.pyi index e9ed0df24dd13..0f0d61a396d5f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/wintypes.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ctypes/wintypes.pyi @@ -21,7 +21,7 @@ from ctypes import ( c_wchar, c_wchar_p, ) -from typing import Any, TypeVar +from typing import Any, Final, TypeVar from typing_extensions import Self, TypeAlias if sys.version_info >= (3, 12): @@ -177,7 +177,7 @@ class MSG(Structure): pt: _CField[POINT, POINT, POINT] tagMSG = MSG -MAX_PATH: int +MAX_PATH: Final = 260 class WIN32_FIND_DATAA(Structure): dwFileAttributes: _CIntLikeField[DWORD] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/curses/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/curses/__init__.pyi index 4c9e7f2beb6ef..78046417fe1ee 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/curses/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/curses/__init__.pyi @@ -26,12 +26,12 @@ _T = TypeVar("_T") _P = ParamSpec("_P") # available after calling `curses.initscr()` -LINES: int -COLS: int +LINES: Final[int] +COLS: Final[int] # available after calling `curses.start_color()` -COLORS: int -COLOR_PAIRS: int +COLORS: Final[int] +COLOR_PAIRS: Final[int] def wrapper(func: Callable[Concatenate[window, _P], _T], /, *arg: _P.args, **kwds: _P.kwargs) -> _T: """Wrapper function that initializes curses and calls another function, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/curses/ascii.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/curses/ascii.pyi index 11e6ae55aa1e6..823f98c139b62 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/curses/ascii.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/curses/ascii.pyi @@ -1,47 +1,47 @@ """Constants and membership tests for ASCII characters""" -from typing import TypeVar +from typing import Final, TypeVar _CharT = TypeVar("_CharT", str, int) -NUL: int -SOH: int -STX: int -ETX: int -EOT: int -ENQ: int -ACK: int -BEL: int -BS: int -TAB: int -HT: int -LF: int -NL: int -VT: int -FF: int -CR: int -SO: int -SI: int -DLE: int -DC1: int -DC2: int -DC3: int -DC4: int -NAK: int -SYN: int -ETB: int -CAN: int -EM: int -SUB: int -ESC: int -FS: int -GS: int -RS: int -US: int -SP: int -DEL: int +NUL: Final = 0x00 +SOH: Final = 0x01 +STX: Final = 0x02 +ETX: Final = 0x03 +EOT: Final = 0x04 +ENQ: Final = 0x05 +ACK: Final = 0x06 +BEL: Final = 0x07 +BS: Final = 0x08 +TAB: Final = 0x09 +HT: Final = 0x09 +LF: Final = 0x0A +NL: Final = 0x0A +VT: Final = 0x0B +FF: Final = 0x0C +CR: Final = 0x0D +SO: Final = 0x0E +SI: Final = 0x0F +DLE: Final = 0x10 +DC1: Final = 0x11 +DC2: Final = 0x12 +DC3: Final = 0x13 +DC4: Final = 0x14 +NAK: Final = 0x15 +SYN: Final = 0x16 +ETB: Final = 0x17 +CAN: Final = 0x18 +EM: Final = 0x19 +SUB: Final = 0x1A +ESC: Final = 0x1B +FS: Final = 0x1C +GS: Final = 0x1D +RS: Final = 0x1E +US: Final = 0x1F +SP: Final = 0x20 +DEL: Final = 0x7F -controlnames: list[int] +controlnames: Final[list[int]] def isalnum(c: str | int) -> bool: ... def isalpha(c: str | int) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi index 3728c9d6d1bef..6a134c3df68ae 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/dataclasses.pyi @@ -5,7 +5,7 @@ from _typeshed import DataclassInstance from builtins import type as Type # alias to avoid name clashes with fields named "type" from collections.abc import Callable, Iterable, Mapping from types import GenericAlias -from typing import Any, Generic, Literal, Protocol, TypeVar, overload, type_check_only +from typing import Any, Final, Generic, Literal, Protocol, TypeVar, overload, type_check_only from typing_extensions import Never, TypeIs _T = TypeVar("_T") @@ -58,7 +58,7 @@ class _DataclassFactory(Protocol): class _MISSING_TYPE(enum.Enum): MISSING = enum.auto() -MISSING = _MISSING_TYPE.MISSING +MISSING: Final = _MISSING_TYPE.MISSING if sys.version_info >= (3, 10): class KW_ONLY: ... @@ -248,6 +248,37 @@ class _DefaultFactory(Protocol[_T_co]): def __call__(self) -> _T_co: ... class Field(Generic[_T]): + if sys.version_info >= (3, 14): + __slots__ = ( + "name", + "type", + "default", + "default_factory", + "repr", + "hash", + "init", + "compare", + "metadata", + "kw_only", + "doc", + "_field_type", + ) + elif sys.version_info >= (3, 10): + __slots__ = ( + "name", + "type", + "default", + "default_factory", + "repr", + "hash", + "init", + "compare", + "metadata", + "kw_only", + "_field_type", + ) + else: + __slots__ = ("name", "type", "default", "default_factory", "repr", "hash", "init", "compare", "metadata", "_field_type") name: str type: Type[_T] | str | Any default: _T | Literal[_MISSING_TYPE.MISSING] @@ -492,6 +523,7 @@ def is_dataclass(obj: object) -> TypeIs[DataclassInstance | type[DataclassInstan class FrozenInstanceError(AttributeError): ... class InitVar(Generic[_T]): + __slots__ = ("type",) type: Type[_T] def __init__(self, type: Type[_T]) -> None: ... @overload diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi index af64aa94c6084..1718f0d1cb8f3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi @@ -4,7 +4,7 @@ import sys import types from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API -from typing import IO, Any, NamedTuple +from typing import IO, Any, Final, NamedTuple from typing_extensions import Self, TypeAlias __all__ = [ @@ -249,7 +249,7 @@ class Bytecode: def dis(self) -> str: """Return a formatted view of the bytecode operations.""" -COMPILER_FLAG_NAMES: dict[int, str] +COMPILER_FLAG_NAMES: Final[dict[int, str]] def findlabels(code: _HaveCodeType) -> list[int]: """Detect all offsets in a byte code which are jump targets. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/doctest.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/doctest.pyi index 3b12009681ba3..55a37fc365282 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/doctest.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/doctest.pyi @@ -42,7 +42,7 @@ import types import unittest from _typeshed import ExcInfo from collections.abc import Callable -from typing import Any, NamedTuple, type_check_only +from typing import Any, Final, NamedTuple, type_check_only from typing_extensions import Self, TypeAlias __all__ = [ @@ -98,29 +98,29 @@ else: failed: int attempted: int -OPTIONFLAGS_BY_NAME: dict[str, int] +OPTIONFLAGS_BY_NAME: Final[dict[str, int]] def register_optionflag(name: str) -> int: ... -DONT_ACCEPT_TRUE_FOR_1: int -DONT_ACCEPT_BLANKLINE: int -NORMALIZE_WHITESPACE: int -ELLIPSIS: int -SKIP: int -IGNORE_EXCEPTION_DETAIL: int +DONT_ACCEPT_TRUE_FOR_1: Final = 1 +DONT_ACCEPT_BLANKLINE: Final = 2 +NORMALIZE_WHITESPACE: Final = 4 +ELLIPSIS: Final = 8 +SKIP: Final = 16 +IGNORE_EXCEPTION_DETAIL: Final = 32 -COMPARISON_FLAGS: int +COMPARISON_FLAGS: Final = 63 -REPORT_UDIFF: int -REPORT_CDIFF: int -REPORT_NDIFF: int -REPORT_ONLY_FIRST_FAILURE: int -FAIL_FAST: int +REPORT_UDIFF: Final = 64 +REPORT_CDIFF: Final = 128 +REPORT_NDIFF: Final = 256 +REPORT_ONLY_FIRST_FAILURE: Final = 512 +FAIL_FAST: Final = 1024 -REPORTING_FLAGS: int +REPORTING_FLAGS: Final = 1984 -BLANKLINE_MARKER: str -ELLIPSIS_MARKER: str +BLANKLINE_MARKER: Final = "" +ELLIPSIS_MARKER: Final = "..." class Example: """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/email/_header_value_parser.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/email/_header_value_parser.pyi index f7c23cf676696..1c73357b5388f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/email/_header_value_parser.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/email/_header_value_parser.pyi @@ -96,7 +96,7 @@ def make_quoted_pairs(value: Any) -> str: def quote_string(value: Any) -> str: ... -rfc2047_matcher: Pattern[str] +rfc2047_matcher: Final[Pattern[str]] class TokenList(list[TokenList | Terminal]): token_type: str | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/email/charset.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/email/charset.pyi index a1b44e899cfa5..3688abc11668d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/email/charset.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/email/charset.pyi @@ -4,9 +4,16 @@ from typing import ClassVar, Final, overload __all__ = ["Charset", "add_alias", "add_charset", "add_codec"] -QP: Final[int] # undocumented -BASE64: Final[int] # undocumented -SHORTEST: Final[int] # undocumented +QP: Final = 1 # undocumented +BASE64: Final = 2 # undocumented +SHORTEST: Final = 3 # undocumented +RFC2047_CHROME_LEN: Final = 7 # undocumented +DEFAULT_CHARSET: Final = "us-ascii" # undocumented +UNKNOWN8BIT: Final = "unknown-8bit" # undocumented +EMPTYSTRING: Final = "" # undocumented +CHARSETS: Final[dict[str, tuple[int | None, int | None, str | None]]] +ALIASES: Final[dict[str, str]] +CODEC_MAP: Final[dict[str, str | None]] # undocumented class Charset: """Map character sets to their email properties. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi index 2258926c917fd..79b49491482d7 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi @@ -4,7 +4,7 @@ import types from _typeshed import SupportsKeysAndGetItem, Unused from builtins import property as _builtins_property from collections.abc import Callable, Iterable, Iterator, Mapping -from typing import Any, Generic, Literal, TypeVar, overload +from typing import Any, Final, Generic, Literal, TypeVar, overload from typing_extensions import Self, TypeAlias __all__ = ["EnumMeta", "Enum", "IntEnum", "Flag", "IntFlag", "auto", "unique"] @@ -551,9 +551,9 @@ if sys.version_info >= (3, 11): NAMED_FLAGS = "multi-flag aliases may not contain unnamed flags" UNIQUE = "one name per value" - CONTINUOUS = EnumCheck.CONTINUOUS - NAMED_FLAGS = EnumCheck.NAMED_FLAGS - UNIQUE = EnumCheck.UNIQUE + CONTINUOUS: Final = EnumCheck.CONTINUOUS + NAMED_FLAGS: Final = EnumCheck.NAMED_FLAGS + UNIQUE: Final = EnumCheck.UNIQUE class verify: """ @@ -577,10 +577,10 @@ if sys.version_info >= (3, 11): EJECT = "eject" KEEP = "keep" - STRICT = FlagBoundary.STRICT - CONFORM = FlagBoundary.CONFORM - EJECT = FlagBoundary.EJECT - KEEP = FlagBoundary.KEEP + STRICT: Final = FlagBoundary.STRICT + CONFORM: Final = FlagBoundary.CONFORM + EJECT: Final = FlagBoundary.EJECT + KEEP: Final = FlagBoundary.KEEP def global_str(self: Enum) -> str: """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/errno.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/errno.pyi index 1efac527bdb8b..0784aceb00ba9 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/errno.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/errno.pyi @@ -14,226 +14,227 @@ e.g. os.strerror(2) could return 'No such file or directory'. import sys from collections.abc import Mapping +from typing import Final errorcode: Mapping[int, str] -EPERM: int -ENOENT: int -ESRCH: int -EINTR: int -EIO: int -ENXIO: int -E2BIG: int -ENOEXEC: int -EBADF: int -ECHILD: int -EAGAIN: int -ENOMEM: int -EACCES: int -EFAULT: int -EBUSY: int -EEXIST: int -EXDEV: int -ENODEV: int -ENOTDIR: int -EISDIR: int -EINVAL: int -ENFILE: int -EMFILE: int -ENOTTY: int -ETXTBSY: int -EFBIG: int -ENOSPC: int -ESPIPE: int -EROFS: int -EMLINK: int -EPIPE: int -EDOM: int -ERANGE: int -EDEADLK: int -ENAMETOOLONG: int -ENOLCK: int -ENOSYS: int -ENOTEMPTY: int -ELOOP: int -EWOULDBLOCK: int -ENOMSG: int -EIDRM: int -ENOSTR: int -ENODATA: int -ETIME: int -ENOSR: int -EREMOTE: int -ENOLINK: int -EPROTO: int -EBADMSG: int -EOVERFLOW: int -EILSEQ: int -EUSERS: int -ENOTSOCK: int -EDESTADDRREQ: int -EMSGSIZE: int -EPROTOTYPE: int -ENOPROTOOPT: int -EPROTONOSUPPORT: int -ESOCKTNOSUPPORT: int -ENOTSUP: int -EOPNOTSUPP: int -EPFNOSUPPORT: int -EAFNOSUPPORT: int -EADDRINUSE: int -EADDRNOTAVAIL: int -ENETDOWN: int -ENETUNREACH: int -ENETRESET: int -ECONNABORTED: int -ECONNRESET: int -ENOBUFS: int -EISCONN: int -ENOTCONN: int -ESHUTDOWN: int -ETOOMANYREFS: int -ETIMEDOUT: int -ECONNREFUSED: int -EHOSTDOWN: int -EHOSTUNREACH: int -EALREADY: int -EINPROGRESS: int -ESTALE: int -EDQUOT: int -ECANCELED: int # undocumented -ENOTRECOVERABLE: int # undocumented -EOWNERDEAD: int # undocumented +EPERM: Final[int] +ENOENT: Final[int] +ESRCH: Final[int] +EINTR: Final[int] +EIO: Final[int] +ENXIO: Final[int] +E2BIG: Final[int] +ENOEXEC: Final[int] +EBADF: Final[int] +ECHILD: Final[int] +EAGAIN: Final[int] +ENOMEM: Final[int] +EACCES: Final[int] +EFAULT: Final[int] +EBUSY: Final[int] +EEXIST: Final[int] +EXDEV: Final[int] +ENODEV: Final[int] +ENOTDIR: Final[int] +EISDIR: Final[int] +EINVAL: Final[int] +ENFILE: Final[int] +EMFILE: Final[int] +ENOTTY: Final[int] +ETXTBSY: Final[int] +EFBIG: Final[int] +ENOSPC: Final[int] +ESPIPE: Final[int] +EROFS: Final[int] +EMLINK: Final[int] +EPIPE: Final[int] +EDOM: Final[int] +ERANGE: Final[int] +EDEADLK: Final[int] +ENAMETOOLONG: Final[int] +ENOLCK: Final[int] +ENOSYS: Final[int] +ENOTEMPTY: Final[int] +ELOOP: Final[int] +EWOULDBLOCK: Final[int] +ENOMSG: Final[int] +EIDRM: Final[int] +ENOSTR: Final[int] +ENODATA: Final[int] +ETIME: Final[int] +ENOSR: Final[int] +EREMOTE: Final[int] +ENOLINK: Final[int] +EPROTO: Final[int] +EBADMSG: Final[int] +EOVERFLOW: Final[int] +EILSEQ: Final[int] +EUSERS: Final[int] +ENOTSOCK: Final[int] +EDESTADDRREQ: Final[int] +EMSGSIZE: Final[int] +EPROTOTYPE: Final[int] +ENOPROTOOPT: Final[int] +EPROTONOSUPPORT: Final[int] +ESOCKTNOSUPPORT: Final[int] +ENOTSUP: Final[int] +EOPNOTSUPP: Final[int] +EPFNOSUPPORT: Final[int] +EAFNOSUPPORT: Final[int] +EADDRINUSE: Final[int] +EADDRNOTAVAIL: Final[int] +ENETDOWN: Final[int] +ENETUNREACH: Final[int] +ENETRESET: Final[int] +ECONNABORTED: Final[int] +ECONNRESET: Final[int] +ENOBUFS: Final[int] +EISCONN: Final[int] +ENOTCONN: Final[int] +ESHUTDOWN: Final[int] +ETOOMANYREFS: Final[int] +ETIMEDOUT: Final[int] +ECONNREFUSED: Final[int] +EHOSTDOWN: Final[int] +EHOSTUNREACH: Final[int] +EALREADY: Final[int] +EINPROGRESS: Final[int] +ESTALE: Final[int] +EDQUOT: Final[int] +ECANCELED: Final[int] # undocumented +ENOTRECOVERABLE: Final[int] # undocumented +EOWNERDEAD: Final[int] # undocumented if sys.platform == "sunos5" or sys.platform == "solaris": # noqa: Y008 - ELOCKUNMAPPED: int - ENOTACTIVE: int + ELOCKUNMAPPED: Final[int] + ENOTACTIVE: Final[int] if sys.platform != "win32": - ENOTBLK: int - EMULTIHOP: int + ENOTBLK: Final[int] + EMULTIHOP: Final[int] if sys.platform == "darwin": # All of the below are undocumented - EAUTH: int - EBADARCH: int - EBADEXEC: int - EBADMACHO: int - EBADRPC: int - EDEVERR: int - EFTYPE: int - ENEEDAUTH: int - ENOATTR: int - ENOPOLICY: int - EPROCLIM: int - EPROCUNAVAIL: int - EPROGMISMATCH: int - EPROGUNAVAIL: int - EPWROFF: int - ERPCMISMATCH: int - ESHLIBVERS: int + EAUTH: Final[int] + EBADARCH: Final[int] + EBADEXEC: Final[int] + EBADMACHO: Final[int] + EBADRPC: Final[int] + EDEVERR: Final[int] + EFTYPE: Final[int] + ENEEDAUTH: Final[int] + ENOATTR: Final[int] + ENOPOLICY: Final[int] + EPROCLIM: Final[int] + EPROCUNAVAIL: Final[int] + EPROGMISMATCH: Final[int] + EPROGUNAVAIL: Final[int] + EPWROFF: Final[int] + ERPCMISMATCH: Final[int] + ESHLIBVERS: Final[int] if sys.version_info >= (3, 11): - EQFULL: int + EQFULL: Final[int] if sys.platform != "darwin": - EDEADLOCK: int + EDEADLOCK: Final[int] if sys.platform != "win32" and sys.platform != "darwin": - ECHRNG: int - EL2NSYNC: int - EL3HLT: int - EL3RST: int - ELNRNG: int - EUNATCH: int - ENOCSI: int - EL2HLT: int - EBADE: int - EBADR: int - EXFULL: int - ENOANO: int - EBADRQC: int - EBADSLT: int - EBFONT: int - ENONET: int - ENOPKG: int - EADV: int - ESRMNT: int - ECOMM: int - EDOTDOT: int - ENOTUNIQ: int - EBADFD: int - EREMCHG: int - ELIBACC: int - ELIBBAD: int - ELIBSCN: int - ELIBMAX: int - ELIBEXEC: int - ERESTART: int - ESTRPIPE: int - EUCLEAN: int - ENOTNAM: int - ENAVAIL: int - EISNAM: int - EREMOTEIO: int + ECHRNG: Final[int] + EL2NSYNC: Final[int] + EL3HLT: Final[int] + EL3RST: Final[int] + ELNRNG: Final[int] + EUNATCH: Final[int] + ENOCSI: Final[int] + EL2HLT: Final[int] + EBADE: Final[int] + EBADR: Final[int] + EXFULL: Final[int] + ENOANO: Final[int] + EBADRQC: Final[int] + EBADSLT: Final[int] + EBFONT: Final[int] + ENONET: Final[int] + ENOPKG: Final[int] + EADV: Final[int] + ESRMNT: Final[int] + ECOMM: Final[int] + EDOTDOT: Final[int] + ENOTUNIQ: Final[int] + EBADFD: Final[int] + EREMCHG: Final[int] + ELIBACC: Final[int] + ELIBBAD: Final[int] + ELIBSCN: Final[int] + ELIBMAX: Final[int] + ELIBEXEC: Final[int] + ERESTART: Final[int] + ESTRPIPE: Final[int] + EUCLEAN: Final[int] + ENOTNAM: Final[int] + ENAVAIL: Final[int] + EISNAM: Final[int] + EREMOTEIO: Final[int] # All of the below are undocumented - EKEYEXPIRED: int - EKEYREJECTED: int - EKEYREVOKED: int - EMEDIUMTYPE: int - ENOKEY: int - ENOMEDIUM: int - ERFKILL: int + EKEYEXPIRED: Final[int] + EKEYREJECTED: Final[int] + EKEYREVOKED: Final[int] + EMEDIUMTYPE: Final[int] + ENOKEY: Final[int] + ENOMEDIUM: Final[int] + ERFKILL: Final[int] if sys.version_info >= (3, 14): - EHWPOISON: int + EHWPOISON: Final[int] if sys.platform == "win32": # All of these are undocumented - WSABASEERR: int - WSAEACCES: int - WSAEADDRINUSE: int - WSAEADDRNOTAVAIL: int - WSAEAFNOSUPPORT: int - WSAEALREADY: int - WSAEBADF: int - WSAECONNABORTED: int - WSAECONNREFUSED: int - WSAECONNRESET: int - WSAEDESTADDRREQ: int - WSAEDISCON: int - WSAEDQUOT: int - WSAEFAULT: int - WSAEHOSTDOWN: int - WSAEHOSTUNREACH: int - WSAEINPROGRESS: int - WSAEINTR: int - WSAEINVAL: int - WSAEISCONN: int - WSAELOOP: int - WSAEMFILE: int - WSAEMSGSIZE: int - WSAENAMETOOLONG: int - WSAENETDOWN: int - WSAENETRESET: int - WSAENETUNREACH: int - WSAENOBUFS: int - WSAENOPROTOOPT: int - WSAENOTCONN: int - WSAENOTEMPTY: int - WSAENOTSOCK: int - WSAEOPNOTSUPP: int - WSAEPFNOSUPPORT: int - WSAEPROCLIM: int - WSAEPROTONOSUPPORT: int - WSAEPROTOTYPE: int - WSAEREMOTE: int - WSAESHUTDOWN: int - WSAESOCKTNOSUPPORT: int - WSAESTALE: int - WSAETIMEDOUT: int - WSAETOOMANYREFS: int - WSAEUSERS: int - WSAEWOULDBLOCK: int - WSANOTINITIALISED: int - WSASYSNOTREADY: int - WSAVERNOTSUPPORTED: int + WSABASEERR: Final[int] + WSAEACCES: Final[int] + WSAEADDRINUSE: Final[int] + WSAEADDRNOTAVAIL: Final[int] + WSAEAFNOSUPPORT: Final[int] + WSAEALREADY: Final[int] + WSAEBADF: Final[int] + WSAECONNABORTED: Final[int] + WSAECONNREFUSED: Final[int] + WSAECONNRESET: Final[int] + WSAEDESTADDRREQ: Final[int] + WSAEDISCON: Final[int] + WSAEDQUOT: Final[int] + WSAEFAULT: Final[int] + WSAEHOSTDOWN: Final[int] + WSAEHOSTUNREACH: Final[int] + WSAEINPROGRESS: Final[int] + WSAEINTR: Final[int] + WSAEINVAL: Final[int] + WSAEISCONN: Final[int] + WSAELOOP: Final[int] + WSAEMFILE: Final[int] + WSAEMSGSIZE: Final[int] + WSAENAMETOOLONG: Final[int] + WSAENETDOWN: Final[int] + WSAENETRESET: Final[int] + WSAENETUNREACH: Final[int] + WSAENOBUFS: Final[int] + WSAENOPROTOOPT: Final[int] + WSAENOTCONN: Final[int] + WSAENOTEMPTY: Final[int] + WSAENOTSOCK: Final[int] + WSAEOPNOTSUPP: Final[int] + WSAEPFNOSUPPORT: Final[int] + WSAEPROCLIM: Final[int] + WSAEPROTONOSUPPORT: Final[int] + WSAEPROTOTYPE: Final[int] + WSAEREMOTE: Final[int] + WSAESHUTDOWN: Final[int] + WSAESOCKTNOSUPPORT: Final[int] + WSAESTALE: Final[int] + WSAETIMEDOUT: Final[int] + WSAETOOMANYREFS: Final[int] + WSAEUSERS: Final[int] + WSAEWOULDBLOCK: Final[int] + WSANOTINITIALISED: Final[int] + WSASYSNOTREADY: Final[int] + WSAVERNOTSUPPORTED: Final[int] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/filecmp.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/filecmp.pyi index ddcce673d1837..33e29bcc32775 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/filecmp.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/filecmp.pyi @@ -18,7 +18,7 @@ from typing import Any, AnyStr, Final, Generic, Literal __all__ = ["clear_cache", "cmp", "dircmp", "cmpfiles", "DEFAULT_IGNORES"] -DEFAULT_IGNORES: list[str] +DEFAULT_IGNORES: Final[list[str]] BUFSIZE: Final = 8192 def cmp(f1: StrOrBytesPath, f2: StrOrBytesPath, shallow: bool | Literal[0, 1] = True) -> bool: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/fractions.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/fractions.pyi index 7175a93952141..07e88ca468ca9 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/fractions.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/fractions.pyi @@ -36,6 +36,7 @@ class Fraction(Rational): """ + __slots__ = ("_numerator", "_denominator") @overload def __new__(cls, numerator: int | Rational = 0, denominator: int | Rational | None = None) -> Self: """Constructs a Rational. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi index 171c5d6fc3368..26c2166122a25 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi @@ -169,7 +169,7 @@ else: tuple[Literal["__module__"], Literal["__name__"], Literal["__qualname__"], Literal["__doc__"], Literal["__annotations__"]] ] -WRAPPER_UPDATES: tuple[Literal["__dict__"]] +WRAPPER_UPDATES: Final[tuple[Literal["__dict__"]]] @type_check_only class _Wrapped(Generic[_PWrapped, _RWrapped, _PWrapper, _RWrapper]): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi index d9863ba3b284f..d3a6642a4c2fc 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/glob.pyi @@ -12,9 +12,13 @@ if sys.version_info >= (3, 13): __all__ += ["translate"] if sys.version_info >= (3, 10): - @deprecated("Will be removed in Python 3.15; Use `glob.glob` and pass *root_dir* argument instead.") + @deprecated( + "Deprecated since Python 3.10; will be removed in Python 3.15. Use `glob.glob()` with the *root_dir* argument instead." + ) def glob0(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... - @deprecated("Will be removed in Python 3.15; Use `glob.glob` and pass *root_dir* argument instead.") + @deprecated( + "Deprecated since Python 3.10; will be removed in Python 3.15. Use `glob.glob()` with the *root_dir* argument instead." + ) def glob1(dirname: AnyStr, pattern: AnyStr) -> list[AnyStr]: ... else: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/hmac.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/hmac.pyi index 1e103ef558e2c..4aa8aea3cd0c6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/hmac.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/hmac.pyi @@ -47,6 +47,7 @@ class HMAC: This supports the API for Cryptographic Hash Functions (PEP 247). """ + __slots__ = ("_hmac", "_inner", "_outer", "block_size", "digest_size") digest_size: int block_size: int @property diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/html/entities.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/html/entities.pyi index a44d3e10e2f96..0f7b8b04bbeca 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/html/entities.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/html/entities.pyi @@ -1,8 +1,10 @@ """HTML character entity references.""" +from typing import Final + __all__ = ["html5", "name2codepoint", "codepoint2name", "entitydefs"] -name2codepoint: dict[str, int] -html5: dict[str, str] -codepoint2name: dict[int, str] -entitydefs: dict[str, str] +name2codepoint: Final[dict[str, int]] +html5: Final[dict[str, str]] +codepoint2name: Final[dict[int, str]] +entitydefs: Final[dict[str, str]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/http/client.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/http/client.pyi index 14a7dd63475d0..4fe786738c744 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/http/client.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/http/client.pyi @@ -77,7 +77,7 @@ from _typeshed import MaybeNone, ReadableBuffer, SupportsRead, SupportsReadline, from collections.abc import Callable, Iterable, Iterator, Mapping from email._policybase import _MessageT from socket import socket -from typing import BinaryIO, Literal, TypeVar, overload +from typing import BinaryIO, Final, TypeVar, overload from typing_extensions import Self, TypeAlias __all__ = [ @@ -106,85 +106,85 @@ _DataType: TypeAlias = SupportsRead[bytes] | Iterable[ReadableBuffer] | Readable _T = TypeVar("_T") _HeaderValue: TypeAlias = ReadableBuffer | str | int -HTTP_PORT: int -HTTPS_PORT: int +HTTP_PORT: Final = 80 +HTTPS_PORT: Final = 443 # Keep these global constants in sync with http.HTTPStatus (http/__init__.pyi). # They are present for backward compatibility reasons. -CONTINUE: Literal[100] -SWITCHING_PROTOCOLS: Literal[101] -PROCESSING: Literal[102] -EARLY_HINTS: Literal[103] - -OK: Literal[200] -CREATED: Literal[201] -ACCEPTED: Literal[202] -NON_AUTHORITATIVE_INFORMATION: Literal[203] -NO_CONTENT: Literal[204] -RESET_CONTENT: Literal[205] -PARTIAL_CONTENT: Literal[206] -MULTI_STATUS: Literal[207] -ALREADY_REPORTED: Literal[208] -IM_USED: Literal[226] - -MULTIPLE_CHOICES: Literal[300] -MOVED_PERMANENTLY: Literal[301] -FOUND: Literal[302] -SEE_OTHER: Literal[303] -NOT_MODIFIED: Literal[304] -USE_PROXY: Literal[305] -TEMPORARY_REDIRECT: Literal[307] -PERMANENT_REDIRECT: Literal[308] - -BAD_REQUEST: Literal[400] -UNAUTHORIZED: Literal[401] -PAYMENT_REQUIRED: Literal[402] -FORBIDDEN: Literal[403] -NOT_FOUND: Literal[404] -METHOD_NOT_ALLOWED: Literal[405] -NOT_ACCEPTABLE: Literal[406] -PROXY_AUTHENTICATION_REQUIRED: Literal[407] -REQUEST_TIMEOUT: Literal[408] -CONFLICT: Literal[409] -GONE: Literal[410] -LENGTH_REQUIRED: Literal[411] -PRECONDITION_FAILED: Literal[412] +CONTINUE: Final = 100 +SWITCHING_PROTOCOLS: Final = 101 +PROCESSING: Final = 102 +EARLY_HINTS: Final = 103 + +OK: Final = 200 +CREATED: Final = 201 +ACCEPTED: Final = 202 +NON_AUTHORITATIVE_INFORMATION: Final = 203 +NO_CONTENT: Final = 204 +RESET_CONTENT: Final = 205 +PARTIAL_CONTENT: Final = 206 +MULTI_STATUS: Final = 207 +ALREADY_REPORTED: Final = 208 +IM_USED: Final = 226 + +MULTIPLE_CHOICES: Final = 300 +MOVED_PERMANENTLY: Final = 301 +FOUND: Final = 302 +SEE_OTHER: Final = 303 +NOT_MODIFIED: Final = 304 +USE_PROXY: Final = 305 +TEMPORARY_REDIRECT: Final = 307 +PERMANENT_REDIRECT: Final = 308 + +BAD_REQUEST: Final = 400 +UNAUTHORIZED: Final = 401 +PAYMENT_REQUIRED: Final = 402 +FORBIDDEN: Final = 403 +NOT_FOUND: Final = 404 +METHOD_NOT_ALLOWED: Final = 405 +NOT_ACCEPTABLE: Final = 406 +PROXY_AUTHENTICATION_REQUIRED: Final = 407 +REQUEST_TIMEOUT: Final = 408 +CONFLICT: Final = 409 +GONE: Final = 410 +LENGTH_REQUIRED: Final = 411 +PRECONDITION_FAILED: Final = 412 if sys.version_info >= (3, 13): - CONTENT_TOO_LARGE: Literal[413] -REQUEST_ENTITY_TOO_LARGE: Literal[413] + CONTENT_TOO_LARGE: Final = 413 +REQUEST_ENTITY_TOO_LARGE: Final = 413 if sys.version_info >= (3, 13): - URI_TOO_LONG: Literal[414] -REQUEST_URI_TOO_LONG: Literal[414] -UNSUPPORTED_MEDIA_TYPE: Literal[415] + URI_TOO_LONG: Final = 414 +REQUEST_URI_TOO_LONG: Final = 414 +UNSUPPORTED_MEDIA_TYPE: Final = 415 if sys.version_info >= (3, 13): - RANGE_NOT_SATISFIABLE: Literal[416] -REQUESTED_RANGE_NOT_SATISFIABLE: Literal[416] -EXPECTATION_FAILED: Literal[417] -IM_A_TEAPOT: Literal[418] -MISDIRECTED_REQUEST: Literal[421] + RANGE_NOT_SATISFIABLE: Final = 416 +REQUESTED_RANGE_NOT_SATISFIABLE: Final = 416 +EXPECTATION_FAILED: Final = 417 +IM_A_TEAPOT: Final = 418 +MISDIRECTED_REQUEST: Final = 421 if sys.version_info >= (3, 13): - UNPROCESSABLE_CONTENT: Literal[422] -UNPROCESSABLE_ENTITY: Literal[422] -LOCKED: Literal[423] -FAILED_DEPENDENCY: Literal[424] -TOO_EARLY: Literal[425] -UPGRADE_REQUIRED: Literal[426] -PRECONDITION_REQUIRED: Literal[428] -TOO_MANY_REQUESTS: Literal[429] -REQUEST_HEADER_FIELDS_TOO_LARGE: Literal[431] -UNAVAILABLE_FOR_LEGAL_REASONS: Literal[451] - -INTERNAL_SERVER_ERROR: Literal[500] -NOT_IMPLEMENTED: Literal[501] -BAD_GATEWAY: Literal[502] -SERVICE_UNAVAILABLE: Literal[503] -GATEWAY_TIMEOUT: Literal[504] -HTTP_VERSION_NOT_SUPPORTED: Literal[505] -VARIANT_ALSO_NEGOTIATES: Literal[506] -INSUFFICIENT_STORAGE: Literal[507] -LOOP_DETECTED: Literal[508] -NOT_EXTENDED: Literal[510] -NETWORK_AUTHENTICATION_REQUIRED: Literal[511] + UNPROCESSABLE_CONTENT: Final = 422 +UNPROCESSABLE_ENTITY: Final = 422 +LOCKED: Final = 423 +FAILED_DEPENDENCY: Final = 424 +TOO_EARLY: Final = 425 +UPGRADE_REQUIRED: Final = 426 +PRECONDITION_REQUIRED: Final = 428 +TOO_MANY_REQUESTS: Final = 429 +REQUEST_HEADER_FIELDS_TOO_LARGE: Final = 431 +UNAVAILABLE_FOR_LEGAL_REASONS: Final = 451 + +INTERNAL_SERVER_ERROR: Final = 500 +NOT_IMPLEMENTED: Final = 501 +BAD_GATEWAY: Final = 502 +SERVICE_UNAVAILABLE: Final = 503 +GATEWAY_TIMEOUT: Final = 504 +HTTP_VERSION_NOT_SUPPORTED: Final = 505 +VARIANT_ALSO_NEGOTIATES: Final = 506 +INSUFFICIENT_STORAGE: Final = 507 +LOOP_DETECTED: Final = 508 +NOT_EXTENDED: Final = 510 +NETWORK_AUTHENTICATION_REQUIRED: Final = 511 responses: dict[int, str] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/http/server.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/http/server.pyi index 214d5bb8f81ac..f558baca6b5e9 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/http/server.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/http/server.pyi @@ -433,46 +433,91 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def executable(path: StrPath) -> bool: # undocumented """Test for executable file.""" -@deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15") -class CGIHTTPRequestHandler(SimpleHTTPRequestHandler): - """Complete HTTP server with GET, HEAD and POST commands. +if sys.version_info >= (3, 13): + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + class CGIHTTPRequestHandler(SimpleHTTPRequestHandler): + """Complete HTTP server with GET, HEAD and POST commands. - GET and HEAD also support running CGI scripts. + GET and HEAD also support running CGI scripts. - The POST command is *only* implemented for CGI scripts. + The POST command is *only* implemented for CGI scripts. - """ + """ - cgi_directories: list[str] - have_fork: bool # undocumented - def do_POST(self) -> None: - """Serve a POST request. + cgi_directories: list[str] + have_fork: bool # undocumented + def do_POST(self) -> None: + """Serve a POST request. - This is only implemented for CGI scripts. + This is only implemented for CGI scripts. - """ + """ + + def is_cgi(self) -> bool: # undocumented + """Test whether self.path corresponds to a CGI script. + + Returns True and updates the cgi_info attribute to the tuple + (dir, rest) if self.path requires running a CGI script. + Returns False otherwise. - def is_cgi(self) -> bool: # undocumented - """Test whether self.path corresponds to a CGI script. + If any exception is raised, the caller should assume that + self.path was rejected as invalid and act accordingly. - Returns True and updates the cgi_info attribute to the tuple - (dir, rest) if self.path requires running a CGI script. - Returns False otherwise. + The default implementation tests whether the normalized url + path begins with one of the strings in self.cgi_directories + (and the next character is a '/' or the end of the string). - If any exception is raised, the caller should assume that - self.path was rejected as invalid and act accordingly. + """ + + def is_executable(self, path: StrPath) -> bool: # undocumented + """Test whether argument path is an executable file.""" + + def is_python(self, path: StrPath) -> bool: # undocumented + """Test whether argument path is a Python script.""" + + def run_cgi(self) -> None: # undocumented + """Execute a CGI script.""" + +else: + class CGIHTTPRequestHandler(SimpleHTTPRequestHandler): + """Complete HTTP server with GET, HEAD and POST commands. - The default implementation tests whether the normalized url - path begins with one of the strings in self.cgi_directories - (and the next character is a '/' or the end of the string). + GET and HEAD also support running CGI scripts. + + The POST command is *only* implemented for CGI scripts. """ - def is_executable(self, path: StrPath) -> bool: # undocumented - """Test whether argument path is an executable file.""" + cgi_directories: list[str] + have_fork: bool # undocumented + def do_POST(self) -> None: + """Serve a POST request. + + This is only implemented for CGI scripts. + + """ + + def is_cgi(self) -> bool: # undocumented + """Test whether self.path corresponds to a CGI script. + + Returns True and updates the cgi_info attribute to the tuple + (dir, rest) if self.path requires running a CGI script. + Returns False otherwise. + + If any exception is raised, the caller should assume that + self.path was rejected as invalid and act accordingly. + + The default implementation tests whether the normalized url + path begins with one of the strings in self.cgi_directories + (and the next character is a '/' or the end of the string). + + """ + + def is_executable(self, path: StrPath) -> bool: # undocumented + """Test whether argument path is an executable file.""" - def is_python(self, path: StrPath) -> bool: # undocumented - """Test whether argument path is a Python script.""" + def is_python(self, path: StrPath) -> bool: # undocumented + """Test whether argument path is a Python script.""" - def run_cgi(self) -> None: # undocumented - """Execute a CGI script.""" + def run_cgi(self) -> None: # undocumented + """Execute a CGI script.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi index 0131b6ae8af65..119a9a497dfb3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/imp.pyi @@ -21,18 +21,18 @@ from _imp import ( from _typeshed import StrPath from os import PathLike from types import TracebackType -from typing import IO, Any, Protocol, type_check_only - -SEARCH_ERROR: int -PY_SOURCE: int -PY_COMPILED: int -C_EXTENSION: int -PY_RESOURCE: int -PKG_DIRECTORY: int -C_BUILTIN: int -PY_FROZEN: int -PY_CODERESOURCE: int -IMP_HOOK: int +from typing import IO, Any, Final, Protocol, type_check_only + +SEARCH_ERROR: Final = 0 +PY_SOURCE: Final = 1 +PY_COMPILED: Final = 2 +C_EXTENSION: Final = 3 +PY_RESOURCE: Final = 4 +PKG_DIRECTORY: Final = 5 +C_BUILTIN: Final = 6 +PY_FROZEN: Final = 7 +PY_CODERESOURCE: Final = 8 +IMP_HOOK: Final = 9 def new_module(name: str) -> types.ModuleType: """**DEPRECATED** diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi index 5dfe7c7272c05..9bbc9e5a91438 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/abc.pyi @@ -81,7 +81,7 @@ if sys.version_info < (3, 12): Deprecated since Python 3.3 """ -@deprecated("Deprecated as of Python 3.7: Use importlib.resources.abc.TraversableResources instead.") +@deprecated("Deprecated since Python 3.7. Use `importlib.resources.abc.TraversableResources` instead.") class ResourceLoader(Loader): """Abstract base class for loaders which can return data from their back-end storage to facilitate reading data to perform an import. @@ -176,7 +176,7 @@ class SourceLoader(_bootstrap_external.SourceLoader, ResourceLoader, ExecutionLo """ - @deprecated("Deprecated as of Python 3.3: Use importlib.resources.abc.SourceLoader.path_stats instead.") + @deprecated("Deprecated since Python 3.3. Use `importlib.resources.abc.SourceLoader.path_stats` instead.") def path_mtime(self, path: str) -> float: """Return the (int) modification time for the path (str).""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi index 478aa35139f61..c6094da324cf8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi @@ -168,6 +168,7 @@ if sys.version_info >= (3, 12): An immutable collection of selectable EntryPoint objects. """ + __slots__ = () def __getitem__(self, name: str) -> EntryPoint: # type: ignore[override] """ Get the EntryPoint in self matching name. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi index bfa55f2f72642..584fe96403459 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi @@ -640,6 +640,7 @@ class Signature: to parameters (simulating 'functools.partial' behavior.) """ + __slots__ = ("_return_annotation", "_parameters") def __init__( self, parameters: Sequence[Parameter] | None = None, *, return_annotation: Any = ..., __validate_parameters__: bool = True ) -> None: @@ -842,6 +843,7 @@ class Parameter: `Parameter.KEYWORD_ONLY`, `Parameter.VAR_KEYWORD`. """ + __slots__ = ("_name", "_kind", "_default", "_annotation") def __init__(self, name: str, kind: _ParameterKind, *, default: Any = ..., annotation: Any = ...) -> None: ... empty = _empty @@ -890,6 +892,7 @@ class BoundArguments: Dict of keyword arguments values. """ + __slots__ = ("arguments", "_signature", "__weakref__") arguments: OrderedDict[str, Any] @property def args(self) -> tuple[Any, ...]: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ipaddress.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ipaddress.pyi index 4e8137a5f10ce..eb6439f5ad516 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ipaddress.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ipaddress.pyi @@ -83,6 +83,7 @@ def ip_interface( class _IPAddressBase: """The mother class.""" + __slots__ = () @property def compressed(self) -> str: """Return the shorthand version of the IP address as a string.""" @@ -111,6 +112,7 @@ class _BaseAddress(_IPAddressBase): used by single IP addresses. """ + __slots__ = () def __add__(self, other: int) -> Self: ... def __hash__(self) -> int: ... def __int__(self) -> int: ... @@ -413,6 +415,7 @@ class _BaseV4: """ + __slots__ = () if sys.version_info >= (3, 14): version: Final = 4 max_prefixlen: Final = 32 @@ -425,6 +428,7 @@ class _BaseV4: class IPv4Address(_BaseV4, _BaseAddress): """Represent and manipulate single IPv4 Addresses.""" + __slots__ = ("_ip", "__weakref__") def __init__(self, address: object) -> None: """ Args: @@ -607,6 +611,7 @@ class _BaseV6: """ + __slots__ = () if sys.version_info >= (3, 14): version: Final = 6 max_prefixlen: Final = 128 @@ -619,6 +624,7 @@ class _BaseV6: class IPv6Address(_BaseV6, _BaseAddress): """Represent and manipulate single IPv6 Addresses.""" + __slots__ = ("_ip", "_scope_id", "__weakref__") def __init__(self, address: object) -> None: """Instantiate a new IPv6 address object. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi index 0c47d8bd6540e..657c65a8b6934 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/logging/__init__.pyi @@ -314,7 +314,7 @@ class Logger(Filterer): logger.warning("Houston, we have a %s", "bit of a problem", exc_info=True) """ - @deprecated("Deprecated; use warning() instead.") + @deprecated("Deprecated since Python 3.3. Use `Logger.warning()` instead.") def warn( self, msg: object, @@ -1005,7 +1005,7 @@ class LoggerAdapter(Generic[_L]): Delegate a warning call to the underlying logger. """ - @deprecated("Deprecated; use warning() instead.") + @deprecated("Deprecated since Python 3.3. Use `LoggerAdapter.warning()` instead.") def warn( self, msg: object, @@ -1189,7 +1189,7 @@ def warning( format. """ -@deprecated("Deprecated; use warning() instead.") +@deprecated("Deprecated since Python 3.3. Use `warning()` instead.") def warn( msg: object, *args: object, @@ -1548,4 +1548,4 @@ class StringTemplateStyle(PercentStyle): # undocumented _STYLES: Final[dict[str, tuple[PercentStyle, str]]] -BASIC_FORMAT: Final[str] +BASIC_FORMAT: Final = "%(levelname)s:%(name)s:%(message)s" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi index 51f3439661b24..77c713032b1d2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi @@ -19,7 +19,7 @@ from typing_extensions import Required, TypeAlias from . import Filter, Filterer, Formatter, Handler, Logger, _FilterType, _FormatStyle, _Level -DEFAULT_LOGGING_CONFIG_PORT: int +DEFAULT_LOGGING_CONFIG_PORT: Final = 9030 RESET_ERROR: Final[int] # undocumented IDENTIFIER: Final[Pattern[str]] # undocumented @@ -163,7 +163,7 @@ class ConvertingTuple(tuple[Any, ...], ConvertingMixin): # undocumented @overload def __getitem__(self, key: slice) -> Any: ... -class BaseConfigurator: # undocumented +class BaseConfigurator: """ The configurator base class which defines some useful defaults. """ @@ -176,6 +176,8 @@ class BaseConfigurator: # undocumented value_converters: dict[str, str] importer: Callable[..., Any] + config: dict[str, Any] # undocumented + def __init__(self, config: _DictConfigArgs | dict[str, Any]) -> None: ... def resolve(self, s: str) -> Any: """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi index 26d811b3ce8b6..cbf27e4b69c8d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/logging/handlers.pyi @@ -23,12 +23,12 @@ from typing_extensions import Self _T = TypeVar("_T") -DEFAULT_TCP_LOGGING_PORT: Final[int] -DEFAULT_UDP_LOGGING_PORT: Final[int] -DEFAULT_HTTP_LOGGING_PORT: Final[int] -DEFAULT_SOAP_LOGGING_PORT: Final[int] -SYSLOG_UDP_PORT: Final[int] -SYSLOG_TCP_PORT: Final[int] +DEFAULT_TCP_LOGGING_PORT: Final = 9020 +DEFAULT_UDP_LOGGING_PORT: Final = 9021 +DEFAULT_HTTP_LOGGING_PORT: Final = 9022 +DEFAULT_SOAP_LOGGING_PORT: Final = 9023 +SYSLOG_UDP_PORT: Final = 514 +SYSLOG_TCP_PORT: Final = 514 class WatchedFileHandler(FileHandler): """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/__init__.pyi index fdf3e44dba17d..0983860e54e6d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/__init__.pyi @@ -1,26 +1,26 @@ import sys from collections.abc import Container, Iterable, Sequence from types import ModuleType -from typing import Any, Literal +from typing import Any, Final if sys.platform == "win32": from _msi import * from _msi import _Database - AMD64: bool - Win64: bool - - datasizemask: Literal[0x00FF] - type_valid: Literal[0x0100] - type_localizable: Literal[0x0200] - typemask: Literal[0x0C00] - type_long: Literal[0x0000] - type_short: Literal[0x0400] - type_string: Literal[0x0C00] - type_binary: Literal[0x0800] - type_nullable: Literal[0x1000] - type_key: Literal[0x2000] - knownbits: Literal[0x3FFF] + AMD64: Final[bool] + Win64: Final[bool] + + datasizemask: Final = 0x00FF + type_valid: Final = 0x0100 + type_localizable: Final = 0x0200 + typemask: Final = 0x0C00 + type_long: Final = 0x0000 + type_short: Final = 0x0400 + type_string: Final = 0x0C00 + type_binary: Final = 0x0800 + type_nullable: Final = 0x1000 + type_key: Final = 0x2000 + knownbits: Final = 0x3FFF class Table: name: str diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/schema.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/schema.pyi index 4ad9a1783fcd0..3bbdc41a1e8ec 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/schema.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/schema.pyi @@ -1,4 +1,5 @@ import sys +from typing import Final if sys.platform == "win32": from . import Table @@ -89,6 +90,6 @@ if sys.platform == "win32": Upgrade: Table Verb: Table - tables: list[Table] + tables: Final[list[Table]] _Validation_records: list[tuple[str, str, str, int | None, int | None, str | None, int | None, str | None, str | None, str]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/sequence.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/sequence.pyi index b8af09f46e65f..a9f5c24717bd3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/sequence.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/sequence.pyi @@ -1,13 +1,14 @@ import sys +from typing import Final from typing_extensions import TypeAlias if sys.platform == "win32": _SequenceType: TypeAlias = list[tuple[str, str | None, int]] - AdminExecuteSequence: _SequenceType - AdminUISequence: _SequenceType - AdvtExecuteSequence: _SequenceType - InstallExecuteSequence: _SequenceType - InstallUISequence: _SequenceType + AdminExecuteSequence: Final[_SequenceType] + AdminUISequence: Final[_SequenceType] + AdvtExecuteSequence: Final[_SequenceType] + InstallExecuteSequence: Final[_SequenceType] + InstallUISequence: Final[_SequenceType] - tables: list[str] + tables: Final[list[str]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/text.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/text.pyi index 441c843ca6cfe..da3c5fd0fb7a1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/msilib/text.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/msilib/text.pyi @@ -1,7 +1,8 @@ import sys +from typing import Final if sys.platform == "win32": - ActionText: list[tuple[str, str, str | None]] - UIText: list[tuple[str, str | None]] + ActionText: Final[list[tuple[str, str, str | None]]] + UIText: Final[list[tuple[str, str | None]]] dirname: str - tables: list[str] + tables: Final[list[str]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/msvcrt.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/msvcrt.pyi index b630b4b80b949..2a11014103a27 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/msvcrt.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/msvcrt.pyi @@ -9,10 +9,10 @@ if sys.platform == "win32": LK_NBLCK: Final = 2 LK_RLCK: Final = 3 LK_NBRLCK: Final = 4 - SEM_FAILCRITICALERRORS: int - SEM_NOALIGNMENTFAULTEXCEPT: int - SEM_NOGPFAULTERRORBOX: int - SEM_NOOPENFILEERRORBOX: int + SEM_FAILCRITICALERRORS: Final = 0x0001 + SEM_NOALIGNMENTFAULTEXCEPT: Final = 0x0004 + SEM_NOGPFAULTERRORBOX: Final = 0x0002 + SEM_NOOPENFILEERRORBOX: Final = 0x8000 def locking(fd: int, mode: int, nbytes: int, /) -> None: """Lock part of a file based on file descriptor fd from the C runtime. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/managers.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/managers.pyi index 049d0bc8b1f18..c4c8182c1ad27 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/managers.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/managers.pyi @@ -42,6 +42,7 @@ class Token: Type to uniquely identify a shared object """ + __slots__ = ("typeid", "address", "id") typeid: str | bytes | None address: _Address | None id: str | bytes | int | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/util.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/util.pyi index fefd35a607c6a..c3592f8bc98c0 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/util.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/multiprocessing/util.pyi @@ -60,7 +60,7 @@ def log_to_stderr(level: _LoggingLevel | None = None) -> Logger: def is_abstract_socket_namespace(address: str | bytes | None) -> bool: ... -abstract_sockets_supported: bool +abstract_sockets_supported: Final[bool] def get_temp_dir() -> str: ... def register_after_fork(obj: _T, func: Callable[[_T], object]) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/nturl2path.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/nturl2path.pyi index ff01fc19c8f2c..b4341638fe5cf 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/nturl2path.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/nturl2path.pyi @@ -8,13 +8,13 @@ import sys from typing_extensions import deprecated if sys.version_info >= (3, 14): - @deprecated("nturl2path module was deprecated since Python 3.14") + @deprecated("The `nturl2path` module is deprecated since Python 3.14.") def url2pathname(url: str) -> str: """OS-specific conversion from a relative URL of the 'file' scheme to a file system path; not recommended for general use. """ - @deprecated("nturl2path module was deprecated since Python 3.14") + @deprecated("The `nturl2path` module is deprecated since Python 3.14.") def pathname2url(p: str) -> str: """OS-specific conversion from a file system path to a relative URL of the 'file' scheme; not recommended for general use. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi index 9565050b2bdbb..dcd77c4188c55 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/numbers.pyi @@ -72,6 +72,7 @@ class Number(metaclass=ABCMeta): caring what kind, use isinstance(x, Number). """ + __slots__ = () @abstractmethod def __hash__(self) -> int: """The type of the None singleton.""" @@ -89,6 +90,7 @@ class Complex(Number, _ComplexLike): type as described below. """ + __slots__ = () @abstractmethod def __complex__(self) -> complex: """Return a builtin complex instance. Called for complex(self).""" @@ -182,6 +184,7 @@ class Real(Complex, _RealLike): Real also provides defaults for the derived operations. """ + __slots__ = () @abstractmethod def __float__(self) -> float: """Any Real can be converted to a native float object. @@ -290,6 +293,7 @@ class Real(Complex, _RealLike): class Rational(Real): """.numerator and .denominator should be in lowest terms.""" + __slots__ = () @property @abstractmethod def numerator(self) -> _IntegralLike: @@ -321,6 +325,7 @@ class Integral(Rational, _IntegralLike): bit-string operations. """ + __slots__ = () @abstractmethod def __int__(self) -> int: """int(self)""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/opcode.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/opcode.pyi index 3afb98232d908..080a968911290 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/opcode.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/opcode.pyi @@ -4,7 +4,7 @@ operate on bytecodes (e.g. peephole optimizers). """ import sys -from typing import Literal +from typing import Final, Literal __all__ = [ "cmp_op", @@ -29,25 +29,25 @@ if sys.version_info >= (3, 13): __all__ += ["hasjump"] cmp_op: tuple[Literal["<"], Literal["<="], Literal["=="], Literal["!="], Literal[">"], Literal[">="]] -hasconst: list[int] -hasname: list[int] -hasjrel: list[int] -hasjabs: list[int] -haslocal: list[int] -hascompare: list[int] -hasfree: list[int] +hasconst: Final[list[int]] +hasname: Final[list[int]] +hasjrel: Final[list[int]] +hasjabs: Final[list[int]] +haslocal: Final[list[int]] +hascompare: Final[list[int]] +hasfree: Final[list[int]] if sys.version_info >= (3, 12): - hasarg: list[int] - hasexc: list[int] + hasarg: Final[list[int]] + hasexc: Final[list[int]] else: - hasnargs: list[int] + hasnargs: Final[list[int]] if sys.version_info >= (3, 13): - hasjump: list[int] -opname: list[str] + hasjump: Final[list[int]] +opname: Final[list[str]] -opmap: dict[str, int] -HAVE_ARGUMENT: int -EXTENDED_ARG: int +opmap: Final[dict[str, int]] +HAVE_ARGUMENT: Final = 43 +EXTENDED_ARG: Final = 69 def stack_effect(opcode: int, oparg: int | None = None, /, *, jump: bool | None = None) -> int: """Compute the stack effect of the opcode.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi index 187f60d7974f8..650246955c738 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi @@ -532,22 +532,22 @@ supports_follow_symlinks: set[Callable[..., Any]] if sys.platform != "win32": # Unix only - PRIO_PROCESS: int - PRIO_PGRP: int - PRIO_USER: int + PRIO_PROCESS: Final[int] + PRIO_PGRP: Final[int] + PRIO_USER: Final[int] - F_LOCK: int - F_TLOCK: int - F_ULOCK: int - F_TEST: int + F_LOCK: Final[int] + F_TLOCK: Final[int] + F_ULOCK: Final[int] + F_TEST: Final[int] if sys.platform != "darwin": - POSIX_FADV_NORMAL: int - POSIX_FADV_SEQUENTIAL: int - POSIX_FADV_RANDOM: int - POSIX_FADV_NOREUSE: int - POSIX_FADV_WILLNEED: int - POSIX_FADV_DONTNEED: int + POSIX_FADV_NORMAL: Final[int] + POSIX_FADV_SEQUENTIAL: Final[int] + POSIX_FADV_RANDOM: Final[int] + POSIX_FADV_NOREUSE: Final[int] + POSIX_FADV_WILLNEED: Final[int] + POSIX_FADV_DONTNEED: Final[int] if sys.platform != "linux" and sys.platform != "darwin": # In the os-module docs, these are marked as being available @@ -557,69 +557,69 @@ if sys.platform != "win32": # so the sys-module docs recommend doing `if sys.platform.startswith('freebsd')` # to detect FreeBSD builds. Unfortunately that would be too dynamic # for type checkers, however. - SF_NODISKIO: int - SF_MNOWAIT: int - SF_SYNC: int + SF_NODISKIO: Final[int] + SF_MNOWAIT: Final[int] + SF_SYNC: Final[int] if sys.version_info >= (3, 11): - SF_NOCACHE: int + SF_NOCACHE: Final[int] if sys.platform == "linux": - XATTR_SIZE_MAX: int - XATTR_CREATE: int - XATTR_REPLACE: int + XATTR_SIZE_MAX: Final[int] + XATTR_CREATE: Final[int] + XATTR_REPLACE: Final[int] - P_PID: int - P_PGID: int - P_ALL: int + P_PID: Final[int] + P_PGID: Final[int] + P_ALL: Final[int] if sys.platform == "linux": - P_PIDFD: int - - WEXITED: int - WSTOPPED: int - WNOWAIT: int - - CLD_EXITED: int - CLD_DUMPED: int - CLD_TRAPPED: int - CLD_CONTINUED: int - CLD_KILLED: int - CLD_STOPPED: int - - SCHED_OTHER: int - SCHED_FIFO: int - SCHED_RR: int + P_PIDFD: Final[int] + + WEXITED: Final[int] + WSTOPPED: Final[int] + WNOWAIT: Final[int] + + CLD_EXITED: Final[int] + CLD_DUMPED: Final[int] + CLD_TRAPPED: Final[int] + CLD_CONTINUED: Final[int] + CLD_KILLED: Final[int] + CLD_STOPPED: Final[int] + + SCHED_OTHER: Final[int] + SCHED_FIFO: Final[int] + SCHED_RR: Final[int] if sys.platform != "darwin" and sys.platform != "linux": - SCHED_SPORADIC: int + SCHED_SPORADIC: Final[int] if sys.platform == "linux": - SCHED_BATCH: int - SCHED_IDLE: int - SCHED_RESET_ON_FORK: int + SCHED_BATCH: Final[int] + SCHED_IDLE: Final[int] + SCHED_RESET_ON_FORK: Final[int] if sys.version_info >= (3, 14) and sys.platform == "linux": - SCHED_DEADLINE: int - SCHED_NORMAL: int + SCHED_DEADLINE: Final[int] + SCHED_NORMAL: Final[int] if sys.platform != "win32": - RTLD_LAZY: int - RTLD_NOW: int - RTLD_GLOBAL: int - RTLD_LOCAL: int - RTLD_NODELETE: int - RTLD_NOLOAD: int + RTLD_LAZY: Final[int] + RTLD_NOW: Final[int] + RTLD_GLOBAL: Final[int] + RTLD_LOCAL: Final[int] + RTLD_NODELETE: Final[int] + RTLD_NOLOAD: Final[int] if sys.platform == "linux": - RTLD_DEEPBIND: int - GRND_NONBLOCK: int - GRND_RANDOM: int + RTLD_DEEPBIND: Final[int] + GRND_NONBLOCK: Final[int] + GRND_RANDOM: Final[int] if sys.platform == "darwin" and sys.version_info >= (3, 12): - PRIO_DARWIN_BG: int - PRIO_DARWIN_NONUI: int - PRIO_DARWIN_PROCESS: int - PRIO_DARWIN_THREAD: int + PRIO_DARWIN_BG: Final[int] + PRIO_DARWIN_NONUI: Final[int] + PRIO_DARWIN_PROCESS: Final[int] + PRIO_DARWIN_THREAD: Final[int] SEEK_SET: Final = 0 SEEK_CUR: Final = 1 @@ -628,74 +628,74 @@ if sys.platform != "win32": SEEK_DATA: Final = 3 SEEK_HOLE: Final = 4 -O_RDONLY: int -O_WRONLY: int -O_RDWR: int -O_APPEND: int -O_CREAT: int -O_EXCL: int -O_TRUNC: int +O_RDONLY: Final[int] +O_WRONLY: Final[int] +O_RDWR: Final[int] +O_APPEND: Final[int] +O_CREAT: Final[int] +O_EXCL: Final[int] +O_TRUNC: Final[int] if sys.platform == "win32": - O_BINARY: int - O_NOINHERIT: int - O_SHORT_LIVED: int - O_TEMPORARY: int - O_RANDOM: int - O_SEQUENTIAL: int - O_TEXT: int + O_BINARY: Final[int] + O_NOINHERIT: Final[int] + O_SHORT_LIVED: Final[int] + O_TEMPORARY: Final[int] + O_RANDOM: Final[int] + O_SEQUENTIAL: Final[int] + O_TEXT: Final[int] if sys.platform != "win32": - O_DSYNC: int - O_SYNC: int - O_NDELAY: int - O_NONBLOCK: int - O_NOCTTY: int - O_CLOEXEC: int - O_ASYNC: int # Gnu extension if in C library - O_DIRECTORY: int # Gnu extension if in C library - O_NOFOLLOW: int # Gnu extension if in C library - O_ACCMODE: int # TODO: when does this exist? + O_DSYNC: Final[int] + O_SYNC: Final[int] + O_NDELAY: Final[int] + O_NONBLOCK: Final[int] + O_NOCTTY: Final[int] + O_CLOEXEC: Final[int] + O_ASYNC: Final[int] # Gnu extension if in C library + O_DIRECTORY: Final[int] # Gnu extension if in C library + O_NOFOLLOW: Final[int] # Gnu extension if in C library + O_ACCMODE: Final[int] # TODO: when does this exist? if sys.platform == "linux": - O_RSYNC: int - O_DIRECT: int # Gnu extension if in C library - O_NOATIME: int # Gnu extension if in C library - O_PATH: int # Gnu extension if in C library - O_TMPFILE: int # Gnu extension if in C library - O_LARGEFILE: int # Gnu extension if in C library + O_RSYNC: Final[int] + O_DIRECT: Final[int] # Gnu extension if in C library + O_NOATIME: Final[int] # Gnu extension if in C library + O_PATH: Final[int] # Gnu extension if in C library + O_TMPFILE: Final[int] # Gnu extension if in C library + O_LARGEFILE: Final[int] # Gnu extension if in C library if sys.platform != "linux" and sys.platform != "win32": - O_SHLOCK: int - O_EXLOCK: int + O_SHLOCK: Final[int] + O_EXLOCK: Final[int] if sys.platform == "darwin" and sys.version_info >= (3, 10): - O_EVTONLY: int - O_NOFOLLOW_ANY: int - O_SYMLINK: int + O_EVTONLY: Final[int] + O_NOFOLLOW_ANY: Final[int] + O_SYMLINK: Final[int] if sys.platform != "win32" and sys.version_info >= (3, 10): - O_FSYNC: int + O_FSYNC: Final[int] if sys.platform != "linux" and sys.platform != "win32" and sys.version_info >= (3, 13): - O_EXEC: int - O_SEARCH: int + O_EXEC: Final[int] + O_SEARCH: Final[int] if sys.platform != "win32" and sys.platform != "darwin": # posix, but apparently missing on macos - ST_APPEND: int - ST_MANDLOCK: int - ST_NOATIME: int - ST_NODEV: int - ST_NODIRATIME: int - ST_NOEXEC: int - ST_RELATIME: int - ST_SYNCHRONOUS: int - ST_WRITE: int + ST_APPEND: Final[int] + ST_MANDLOCK: Final[int] + ST_NOATIME: Final[int] + ST_NODEV: Final[int] + ST_NODIRATIME: Final[int] + ST_NOEXEC: Final[int] + ST_RELATIME: Final[int] + ST_SYNCHRONOUS: Final[int] + ST_WRITE: Final[int] if sys.platform != "win32": - NGROUPS_MAX: int - ST_NOSUID: int - ST_RDONLY: int + NGROUPS_MAX: Final[int] + ST_NOSUID: Final[int] + ST_RDONLY: Final[int] curdir: str pardir: str @@ -711,10 +711,10 @@ linesep: Literal["\n", "\r\n"] devnull: str name: str -F_OK: int -R_OK: int -W_OK: int -X_OK: int +F_OK: Final = 0 +R_OK: Final = 4 +W_OK: Final = 2 +X_OK: Final = 1 _EnvironCodeFunc: TypeAlias = Callable[[AnyStr], AnyStr] @@ -753,47 +753,47 @@ if sys.platform != "win32": environb: _Environ[bytes] if sys.version_info >= (3, 11) or sys.platform != "win32": - EX_OK: int + EX_OK: Final[int] if sys.platform != "win32": confstr_names: dict[str, int] pathconf_names: dict[str, int] sysconf_names: dict[str, int] - EX_USAGE: int - EX_DATAERR: int - EX_NOINPUT: int - EX_NOUSER: int - EX_NOHOST: int - EX_UNAVAILABLE: int - EX_SOFTWARE: int - EX_OSERR: int - EX_OSFILE: int - EX_CANTCREAT: int - EX_IOERR: int - EX_TEMPFAIL: int - EX_PROTOCOL: int - EX_NOPERM: int - EX_CONFIG: int + EX_USAGE: Final[int] + EX_DATAERR: Final[int] + EX_NOINPUT: Final[int] + EX_NOUSER: Final[int] + EX_NOHOST: Final[int] + EX_UNAVAILABLE: Final[int] + EX_SOFTWARE: Final[int] + EX_OSERR: Final[int] + EX_OSFILE: Final[int] + EX_CANTCREAT: Final[int] + EX_IOERR: Final[int] + EX_TEMPFAIL: Final[int] + EX_PROTOCOL: Final[int] + EX_NOPERM: Final[int] + EX_CONFIG: Final[int] # Exists on some Unix platforms, e.g. Solaris. if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": - EX_NOTFOUND: int + EX_NOTFOUND: Final[int] -P_NOWAIT: int -P_NOWAITO: int -P_WAIT: int +P_NOWAIT: Final[int] +P_NOWAITO: Final[int] +P_WAIT: Final[int] if sys.platform == "win32": - P_DETACH: int - P_OVERLAY: int + P_DETACH: Final[int] + P_OVERLAY: Final[int] # wait()/waitpid() options if sys.platform != "win32": - WNOHANG: int # Unix only - WCONTINUED: int # some Unix systems - WUNTRACED: int # Unix only + WNOHANG: Final[int] # Unix only + WCONTINUED: Final[int] # some Unix systems + WUNTRACED: Final[int] # Unix only -TMP_MAX: int # Undocumented, but used by tempfile +TMP_MAX: Final[int] # Undocumented, but used by tempfile # ----- os classes (structures) ----- @final @@ -937,6 +937,7 @@ In the future, this property will contain the last metadata change time.""" class PathLike(ABC, Protocol[AnyStr_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] """Abstract base class for implementing the file system path protocol.""" + __slots__ = () @abstractmethod def __fspath__(self) -> AnyStr_co: """Return the file system path representation of the object.""" @@ -1575,11 +1576,11 @@ if sys.platform != "win32": """ if sys.platform != "darwin": if sys.version_info >= (3, 10): - RWF_APPEND: int # docs say available on 3.7+, stubtest says otherwise - RWF_DSYNC: int - RWF_SYNC: int - RWF_HIPRI: int - RWF_NOWAIT: int + RWF_APPEND: Final[int] # docs say available on 3.7+, stubtest says otherwise + RWF_DSYNC: Final[int] + RWF_SYNC: Final[int] + RWF_HIPRI: Final[int] + RWF_NOWAIT: Final[int] if sys.platform == "linux": def sendfile(out_fd: FileDescriptor, in_fd: FileDescriptor, offset: int | None, count: int) -> int: @@ -1590,8 +1591,8 @@ if sys.platform != "win32": in_fd: FileDescriptor, offset: int, count: int, - headers: Sequence[ReadableBuffer] = ..., - trailers: Sequence[ReadableBuffer] = ..., + headers: Sequence[ReadableBuffer] = (), + trailers: Sequence[ReadableBuffer] = (), flags: int = 0, ) -> int: # FreeBSD and Mac OS X only """Copy count bytes from file descriptor in_fd to file descriptor out_fd.""" @@ -2816,9 +2817,9 @@ else: scheduler A tuple with the scheduler policy (optional) and parameters. """ - POSIX_SPAWN_OPEN: int - POSIX_SPAWN_CLOSE: int - POSIX_SPAWN_DUP2: int + POSIX_SPAWN_OPEN: Final = 0 + POSIX_SPAWN_CLOSE: Final = 1 + POSIX_SPAWN_DUP2: Final = 2 if sys.platform != "win32": @final @@ -2978,23 +2979,23 @@ if sys.platform == "win32": """ if sys.platform == "linux": - MFD_CLOEXEC: int - MFD_ALLOW_SEALING: int - MFD_HUGETLB: int - MFD_HUGE_SHIFT: int - MFD_HUGE_MASK: int - MFD_HUGE_64KB: int - MFD_HUGE_512KB: int - MFD_HUGE_1MB: int - MFD_HUGE_2MB: int - MFD_HUGE_8MB: int - MFD_HUGE_16MB: int - MFD_HUGE_32MB: int - MFD_HUGE_256MB: int - MFD_HUGE_512MB: int - MFD_HUGE_1GB: int - MFD_HUGE_2GB: int - MFD_HUGE_16GB: int + MFD_CLOEXEC: Final[int] + MFD_ALLOW_SEALING: Final[int] + MFD_HUGETLB: Final[int] + MFD_HUGE_SHIFT: Final[int] + MFD_HUGE_MASK: Final[int] + MFD_HUGE_64KB: Final[int] + MFD_HUGE_512KB: Final[int] + MFD_HUGE_1MB: Final[int] + MFD_HUGE_2MB: Final[int] + MFD_HUGE_8MB: Final[int] + MFD_HUGE_16MB: Final[int] + MFD_HUGE_32MB: Final[int] + MFD_HUGE_256MB: Final[int] + MFD_HUGE_512MB: Final[int] + MFD_HUGE_1GB: Final[int] + MFD_HUGE_2GB: Final[int] + MFD_HUGE_16GB: Final[int] def memfd_create(name: str, flags: int = ...) -> int: ... def copy_file_range(src: int, dst: int, count: int, offset_src: int | None = ..., offset_dst: int | None = ...) -> int: """Copy count bytes from one file descriptor to another. @@ -3061,12 +3062,12 @@ if sys.version_info >= (3, 12) and sys.platform == "win32": """ if sys.version_info >= (3, 10) and sys.platform == "linux": - EFD_CLOEXEC: int - EFD_NONBLOCK: int - EFD_SEMAPHORE: int - SPLICE_F_MORE: int - SPLICE_F_MOVE: int - SPLICE_F_NONBLOCK: int + EFD_CLOEXEC: Final[int] + EFD_NONBLOCK: Final[int] + EFD_SEMAPHORE: Final[int] + SPLICE_F_MORE: Final[int] + SPLICE_F_MOVE: Final[int] + SPLICE_F_NONBLOCK: Final[int] def eventfd(initval: int, flags: int = 524288) -> FileDescriptor: """Creates and returns an event notification file descriptor.""" @@ -3105,20 +3106,20 @@ if sys.version_info >= (3, 10) and sys.platform == "linux": """ if sys.version_info >= (3, 12) and sys.platform == "linux": - CLONE_FILES: int - CLONE_FS: int - CLONE_NEWCGROUP: int # Linux 4.6+ - CLONE_NEWIPC: int # Linux 2.6.19+ - CLONE_NEWNET: int # Linux 2.6.24+ - CLONE_NEWNS: int - CLONE_NEWPID: int # Linux 3.8+ - CLONE_NEWTIME: int # Linux 5.6+ - CLONE_NEWUSER: int # Linux 3.8+ - CLONE_NEWUTS: int # Linux 2.6.19+ - CLONE_SIGHAND: int - CLONE_SYSVSEM: int # Linux 2.6.26+ - CLONE_THREAD: int - CLONE_VM: int + CLONE_FILES: Final[int] + CLONE_FS: Final[int] + CLONE_NEWCGROUP: Final[int] # Linux 4.6+ + CLONE_NEWIPC: Final[int] # Linux 2.6.19+ + CLONE_NEWNET: Final[int] # Linux 2.6.24+ + CLONE_NEWNS: Final[int] + CLONE_NEWPID: Final[int] # Linux 3.8+ + CLONE_NEWTIME: Final[int] # Linux 5.6+ + CLONE_NEWUSER: Final[int] # Linux 3.8+ + CLONE_NEWUTS: Final[int] # Linux 2.6.19+ + CLONE_SIGHAND: Final[int] + CLONE_SYSVSEM: Final[int] # Linux 2.6.26+ + CLONE_THREAD: Final[int] + CLONE_VM: Final[int] def unshare(flags: int) -> None: """Disassociate parts of a process (or thread) execution context. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ossaudiodev.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ossaudiodev.pyi index b9ee3edab033e..f8230b4f02123 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ossaudiodev.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ossaudiodev.pyi @@ -1,119 +1,120 @@ import sys -from typing import Any, Literal, overload +from typing import Any, Final, Literal, overload if sys.platform != "win32" and sys.platform != "darwin": - AFMT_AC3: int - AFMT_A_LAW: int - AFMT_IMA_ADPCM: int - AFMT_MPEG: int - AFMT_MU_LAW: int - AFMT_QUERY: int - AFMT_S16_BE: int - AFMT_S16_LE: int - AFMT_S16_NE: int - AFMT_S8: int - AFMT_U16_BE: int - AFMT_U16_LE: int - AFMT_U8: int - SNDCTL_COPR_HALT: int - SNDCTL_COPR_LOAD: int - SNDCTL_COPR_RCODE: int - SNDCTL_COPR_RCVMSG: int - SNDCTL_COPR_RDATA: int - SNDCTL_COPR_RESET: int - SNDCTL_COPR_RUN: int - SNDCTL_COPR_SENDMSG: int - SNDCTL_COPR_WCODE: int - SNDCTL_COPR_WDATA: int - SNDCTL_DSP_BIND_CHANNEL: int - SNDCTL_DSP_CHANNELS: int - SNDCTL_DSP_GETBLKSIZE: int - SNDCTL_DSP_GETCAPS: int - SNDCTL_DSP_GETCHANNELMASK: int - SNDCTL_DSP_GETFMTS: int - SNDCTL_DSP_GETIPTR: int - SNDCTL_DSP_GETISPACE: int - SNDCTL_DSP_GETODELAY: int - SNDCTL_DSP_GETOPTR: int - SNDCTL_DSP_GETOSPACE: int - SNDCTL_DSP_GETSPDIF: int - SNDCTL_DSP_GETTRIGGER: int - SNDCTL_DSP_MAPINBUF: int - SNDCTL_DSP_MAPOUTBUF: int - SNDCTL_DSP_NONBLOCK: int - SNDCTL_DSP_POST: int - SNDCTL_DSP_PROFILE: int - SNDCTL_DSP_RESET: int - SNDCTL_DSP_SAMPLESIZE: int - SNDCTL_DSP_SETDUPLEX: int - SNDCTL_DSP_SETFMT: int - SNDCTL_DSP_SETFRAGMENT: int - SNDCTL_DSP_SETSPDIF: int - SNDCTL_DSP_SETSYNCRO: int - SNDCTL_DSP_SETTRIGGER: int - SNDCTL_DSP_SPEED: int - SNDCTL_DSP_STEREO: int - SNDCTL_DSP_SUBDIVIDE: int - SNDCTL_DSP_SYNC: int - SNDCTL_FM_4OP_ENABLE: int - SNDCTL_FM_LOAD_INSTR: int - SNDCTL_MIDI_INFO: int - SNDCTL_MIDI_MPUCMD: int - SNDCTL_MIDI_MPUMODE: int - SNDCTL_MIDI_PRETIME: int - SNDCTL_SEQ_CTRLRATE: int - SNDCTL_SEQ_GETINCOUNT: int - SNDCTL_SEQ_GETOUTCOUNT: int - SNDCTL_SEQ_GETTIME: int - SNDCTL_SEQ_NRMIDIS: int - SNDCTL_SEQ_NRSYNTHS: int - SNDCTL_SEQ_OUTOFBAND: int - SNDCTL_SEQ_PANIC: int - SNDCTL_SEQ_PERCMODE: int - SNDCTL_SEQ_RESET: int - SNDCTL_SEQ_RESETSAMPLES: int - SNDCTL_SEQ_SYNC: int - SNDCTL_SEQ_TESTMIDI: int - SNDCTL_SEQ_THRESHOLD: int - SNDCTL_SYNTH_CONTROL: int - SNDCTL_SYNTH_ID: int - SNDCTL_SYNTH_INFO: int - SNDCTL_SYNTH_MEMAVL: int - SNDCTL_SYNTH_REMOVESAMPLE: int - SNDCTL_TMR_CONTINUE: int - SNDCTL_TMR_METRONOME: int - SNDCTL_TMR_SELECT: int - SNDCTL_TMR_SOURCE: int - SNDCTL_TMR_START: int - SNDCTL_TMR_STOP: int - SNDCTL_TMR_TEMPO: int - SNDCTL_TMR_TIMEBASE: int - SOUND_MIXER_ALTPCM: int - SOUND_MIXER_BASS: int - SOUND_MIXER_CD: int - SOUND_MIXER_DIGITAL1: int - SOUND_MIXER_DIGITAL2: int - SOUND_MIXER_DIGITAL3: int - SOUND_MIXER_IGAIN: int - SOUND_MIXER_IMIX: int - SOUND_MIXER_LINE: int - SOUND_MIXER_LINE1: int - SOUND_MIXER_LINE2: int - SOUND_MIXER_LINE3: int - SOUND_MIXER_MIC: int - SOUND_MIXER_MONITOR: int - SOUND_MIXER_NRDEVICES: int - SOUND_MIXER_OGAIN: int - SOUND_MIXER_PCM: int - SOUND_MIXER_PHONEIN: int - SOUND_MIXER_PHONEOUT: int - SOUND_MIXER_RADIO: int - SOUND_MIXER_RECLEV: int - SOUND_MIXER_SPEAKER: int - SOUND_MIXER_SYNTH: int - SOUND_MIXER_TREBLE: int - SOUND_MIXER_VIDEO: int - SOUND_MIXER_VOLUME: int + # Depends on soundcard.h + AFMT_AC3: Final[int] + AFMT_A_LAW: Final[int] + AFMT_IMA_ADPCM: Final[int] + AFMT_MPEG: Final[int] + AFMT_MU_LAW: Final[int] + AFMT_QUERY: Final[int] + AFMT_S16_BE: Final[int] + AFMT_S16_LE: Final[int] + AFMT_S16_NE: Final[int] + AFMT_S8: Final[int] + AFMT_U16_BE: Final[int] + AFMT_U16_LE: Final[int] + AFMT_U8: Final[int] + SNDCTL_COPR_HALT: Final[int] + SNDCTL_COPR_LOAD: Final[int] + SNDCTL_COPR_RCODE: Final[int] + SNDCTL_COPR_RCVMSG: Final[int] + SNDCTL_COPR_RDATA: Final[int] + SNDCTL_COPR_RESET: Final[int] + SNDCTL_COPR_RUN: Final[int] + SNDCTL_COPR_SENDMSG: Final[int] + SNDCTL_COPR_WCODE: Final[int] + SNDCTL_COPR_WDATA: Final[int] + SNDCTL_DSP_BIND_CHANNEL: Final[int] + SNDCTL_DSP_CHANNELS: Final[int] + SNDCTL_DSP_GETBLKSIZE: Final[int] + SNDCTL_DSP_GETCAPS: Final[int] + SNDCTL_DSP_GETCHANNELMASK: Final[int] + SNDCTL_DSP_GETFMTS: Final[int] + SNDCTL_DSP_GETIPTR: Final[int] + SNDCTL_DSP_GETISPACE: Final[int] + SNDCTL_DSP_GETODELAY: Final[int] + SNDCTL_DSP_GETOPTR: Final[int] + SNDCTL_DSP_GETOSPACE: Final[int] + SNDCTL_DSP_GETSPDIF: Final[int] + SNDCTL_DSP_GETTRIGGER: Final[int] + SNDCTL_DSP_MAPINBUF: Final[int] + SNDCTL_DSP_MAPOUTBUF: Final[int] + SNDCTL_DSP_NONBLOCK: Final[int] + SNDCTL_DSP_POST: Final[int] + SNDCTL_DSP_PROFILE: Final[int] + SNDCTL_DSP_RESET: Final[int] + SNDCTL_DSP_SAMPLESIZE: Final[int] + SNDCTL_DSP_SETDUPLEX: Final[int] + SNDCTL_DSP_SETFMT: Final[int] + SNDCTL_DSP_SETFRAGMENT: Final[int] + SNDCTL_DSP_SETSPDIF: Final[int] + SNDCTL_DSP_SETSYNCRO: Final[int] + SNDCTL_DSP_SETTRIGGER: Final[int] + SNDCTL_DSP_SPEED: Final[int] + SNDCTL_DSP_STEREO: Final[int] + SNDCTL_DSP_SUBDIVIDE: Final[int] + SNDCTL_DSP_SYNC: Final[int] + SNDCTL_FM_4OP_ENABLE: Final[int] + SNDCTL_FM_LOAD_INSTR: Final[int] + SNDCTL_MIDI_INFO: Final[int] + SNDCTL_MIDI_MPUCMD: Final[int] + SNDCTL_MIDI_MPUMODE: Final[int] + SNDCTL_MIDI_PRETIME: Final[int] + SNDCTL_SEQ_CTRLRATE: Final[int] + SNDCTL_SEQ_GETINCOUNT: Final[int] + SNDCTL_SEQ_GETOUTCOUNT: Final[int] + SNDCTL_SEQ_GETTIME: Final[int] + SNDCTL_SEQ_NRMIDIS: Final[int] + SNDCTL_SEQ_NRSYNTHS: Final[int] + SNDCTL_SEQ_OUTOFBAND: Final[int] + SNDCTL_SEQ_PANIC: Final[int] + SNDCTL_SEQ_PERCMODE: Final[int] + SNDCTL_SEQ_RESET: Final[int] + SNDCTL_SEQ_RESETSAMPLES: Final[int] + SNDCTL_SEQ_SYNC: Final[int] + SNDCTL_SEQ_TESTMIDI: Final[int] + SNDCTL_SEQ_THRESHOLD: Final[int] + SNDCTL_SYNTH_CONTROL: Final[int] + SNDCTL_SYNTH_ID: Final[int] + SNDCTL_SYNTH_INFO: Final[int] + SNDCTL_SYNTH_MEMAVL: Final[int] + SNDCTL_SYNTH_REMOVESAMPLE: Final[int] + SNDCTL_TMR_CONTINUE: Final[int] + SNDCTL_TMR_METRONOME: Final[int] + SNDCTL_TMR_SELECT: Final[int] + SNDCTL_TMR_SOURCE: Final[int] + SNDCTL_TMR_START: Final[int] + SNDCTL_TMR_STOP: Final[int] + SNDCTL_TMR_TEMPO: Final[int] + SNDCTL_TMR_TIMEBASE: Final[int] + SOUND_MIXER_ALTPCM: Final[int] + SOUND_MIXER_BASS: Final[int] + SOUND_MIXER_CD: Final[int] + SOUND_MIXER_DIGITAL1: Final[int] + SOUND_MIXER_DIGITAL2: Final[int] + SOUND_MIXER_DIGITAL3: Final[int] + SOUND_MIXER_IGAIN: Final[int] + SOUND_MIXER_IMIX: Final[int] + SOUND_MIXER_LINE: Final[int] + SOUND_MIXER_LINE1: Final[int] + SOUND_MIXER_LINE2: Final[int] + SOUND_MIXER_LINE3: Final[int] + SOUND_MIXER_MIC: Final[int] + SOUND_MIXER_MONITOR: Final[int] + SOUND_MIXER_NRDEVICES: Final[int] + SOUND_MIXER_OGAIN: Final[int] + SOUND_MIXER_PCM: Final[int] + SOUND_MIXER_PHONEIN: Final[int] + SOUND_MIXER_PHONEOUT: Final[int] + SOUND_MIXER_RADIO: Final[int] + SOUND_MIXER_RECLEV: Final[int] + SOUND_MIXER_SPEAKER: Final[int] + SOUND_MIXER_SYNTH: Final[int] + SOUND_MIXER_TREBLE: Final[int] + SOUND_MIXER_VIDEO: Final[int] + SOUND_MIXER_VOLUME: Final[int] control_labels: list[str] control_names: list[str] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi index 6d9b4eccee3c1..b552301ba5e9f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi @@ -45,6 +45,31 @@ class PurePath(PathLike[str]): directly, regardless of your system. """ + if sys.version_info >= (3, 13): + __slots__ = ( + "_raw_paths", + "_drv", + "_root", + "_tail_cached", + "_str", + "_str_normcase_cached", + "_parts_normcase_cached", + "_hash", + ) + elif sys.version_info >= (3, 12): + __slots__ = ( + "_raw_paths", + "_drv", + "_root", + "_tail_cached", + "_str", + "_str_normcase_cached", + "_parts_normcase_cached", + "_lines_cached", + "_hash", + ) + else: + __slots__ = ("_drv", "_root", "_parts", "_str", "_hash", "_pparts", "_cached_cparts") if sys.version_info >= (3, 13): parser: ClassVar[types.ModuleType] def full_match(self, pattern: StrPath, *, case_sensitive: bool | None = None) -> bool: @@ -240,6 +265,8 @@ class PurePosixPath(PurePath): However, you can also instantiate it directly on any system. """ + __slots__ = () + class PureWindowsPath(PurePath): """PurePath subclass for Windows systems. @@ -247,6 +274,8 @@ class PureWindowsPath(PurePath): However, you can also instantiate it directly on any system. """ + __slots__ = () + class Path(PurePath): """PurePath subclass that can make system calls. @@ -257,6 +286,12 @@ class Path(PurePath): but cannot instantiate a WindowsPath on a POSIX system or vice versa. """ + if sys.version_info >= (3, 14): + __slots__ = ("_info",) + elif sys.version_info >= (3, 10): + __slots__ = () + else: + __slots__ = ("_accessor",) if sys.version_info >= (3, 12): def __new__(cls, *args: StrPath, **kwargs: Unused) -> Self: ... # pyright: ignore[reportInconsistentConstructor] else: @@ -737,7 +772,7 @@ class Path(PurePath): """ if sys.version_info >= (3, 12): def walk( - self, top_down: bool = ..., on_error: Callable[[OSError], object] | None = ..., follow_symlinks: bool = ... + self, top_down: bool = True, on_error: Callable[[OSError], object] | None = None, follow_symlinks: bool = False ) -> Iterator[tuple[Self, list[str], list[str]]]: """Walk the directory tree from this directory, similar to os.walk().""" @@ -747,12 +782,16 @@ class PosixPath(Path, PurePosixPath): On a POSIX system, instantiating a Path should return this object. """ + __slots__ = () + class WindowsPath(Path, PureWindowsPath): """Path subclass for Windows systems. On a Windows system, instantiating a Path should return this object. """ + __slots__ = () + if sys.version_info >= (3, 13): class UnsupportedOperation(NotImplementedError): """An exception that is raised when an unsupported operation is attempted.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi index a8d81ead5791d..b56ca9eab8f0c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi @@ -355,7 +355,7 @@ _T = TypeVar("_T") _P = ParamSpec("_P") _Mode: TypeAlias = Literal["inline", "cli"] -line_prefix: str # undocumented +line_prefix: Final[str] # undocumented class Restart(Exception): """Causes a debugger to be restarted for the debugged python program.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pickle.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pickle.pyi index 071214bdc562f..1348b91018be7 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pickle.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pickle.pyi @@ -39,7 +39,7 @@ from _pickle import ( ) from _typeshed import ReadableBuffer, SupportsWrite from collections.abc import Callable, Iterable, Mapping -from typing import Any, ClassVar, SupportsBytes, SupportsIndex, final +from typing import Any, ClassVar, Final, SupportsBytes, SupportsIndex, final from typing_extensions import Self __all__ = [ @@ -127,8 +127,8 @@ __all__ = [ "UNICODE", ] -HIGHEST_PROTOCOL: int -DEFAULT_PROTOCOL: int +HIGHEST_PROTOCOL: Final = 5 +DEFAULT_PROTOCOL: Final = 5 bytes_types: tuple[type[Any], ...] # undocumented @@ -151,85 +151,85 @@ class PickleBuffer: def __release_buffer__(self, buffer: memoryview, /) -> None: """Release the buffer object that exposes the underlying memory of the object.""" -MARK: bytes -STOP: bytes -POP: bytes -POP_MARK: bytes -DUP: bytes -FLOAT: bytes -INT: bytes -BININT: bytes -BININT1: bytes -LONG: bytes -BININT2: bytes -NONE: bytes -PERSID: bytes -BINPERSID: bytes -REDUCE: bytes -STRING: bytes -BINSTRING: bytes -SHORT_BINSTRING: bytes -UNICODE: bytes -BINUNICODE: bytes -APPEND: bytes -BUILD: bytes -GLOBAL: bytes -DICT: bytes -EMPTY_DICT: bytes -APPENDS: bytes -GET: bytes -BINGET: bytes -INST: bytes -LONG_BINGET: bytes -LIST: bytes -EMPTY_LIST: bytes -OBJ: bytes -PUT: bytes -BINPUT: bytes -LONG_BINPUT: bytes -SETITEM: bytes -TUPLE: bytes -EMPTY_TUPLE: bytes -SETITEMS: bytes -BINFLOAT: bytes - -TRUE: bytes -FALSE: bytes +MARK: Final = b"(" +STOP: Final = b"." +POP: Final = b"0" +POP_MARK: Final = b"1" +DUP: Final = b"2" +FLOAT: Final = b"F" +INT: Final = b"I" +BININT: Final = b"J" +BININT1: Final = b"K" +LONG: Final = b"L" +BININT2: Final = b"M" +NONE: Final = b"N" +PERSID: Final = b"P" +BINPERSID: Final = b"Q" +REDUCE: Final = b"R" +STRING: Final = b"S" +BINSTRING: Final = b"T" +SHORT_BINSTRING: Final = b"U" +UNICODE: Final = b"V" +BINUNICODE: Final = b"X" +APPEND: Final = b"a" +BUILD: Final = b"b" +GLOBAL: Final = b"c" +DICT: Final = b"d" +EMPTY_DICT: Final = b"}" +APPENDS: Final = b"e" +GET: Final = b"g" +BINGET: Final = b"h" +INST: Final = b"i" +LONG_BINGET: Final = b"j" +LIST: Final = b"l" +EMPTY_LIST: Final = b"]" +OBJ: Final = b"o" +PUT: Final = b"p" +BINPUT: Final = b"q" +LONG_BINPUT: Final = b"r" +SETITEM: Final = b"s" +TUPLE: Final = b"t" +EMPTY_TUPLE: Final = b")" +SETITEMS: Final = b"u" +BINFLOAT: Final = b"G" + +TRUE: Final = b"I01\n" +FALSE: Final = b"I00\n" # protocol 2 -PROTO: bytes -NEWOBJ: bytes -EXT1: bytes -EXT2: bytes -EXT4: bytes -TUPLE1: bytes -TUPLE2: bytes -TUPLE3: bytes -NEWTRUE: bytes -NEWFALSE: bytes -LONG1: bytes -LONG4: bytes +PROTO: Final = b"\x80" +NEWOBJ: Final = b"\x81" +EXT1: Final = b"\x82" +EXT2: Final = b"\x83" +EXT4: Final = b"\x84" +TUPLE1: Final = b"\x85" +TUPLE2: Final = b"\x86" +TUPLE3: Final = b"\x87" +NEWTRUE: Final = b"\x88" +NEWFALSE: Final = b"\x89" +LONG1: Final = b"\x8a" +LONG4: Final = b"\x8b" # protocol 3 -BINBYTES: bytes -SHORT_BINBYTES: bytes +BINBYTES: Final = b"B" +SHORT_BINBYTES: Final = b"C" # protocol 4 -SHORT_BINUNICODE: bytes -BINUNICODE8: bytes -BINBYTES8: bytes -EMPTY_SET: bytes -ADDITEMS: bytes -FROZENSET: bytes -NEWOBJ_EX: bytes -STACK_GLOBAL: bytes -MEMOIZE: bytes -FRAME: bytes +SHORT_BINUNICODE: Final = b"\x8c" +BINUNICODE8: Final = b"\x8d" +BINBYTES8: Final = b"\x8e" +EMPTY_SET: Final = b"\x8f" +ADDITEMS: Final = b"\x90" +FROZENSET: Final = b"\x91" +NEWOBJ_EX: Final = b"\x92" +STACK_GLOBAL: Final = b"\x93" +MEMOIZE: Final = b"\x94" +FRAME: Final = b"\x95" # protocol 5 -BYTEARRAY8: bytes -NEXT_BUFFER: bytes -READONLY_BUFFER: bytes +BYTEARRAY8: Final = b"\x96" +NEXT_BUFFER: Final = b"\x97" +READONLY_BUFFER: Final = b"\x98" def encode_long(x: int) -> bytes: # undocumented """Encode a long to a two's complement little-endian binary string. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pickletools.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pickletools.pyi index 17f51626d1d1f..e5497b1ecb2f6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pickletools.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pickletools.pyi @@ -12,7 +12,7 @@ dis(pickle, out=None, memo=None, indentlevel=4) import sys from collections.abc import Callable, Iterator, MutableMapping -from typing import IO, Any +from typing import IO, Any, Final from typing_extensions import TypeAlias __all__ = ["dis", "genops", "optimize"] @@ -20,13 +20,14 @@ __all__ = ["dis", "genops", "optimize"] _Reader: TypeAlias = Callable[[IO[bytes]], Any] bytes_types: tuple[type[Any], ...] -UP_TO_NEWLINE: int -TAKEN_FROM_ARGUMENT1: int -TAKEN_FROM_ARGUMENT4: int -TAKEN_FROM_ARGUMENT4U: int -TAKEN_FROM_ARGUMENT8U: int +UP_TO_NEWLINE: Final = -1 +TAKEN_FROM_ARGUMENT1: Final = -2 +TAKEN_FROM_ARGUMENT4: Final = -3 +TAKEN_FROM_ARGUMENT4U: Final = -4 +TAKEN_FROM_ARGUMENT8U: Final = -5 class ArgumentDescriptor: + __slots__ = ("name", "n", "reader", "doc") name: str n: int reader: _Reader @@ -376,6 +377,7 @@ def read_long4(f: IO[bytes]) -> int: long4: ArgumentDescriptor class StackObject: + __slots__ = ("name", "obtype", "doc") name: str obtype: type[Any] | tuple[type[Any], ...] doc: str @@ -401,6 +403,7 @@ markobject: StackObject stackslice: StackObject class OpcodeInfo: + __slots__ = ("name", "code", "arg", "stack_before", "stack_after", "proto", "doc") name: str code: str arg: ArgumentDescriptor | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi index bb9cd3d717b7c..e6d49bd3ff2b1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi @@ -259,7 +259,7 @@ def python_compiler() -> str: """ -def platform(aliased: bool = ..., terse: bool = ...) -> str: +def platform(aliased: bool = False, terse: bool = False) -> str: """Returns a single string identifying the underlying platform with as much useful information as possible (but no more :). diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/plistlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/plistlib.pyi index 33d659c787321..845d5a7d2d4bf 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/plistlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/plistlib.pyi @@ -60,7 +60,7 @@ from _typeshed import ReadableBuffer from collections.abc import Mapping, MutableMapping from datetime import datetime from enum import Enum -from typing import IO, Any +from typing import IO, Any, Final from typing_extensions import Self __all__ = ["InvalidFileException", "FMT_XML", "FMT_BINARY", "load", "dump", "loads", "dumps", "UID"] @@ -71,8 +71,8 @@ class PlistFormat(Enum): FMT_XML = 1 FMT_BINARY = 2 -FMT_XML = PlistFormat.FMT_XML -FMT_BINARY = PlistFormat.FMT_BINARY +FMT_XML: Final = PlistFormat.FMT_XML +FMT_BINARY: Final = PlistFormat.FMT_BINARY if sys.version_info >= (3, 13): def load( fp: IO[bytes], diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/poplib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/poplib.pyi index 25a5f84d62f46..c5c59d710f586 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/poplib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/poplib.pyi @@ -22,7 +22,7 @@ POP3_SSL_PORT: Final = 995 CR: Final = b"\r" LF: Final = b"\n" CRLF: Final = b"\r\n" -HAVE_SSL: bool +HAVE_SSL: Final[bool] class POP3: """This class supports both the minimal and optional command sets. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi index 0a056f84f9a1d..cd5a5c1b94a60 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pydoc.pyi @@ -92,12 +92,12 @@ def classify_class_attrs(object: object) -> list[tuple[str, str, type, str]]: """Wrap inspect.classify_class_attrs, with fixup for data descriptors and bound methods.""" if sys.version_info >= (3, 13): - @deprecated("Deprecated in Python 3.13.") - def ispackage(path: str) -> bool: + @deprecated("Deprecated since Python 3.13.") + def ispackage(path: str) -> bool: # undocumented """Guess whether a path refers to a package directory.""" else: - def ispackage(path: str) -> bool: + def ispackage(path: str) -> bool: # undocumented """Guess whether a path refers to a package directory.""" def source_synopsis(file: IO[AnyStr]) -> AnyStr | None: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pydoc_data/topics.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pydoc_data/topics.pyi index 091d34300106e..ce907a41c0053 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pydoc_data/topics.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pydoc_data/topics.pyi @@ -1 +1,3 @@ -topics: dict[str, str] +from typing import Final + +topics: Final[dict[str, str]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/resource.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/resource.pyi index be5ee3eb14962..f5b27d28cef0e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/resource.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/resource.pyi @@ -3,27 +3,28 @@ from _typeshed import structseq from typing import Final, final if sys.platform != "win32": - RLIMIT_AS: int - RLIMIT_CORE: int - RLIMIT_CPU: int - RLIMIT_DATA: int - RLIMIT_FSIZE: int - RLIMIT_MEMLOCK: int - RLIMIT_NOFILE: int - RLIMIT_NPROC: int - RLIMIT_RSS: int - RLIMIT_STACK: int - RLIM_INFINITY: int - RUSAGE_CHILDREN: int - RUSAGE_SELF: int + # Depends on resource.h + RLIMIT_AS: Final[int] + RLIMIT_CORE: Final[int] + RLIMIT_CPU: Final[int] + RLIMIT_DATA: Final[int] + RLIMIT_FSIZE: Final[int] + RLIMIT_MEMLOCK: Final[int] + RLIMIT_NOFILE: Final[int] + RLIMIT_NPROC: Final[int] + RLIMIT_RSS: Final[int] + RLIMIT_STACK: Final[int] + RLIM_INFINITY: Final[int] + RUSAGE_CHILDREN: Final[int] + RUSAGE_SELF: Final[int] if sys.platform == "linux": - RLIMIT_MSGQUEUE: int - RLIMIT_NICE: int - RLIMIT_OFILE: int - RLIMIT_RTPRIO: int - RLIMIT_RTTIME: int - RLIMIT_SIGPENDING: int - RUSAGE_THREAD: int + RLIMIT_MSGQUEUE: Final[int] + RLIMIT_NICE: Final[int] + RLIMIT_OFILE: Final[int] + RLIMIT_RTPRIO: Final[int] + RLIMIT_RTTIME: Final[int] + RLIMIT_SIGPENDING: Final[int] + RUSAGE_THREAD: Final[int] @final class struct_rusage( diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi index 71d08a1ee289f..59937607821ee 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi @@ -8,25 +8,25 @@ import sys from _typeshed import FileDescriptorLike from collections.abc import Iterable from types import TracebackType -from typing import Any, ClassVar, final +from typing import Any, ClassVar, Final, final from typing_extensions import Self if sys.platform != "win32": - PIPE_BUF: int - POLLERR: int - POLLHUP: int - POLLIN: int + PIPE_BUF: Final[int] + POLLERR: Final[int] + POLLHUP: Final[int] + POLLIN: Final[int] if sys.platform == "linux": - POLLMSG: int - POLLNVAL: int - POLLOUT: int - POLLPRI: int - POLLRDBAND: int + POLLMSG: Final[int] + POLLNVAL: Final[int] + POLLOUT: Final[int] + POLLPRI: Final[int] + POLLRDBAND: Final[int] if sys.platform == "linux": - POLLRDHUP: int - POLLRDNORM: int - POLLWRBAND: int - POLLWRNORM: int + POLLRDHUP: Final[int] + POLLRDNORM: Final[int] + POLLWRBAND: Final[int] + POLLWRNORM: Final[int] # This is actually a function that returns an instance of a class. # The class is not accessible directly, and also calls itself select.poll. @@ -155,45 +155,45 @@ if sys.platform != "linux" and sys.platform != "win32": def fromfd(cls, fd: FileDescriptorLike, /) -> kqueue: """Create a kqueue object from a given control fd.""" - KQ_EV_ADD: int - KQ_EV_CLEAR: int - KQ_EV_DELETE: int - KQ_EV_DISABLE: int - KQ_EV_ENABLE: int - KQ_EV_EOF: int - KQ_EV_ERROR: int - KQ_EV_FLAG1: int - KQ_EV_ONESHOT: int - KQ_EV_SYSFLAGS: int - KQ_FILTER_AIO: int + KQ_EV_ADD: Final[int] + KQ_EV_CLEAR: Final[int] + KQ_EV_DELETE: Final[int] + KQ_EV_DISABLE: Final[int] + KQ_EV_ENABLE: Final[int] + KQ_EV_EOF: Final[int] + KQ_EV_ERROR: Final[int] + KQ_EV_FLAG1: Final[int] + KQ_EV_ONESHOT: Final[int] + KQ_EV_SYSFLAGS: Final[int] + KQ_FILTER_AIO: Final[int] if sys.platform != "darwin": - KQ_FILTER_NETDEV: int - KQ_FILTER_PROC: int - KQ_FILTER_READ: int - KQ_FILTER_SIGNAL: int - KQ_FILTER_TIMER: int - KQ_FILTER_VNODE: int - KQ_FILTER_WRITE: int - KQ_NOTE_ATTRIB: int - KQ_NOTE_CHILD: int - KQ_NOTE_DELETE: int - KQ_NOTE_EXEC: int - KQ_NOTE_EXIT: int - KQ_NOTE_EXTEND: int - KQ_NOTE_FORK: int - KQ_NOTE_LINK: int + KQ_FILTER_NETDEV: Final[int] + KQ_FILTER_PROC: Final[int] + KQ_FILTER_READ: Final[int] + KQ_FILTER_SIGNAL: Final[int] + KQ_FILTER_TIMER: Final[int] + KQ_FILTER_VNODE: Final[int] + KQ_FILTER_WRITE: Final[int] + KQ_NOTE_ATTRIB: Final[int] + KQ_NOTE_CHILD: Final[int] + KQ_NOTE_DELETE: Final[int] + KQ_NOTE_EXEC: Final[int] + KQ_NOTE_EXIT: Final[int] + KQ_NOTE_EXTEND: Final[int] + KQ_NOTE_FORK: Final[int] + KQ_NOTE_LINK: Final[int] if sys.platform != "darwin": - KQ_NOTE_LINKDOWN: int - KQ_NOTE_LINKINV: int - KQ_NOTE_LINKUP: int - KQ_NOTE_LOWAT: int - KQ_NOTE_PCTRLMASK: int - KQ_NOTE_PDATAMASK: int - KQ_NOTE_RENAME: int - KQ_NOTE_REVOKE: int - KQ_NOTE_TRACK: int - KQ_NOTE_TRACKERR: int - KQ_NOTE_WRITE: int + KQ_NOTE_LINKDOWN: Final[int] + KQ_NOTE_LINKINV: Final[int] + KQ_NOTE_LINKUP: Final[int] + KQ_NOTE_LOWAT: Final[int] + KQ_NOTE_PCTRLMASK: Final[int] + KQ_NOTE_PDATAMASK: Final[int] + KQ_NOTE_RENAME: Final[int] + KQ_NOTE_REVOKE: Final[int] + KQ_NOTE_TRACK: Final[int] + KQ_NOTE_TRACKERR: Final[int] + KQ_NOTE_WRITE: Final[int] if sys.platform == "linux": @final @@ -269,23 +269,23 @@ if sys.platform == "linux": def fromfd(cls, fd: FileDescriptorLike, /) -> epoll: """Create an epoll object from a given control fd.""" - EPOLLERR: int - EPOLLEXCLUSIVE: int - EPOLLET: int - EPOLLHUP: int - EPOLLIN: int - EPOLLMSG: int - EPOLLONESHOT: int - EPOLLOUT: int - EPOLLPRI: int - EPOLLRDBAND: int - EPOLLRDHUP: int - EPOLLRDNORM: int - EPOLLWRBAND: int - EPOLLWRNORM: int - EPOLL_CLOEXEC: int + EPOLLERR: Final[int] + EPOLLEXCLUSIVE: Final[int] + EPOLLET: Final[int] + EPOLLHUP: Final[int] + EPOLLIN: Final[int] + EPOLLMSG: Final[int] + EPOLLONESHOT: Final[int] + EPOLLOUT: Final[int] + EPOLLPRI: Final[int] + EPOLLRDBAND: Final[int] + EPOLLRDHUP: Final[int] + EPOLLRDNORM: Final[int] + EPOLLWRBAND: Final[int] + EPOLLWRNORM: Final[int] + EPOLL_CLOEXEC: Final[int] if sys.version_info >= (3, 14): - EPOLLWAKEUP: int + EPOLLWAKEUP: Final[int] if sys.platform != "linux" and sys.platform != "darwin" and sys.platform != "win32": # Solaris only diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/selectors.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/selectors.pyi index d35e4370344ef..ed95b56b13847 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/selectors.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/selectors.pyi @@ -8,13 +8,13 @@ import sys from _typeshed import FileDescriptor, FileDescriptorLike, Unused from abc import ABCMeta, abstractmethod from collections.abc import Mapping -from typing import Any, NamedTuple +from typing import Any, Final, NamedTuple from typing_extensions import Self, TypeAlias _EventMask: TypeAlias = int -EVENT_READ: _EventMask -EVENT_WRITE: _EventMask +EVENT_READ: Final = 1 +EVENT_WRITE: Final = 2 class SelectorKey(NamedTuple): """SelectorKey(fileobj, fd, events, data) diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi index 9c5dc852c248a..d2df39ff39189 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/smtplib.pyi @@ -39,7 +39,7 @@ from re import Pattern from socket import socket from ssl import SSLContext from types import TracebackType -from typing import Any, Protocol, overload, type_check_only +from typing import Any, Final, Protocol, overload, type_check_only from typing_extensions import Self, TypeAlias __all__ = [ @@ -62,12 +62,12 @@ __all__ = [ _Reply: TypeAlias = tuple[int, bytes] _SendErrs: TypeAlias = dict[str, _Reply] -SMTP_PORT: int -SMTP_SSL_PORT: int -CRLF: str -bCRLF: bytes +SMTP_PORT: Final = 25 +SMTP_SSL_PORT: Final = 465 +CRLF: Final[str] +bCRLF: Final[bytes] -OLDSTYLE_AUTH: Pattern[str] +OLDSTYLE_AUTH: Final[Pattern[str]] class SMTPException(OSError): """Base class for all exceptions raised by this module.""" @@ -590,7 +590,7 @@ class SMTP_SSL(SMTP): context: SSLContext | None = None, ) -> None: ... -LMTP_PORT: int +LMTP_PORT: Final = 2003 class LMTP(SMTP): """LMTP - Local Mail Transfer Protocol diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi index 95551819860b7..ad2af8629207e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/socket.pyi @@ -183,7 +183,7 @@ from _typeshed import ReadableBuffer, Unused, WriteableBuffer from collections.abc import Iterable from enum import IntEnum, IntFlag from io import BufferedReader, BufferedRWPair, BufferedWriter, IOBase, RawIOBase, TextIOWrapper -from typing import Any, Literal, Protocol, SupportsIndex, overload, type_check_only +from typing import Any, Final, Literal, Protocol, SupportsIndex, overload, type_check_only from typing_extensions import Self __all__ = [ @@ -1106,9 +1106,9 @@ if sys.version_info >= (3, 14): __all__ += ["IP_FREEBIND", "IP_RECVORIGDSTADDR", "VMADDR_CID_LOCAL"] # Re-exported from errno -EBADF: int -EAGAIN: int -EWOULDBLOCK: int +EBADF: Final[int] +EAGAIN: Final[int] +EWOULDBLOCK: Final[int] # These errors are implemented in _socket at runtime # but they consider themselves to live in socket so we'll put them here. @@ -1173,60 +1173,60 @@ class AddressFamily(IntEnum): # FreeBSD >= 14.0 AF_DIVERT = 44 -AF_INET = AddressFamily.AF_INET -AF_INET6 = AddressFamily.AF_INET6 -AF_APPLETALK = AddressFamily.AF_APPLETALK -AF_DECnet: Literal[12] -AF_IPX = AddressFamily.AF_IPX -AF_SNA = AddressFamily.AF_SNA -AF_UNSPEC = AddressFamily.AF_UNSPEC +AF_INET: Final = AddressFamily.AF_INET +AF_INET6: Final = AddressFamily.AF_INET6 +AF_APPLETALK: Final = AddressFamily.AF_APPLETALK +AF_DECnet: Final = 12 +AF_IPX: Final = AddressFamily.AF_IPX +AF_SNA: Final = AddressFamily.AF_SNA +AF_UNSPEC: Final = AddressFamily.AF_UNSPEC if sys.platform != "darwin": - AF_IRDA = AddressFamily.AF_IRDA + AF_IRDA: Final = AddressFamily.AF_IRDA if sys.platform != "win32": - AF_ROUTE = AddressFamily.AF_ROUTE - AF_UNIX = AddressFamily.AF_UNIX + AF_ROUTE: Final = AddressFamily.AF_ROUTE + AF_UNIX: Final = AddressFamily.AF_UNIX if sys.platform == "darwin": - AF_SYSTEM = AddressFamily.AF_SYSTEM + AF_SYSTEM: Final = AddressFamily.AF_SYSTEM if sys.platform != "win32" and sys.platform != "darwin": - AF_ASH = AddressFamily.AF_ASH - AF_ATMPVC = AddressFamily.AF_ATMPVC - AF_ATMSVC = AddressFamily.AF_ATMSVC - AF_AX25 = AddressFamily.AF_AX25 - AF_BRIDGE = AddressFamily.AF_BRIDGE - AF_ECONET = AddressFamily.AF_ECONET - AF_KEY = AddressFamily.AF_KEY - AF_LLC = AddressFamily.AF_LLC - AF_NETBEUI = AddressFamily.AF_NETBEUI - AF_NETROM = AddressFamily.AF_NETROM - AF_PPPOX = AddressFamily.AF_PPPOX - AF_ROSE = AddressFamily.AF_ROSE - AF_SECURITY = AddressFamily.AF_SECURITY - AF_WANPIPE = AddressFamily.AF_WANPIPE - AF_X25 = AddressFamily.AF_X25 + AF_ASH: Final = AddressFamily.AF_ASH + AF_ATMPVC: Final = AddressFamily.AF_ATMPVC + AF_ATMSVC: Final = AddressFamily.AF_ATMSVC + AF_AX25: Final = AddressFamily.AF_AX25 + AF_BRIDGE: Final = AddressFamily.AF_BRIDGE + AF_ECONET: Final = AddressFamily.AF_ECONET + AF_KEY: Final = AddressFamily.AF_KEY + AF_LLC: Final = AddressFamily.AF_LLC + AF_NETBEUI: Final = AddressFamily.AF_NETBEUI + AF_NETROM: Final = AddressFamily.AF_NETROM + AF_PPPOX: Final = AddressFamily.AF_PPPOX + AF_ROSE: Final = AddressFamily.AF_ROSE + AF_SECURITY: Final = AddressFamily.AF_SECURITY + AF_WANPIPE: Final = AddressFamily.AF_WANPIPE + AF_X25: Final = AddressFamily.AF_X25 if sys.platform == "linux": - AF_CAN = AddressFamily.AF_CAN - AF_PACKET = AddressFamily.AF_PACKET - AF_RDS = AddressFamily.AF_RDS - AF_TIPC = AddressFamily.AF_TIPC - AF_ALG = AddressFamily.AF_ALG - AF_NETLINK = AddressFamily.AF_NETLINK - AF_VSOCK = AddressFamily.AF_VSOCK - AF_QIPCRTR = AddressFamily.AF_QIPCRTR + AF_CAN: Final = AddressFamily.AF_CAN + AF_PACKET: Final = AddressFamily.AF_PACKET + AF_RDS: Final = AddressFamily.AF_RDS + AF_TIPC: Final = AddressFamily.AF_TIPC + AF_ALG: Final = AddressFamily.AF_ALG + AF_NETLINK: Final = AddressFamily.AF_NETLINK + AF_VSOCK: Final = AddressFamily.AF_VSOCK + AF_QIPCRTR: Final = AddressFamily.AF_QIPCRTR if sys.platform != "linux": - AF_LINK = AddressFamily.AF_LINK + AF_LINK: Final = AddressFamily.AF_LINK if sys.platform != "darwin" and sys.platform != "linux": - AF_BLUETOOTH = AddressFamily.AF_BLUETOOTH + AF_BLUETOOTH: Final = AddressFamily.AF_BLUETOOTH if sys.platform == "win32" and sys.version_info >= (3, 12): - AF_HYPERV = AddressFamily.AF_HYPERV + AF_HYPERV: Final = AddressFamily.AF_HYPERV if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin" and sys.version_info >= (3, 12): # FreeBSD >= 14.0 - AF_DIVERT = AddressFamily.AF_DIVERT + AF_DIVERT: Final = AddressFamily.AF_DIVERT class SocketKind(IntEnum): """An enumeration.""" @@ -1240,14 +1240,14 @@ class SocketKind(IntEnum): SOCK_CLOEXEC = 524288 SOCK_NONBLOCK = 2048 -SOCK_STREAM = SocketKind.SOCK_STREAM -SOCK_DGRAM = SocketKind.SOCK_DGRAM -SOCK_RAW = SocketKind.SOCK_RAW -SOCK_RDM = SocketKind.SOCK_RDM -SOCK_SEQPACKET = SocketKind.SOCK_SEQPACKET +SOCK_STREAM: Final = SocketKind.SOCK_STREAM +SOCK_DGRAM: Final = SocketKind.SOCK_DGRAM +SOCK_RAW: Final = SocketKind.SOCK_RAW +SOCK_RDM: Final = SocketKind.SOCK_RDM +SOCK_SEQPACKET: Final = SocketKind.SOCK_SEQPACKET if sys.platform == "linux": - SOCK_CLOEXEC = SocketKind.SOCK_CLOEXEC - SOCK_NONBLOCK = SocketKind.SOCK_NONBLOCK + SOCK_CLOEXEC: Final = SocketKind.SOCK_CLOEXEC + SOCK_NONBLOCK: Final = SocketKind.SOCK_NONBLOCK class MsgFlag(IntFlag): """An enumeration.""" @@ -1281,36 +1281,36 @@ class MsgFlag(IntFlag): if sys.platform != "win32" and sys.platform != "linux": MSG_EOF = 256 -MSG_CTRUNC = MsgFlag.MSG_CTRUNC -MSG_DONTROUTE = MsgFlag.MSG_DONTROUTE -MSG_OOB = MsgFlag.MSG_OOB -MSG_PEEK = MsgFlag.MSG_PEEK -MSG_TRUNC = MsgFlag.MSG_TRUNC -MSG_WAITALL = MsgFlag.MSG_WAITALL +MSG_CTRUNC: Final = MsgFlag.MSG_CTRUNC +MSG_DONTROUTE: Final = MsgFlag.MSG_DONTROUTE +MSG_OOB: Final = MsgFlag.MSG_OOB +MSG_PEEK: Final = MsgFlag.MSG_PEEK +MSG_TRUNC: Final = MsgFlag.MSG_TRUNC +MSG_WAITALL: Final = MsgFlag.MSG_WAITALL if sys.platform == "win32": - MSG_BCAST = MsgFlag.MSG_BCAST - MSG_MCAST = MsgFlag.MSG_MCAST + MSG_BCAST: Final = MsgFlag.MSG_BCAST + MSG_MCAST: Final = MsgFlag.MSG_MCAST if sys.platform != "darwin": - MSG_ERRQUEUE = MsgFlag.MSG_ERRQUEUE + MSG_ERRQUEUE: Final = MsgFlag.MSG_ERRQUEUE if sys.platform != "win32": - MSG_DONTWAIT = MsgFlag.MSG_DONTWAIT - MSG_EOR = MsgFlag.MSG_EOR - MSG_NOSIGNAL = MsgFlag.MSG_NOSIGNAL # Sometimes this exists on darwin, sometimes not + MSG_DONTWAIT: Final = MsgFlag.MSG_DONTWAIT + MSG_EOR: Final = MsgFlag.MSG_EOR + MSG_NOSIGNAL: Final = MsgFlag.MSG_NOSIGNAL # Sometimes this exists on darwin, sometimes not if sys.platform != "win32" and sys.platform != "darwin": - MSG_CMSG_CLOEXEC = MsgFlag.MSG_CMSG_CLOEXEC - MSG_CONFIRM = MsgFlag.MSG_CONFIRM - MSG_FASTOPEN = MsgFlag.MSG_FASTOPEN - MSG_MORE = MsgFlag.MSG_MORE + MSG_CMSG_CLOEXEC: Final = MsgFlag.MSG_CMSG_CLOEXEC + MSG_CONFIRM: Final = MsgFlag.MSG_CONFIRM + MSG_FASTOPEN: Final = MsgFlag.MSG_FASTOPEN + MSG_MORE: Final = MsgFlag.MSG_MORE if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux": - MSG_NOTIFICATION = MsgFlag.MSG_NOTIFICATION + MSG_NOTIFICATION: Final = MsgFlag.MSG_NOTIFICATION if sys.platform != "win32" and sys.platform != "linux": - MSG_EOF = MsgFlag.MSG_EOF + MSG_EOF: Final = MsgFlag.MSG_EOF class AddressInfo(IntFlag): """An enumeration.""" @@ -1327,18 +1327,18 @@ class AddressInfo(IntFlag): AI_MASK = 5127 AI_V4MAPPED_CFG = 512 -AI_ADDRCONFIG = AddressInfo.AI_ADDRCONFIG -AI_ALL = AddressInfo.AI_ALL -AI_CANONNAME = AddressInfo.AI_CANONNAME -AI_NUMERICHOST = AddressInfo.AI_NUMERICHOST -AI_NUMERICSERV = AddressInfo.AI_NUMERICSERV -AI_PASSIVE = AddressInfo.AI_PASSIVE -AI_V4MAPPED = AddressInfo.AI_V4MAPPED +AI_ADDRCONFIG: Final = AddressInfo.AI_ADDRCONFIG +AI_ALL: Final = AddressInfo.AI_ALL +AI_CANONNAME: Final = AddressInfo.AI_CANONNAME +AI_NUMERICHOST: Final = AddressInfo.AI_NUMERICHOST +AI_NUMERICSERV: Final = AddressInfo.AI_NUMERICSERV +AI_PASSIVE: Final = AddressInfo.AI_PASSIVE +AI_V4MAPPED: Final = AddressInfo.AI_V4MAPPED if sys.platform != "win32" and sys.platform != "linux": - AI_DEFAULT = AddressInfo.AI_DEFAULT - AI_MASK = AddressInfo.AI_MASK - AI_V4MAPPED_CFG = AddressInfo.AI_V4MAPPED_CFG + AI_DEFAULT: Final = AddressInfo.AI_DEFAULT + AI_MASK: Final = AddressInfo.AI_MASK + AI_V4MAPPED_CFG: Final = AddressInfo.AI_V4MAPPED_CFG if sys.platform == "win32": errorTab: dict[int, str] # undocumented @@ -1357,6 +1357,7 @@ class _SendableFile(Protocol): class socket(_socket.socket): """A subclass of _socket.socket adding the makefile() method.""" + __slots__ = ["__weakref__", "_io_refs", "_closed"] def __init__( self, family: AddressFamily | int = -1, type: SocketKind | int = -1, proto: int = -1, fileno: int | None = None ) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/dbapi2.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/dbapi2.pyi index d37a0d391ec6a..9e170a81243d8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/dbapi2.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/dbapi2.pyi @@ -66,7 +66,8 @@ from sqlite3 import ( Row as Row, Warning as Warning, ) -from typing import Literal +from typing import Final, Literal +from typing_extensions import deprecated if sys.version_info >= (3, 12): from _sqlite3 import ( @@ -211,11 +212,15 @@ if sys.version_info >= (3, 11): if sys.version_info < (3, 14): # Deprecated and removed from _sqlite3 in 3.12, but removed from here in 3.14. - version: str + version: Final[str] if sys.version_info < (3, 12): if sys.version_info >= (3, 10): # deprecation wrapper that has a different name for the argument... + @deprecated( + "Deprecated since Python 3.10; removed in Python 3.12. " + "Open database in URI mode using `cache=shared` parameter instead." + ) def enable_shared_cache(enable: int) -> None: ... else: from _sqlite3 import enable_shared_cache as enable_shared_cache @@ -223,9 +228,9 @@ if sys.version_info < (3, 12): if sys.version_info < (3, 10): from _sqlite3 import OptimizedUnicode as OptimizedUnicode -paramstyle: str +paramstyle: Final = "qmark" threadsafety: Literal[0, 1, 3] -apilevel: str +apilevel: Final[str] Date = date Time = time Timestamp = datetime @@ -236,7 +241,7 @@ def TimestampFromTicks(ticks: float) -> Timestamp: ... if sys.version_info < (3, 14): # Deprecated in 3.12, removed in 3.14. - version_info: tuple[int, int, int] + version_info: Final[tuple[int, int, int]] -sqlite_version_info: tuple[int, int, int] +sqlite_version_info: Final[tuple[int, int, int]] Binary = memoryview diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sre_compile.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sre_compile.pyi index 684f8d77f7f4f..b3205231f6f5d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sre_compile.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sre_compile.pyi @@ -4,9 +4,9 @@ from re import Pattern from sre_constants import * from sre_constants import _NamedIntConstant from sre_parse import SubPattern -from typing import Any +from typing import Any, Final -MAXCODE: int +MAXCODE: Final[int] def dis(code: list[_NamedIntConstant]) -> None: ... def isstring(obj: Any) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sre_parse.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sre_parse.pyi index ad121383c7ae1..89d33fcdd2379 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sre_parse.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sre_parse.pyi @@ -5,24 +5,24 @@ from collections.abc import Iterable from re import Match, Pattern as _Pattern from sre_constants import * from sre_constants import _NamedIntConstant as _NIC, error as _Error -from typing import Any, overload +from typing import Any, Final, overload from typing_extensions import TypeAlias -SPECIAL_CHARS: str -REPEAT_CHARS: str -DIGITS: frozenset[str] -OCTDIGITS: frozenset[str] -HEXDIGITS: frozenset[str] -ASCIILETTERS: frozenset[str] -WHITESPACE: frozenset[str] -ESCAPES: dict[str, tuple[_NIC, int]] -CATEGORIES: dict[str, tuple[_NIC, _NIC] | tuple[_NIC, list[tuple[_NIC, _NIC]]]] -FLAGS: dict[str, int] -TYPE_FLAGS: int -GLOBAL_FLAGS: int +SPECIAL_CHARS: Final = ".\\[{()*+?^$|" +REPEAT_CHARS: Final = "*+?{" +DIGITS: Final[frozenset[str]] +OCTDIGITS: Final[frozenset[str]] +HEXDIGITS: Final[frozenset[str]] +ASCIILETTERS: Final[frozenset[str]] +WHITESPACE: Final[frozenset[str]] +ESCAPES: Final[dict[str, tuple[_NIC, int]]] +CATEGORIES: Final[dict[str, tuple[_NIC, _NIC] | tuple[_NIC, list[tuple[_NIC, _NIC]]]]] +FLAGS: Final[dict[str, int]] +TYPE_FLAGS: Final[int] +GLOBAL_FLAGS: Final[int] if sys.version_info >= (3, 11): - MAXWIDTH: int + MAXWIDTH: Final[int] if sys.version_info < (3, 11): class Verbose(Exception): ... @@ -41,7 +41,7 @@ class State: lookbehindgroups: int | None @property def groups(self) -> int: ... - def opengroup(self, name: str | None = ...) -> int: ... + def opengroup(self, name: str | None = None) -> int: ... def closegroup(self, gid: int, p: SubPattern) -> None: ... def checkgroup(self, gid: int) -> bool: ... def checklookbehindgroup(self, gid: int, source: Tokenizer) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi index f81f51970a1ad..b4540c8ca8c97 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ssl.pyi @@ -188,7 +188,7 @@ class SSLCertVerificationError(SSLError, ValueError): CertificateError = SSLCertVerificationError if sys.version_info < (3, 12): - @deprecated("Deprecated since Python 3.7. Removed in Python 3.12. Use `SSLContext.wrap_socket()` instead.") + @deprecated("Deprecated since Python 3.7; removed in Python 3.12. Use `SSLContext.wrap_socket()` instead.") def wrap_socket( sock: socket.socket, keyfile: StrOrBytesPath | None = None, @@ -201,7 +201,7 @@ if sys.version_info < (3, 12): suppress_ragged_eofs: bool = True, ciphers: str | None = None, ) -> SSLSocket: ... - @deprecated("Deprecated since Python 3.7. Removed in Python 3.12.") + @deprecated("Deprecated since Python 3.7; removed in Python 3.12.") def match_hostname(cert: _PeerCertRetDictType, hostname: str) -> None: """Verify that *cert* (in decoded format as returned by SSLSocket.getpeercert()) matches the *hostname*. RFC 2818 and RFC 6125 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/statistics.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/statistics.pyi index 67deb3720bb51..f5f731c46275e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/statistics.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/statistics.pyi @@ -523,6 +523,7 @@ def variance(data: Iterable[_NumberT], xbar: _NumberT | None = None) -> _NumberT class NormalDist: """Normal distribution of a random variable""" + __slots__ = {"_mu": "Arithmetic mean of a normal distribution", "_sigma": "Standard deviation of a normal distribution"} def __init__(self, mu: float = 0.0, sigma: float = 1.0) -> None: """NormalDist where mu is the mean and sigma is the standard deviation.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/string/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/string/__init__.pyi index e539981969b5b..6d87737eff51f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/string/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/string/__init__.pyi @@ -18,7 +18,7 @@ import sys from _typeshed import StrOrLiteralStr from collections.abc import Iterable, Mapping, Sequence from re import Pattern, RegexFlag -from typing import Any, ClassVar, overload +from typing import Any, ClassVar, Final, overload from typing_extensions import LiteralString __all__ = [ @@ -36,15 +36,15 @@ __all__ = [ "Template", ] -ascii_letters: LiteralString -ascii_lowercase: LiteralString -ascii_uppercase: LiteralString -digits: LiteralString -hexdigits: LiteralString -octdigits: LiteralString -punctuation: LiteralString -printable: LiteralString -whitespace: LiteralString +whitespace: Final = " \t\n\r\v\f" +ascii_lowercase: Final = "abcdefghijklmnopqrstuvwxyz" +ascii_uppercase: Final = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" +ascii_letters: Final[LiteralString] # string too long +digits: Final = "0123456789" +hexdigits: Final = "0123456789abcdefABCDEF" +octdigits: Final = "01234567" +punctuation: Final = r"""!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" +printable: Final[LiteralString] # string too long def capwords(s: StrOrLiteralStr, sep: StrOrLiteralStr | None = None) -> StrOrLiteralStr: """capwords(s [,sep]) -> string diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/stringprep.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/stringprep.pyi index 4d262df8d9fc9..75a354552168e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/stringprep.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/stringprep.pyi @@ -4,13 +4,15 @@ There are two kinds of tables: sets, for which a member test is provided, and mappings, for which a mapping function is provided. """ -b1_set: set[int] -b3_exceptions: dict[int, str] -c22_specials: set[int] -c6_set: set[int] -c7_set: set[int] -c8_set: set[int] -c9_set: set[int] +from typing import Final + +b1_set: Final[set[int]] +b3_exceptions: Final[dict[int, str]] +c22_specials: Final[set[int]] +c6_set: Final[set[int]] +c7_set: Final[set[int]] +c8_set: Final[set[int]] +c9_set: Final[set[int]] def in_table_a1(code: str) -> bool: ... def in_table_b1(code: str) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sunau.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sunau.pyi index 7ccb82de854cf..5dbcffbe8914d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sunau.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sunau.pyi @@ -104,27 +104,27 @@ is destroyed. """ from _typeshed import Unused -from typing import IO, Any, Literal, NamedTuple, NoReturn, overload +from typing import IO, Any, Final, Literal, NamedTuple, NoReturn, overload from typing_extensions import Self, TypeAlias _File: TypeAlias = str | IO[bytes] class Error(Exception): ... -AUDIO_FILE_MAGIC: int -AUDIO_FILE_ENCODING_MULAW_8: int -AUDIO_FILE_ENCODING_LINEAR_8: int -AUDIO_FILE_ENCODING_LINEAR_16: int -AUDIO_FILE_ENCODING_LINEAR_24: int -AUDIO_FILE_ENCODING_LINEAR_32: int -AUDIO_FILE_ENCODING_FLOAT: int -AUDIO_FILE_ENCODING_DOUBLE: int -AUDIO_FILE_ENCODING_ADPCM_G721: int -AUDIO_FILE_ENCODING_ADPCM_G722: int -AUDIO_FILE_ENCODING_ADPCM_G723_3: int -AUDIO_FILE_ENCODING_ADPCM_G723_5: int -AUDIO_FILE_ENCODING_ALAW_8: int -AUDIO_UNKNOWN_SIZE: int +AUDIO_FILE_MAGIC: Final = 0x2E736E64 +AUDIO_FILE_ENCODING_MULAW_8: Final = 1 +AUDIO_FILE_ENCODING_LINEAR_8: Final = 2 +AUDIO_FILE_ENCODING_LINEAR_16: Final = 3 +AUDIO_FILE_ENCODING_LINEAR_24: Final = 4 +AUDIO_FILE_ENCODING_LINEAR_32: Final = 5 +AUDIO_FILE_ENCODING_FLOAT: Final = 6 +AUDIO_FILE_ENCODING_DOUBLE: Final = 7 +AUDIO_FILE_ENCODING_ADPCM_G721: Final = 23 +AUDIO_FILE_ENCODING_ADPCM_G722: Final = 24 +AUDIO_FILE_ENCODING_ADPCM_G723_3: Final = 25 +AUDIO_FILE_ENCODING_ADPCM_G723_5: Final = 26 +AUDIO_FILE_ENCODING_ALAW_8: Final = 27 +AUDIO_UNKNOWN_SIZE: Final = 0xFFFFFFFF class _sunau_params(NamedTuple): """_sunau_params(nchannels, sampwidth, framerate, nframes, comptype, compname)""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/symbol.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/symbol.pyi index 1baab2b67419b..3eb6e5d171a89 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/symbol.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/symbol.pyi @@ -1,95 +1,97 @@ """Non-terminal symbols of Python grammar (from "graminit.h").""" -single_input: int -file_input: int -eval_input: int -decorator: int -decorators: int -decorated: int -async_funcdef: int -funcdef: int -parameters: int -typedargslist: int -tfpdef: int -varargslist: int -vfpdef: int -stmt: int -simple_stmt: int -small_stmt: int -expr_stmt: int -annassign: int -testlist_star_expr: int -augassign: int -del_stmt: int -pass_stmt: int -flow_stmt: int -break_stmt: int -continue_stmt: int -return_stmt: int -yield_stmt: int -raise_stmt: int -import_stmt: int -import_name: int -import_from: int -import_as_name: int -dotted_as_name: int -import_as_names: int -dotted_as_names: int -dotted_name: int -global_stmt: int -nonlocal_stmt: int -assert_stmt: int -compound_stmt: int -async_stmt: int -if_stmt: int -while_stmt: int -for_stmt: int -try_stmt: int -with_stmt: int -with_item: int -except_clause: int -suite: int -test: int -test_nocond: int -lambdef: int -lambdef_nocond: int -or_test: int -and_test: int -not_test: int -comparison: int -comp_op: int -star_expr: int -expr: int -xor_expr: int -and_expr: int -shift_expr: int -arith_expr: int -term: int -factor: int -power: int -atom_expr: int -atom: int -testlist_comp: int -trailer: int -subscriptlist: int -subscript: int -sliceop: int -exprlist: int -testlist: int -dictorsetmaker: int -classdef: int -arglist: int -argument: int -comp_iter: int -comp_for: int -comp_if: int -encoding_decl: int -yield_expr: int -yield_arg: int -sync_comp_for: int -func_body_suite: int -func_type: int -func_type_input: int -namedexpr_test: int -typelist: int -sym_name: dict[int, str] +from typing import Final + +single_input: Final[int] +file_input: Final[int] +eval_input: Final[int] +decorator: Final[int] +decorators: Final[int] +decorated: Final[int] +async_funcdef: Final[int] +funcdef: Final[int] +parameters: Final[int] +typedargslist: Final[int] +tfpdef: Final[int] +varargslist: Final[int] +vfpdef: Final[int] +stmt: Final[int] +simple_stmt: Final[int] +small_stmt: Final[int] +expr_stmt: Final[int] +annassign: Final[int] +testlist_star_expr: Final[int] +augassign: Final[int] +del_stmt: Final[int] +pass_stmt: Final[int] +flow_stmt: Final[int] +break_stmt: Final[int] +continue_stmt: Final[int] +return_stmt: Final[int] +yield_stmt: Final[int] +raise_stmt: Final[int] +import_stmt: Final[int] +import_name: Final[int] +import_from: Final[int] +import_as_name: Final[int] +dotted_as_name: Final[int] +import_as_names: Final[int] +dotted_as_names: Final[int] +dotted_name: Final[int] +global_stmt: Final[int] +nonlocal_stmt: Final[int] +assert_stmt: Final[int] +compound_stmt: Final[int] +async_stmt: Final[int] +if_stmt: Final[int] +while_stmt: Final[int] +for_stmt: Final[int] +try_stmt: Final[int] +with_stmt: Final[int] +with_item: Final[int] +except_clause: Final[int] +suite: Final[int] +test: Final[int] +test_nocond: Final[int] +lambdef: Final[int] +lambdef_nocond: Final[int] +or_test: Final[int] +and_test: Final[int] +not_test: Final[int] +comparison: Final[int] +comp_op: Final[int] +star_expr: Final[int] +expr: Final[int] +xor_expr: Final[int] +and_expr: Final[int] +shift_expr: Final[int] +arith_expr: Final[int] +term: Final[int] +factor: Final[int] +power: Final[int] +atom_expr: Final[int] +atom: Final[int] +testlist_comp: Final[int] +trailer: Final[int] +subscriptlist: Final[int] +subscript: Final[int] +sliceop: Final[int] +exprlist: Final[int] +testlist: Final[int] +dictorsetmaker: Final[int] +classdef: Final[int] +arglist: Final[int] +argument: Final[int] +comp_iter: Final[int] +comp_for: Final[int] +comp_if: Final[int] +encoding_decl: Final[int] +yield_expr: Final[int] +yield_arg: Final[int] +sync_comp_for: Final[int] +func_body_suite: Final[int] +func_type: Final[int] +func_type_input: Final[int] +namedexpr_test: Final[int] +typelist: Final[int] +sym_name: Final[dict[int, str]] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/symtable.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/symtable.pyi index 413dee3477da4..14d5f762b5e2a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/symtable.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/symtable.pyi @@ -110,9 +110,13 @@ class Function(SymbolTable): """Return a tuple of nonlocals in the function.""" class Class(SymbolTable): - @deprecated("deprecated in Python 3.14, will be removed in Python 3.16") - def get_methods(self) -> tuple[str, ...]: - """Return a tuple of methods declared in the class.""" + if sys.version_info >= (3, 14): + @deprecated("Deprecated since Python 3.14; will be removed in Python 3.16.") + def get_methods(self) -> tuple[str, ...]: + """Return a tuple of methods declared in the class.""" + else: + def get_methods(self) -> tuple[str, ...]: + """Return a tuple of methods declared in the class.""" class Symbol: def __init__( diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi index 6f8783c351dd7..21514c7609d2d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sys/__init__.pyi @@ -552,7 +552,7 @@ def call_tracing(func: Callable[..., _T], args: Any, /) -> _T: """ if sys.version_info >= (3, 13): - @deprecated("Deprecated in Python 3.13; use _clear_internal_caches() instead.") + @deprecated("Deprecated since Python 3.13. Use `_clear_internal_caches()` instead.") def _clear_type_cache() -> None: """Clear the internal type lookup cache.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sys/_monitoring.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sys/_monitoring.pyi index 3a8292ea0df4e..5d231c7a93b39 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sys/_monitoring.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sys/_monitoring.pyi @@ -11,10 +11,10 @@ from types import CodeType from typing import Any, Final, type_check_only from typing_extensions import deprecated -DEBUGGER_ID: Final[int] -COVERAGE_ID: Final[int] -PROFILER_ID: Final[int] -OPTIMIZER_ID: Final[int] +DEBUGGER_ID: Final = 0 +COVERAGE_ID: Final = 1 +PROFILER_ID: Final = 2 +OPTIMIZER_ID: Final = 5 def use_tool_id(tool_id: int, name: str, /) -> None: ... def free_tool_id(tool_id: int, /) -> None: ... @@ -46,7 +46,7 @@ class _events: BRANCH_TAKEN: Final[int] @property - @deprecated("BRANCH is deprecated; use BRANCH_LEFT or BRANCH_TAKEN instead") + @deprecated("Deprecated since Python 3.14. Use `BRANCH_LEFT` or `BRANCH_TAKEN` instead.") def BRANCH(self) -> int: ... else: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi index 1faae7bb4d6bf..b73e3966da692 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi @@ -840,7 +840,7 @@ class TarFile: members: Iterable[TarInfo] | None = None, *, numeric_owner: bool = False, - filter: _TarfileFilter | None = ..., + filter: _TarfileFilter | None = None, ) -> None: """Extract all members from the archive to the current working directory and set owner, modification time and permissions on @@ -862,7 +862,7 @@ class TarFile: set_attrs: bool = True, *, numeric_owner: bool = False, - filter: _TarfileFilter | None = ..., + filter: _TarfileFilter | None = None, ) -> None: """Extract a member from the archive to the current working directory, using its full name. Its file information is extracted as accurately @@ -1077,10 +1077,10 @@ class TarInfo: """ if sys.version_info >= (3, 13): @property - @deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.16") + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.16.") def tarfile(self) -> TarFile | None: ... @tarfile.setter - @deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.16") + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.16.") def tarfile(self, tarfile: TarFile | None) -> None: ... else: tarfile: TarFile | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/telnetlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/telnetlib.pyi index 02a97056dfbfa..24255fbb39cec 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/telnetlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/telnetlib.pyi @@ -35,89 +35,89 @@ import socket from collections.abc import Callable, MutableSequence, Sequence from re import Match, Pattern from types import TracebackType -from typing import Any +from typing import Any, Final from typing_extensions import Self __all__ = ["Telnet"] -DEBUGLEVEL: int -TELNET_PORT: int - -IAC: bytes -DONT: bytes -DO: bytes -WONT: bytes -WILL: bytes -theNULL: bytes - -SE: bytes -NOP: bytes -DM: bytes -BRK: bytes -IP: bytes -AO: bytes -AYT: bytes -EC: bytes -EL: bytes -GA: bytes -SB: bytes - -BINARY: bytes -ECHO: bytes -RCP: bytes -SGA: bytes -NAMS: bytes -STATUS: bytes -TM: bytes -RCTE: bytes -NAOL: bytes -NAOP: bytes -NAOCRD: bytes -NAOHTS: bytes -NAOHTD: bytes -NAOFFD: bytes -NAOVTS: bytes -NAOVTD: bytes -NAOLFD: bytes -XASCII: bytes -LOGOUT: bytes -BM: bytes -DET: bytes -SUPDUP: bytes -SUPDUPOUTPUT: bytes -SNDLOC: bytes -TTYPE: bytes -EOR: bytes -TUID: bytes -OUTMRK: bytes -TTYLOC: bytes -VT3270REGIME: bytes -X3PAD: bytes -NAWS: bytes -TSPEED: bytes -LFLOW: bytes -LINEMODE: bytes -XDISPLOC: bytes -OLD_ENVIRON: bytes -AUTHENTICATION: bytes -ENCRYPT: bytes -NEW_ENVIRON: bytes - -TN3270E: bytes -XAUTH: bytes -CHARSET: bytes -RSP: bytes -COM_PORT_OPTION: bytes -SUPPRESS_LOCAL_ECHO: bytes -TLS: bytes -KERMIT: bytes -SEND_URL: bytes -FORWARD_X: bytes -PRAGMA_LOGON: bytes -SSPI_LOGON: bytes -PRAGMA_HEARTBEAT: bytes -EXOPL: bytes -NOOPT: bytes +DEBUGLEVEL: Final = 0 +TELNET_PORT: Final = 23 + +IAC: Final = b"\xff" +DONT: Final = b"\xfe" +DO: Final = b"\xfd" +WONT: Final = b"\xfc" +WILL: Final = b"\xfb" +theNULL: Final = b"\x00" + +SE: Final = b"\xf0" +NOP: Final = b"\xf1" +DM: Final = b"\xf2" +BRK: Final = b"\xf3" +IP: Final = b"\xf4" +AO: Final = b"\xf5" +AYT: Final = b"\xf6" +EC: Final = b"\xf7" +EL: Final = b"\xf8" +GA: Final = b"\xf9" +SB: Final = b"\xfa" + +BINARY: Final = b"\x00" +ECHO: Final = b"\x01" +RCP: Final = b"\x02" +SGA: Final = b"\x03" +NAMS: Final = b"\x04" +STATUS: Final = b"\x05" +TM: Final = b"\x06" +RCTE: Final = b"\x07" +NAOL: Final = b"\x08" +NAOP: Final = b"\t" +NAOCRD: Final = b"\n" +NAOHTS: Final = b"\x0b" +NAOHTD: Final = b"\x0c" +NAOFFD: Final = b"\r" +NAOVTS: Final = b"\x0e" +NAOVTD: Final = b"\x0f" +NAOLFD: Final = b"\x10" +XASCII: Final = b"\x11" +LOGOUT: Final = b"\x12" +BM: Final = b"\x13" +DET: Final = b"\x14" +SUPDUP: Final = b"\x15" +SUPDUPOUTPUT: Final = b"\x16" +SNDLOC: Final = b"\x17" +TTYPE: Final = b"\x18" +EOR: Final = b"\x19" +TUID: Final = b"\x1a" +OUTMRK: Final = b"\x1b" +TTYLOC: Final = b"\x1c" +VT3270REGIME: Final = b"\x1d" +X3PAD: Final = b"\x1e" +NAWS: Final = b"\x1f" +TSPEED: Final = b" " +LFLOW: Final = b"!" +LINEMODE: Final = b'"' +XDISPLOC: Final = b"#" +OLD_ENVIRON: Final = b"$" +AUTHENTICATION: Final = b"%" +ENCRYPT: Final = b"&" +NEW_ENVIRON: Final = b"'" + +TN3270E: Final = b"(" +XAUTH: Final = b")" +CHARSET: Final = b"*" +RSP: Final = b"+" +COM_PORT_OPTION: Final = b"," +SUPPRESS_LOCAL_ECHO: Final = b"-" +TLS: Final = b"." +KERMIT: Final = b"/" +SEND_URL: Final = b"0" +FORWARD_X: Final = b"1" +PRAGMA_LOGON: Final = b"\x8a" +SSPI_LOGON: Final = b"\x8b" +PRAGMA_HEARTBEAT: Final = b"\x8c" +EXOPL: Final = b"\xff" +NOOPT: Final = b"\x00" class Telnet: """Telnet interface class. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tempfile.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tempfile.pyi index a3b369f602efc..7b0af097ed1d6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tempfile.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tempfile.pyi @@ -39,7 +39,7 @@ from _typeshed import ( ) from collections.abc import Iterable, Iterator from types import GenericAlias, TracebackType -from typing import IO, Any, AnyStr, Generic, Literal, overload +from typing import IO, Any, AnyStr, Final, Generic, Literal, overload from typing_extensions import Self, deprecated __all__ = [ @@ -59,7 +59,7 @@ __all__ = [ ] # global variables -TMP_MAX: int +TMP_MAX: Final[int] tempdir: str | None template: str diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/threading.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/threading.pyi index 502b8064c7015..95244ee608683 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/threading.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/threading.pyi @@ -7,7 +7,7 @@ from _typeshed import ProfileFunction, TraceFunction from collections.abc import Callable, Iterable, Mapping from contextvars import ContextVar from types import TracebackType -from typing import Any, TypeVar, final +from typing import Any, Final, TypeVar, final from typing_extensions import deprecated _T = TypeVar("_T") @@ -55,7 +55,7 @@ def active_count() -> int: """ -@deprecated("Use active_count() instead") +@deprecated("Deprecated since Python 3.10. Use `active_count()` instead.") def activeCount() -> int: """Return the number of Thread objects currently alive. @@ -71,7 +71,7 @@ def current_thread() -> Thread: """ -@deprecated("Use current_thread() instead") +@deprecated("Deprecated since Python 3.10. Use `current_thread()` instead.") def currentThread() -> Thread: """Return the current Thread object, corresponding to the caller's thread of control. @@ -162,7 +162,7 @@ def stack_size(size: int = 0, /) -> int: the suggested approach in the absence of more specific information). """ -TIMEOUT_MAX: float +TIMEOUT_MAX: Final[float] ThreadError = _thread.error local = _thread._local @@ -325,7 +325,7 @@ class Thread: """ - @deprecated("Get the daemon attribute instead") + @deprecated("Deprecated since Python 3.10. Read the `daemon` attribute instead.") def isDaemon(self) -> bool: """Return whether this thread is a daemon. @@ -333,7 +333,7 @@ class Thread: """ - @deprecated("Set the daemon attribute instead") + @deprecated("Deprecated since Python 3.10. Set the `daemon` attribute instead.") def setDaemon(self, daemonic: bool) -> None: """Set whether this thread is a daemon. @@ -341,7 +341,7 @@ class Thread: """ - @deprecated("Use the name attribute instead") + @deprecated("Deprecated since Python 3.10. Read the `name` attribute instead.") def getName(self) -> str: """Return a string used for identification purposes only. @@ -349,7 +349,7 @@ class Thread: """ - @deprecated("Use the name attribute instead") + @deprecated("Deprecated since Python 3.10. Set the `name` attribute instead.") def setName(self, name: str) -> None: """Set the name string for this thread. @@ -499,7 +499,7 @@ class Condition: """ - @deprecated("Use notify_all() instead") + @deprecated("Deprecated since Python 3.10. Use `notify_all()` instead.") def notifyAll(self) -> None: """Wake up all threads waiting on this condition. @@ -607,7 +607,7 @@ class Event: def is_set(self) -> bool: """Return true if and only if the internal flag is true.""" - @deprecated("Use is_set() instead") + @deprecated("Deprecated since Python 3.10. Use `is_set()` instead.") def isSet(self) -> bool: """Return true if and only if the internal flag is true. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi index 5046965453766..a9e363b9f60a6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/time.pyi @@ -35,28 +35,28 @@ timezone: int tzname: tuple[str, str] if sys.platform == "linux": - CLOCK_BOOTTIME: int + CLOCK_BOOTTIME: Final[int] if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin": - CLOCK_PROF: int # FreeBSD, NetBSD, OpenBSD - CLOCK_UPTIME: int # FreeBSD, OpenBSD + CLOCK_PROF: Final[int] # FreeBSD, NetBSD, OpenBSD + CLOCK_UPTIME: Final[int] # FreeBSD, OpenBSD if sys.platform != "win32": - CLOCK_MONOTONIC: int - CLOCK_MONOTONIC_RAW: int - CLOCK_PROCESS_CPUTIME_ID: int - CLOCK_REALTIME: int - CLOCK_THREAD_CPUTIME_ID: int + CLOCK_MONOTONIC: Final[int] + CLOCK_MONOTONIC_RAW: Final[int] + CLOCK_PROCESS_CPUTIME_ID: Final[int] + CLOCK_REALTIME: Final[int] + CLOCK_THREAD_CPUTIME_ID: Final[int] if sys.platform != "linux" and sys.platform != "darwin": - CLOCK_HIGHRES: int # Solaris only + CLOCK_HIGHRES: Final[int] # Solaris only if sys.platform == "darwin": - CLOCK_UPTIME_RAW: int + CLOCK_UPTIME_RAW: Final[int] if sys.version_info >= (3, 13): - CLOCK_UPTIME_RAW_APPROX: int - CLOCK_MONOTONIC_RAW_APPROX: int + CLOCK_UPTIME_RAW_APPROX: Final[int] + CLOCK_MONOTONIC_RAW_APPROX: Final[int] if sys.platform == "linux": - CLOCK_TAI: int + CLOCK_TAI: Final[int] # Constructor takes an iterable of any type, of length between 9 and 11 elements. # However, it always *behaves* like a tuple of 9 elements, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi index 5625aac9c1253..febd62c5c0920 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi @@ -37,7 +37,7 @@ from collections.abc import Callable, Iterable, Mapping, Sequence from tkinter.constants import * from tkinter.font import _FontDescription from types import GenericAlias, TracebackType -from typing import Any, ClassVar, Generic, Literal, NamedTuple, Protocol, TypedDict, TypeVar, overload, type_check_only +from typing import Any, ClassVar, Final, Generic, Literal, NamedTuple, Protocol, TypedDict, TypeVar, overload, type_check_only from typing_extensions import TypeAlias, TypeVarTuple, Unpack, deprecated if sys.version_info >= (3, 11): @@ -185,11 +185,11 @@ __all__ = [ TclError = _tkinter.TclError wantobjects: int -TkVersion: float -TclVersion: float -READABLE = _tkinter.READABLE -WRITABLE = _tkinter.WRITABLE -EXCEPTION = _tkinter.EXCEPTION +TkVersion: Final[float] +TclVersion: Final[float] +READABLE: Final = _tkinter.READABLE +WRITABLE: Final = _tkinter.WRITABLE +EXCEPTION: Final = _tkinter.EXCEPTION # Quick guide for figuring out which widget class to choose: # - Misc: any widget (don't use BaseWidget because Tk doesn't inherit from BaseWidget) @@ -445,53 +445,96 @@ class Variable: def trace_info(self) -> list[tuple[tuple[Literal["array", "read", "write", "unset"], ...], str]]: """Return all trace callback information.""" + if sys.version_info >= (3, 14): + @deprecated("Deprecated since Python 3.14. Use `trace_add()` instead.") + def trace(self, mode, callback) -> str: + """Define a trace callback for the variable. - @deprecated("use trace_add() instead of trace()") - def trace(self, mode, callback): - """Define a trace callback for the variable. + MODE is one of "r", "w", "u" for read, write, undefine. + CALLBACK must be a function which is called when + the variable is read, written or undefined. - MODE is one of "r", "w", "u" for read, write, undefine. - CALLBACK must be a function which is called when - the variable is read, written or undefined. + Return the name of the callback. - Return the name of the callback. + This deprecated method wraps a deprecated Tcl method removed + in Tcl 9.0. Use trace_add() instead. + """ - This deprecated method wraps a deprecated Tcl method removed - in Tcl 9.0. Use trace_add() instead. - """ + @deprecated("Deprecated since Python 3.14. Use `trace_add()` instead.") + def trace_variable(self, mode, callback) -> str: + """Define a trace callback for the variable. - @deprecated("use trace_add() instead of trace_variable()") - def trace_variable(self, mode, callback): - """Define a trace callback for the variable. + MODE is one of "r", "w", "u" for read, write, undefine. + CALLBACK must be a function which is called when + the variable is read, written or undefined. - MODE is one of "r", "w", "u" for read, write, undefine. - CALLBACK must be a function which is called when - the variable is read, written or undefined. + Return the name of the callback. - Return the name of the callback. + This deprecated method wraps a deprecated Tcl method removed + in Tcl 9.0. Use trace_add() instead. + """ - This deprecated method wraps a deprecated Tcl method removed - in Tcl 9.0. Use trace_add() instead. - """ + @deprecated("Deprecated since Python 3.14. Use `trace_remove()` instead.") + def trace_vdelete(self, mode, cbname) -> None: + """Delete the trace callback for a variable. - @deprecated("use trace_remove() instead of trace_vdelete()") - def trace_vdelete(self, mode, cbname) -> None: - """Delete the trace callback for a variable. + MODE is one of "r", "w", "u" for read, write, undefine. + CBNAME is the name of the callback returned from trace_variable or trace. - MODE is one of "r", "w", "u" for read, write, undefine. - CBNAME is the name of the callback returned from trace_variable or trace. + This deprecated method wraps a deprecated Tcl method removed + in Tcl 9.0. Use trace_remove() instead. + """ - This deprecated method wraps a deprecated Tcl method removed - in Tcl 9.0. Use trace_remove() instead. - """ + @deprecated("Deprecated since Python 3.14. Use `trace_info()` instead.") + def trace_vinfo(self): + """Return all trace callback information. - @deprecated("use trace_info() instead of trace_vinfo()") - def trace_vinfo(self): - """Return all trace callback information. + This deprecated method wraps a deprecated Tcl method removed + in Tcl 9.0. Use trace_info() instead. + """ + else: + def trace(self, mode, callback) -> str: + """Define a trace callback for the variable. - This deprecated method wraps a deprecated Tcl method removed - in Tcl 9.0. Use trace_info() instead. - """ + MODE is one of "r", "w", "u" for read, write, undefine. + CALLBACK must be a function which is called when + the variable is read, written or undefined. + + Return the name of the callback. + + This deprecated method wraps a deprecated Tcl method that will + likely be removed in the future. Use trace_add() instead. + """ + + def trace_variable(self, mode, callback) -> str: + """Define a trace callback for the variable. + + MODE is one of "r", "w", "u" for read, write, undefine. + CALLBACK must be a function which is called when + the variable is read, written or undefined. + + Return the name of the callback. + + This deprecated method wraps a deprecated Tcl method that will + likely be removed in the future. Use trace_add() instead. + """ + + def trace_vdelete(self, mode, cbname) -> None: + """Delete the trace callback for a variable. + + MODE is one of "r", "w", "u" for read, write, undefine. + CBNAME is the name of the callback returned from trace_variable or trace. + + This deprecated method wraps a deprecated Tcl method that will + likely be removed in the future. Use trace_remove() instead. + """ + + def trace_vinfo(self): + """Return all trace callback information. + + This deprecated method wraps a deprecated Tcl method that will + likely be removed in the future. Use trace_info() instead. + """ def __eq__(self, other: object) -> bool: ... def __del__(self) -> None: @@ -581,8 +624,8 @@ class BooleanVar(Variable): def mainloop(n: int = 0) -> None: """Run the main loop of Tcl.""" -getint: Incomplete -getdouble: Incomplete +getint = int +getdouble = float def getboolean(s): """Convert Tcl object to True or False.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/messagebox.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/messagebox.pyi index c92e23f7b021c..424e8903d6d49 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/messagebox.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/messagebox.pyi @@ -32,7 +32,7 @@ def showinfo( *, detail: str = ..., icon: Literal["error", "info", "question", "warning"] = ..., - default: Literal["ok"] = ..., + default: Literal["ok"] = "ok", parent: Misc = ..., ) -> str: """Show an info message""" @@ -43,7 +43,7 @@ def showwarning( *, detail: str = ..., icon: Literal["error", "info", "question", "warning"] = ..., - default: Literal["ok"] = ..., + default: Literal["ok"] = "ok", parent: Misc = ..., ) -> str: """Show a warning message""" @@ -54,7 +54,7 @@ def showerror( *, detail: str = ..., icon: Literal["error", "info", "question", "warning"] = ..., - default: Literal["ok"] = ..., + default: Literal["ok"] = "ok", parent: Misc = ..., ) -> str: """Show an error message""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi index c049515d858b5..f9f7f6984919f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi @@ -25,7 +25,7 @@ from _typeshed import FileDescriptorOrPath from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern from token import * -from typing import Any, NamedTuple, TextIO, type_check_only +from typing import Any, Final, NamedTuple, TextIO, type_check_only from typing_extensions import TypeAlias if sys.version_info < (3, 12): @@ -123,8 +123,8 @@ if sys.version_info >= (3, 13): if sys.version_info >= (3, 14): __all__ += ["TSTRING_START", "TSTRING_MIDDLE", "TSTRING_END"] -cookie_re: Pattern[str] -blank_re: Pattern[bytes] +cookie_re: Final[Pattern[str]] +blank_re: Final[Pattern[bytes]] _Position: TypeAlias = tuple[int, int] @@ -238,46 +238,46 @@ def group(*choices: str) -> str: ... # undocumented def any(*choices: str) -> str: ... # undocumented def maybe(*choices: str) -> str: ... # undocumented -Whitespace: str # undocumented -Comment: str # undocumented -Ignore: str # undocumented -Name: str # undocumented - -Hexnumber: str # undocumented -Binnumber: str # undocumented -Octnumber: str # undocumented -Decnumber: str # undocumented -Intnumber: str # undocumented -Exponent: str # undocumented -Pointfloat: str # undocumented -Expfloat: str # undocumented -Floatnumber: str # undocumented -Imagnumber: str # undocumented -Number: str # undocumented +Whitespace: Final[str] # undocumented +Comment: Final[str] # undocumented +Ignore: Final[str] # undocumented +Name: Final[str] # undocumented + +Hexnumber: Final[str] # undocumented +Binnumber: Final[str] # undocumented +Octnumber: Final[str] # undocumented +Decnumber: Final[str] # undocumented +Intnumber: Final[str] # undocumented +Exponent: Final[str] # undocumented +Pointfloat: Final[str] # undocumented +Expfloat: Final[str] # undocumented +Floatnumber: Final[str] # undocumented +Imagnumber: Final[str] # undocumented +Number: Final[str] # undocumented def _all_string_prefixes() -> set[str]: ... # undocumented -StringPrefix: str # undocumented +StringPrefix: Final[str] # undocumented -Single: str # undocumented -Double: str # undocumented -Single3: str # undocumented -Double3: str # undocumented -Triple: str # undocumented -String: str # undocumented +Single: Final[str] # undocumented +Double: Final[str] # undocumented +Single3: Final[str] # undocumented +Double3: Final[str] # undocumented +Triple: Final[str] # undocumented +String: Final[str] # undocumented -Special: str # undocumented -Funny: str # undocumented +Special: Final[str] # undocumented +Funny: Final[str] # undocumented -PlainToken: str # undocumented -Token: str # undocumented +PlainToken: Final[str] # undocumented +Token: Final[str] # undocumented -ContStr: str # undocumented -PseudoExtras: str # undocumented -PseudoToken: str # undocumented +ContStr: Final[str] # undocumented +PseudoExtras: Final[str] # undocumented +PseudoToken: Final[str] # undocumented -endpats: dict[str, str] # undocumented -single_quoted: set[str] # undocumented -triple_quoted: set[str] # undocumented +endpats: Final[dict[str, str]] # undocumented +single_quoted: Final[set[str]] # undocumented +triple_quoted: Final[set[str]] # undocumented -tabsize: int # undocumented +tabsize: Final = 8 # undocumented diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tomllib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tomllib.pyi index c9024b51e86e4..81a39b0ded553 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tomllib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tomllib.pyi @@ -26,7 +26,7 @@ if sys.version_info >= (3, 14): @overload def __init__(self, msg: str, doc: str, pos: int) -> None: ... @overload - @deprecated("Deprecated in Python 3.14; Please set 'msg', 'doc' and 'pos' arguments only.") + @deprecated("Deprecated since Python 3.14. Set the 'msg', 'doc' and 'pos' arguments only.") def __init__(self, msg: str | type = ..., doc: str | type = ..., pos: int | type = ..., *args: Any) -> None: ... else: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/traceback.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/traceback.pyi index 2ae3020325bf0..4aa3b7a49284c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/traceback.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/traceback.pyi @@ -333,7 +333,7 @@ class TracebackException: @property def exc_type_str(self) -> str: ... @property - @deprecated("Deprecated in 3.13. Use exc_type_str instead.") + @deprecated("Deprecated since Python 3.13. Use `exc_type_str` instead.") def exc_type(self) -> type[BaseException] | None: ... else: exc_type: type[BaseException] @@ -505,6 +505,23 @@ class FrameSummary: mapping the name to the repr() of the variable. """ + if sys.version_info >= (3, 13): + __slots__ = ( + "filename", + "lineno", + "end_lineno", + "colno", + "end_colno", + "name", + "_lines", + "_lines_dedented", + "locals", + "_code", + ) + elif sys.version_info >= (3, 11): + __slots__ = ("filename", "lineno", "end_lineno", "colno", "end_colno", "name", "_line", "locals") + else: + __slots__ = ("filename", "lineno", "name", "_line", "locals") if sys.version_info >= (3, 11): def __init__( self, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tracemalloc.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tracemalloc.pyi index dd47525911546..5a5bb840853c4 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tracemalloc.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tracemalloc.pyi @@ -47,6 +47,7 @@ class Statistic: Statistic difference on memory allocations between two Snapshot instance. """ + __slots__ = ("traceback", "size", "count") count: int size: int traceback: Traceback @@ -60,6 +61,7 @@ class StatisticDiff: Snapshot instance. """ + __slots__ = ("traceback", "size", "size_diff", "count", "count_diff") count: int count_diff: int size: int @@ -76,6 +78,7 @@ class Frame: Frame of a traceback. """ + __slots__ = ("_frame",) @property def filename(self) -> str: ... @property @@ -110,6 +113,7 @@ class Trace: Trace of a memory block. """ + __slots__ = ("_trace",) @property def domain(self) -> int: ... @property @@ -126,6 +130,7 @@ class Traceback(Sequence[Frame]): to the most recent frame. """ + __slots__ = ("_frames", "_total_nframe") @property def total_nframe(self) -> int | None: ... def __init__(self, frames: Sequence[_FrameTuple], total_nframe: int | None = None) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi index d946703ee0df8..06f11b8b71f32 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi @@ -177,7 +177,7 @@ class CodeType: def co_firstlineno(self) -> int: ... if sys.version_info >= (3, 10): @property - @deprecated("Will be removed in Python 3.15. Use the co_lines() method instead.") + @deprecated("Deprecated since Python 3.10; will be removed in Python 3.15. Use `CodeType.co_lines()` instead.") def co_lnotab(self) -> bytes: ... else: @property diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi index 90743a7cc371f..4167d2a2a305d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi @@ -25,7 +25,7 @@ import collections # noqa: F401 # pyright: ignore[reportUnusedImport] import sys import typing_extensions from _collections_abc import dict_items, dict_keys, dict_values -from _typeshed import IdentityFunction, ReadableBuffer, SupportsKeysAndGetItem +from _typeshed import IdentityFunction, ReadableBuffer, SupportsGetItem, SupportsGetItemViewable, SupportsKeysAndGetItem, Viewable from abc import ABCMeta, abstractmethod from re import Match as Match, Pattern as Pattern from types import ( @@ -180,6 +180,8 @@ class Any: class _Final: """Mixin to prohibit subclassing.""" + __slots__ = ("__weakref__",) + def final(f: _T) -> _T: """Decorator to indicate final methods and final classes. @@ -335,13 +337,13 @@ _promote = object() # N.B. Keep this definition in sync with typing_extensions._SpecialForm @final class _SpecialForm(_Final): + __slots__ = ("_name", "__doc__", "_getitem") def __getitem__(self, parameters: Any) -> object: ... if sys.version_info >= (3, 10): def __or__(self, other: Any) -> _SpecialForm: ... def __ror__(self, other: Any) -> _SpecialForm: ... Union: _SpecialForm -Generic: _SpecialForm Protocol: _SpecialForm Callable: _SpecialForm Type: _SpecialForm @@ -759,6 +761,20 @@ Annotated: _SpecialForm # Predefined type variables. AnyStr = TypeVar("AnyStr", str, bytes) # noqa: Y001 +@type_check_only +class _Generic: + if sys.version_info < (3, 12): + __slots__ = () + + if sys.version_info >= (3, 10): + @classmethod + def __class_getitem__(cls, args: TypeVar | ParamSpec | tuple[TypeVar | ParamSpec, ...]) -> _Final: ... + else: + @classmethod + def __class_getitem__(cls, args: TypeVar | tuple[TypeVar, ...]) -> _Final: ... + +Generic: type[_Generic] + class _ProtocolMeta(ABCMeta): if sys.version_info >= (3, 12): def __init__(cls, *args: Any, **kwargs: Any) -> None: ... @@ -789,6 +805,7 @@ def runtime_checkable(cls: _TC) -> _TC: class SupportsInt(Protocol, metaclass=ABCMeta): """An ABC with one abstract method __int__.""" + __slots__ = () @abstractmethod def __int__(self) -> int: ... @@ -796,6 +813,7 @@ class SupportsInt(Protocol, metaclass=ABCMeta): class SupportsFloat(Protocol, metaclass=ABCMeta): """An ABC with one abstract method __float__.""" + __slots__ = () @abstractmethod def __float__(self) -> float: ... @@ -803,6 +821,7 @@ class SupportsFloat(Protocol, metaclass=ABCMeta): class SupportsComplex(Protocol, metaclass=ABCMeta): """An ABC with one abstract method __complex__.""" + __slots__ = () @abstractmethod def __complex__(self) -> complex: ... @@ -810,6 +829,7 @@ class SupportsComplex(Protocol, metaclass=ABCMeta): class SupportsBytes(Protocol, metaclass=ABCMeta): """An ABC with one abstract method __bytes__.""" + __slots__ = () @abstractmethod def __bytes__(self) -> bytes: ... @@ -817,6 +837,7 @@ class SupportsBytes(Protocol, metaclass=ABCMeta): class SupportsIndex(Protocol, metaclass=ABCMeta): """An ABC with one abstract method __index__.""" + __slots__ = () @abstractmethod def __index__(self) -> int: ... @@ -824,6 +845,7 @@ class SupportsIndex(Protocol, metaclass=ABCMeta): class SupportsAbs(Protocol[_T_co]): """An ABC with one abstract method __abs__ that is covariant in its return type.""" + __slots__ = () @abstractmethod def __abs__(self) -> _T_co: ... @@ -831,6 +853,7 @@ class SupportsAbs(Protocol[_T_co]): class SupportsRound(Protocol[_T_co]): """An ABC with one abstract method __round__ that is covariant in its return type.""" + __slots__ = () @overload @abstractmethod def __round__(self) -> int: ... @@ -1181,14 +1204,14 @@ class MutableSet(AbstractSet[_T]): def __isub__(self, it: AbstractSet[Any]) -> typing_extensions.Self: ... class MappingView(Sized): - def __init__(self, mapping: Mapping[Any, Any]) -> None: ... # undocumented + def __init__(self, mapping: Sized) -> None: ... # undocumented def __len__(self) -> int: ... class ItemsView(MappingView, AbstractSet[tuple[_KT_co, _VT_co]], Generic[_KT_co, _VT_co]): - def __init__(self, mapping: Mapping[_KT_co, _VT_co]) -> None: ... # undocumented + def __init__(self, mapping: SupportsGetItemViewable[_KT_co, _VT_co]) -> None: ... # undocumented def __and__(self, other: Iterable[Any]) -> set[tuple[_KT_co, _VT_co]]: ... def __rand__(self, other: Iterable[_T]) -> set[_T]: ... - def __contains__(self, item: object) -> bool: ... + def __contains__(self, item: tuple[object, object]) -> bool: ... # type: ignore[override] def __iter__(self) -> Iterator[tuple[_KT_co, _VT_co]]: ... def __or__(self, other: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ... def __ror__(self, other: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ... @@ -1198,7 +1221,7 @@ class ItemsView(MappingView, AbstractSet[tuple[_KT_co, _VT_co]], Generic[_KT_co, def __rxor__(self, other: Iterable[_T]) -> set[tuple[_KT_co, _VT_co] | _T]: ... class KeysView(MappingView, AbstractSet[_KT_co]): - def __init__(self, mapping: Mapping[_KT_co, Any]) -> None: ... # undocumented + def __init__(self, mapping: Viewable[_KT_co]) -> None: ... # undocumented def __and__(self, other: Iterable[Any]) -> set[_KT_co]: ... def __rand__(self, other: Iterable[_T]) -> set[_T]: ... def __contains__(self, key: object) -> bool: ... @@ -1211,7 +1234,7 @@ class KeysView(MappingView, AbstractSet[_KT_co]): def __rxor__(self, other: Iterable[_T]) -> set[_KT_co | _T]: ... class ValuesView(MappingView, Collection[_VT_co]): - def __init__(self, mapping: Mapping[Any, _VT_co]) -> None: ... # undocumented + def __init__(self, mapping: SupportsGetItemViewable[Any, _VT_co]) -> None: ... # undocumented def __contains__(self, value: object) -> bool: ... def __iter__(self) -> Iterator[_VT_co]: ... @@ -1319,13 +1342,13 @@ class MutableMapping(Mapping[_KT, _VT]): """ @overload - def update(self: Mapping[str, _VT], m: SupportsKeysAndGetItem[str, _VT], /, **kwargs: _VT) -> None: ... + def update(self: SupportsGetItem[str, _VT], m: SupportsKeysAndGetItem[str, _VT], /, **kwargs: _VT) -> None: ... @overload def update(self, m: Iterable[tuple[_KT, _VT]], /) -> None: ... @overload - def update(self: Mapping[str, _VT], m: Iterable[tuple[str, _VT]], /, **kwargs: _VT) -> None: ... + def update(self: SupportsGetItem[str, _VT], m: Iterable[tuple[str, _VT]], /, **kwargs: _VT) -> None: ... @overload - def update(self: Mapping[str, _VT], **kwargs: _VT) -> None: ... + def update(self: SupportsGetItem[str, _VT], **kwargs: _VT) -> None: ... Text = str @@ -1350,6 +1373,7 @@ class IO(Generic[AnyStr]): # At runtime these are all abstract properties, # but making them abstract in the stub is hugely disruptive, for not much gain. # See #8726 + __slots__ = () @property def mode(self) -> str: ... # Usually str, but may be bytes if a bytes path was passed to open(). See #10737. @@ -1410,6 +1434,7 @@ class IO(Generic[AnyStr]): class BinaryIO(IO[bytes]): """Typed version of the return of open() in binary mode.""" + __slots__ = () @abstractmethod def __enter__(self) -> BinaryIO: ... @@ -1417,6 +1442,7 @@ class TextIO(IO[str]): """Typed version of the return of open() in text mode.""" # See comment regarding the @properties in the `IO` class + __slots__ = () @property def buffer(self) -> BinaryIO: ... @property @@ -1854,6 +1880,15 @@ else: class ForwardRef(_Final): """Internal wrapper to hold a forward reference.""" + __slots__ = ( + "__forward_arg__", + "__forward_code__", + "__forward_evaluated__", + "__forward_value__", + "__forward_is_argument__", + "__forward_is_class__", + "__forward_module__", + ) __forward_arg__: str __forward_code__: CodeType __forward_evaluated__: bool diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi index 49a80fcd14b3c..fe1d83951aced 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi @@ -120,6 +120,7 @@ __all__ = [ "clear_overloads", "dataclass_transform", "deprecated", + "disjoint_base", "Doc", "evaluate_forward_ref", "get_overloads", @@ -150,6 +151,7 @@ __all__ = [ "TypeGuard", "TypeIs", "TYPE_CHECKING", + "type_repr", "Never", "NoReturn", "ReadOnly", @@ -263,6 +265,8 @@ def final(f: _F) -> _F: object to allow runtime introspection. """ +def disjoint_base(cls: _TC) -> _TC: ... + Literal: _SpecialForm def IntVar(name: str) -> Any: ... # returns a new TypeVar @@ -837,6 +841,7 @@ else: This protocol only supports blocking I/O. """ + __slots__ = () @abc.abstractmethod def read(self, size: int = ..., /) -> _T_co: """Read data from the input stream and return it. @@ -852,6 +857,7 @@ else: This protocol only supports blocking I/O. """ + __slots__ = () @abc.abstractmethod def write(self, data: _T_contra, /) -> int: """Write *data* to the output stream and return the number of items written.""" @@ -1163,7 +1169,7 @@ TypeForm: _SpecialForm if sys.version_info >= (3, 14): from typing import evaluate_forward_ref as evaluate_forward_ref - from annotationlib import Format as Format, get_annotations as get_annotations + from annotationlib import Format as Format, get_annotations as get_annotations, type_repr as type_repr else: class Format(enum.IntEnum): """An enumeration.""" @@ -1292,6 +1298,7 @@ else: format: Format | None = None, _recursive_guard: Container[str] = ..., ) -> AnnotationForm: ... + def type_repr(value: object) -> str: ... # PEP 661 class Sentinel: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unicodedata.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unicodedata.pyi index d0c1559e922c4..f0ef68d8478f8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unicodedata.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unicodedata.pyi @@ -9,11 +9,11 @@ UnicodeData File Format 16.0.0. import sys from _typeshed import ReadOnlyBuffer -from typing import Any, Literal, TypeVar, final, overload +from typing import Any, Final, Literal, TypeVar, final, overload from typing_extensions import TypeAlias ucd_3_2_0: UCD -unidata_version: str +unidata_version: Final[str] if sys.version_info < (3, 10): ucnhash_CAPI: Any diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/loader.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/loader.pyi index 5c01b4981d129..9473618bb255f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/loader.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/loader.pyi @@ -86,21 +86,38 @@ class TestLoader: defaultTestLoader: TestLoader if sys.version_info < (3, 13): - @deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13") - def getTestCaseNames( - testCaseClass: type[unittest.case.TestCase], - prefix: str, - sortUsing: _SortComparisonMethod = ..., - testNamePatterns: list[str] | None = None, - ) -> Sequence[str]: ... - @deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13") - def makeSuite( - testCaseClass: type[unittest.case.TestCase], - prefix: str = "test", - sortUsing: _SortComparisonMethod = ..., - suiteClass: _SuiteClass = ..., - ) -> unittest.suite.TestSuite: ... - @deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13") - def findTestCases( - module: ModuleType, prefix: str = "test", sortUsing: _SortComparisonMethod = ..., suiteClass: _SuiteClass = ... - ) -> unittest.suite.TestSuite: ... + if sys.version_info >= (3, 11): + @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + def getTestCaseNames( + testCaseClass: type[unittest.case.TestCase], + prefix: str, + sortUsing: _SortComparisonMethod = ..., + testNamePatterns: list[str] | None = None, + ) -> Sequence[str]: ... + @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + def makeSuite( + testCaseClass: type[unittest.case.TestCase], + prefix: str = "test", + sortUsing: _SortComparisonMethod = ..., + suiteClass: _SuiteClass = ..., + ) -> unittest.suite.TestSuite: ... + @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + def findTestCases( + module: ModuleType, prefix: str = "test", sortUsing: _SortComparisonMethod = ..., suiteClass: _SuiteClass = ... + ) -> unittest.suite.TestSuite: ... + else: + def getTestCaseNames( + testCaseClass: type[unittest.case.TestCase], + prefix: str, + sortUsing: _SortComparisonMethod = ..., + testNamePatterns: list[str] | None = None, + ) -> Sequence[str]: ... + def makeSuite( + testCaseClass: type[unittest.case.TestCase], + prefix: str = "test", + sortUsing: _SortComparisonMethod = ..., + suiteClass: _SuiteClass = ..., + ) -> unittest.suite.TestSuite: ... + def findTestCases( + module: ModuleType, prefix: str = "test", sortUsing: _SortComparisonMethod = ..., suiteClass: _SuiteClass = ... + ) -> unittest.suite.TestSuite: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi index 924967d7f294d..a4e8e9cb02bdf 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/main.pyi @@ -70,8 +70,11 @@ class TestProgram: ) -> None: ... if sys.version_info < (3, 13): - @deprecated("Deprecated in Python 3.11; removal scheduled for Python 3.13") - def usageExit(self, msg: Any = None) -> None: ... + if sys.version_info >= (3, 11): + @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + def usageExit(self, msg: Any = None) -> None: ... + else: + def usageExit(self, msg: Any = None) -> None: ... def parseArgs(self, argv: list[str]) -> None: ... def createTests(self, from_discovery: bool = False, Loader: unittest.loader.TestLoader | None = None) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi index ba2ba19d86427..50e722e206ee7 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi @@ -52,7 +52,7 @@ else: "seal", ) -FILTER_DIR: Any +FILTER_DIR: bool # controls the way mock objects respond to `dir` function class _SentinelObject: """A unique, named, sentinel object.""" @@ -65,7 +65,7 @@ class _Sentinel: def __getattr__(self, name: str) -> Any: ... -sentinel: Any +sentinel: _Sentinel DEFAULT: Any _ArgsKwargs: TypeAlias = tuple[tuple[Any, ...], Mapping[str, Any]] @@ -555,7 +555,7 @@ class _patcher: create: bool = ..., spec_set: Any | None = ..., autospec: Any | None = ..., - new_callable: None = ..., + new_callable: None = None, **kwargs: Any, ) -> _patch_pass_arg[MagicMock | AsyncMock]: ... @overload @@ -594,7 +594,7 @@ class _patcher: create: bool = ..., spec_set: Any | None = ..., autospec: Any | None = ..., - new_callable: None = ..., + new_callable: None = None, **kwargs: Any, ) -> _patch_pass_arg[MagicMock | AsyncMock]: ... @staticmethod @@ -752,7 +752,7 @@ class _ANY: def __ne__(self, other: object) -> Literal[False]: ... __hash__: ClassVar[None] # type: ignore[assignment] -ANY: Any +ANY: _ANY if sys.version_info >= (3, 10): def create_autospec( diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/util.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/util.pyi index d0e0dfbacd4d5..0bed55dbccf72 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/util.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/util.pyi @@ -7,12 +7,12 @@ from typing_extensions import TypeAlias _T = TypeVar("_T") _Mismatch: TypeAlias = tuple[_T, _T, int] -_MAX_LENGTH: Final[int] -_PLACEHOLDER_LEN: Final[int] -_MIN_BEGIN_LEN: Final[int] -_MIN_END_LEN: Final[int] -_MIN_COMMON_LEN: Final[int] -_MIN_DIFF_LEN: Final[int] +_MAX_LENGTH: Final = 80 +_PLACEHOLDER_LEN: Final = 12 +_MIN_BEGIN_LEN: Final = 5 +_MIN_END_LEN: Final = 5 +_MIN_COMMON_LEN: Final = 5 +_MIN_DIFF_LEN: Final = 41 def _shorten(s: str, prefixlen: int, suffixlen: int) -> str: ... def _common_shorten_repr(*args: str) -> tuple[str, ...]: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/urllib/parse.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/urllib/parse.pyi index c5c2004083f75..10b9bcf0b6ac0 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/urllib/parse.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/urllib/parse.pyi @@ -34,7 +34,7 @@ It serves as a useful guide when making changes. import sys from collections.abc import Iterable, Mapping, Sequence from types import GenericAlias -from typing import Any, AnyStr, Generic, Literal, NamedTuple, Protocol, overload, type_check_only +from typing import Any, AnyStr, Final, Generic, Literal, NamedTuple, Protocol, overload, type_check_only from typing_extensions import TypeAlias __all__ = [ @@ -61,29 +61,32 @@ __all__ = [ "SplitResultBytes", ] -uses_relative: list[str] -uses_netloc: list[str] -uses_params: list[str] -non_hierarchical: list[str] -uses_query: list[str] -uses_fragment: list[str] -scheme_chars: str +uses_relative: Final[list[str]] +uses_netloc: Final[list[str]] +uses_params: Final[list[str]] +non_hierarchical: Final[list[str]] +uses_query: Final[list[str]] +uses_fragment: Final[list[str]] +scheme_chars: Final[str] if sys.version_info < (3, 11): - MAX_CACHE_SIZE: int + MAX_CACHE_SIZE: Final[int] class _ResultMixinStr: """Standard approach to encoding parsed results from str to bytes""" + __slots__ = () def encode(self, encoding: str = "ascii", errors: str = "strict") -> _ResultMixinBytes: ... class _ResultMixinBytes: """Standard approach to decoding parsed results from bytes to str""" + __slots__ = () def decode(self, encoding: str = "ascii", errors: str = "strict") -> _ResultMixinStr: ... class _NetlocResultMixinBase(Generic[AnyStr]): """Shared methods for the parsed result objects containing a netloc element""" + __slots__ = () @property def username(self) -> AnyStr | None: ... @property @@ -98,8 +101,11 @@ class _NetlocResultMixinBase(Generic[AnyStr]): E.g. for t = list[int], t.__origin__ is list and t.__args__ is (int,). """ -class _NetlocResultMixinStr(_NetlocResultMixinBase[str], _ResultMixinStr): ... -class _NetlocResultMixinBytes(_NetlocResultMixinBase[bytes], _ResultMixinBytes): ... +class _NetlocResultMixinStr(_NetlocResultMixinBase[str], _ResultMixinStr): + __slots__ = () + +class _NetlocResultMixinBytes(_NetlocResultMixinBase[bytes], _ResultMixinBytes): + __slots__ = () class _DefragResultBase(NamedTuple, Generic[AnyStr]): """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/uuid.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/uuid.pyi index 4241f5b881e5d..86a27772a7950 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/uuid.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/uuid.pyi @@ -133,6 +133,7 @@ class UUID: uuid_generate_time_safe(3). """ + __slots__ = ("int", "is_safe", "__weakref__") def __init__( self, hex: str | None = None, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/venv/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/venv/__init__.pyi index f5645f3fdc046..aa09f42e017e1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/venv/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/venv/__init__.pyi @@ -9,10 +9,11 @@ import sys from _typeshed import StrOrBytesPath from collections.abc import Iterable, Sequence from types import SimpleNamespace +from typing import Final logger: logging.Logger -CORE_VENV_DEPS: tuple[str, ...] +CORE_VENV_DEPS: Final[tuple[str, ...]] class EnvBuilder: """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/wave.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/wave.pyi index 11d79c127c55e..9819c4fa1907b 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/wave.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/wave.pyi @@ -71,6 +71,7 @@ The close() method is called automatically when the class instance is destroyed. """ +import sys from _typeshed import ReadableBuffer, Unused from typing import IO, Any, BinaryIO, Final, Literal, NamedTuple, NoReturn, overload from typing_extensions import Self, TypeAlias, deprecated @@ -81,7 +82,7 @@ _File: TypeAlias = str | IO[bytes] class Error(Exception): ... -WAVE_FORMAT_PCM: Final = 1 +WAVE_FORMAT_PCM: Final = 0x0001 class _wave_params(NamedTuple): """_wave_params(nchannels, sampwidth, framerate, nframes, comptype, compname)""" @@ -139,10 +140,15 @@ class Wave_read: def getcomptype(self) -> str: ... def getcompname(self) -> str: ... def getparams(self) -> _wave_params: ... - @deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15") - def getmarkers(self) -> None: ... - @deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15") - def getmark(self, id: Any) -> NoReturn: ... + if sys.version_info >= (3, 13): + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + def getmarkers(self) -> None: ... + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + def getmark(self, id: Any) -> NoReturn: ... + else: + def getmarkers(self) -> None: ... + def getmark(self, id: Any) -> NoReturn: ... + def setpos(self, pos: int) -> None: ... def readframes(self, nframes: int) -> bytes: ... @@ -189,12 +195,18 @@ class Wave_write: def getcompname(self) -> str: ... def setparams(self, params: _wave_params | tuple[int, int, int, int, str, str]) -> None: ... def getparams(self) -> _wave_params: ... - @deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15") - def setmark(self, id: Any, pos: Any, name: Any) -> NoReturn: ... - @deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15") - def getmark(self, id: Any) -> NoReturn: ... - @deprecated("Deprecated in Python 3.13; removal scheduled for Python 3.15") - def getmarkers(self) -> None: ... + if sys.version_info >= (3, 13): + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + def setmark(self, id: Any, pos: Any, name: Any) -> NoReturn: ... + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + def getmark(self, id: Any) -> NoReturn: ... + @deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.") + def getmarkers(self) -> None: ... + else: + def setmark(self, id: Any, pos: Any, name: Any) -> NoReturn: ... + def getmark(self, id: Any) -> NoReturn: ... + def getmarkers(self) -> None: ... + def tell(self) -> int: ... def writeframesraw(self, data: ReadableBuffer) -> None: ... def writeframes(self, data: ReadableBuffer) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi index e7487c089fb40..11b2f3f5ccb89 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi @@ -80,6 +80,7 @@ class WeakMethod(ref[_CallableT]): a bound method, working around the lifetime problem of bound methods. """ + __slots__ = ("_func_ref", "_meth_type", "_alive", "__weakref__") def __new__(cls, meth: _CallableT, callback: Callable[[Self], Any] | None = None) -> Self: ... def __call__(self) -> _CallableT | None: ... def __eq__(self, other: object) -> bool: ... @@ -180,6 +181,7 @@ class KeyedRef(ref[_T], Generic[_KT, _T]): """ + __slots__ = ("key",) key: _KT def __new__(type, ob: _T, callback: Callable[[Self], Any], key: _KT) -> Self: ... def __init__(self, ob: _T, callback: Callable[[Self], Any], key: _KT) -> None: ... @@ -267,6 +269,7 @@ class finalize(Generic[_P, _T]): By default atexit is true. """ + __slots__ = () def __init__(self, obj: _T, func: Callable[_P, Any], /, *args: _P.args, **kwargs: _P.kwargs) -> None: ... def __call__(self, _: Any = None) -> Any | None: """If alive then mark as dead and return func(*args, **kwargs); diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/webbrowser.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/webbrowser.pyi index 84e1466005d73..f02ee7477a512 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/webbrowser.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/webbrowser.pyi @@ -116,20 +116,36 @@ if sys.platform == "win32": if sys.platform == "darwin": if sys.version_info < (3, 13): - @deprecated("Deprecated in 3.11, to be removed in 3.13.") - class MacOSX(BaseBrowser): - """Launcher class for Aqua browsers on Mac OS X + if sys.version_info >= (3, 11): + @deprecated("Deprecated since Python 3.11; removed in Python 3.13.") + class MacOSX(BaseBrowser): + """Launcher class for Aqua browsers on Mac OS X - Optionally specify a browser name on instantiation. Note that this - will not work for Aqua browsers if the user has moved the application - package after installation. + Optionally specify a browser name on instantiation. Note that this + will not work for Aqua browsers if the user has moved the application + package after installation. - If no browser is specified, the default browser, as specified in the - Internet System Preferences panel, will be used. - """ + If no browser is specified, the default browser, as specified in the + Internet System Preferences panel, will be used. + """ - def __init__(self, name: str) -> None: ... - def open(self, url: str, new: int = 0, autoraise: bool = True) -> bool: ... + def __init__(self, name: str) -> None: ... + def open(self, url: str, new: int = 0, autoraise: bool = True) -> bool: ... + + else: + class MacOSX(BaseBrowser): + """Launcher class for Aqua browsers on Mac OS X + + Optionally specify a browser name on instantiation. Note that this + will not work for Aqua browsers if the user has moved the application + package after installation. + + If no browser is specified, the default browser, as specified in the + Internet System Preferences panel, will be used. + """ + + def __init__(self, name: str) -> None: ... + def open(self, url: str, new: int = 0, autoraise: bool = True) -> bool: ... class MacOSXOSAScript(BaseBrowser): # In runtime this class does not have `name` and `basename` if sys.version_info >= (3, 11): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi index ca9a49b033e04..ae3009add5e55 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/winreg.pyi @@ -460,13 +460,13 @@ if sys.platform == "win32": Will generally raise NotImplementedError if executed on a 32bit OS. """ - HKEY_CLASSES_ROOT: int - HKEY_CURRENT_USER: int - HKEY_LOCAL_MACHINE: int - HKEY_USERS: int - HKEY_PERFORMANCE_DATA: int - HKEY_CURRENT_CONFIG: int - HKEY_DYN_DATA: int + HKEY_CLASSES_ROOT: Final[int] + HKEY_CURRENT_USER: Final[int] + HKEY_LOCAL_MACHINE: Final[int] + HKEY_USERS: Final[int] + HKEY_PERFORMANCE_DATA: Final[int] + HKEY_CURRENT_CONFIG: Final[int] + HKEY_DYN_DATA: Final[int] KEY_ALL_ACCESS: Final = 983103 KEY_WRITE: Final = 131078 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/headers.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/headers.pyi index 324876c9ab75f..6019972f31b1e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/headers.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/headers.pyi @@ -6,12 +6,12 @@ written by Barry Warsaw. """ from re import Pattern -from typing import overload +from typing import Final, overload from typing_extensions import TypeAlias _HeaderList: TypeAlias = list[tuple[str, str]] -tspecials: Pattern[str] # undocumented +tspecials: Final[Pattern[str]] # undocumented class Headers: """Manage a collection of HTTP response headers""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/simple_server.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/simple_server.pyi index 4dd421534e793..87bdda21f280c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/simple_server.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/wsgiref/simple_server.pyi @@ -12,15 +12,15 @@ module. See also the BaseHTTPServer module docs for other API information. from _typeshed.wsgi import ErrorStream, StartResponse, WSGIApplication, WSGIEnvironment from http.server import BaseHTTPRequestHandler, HTTPServer -from typing import TypeVar, overload +from typing import Final, TypeVar, overload from .handlers import SimpleHandler __all__ = ["WSGIServer", "WSGIRequestHandler", "demo_app", "make_server"] -server_version: str # undocumented -sys_version: str # undocumented -software_version: str # undocumented +server_version: Final[str] # undocumented +sys_version: Final[str] # undocumented +software_version: Final[str] # undocumented class ServerHandler(SimpleHandler): # undocumented server_software: str diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/NodeFilter.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/NodeFilter.pyi index b1c7d2059aa63..47f645764b214 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/NodeFilter.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/NodeFilter.pyi @@ -1,4 +1,4 @@ -from typing import Literal +from typing import Final from xml.dom.minidom import Node class NodeFilter: @@ -6,21 +6,21 @@ class NodeFilter: This is the DOM2 NodeFilter interface. It contains only constants. """ - FILTER_ACCEPT: Literal[1] - FILTER_REJECT: Literal[2] - FILTER_SKIP: Literal[3] + FILTER_ACCEPT: Final = 1 + FILTER_REJECT: Final = 2 + FILTER_SKIP: Final = 3 - SHOW_ALL: int - SHOW_ELEMENT: int - SHOW_ATTRIBUTE: int - SHOW_TEXT: int - SHOW_CDATA_SECTION: int - SHOW_ENTITY_REFERENCE: int - SHOW_ENTITY: int - SHOW_PROCESSING_INSTRUCTION: int - SHOW_COMMENT: int - SHOW_DOCUMENT: int - SHOW_DOCUMENT_TYPE: int - SHOW_DOCUMENT_FRAGMENT: int - SHOW_NOTATION: int + SHOW_ALL: Final = 0xFFFFFFFF + SHOW_ELEMENT: Final = 0x00000001 + SHOW_ATTRIBUTE: Final = 0x00000002 + SHOW_TEXT: Final = 0x00000004 + SHOW_CDATA_SECTION: Final = 0x00000008 + SHOW_ENTITY_REFERENCE: Final = 0x00000010 + SHOW_ENTITY: Final = 0x00000020 + SHOW_PROCESSING_INSTRUCTION: Final = 0x00000040 + SHOW_COMMENT: Final = 0x00000080 + SHOW_DOCUMENT: Final = 0x00000100 + SHOW_DOCUMENT_TYPE: Final = 0x00000200 + SHOW_DOCUMENT_FRAGMENT: Final = 0x00000400 + SHOW_NOTATION: Final = 0x00000800 def acceptNode(self, node: Node) -> int: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/__init__.pyi index b620f0ac0c8a1..2022c8dc422e9 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/__init__.pyi @@ -21,18 +21,19 @@ from .domreg import getDOMImplementation as getDOMImplementation, registerDOMImp class Node: """Class giving the NodeType constants.""" - ELEMENT_NODE: Literal[1] - ATTRIBUTE_NODE: Literal[2] - TEXT_NODE: Literal[3] - CDATA_SECTION_NODE: Literal[4] - ENTITY_REFERENCE_NODE: Literal[5] - ENTITY_NODE: Literal[6] - PROCESSING_INSTRUCTION_NODE: Literal[7] - COMMENT_NODE: Literal[8] - DOCUMENT_NODE: Literal[9] - DOCUMENT_TYPE_NODE: Literal[10] - DOCUMENT_FRAGMENT_NODE: Literal[11] - NOTATION_NODE: Literal[12] + __slots__ = () + ELEMENT_NODE: Final = 1 + ATTRIBUTE_NODE: Final = 2 + TEXT_NODE: Final = 3 + CDATA_SECTION_NODE: Final = 4 + ENTITY_REFERENCE_NODE: Final = 5 + ENTITY_NODE: Final = 6 + PROCESSING_INSTRUCTION_NODE: Final = 7 + COMMENT_NODE: Final = 8 + DOCUMENT_NODE: Final = 9 + DOCUMENT_TYPE_NODE: Final = 10 + DOCUMENT_FRAGMENT_NODE: Final = 11 + NOTATION_NODE: Final = 12 # ExceptionCode INDEX_SIZE_ERR: Final = 1 @@ -112,10 +113,10 @@ class ValidationErr(DOMException): class UserDataHandler: """Class giving the operation constants for UserDataHandler.handle().""" - NODE_CLONED: Literal[1] - NODE_IMPORTED: Literal[2] - NODE_DELETED: Literal[3] - NODE_RENAMED: Literal[4] + NODE_CLONED: Final = 1 + NODE_IMPORTED: Final = 2 + NODE_DELETED: Final = 3 + NODE_RENAMED: Final = 4 XML_NAMESPACE: Final = "http://www.w3.org/XML/1998/namespace" XMLNS_NAMESPACE: Final = "http://www.w3.org/2000/xmlns/" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/expatbuilder.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/expatbuilder.pyi index 658d9830d8fce..e5536237d7187 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/expatbuilder.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/expatbuilder.pyi @@ -5,7 +5,7 @@ This avoids all the overhead of SAX and pulldom to gain performance. """ from _typeshed import ReadableBuffer, SupportsRead -from typing import Any, NoReturn +from typing import Any, Final, NoReturn from typing_extensions import TypeAlias from xml.dom.minidom import Document, DocumentFragment, DOMImplementation, Element, Node, TypeInfo from xml.dom.xmlbuilder import DOMBuilderFilter, Options @@ -13,16 +13,17 @@ from xml.parsers.expat import XMLParserType _Model: TypeAlias = tuple[int, int, str | None, tuple[Any, ...]] # same as in pyexpat -TEXT_NODE = Node.TEXT_NODE -CDATA_SECTION_NODE = Node.CDATA_SECTION_NODE -DOCUMENT_NODE = Node.DOCUMENT_NODE -FILTER_ACCEPT = DOMBuilderFilter.FILTER_ACCEPT -FILTER_REJECT = DOMBuilderFilter.FILTER_REJECT -FILTER_SKIP = DOMBuilderFilter.FILTER_SKIP -FILTER_INTERRUPT = DOMBuilderFilter.FILTER_INTERRUPT +TEXT_NODE: Final = Node.TEXT_NODE +CDATA_SECTION_NODE: Final = Node.CDATA_SECTION_NODE +DOCUMENT_NODE: Final = Node.DOCUMENT_NODE +FILTER_ACCEPT: Final = DOMBuilderFilter.FILTER_ACCEPT +FILTER_REJECT: Final = DOMBuilderFilter.FILTER_REJECT +FILTER_SKIP: Final = DOMBuilderFilter.FILTER_SKIP +FILTER_INTERRUPT: Final = DOMBuilderFilter.FILTER_INTERRUPT theDOMImplementation: DOMImplementation class ElementInfo: + __slots__ = ("_attr_info", "_model", "tagName") tagName: str def __init__(self, tagName: str, model: _Model | None = None) -> None: ... def getAttributeType(self, aname: str) -> TypeInfo: ... @@ -94,19 +95,23 @@ class FilterVisibilityController: to make the whatToShow filter attribute work. """ + __slots__ = ("filter",) filter: DOMBuilderFilter def __init__(self, filter: DOMBuilderFilter) -> None: ... def startContainer(self, node: Node) -> int: ... def acceptNode(self, node: Node) -> int: ... class FilterCrutch: + __slots__ = ("_builder", "_level", "_old_start", "_old_end") def __init__(self, builder: ExpatBuilder) -> None: ... class Rejecter(FilterCrutch): + __slots__ = () def start_element_handler(self, *args: Any) -> None: ... def end_element_handler(self, *args: Any) -> None: ... class Skipper(FilterCrutch): + __slots__ = () def start_element_handler(self, *args: Any) -> None: ... def end_element_handler(self, *args: Any) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minicompat.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minicompat.pyi index 2ca37b881b2bb..a0dffd6cc5434 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minicompat.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minicompat.pyi @@ -14,6 +14,7 @@ _T = TypeVar("_T") StringTypes: tuple[type[str]] class NodeList(list[_T]): + __slots__ = () @property def length(self) -> int: """The number of nodes in the NodeList.""" @@ -21,6 +22,7 @@ class NodeList(list[_T]): def item(self, index: int) -> _T | None: ... class EmptyNodeList(tuple[()]): + __slots__ = () @property def length(self) -> Literal[0]: """The number of nodes in the NodeList.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi index e455f0f4b2cd1..6547439155c1c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/minidom.pyi @@ -219,6 +219,7 @@ _AttrChildrenVar = TypeVar("_AttrChildrenVar", bound=_AttrChildren) _AttrChildrenPlusFragment = TypeVar("_AttrChildrenPlusFragment", bound=_AttrChildren | DocumentFragment) class Attr(Node): + __slots__ = ("_name", "_value", "namespaceURI", "_prefix", "childNodes", "_localName", "ownerDocument", "ownerElement") nodeType: ClassVar[Literal[2]] nodeName: str # same as Attr.name nodeValue: str # same as Attr.value @@ -276,6 +277,7 @@ class NamedNodeMap: attributes as found in an input document. """ + __slots__ = ("_attrs", "_attrsNS", "_ownerElement") def __init__(self, attrs: dict[str, Attr], attrsNS: dict[_NSName, Attr], ownerElement: Element) -> None: ... @property def length(self) -> int: @@ -309,6 +311,7 @@ class NamedNodeMap: AttributeList = NamedNodeMap class TypeInfo: + __slots__ = ("namespace", "name") namespace: str | None name: str | None def __init__(self, namespace: Incomplete | None, name: str | None) -> None: ... @@ -317,6 +320,20 @@ _ElementChildrenVar = TypeVar("_ElementChildrenVar", bound=_ElementChildren) _ElementChildrenPlusFragment = TypeVar("_ElementChildrenPlusFragment", bound=_ElementChildren | DocumentFragment) class Element(Node): + __slots__ = ( + "ownerDocument", + "parentNode", + "tagName", + "nodeName", + "prefix", + "namespaceURI", + "_localName", + "childNodes", + "_attrs", + "_attrsNS", + "nextSibling", + "previousSibling", + ) nodeType: ClassVar[Literal[1]] nodeName: str # same as Element.tagName nodeValue: None @@ -411,6 +428,7 @@ class Childless: the complexity of the Node methods that deal with children. """ + __slots__ = () attributes: None childNodes: EmptyNodeList @property @@ -431,6 +449,7 @@ class Childless: def replaceChild(self, newChild: _NodesThatAreChildren | DocumentFragment, oldChild: _NodesThatAreChildren) -> NoReturn: ... class ProcessingInstruction(Childless, Node): + __slots__ = ("target", "data") nodeType: ClassVar[Literal[7]] nodeName: str # same as ProcessingInstruction.target nodeValue: str # same as ProcessingInstruction.data @@ -459,6 +478,7 @@ class ProcessingInstruction(Childless, Node): def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... class CharacterData(Childless, Node): + __slots__ = ("_data", "ownerDocument", "parentNode", "previousSibling", "nextSibling") nodeValue: str attributes: None @@ -485,6 +505,7 @@ class CharacterData(Childless, Node): def replaceData(self, offset: int, count: int, arg: str) -> None: ... class Text(CharacterData): + __slots__ = () nodeType: ClassVar[Literal[3]] nodeName: Literal["#text"] nodeValue: str # same as CharacterData.data, the content of the text node @@ -545,6 +566,7 @@ class Comment(CharacterData): def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... class CDATASection(Text): + __slots__ = () nodeType: ClassVar[Literal[4]] # type: ignore[assignment] nodeName: Literal["#cdata-section"] # type: ignore[assignment] nodeValue: str # same as CharacterData.data, the content of the CDATA Section @@ -557,6 +579,7 @@ class CDATASection(Text): def writexml(self, writer: SupportsWrite[str], indent: str = "", addindent: str = "", newl: str = "") -> None: ... class ReadOnlySequentialNamedNodeMap(Generic[_N]): + __slots__ = ("_seq",) def __init__(self, seq: Sequence[_N] = ()) -> None: ... def __len__(self) -> int: ... def getNamedItem(self, name: str) -> _N | None: ... @@ -574,6 +597,7 @@ class ReadOnlySequentialNamedNodeMap(Generic[_N]): class Identified: """Mix-in class that supports the publicId and systemId attributes.""" + __slots__ = ("publicId", "systemId") publicId: str | None systemId: str | None @@ -681,6 +705,7 @@ class ElementInfo: """ + __slots__ = ("tagName",) tagName: str def __init__(self, name: str) -> None: ... def getAttributeType(self, aname: str) -> TypeInfo: ... @@ -700,6 +725,7 @@ class ElementInfo: _DocumentChildrenPlusFragment = TypeVar("_DocumentChildrenPlusFragment", bound=_DocumentChildren | DocumentFragment) class Document(Node, DocumentLS): + __slots__ = ("_elem_info", "doctype", "_id_search_stack", "childNodes", "_id_cache") nodeType: ClassVar[Literal[9]] nodeName: Literal["#document"] nodeValue: None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/pulldom.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/pulldom.pyi index aef911a90f79f..2518ca34ccd53 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/pulldom.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/pulldom.pyi @@ -101,7 +101,7 @@ class SAX2DOM(PullDOM): def ignorableWhitespace(self, chars: str) -> None: ... def characters(self, chars: str) -> None: ... -default_bufsize: int +default_bufsize: Final[int] def parse( stream_or_string: str | _SupportsReadClose[bytes] | _SupportsReadClose[str], diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/xmlbuilder.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/xmlbuilder.pyi index 6a03e23a8e3fe..837803c4724ae 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/xmlbuilder.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/dom/xmlbuilder.pyi @@ -1,7 +1,7 @@ """Implementation of the DOM Level 3 'LS-Load' feature.""" from _typeshed import SupportsRead -from typing import Any, Literal, NoReturn +from typing import Any, Final, Literal, NoReturn from xml.dom.minidom import Document, Node, _DOMErrorHandler __all__ = ["DOMBuilder", "DOMEntityResolver", "DOMInputSource"] @@ -37,10 +37,10 @@ class DOMBuilder: entityResolver: DOMEntityResolver | None errorHandler: _DOMErrorHandler | None filter: DOMBuilderFilter | None - ACTION_REPLACE: Literal[1] - ACTION_APPEND_AS_CHILDREN: Literal[2] - ACTION_INSERT_AFTER: Literal[3] - ACTION_INSERT_BEFORE: Literal[4] + ACTION_REPLACE: Final = 1 + ACTION_APPEND_AS_CHILDREN: Final = 2 + ACTION_INSERT_AFTER: Final = 3 + ACTION_INSERT_BEFORE: Final = 4 def __init__(self) -> None: ... def setFeature(self, name: str, state: int) -> None: ... def supportsFeature(self, name: str) -> bool: ... @@ -52,9 +52,11 @@ class DOMBuilder: def parseWithContext(self, input: DOMInputSource, cnode: Node, action: Literal[1, 2, 3, 4]) -> NoReturn: ... class DOMEntityResolver: + __slots__ = ("_opener",) def resolveEntity(self, publicId: str | None, systemId: str) -> DOMInputSource: ... class DOMInputSource: + __slots__ = ("byteStream", "characterStream", "stringData", "encoding", "publicId", "systemId", "baseURI") byteStream: SupportsRead[bytes] | None characterStream: SupportsRead[str] | None stringData: str | None @@ -68,10 +70,10 @@ class DOMBuilderFilter: a DOM instance. """ - FILTER_ACCEPT: Literal[1] - FILTER_REJECT: Literal[2] - FILTER_SKIP: Literal[3] - FILTER_INTERRUPT: Literal[4] + FILTER_ACCEPT: Final = 1 + FILTER_REJECT: Final = 2 + FILTER_SKIP: Final = 3 + FILTER_INTERRUPT: Final = 4 whatToShow: int def acceptNode(self, element: Node) -> Literal[1, 2, 3, 4]: ... def startContainer(self, element: Node) -> Literal[1, 2, 3, 4]: ... @@ -86,8 +88,8 @@ class DocumentLS: def saveXML(self, snode: Node | None) -> str: ... class DOMImplementationLS: - MODE_SYNCHRONOUS: Literal[1] - MODE_ASYNCHRONOUS: Literal[2] + MODE_SYNCHRONOUS: Final = 1 + MODE_ASYNCHRONOUS: Final = 2 def createDOMBuilder(self, mode: Literal[1], schemaType: None) -> DOMBuilder: ... def createDOMWriter(self) -> NoReturn: ... def createDOMInputSource(self) -> DOMInputSource: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi index fd829fdaa5ffc..10784e7d40214 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementInclude.pyi @@ -9,9 +9,10 @@ class _Loader(Protocol): @overload def __call__(self, href: FileDescriptorOrPath, parse: Literal["text"], encoding: str | None = None) -> str: ... -XINCLUDE: Final[str] -XINCLUDE_INCLUDE: Final[str] -XINCLUDE_FALLBACK: Final[str] +XINCLUDE: Final = "{http://www.w3.org/2001/XInclude}" + +XINCLUDE_INCLUDE: Final = "{http://www.w3.org/2001/XInclude}include" +XINCLUDE_FALLBACK: Final = "{http://www.w3.org/2001/XInclude}fallback" DEFAULT_MAX_INCLUSION_DEPTH: Final = 6 diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementPath.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementPath.pyi index ebfb4f1ffbb9c..80f3c55c14899 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementPath.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementPath.pyi @@ -1,10 +1,10 @@ from collections.abc import Callable, Generator, Iterable from re import Pattern -from typing import Any, Literal, TypeVar, overload +from typing import Any, Final, Literal, TypeVar, overload from typing_extensions import TypeAlias from xml.etree.ElementTree import Element -xpath_tokenizer_re: Pattern[str] +xpath_tokenizer_re: Final[Pattern[str]] _Token: TypeAlias = tuple[str, str] _Next: TypeAlias = Callable[[], _Token] @@ -20,7 +20,7 @@ def prepare_descendant(next: _Next, token: _Token) -> _Callback | None: ... def prepare_parent(next: _Next, token: _Token) -> _Callback: ... def prepare_predicate(next: _Next, token: _Token) -> _Callback | None: ... -ops: dict[str, Callable[[_Next, _Token], _Callback | None]] +ops: Final[dict[str, Callable[[_Next, _Token], _Callback | None]]] class _SelectorContext: parent_map: dict[Element, Element] | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi index a92ae79cbd1ea..2af9feea5d835 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi @@ -128,10 +128,8 @@ def canonicalize( ) -> None: ... # The tag for Element can be set to the Comment or ProcessingInstruction -# functions defined in this module. _ElementCallable could be a recursive -# type, but defining it that way uncovered a bug in pytype. -_ElementCallable: TypeAlias = Callable[..., Element[Any]] -_CallableElement: TypeAlias = Element[_ElementCallable] +# functions defined in this module. +_ElementCallable: TypeAlias = Callable[..., Element[_ElementCallable]] _Tag = TypeVar("_Tag", default=str, bound=str | _ElementCallable) _OtherTag = TypeVar("_OtherTag", default=str, bound=str | _ElementCallable) @@ -196,7 +194,7 @@ class Element(Generic[_Tag]): """True if self else False""" def SubElement(parent: Element, tag: str, attrib: dict[str, str] = ..., **extra: str) -> Element: ... -def Comment(text: str | None = None) -> _CallableElement: +def Comment(text: str | None = None) -> Element[_ElementCallable]: """Comment element factory. This function creates a special element which the standard serializer @@ -206,7 +204,7 @@ def Comment(text: str | None = None) -> _CallableElement: """ -def ProcessingInstruction(target: str, text: str | None = None) -> _CallableElement: +def ProcessingInstruction(target: str, text: str | None = None) -> Element[_ElementCallable]: """Processing Instruction element factory. This function creates a special element which the standard serializer @@ -373,7 +371,7 @@ class ElementTree(Generic[_Root]): def write_c14n(self, file: _FileWriteC14N) -> None: ... -HTML_EMPTY: set[str] +HTML_EMPTY: Final[set[str]] def register_namespace(prefix: str, uri: str) -> None: """Register a namespace prefix. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi index e9f5a4de555ea..48fd8107f293a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/__init__.pyi @@ -22,7 +22,7 @@ expatreader -- Driver that allows use of the Expat parser with SAX. import sys from _typeshed import ReadableBuffer, StrPath, SupportsRead, _T_co from collections.abc import Iterable -from typing import Protocol, type_check_only +from typing import Final, Protocol, type_check_only from typing_extensions import TypeAlias from xml.sax._exceptions import ( SAXException as SAXException, @@ -40,7 +40,7 @@ class _SupportsReadClose(SupportsRead[_T_co], Protocol[_T_co]): _Source: TypeAlias = StrPath | _SupportsReadClose[bytes] | _SupportsReadClose[str] -default_parser_list: list[str] +default_parser_list: Final[list[str]] def make_parser(parser_list: Iterable[str] = ()) -> XMLReader: """Creates and returns a SAX parser. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/expatreader.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/expatreader.pyi index 366cb60c806fe..42e85c503ad99 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/expatreader.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/expatreader.pyi @@ -6,7 +6,7 @@ pyexpat.__version__ == '2.22'. import sys from _typeshed import ReadableBuffer from collections.abc import Mapping -from typing import Any, Literal, overload +from typing import Any, Final, Literal, overload from typing_extensions import TypeAlias from xml.sax import _Source, xmlreader from xml.sax.handler import _ContentHandlerProtocol @@ -16,7 +16,7 @@ if sys.version_info >= (3, 10): _BoolType: TypeAlias = Literal[0, 1] | bool -version: str +version: Final[str] AttributesImpl = xmlreader.AttributesImpl AttributesNSImpl = xmlreader.AttributesNSImpl diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/handler.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/handler.pyi index d35ad8a71382e..97f8c2f4fa0e4 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/handler.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/sax/handler.pyi @@ -10,10 +10,10 @@ $Id$ """ import sys -from typing import Literal, NoReturn, Protocol, type_check_only +from typing import Final, NoReturn, Protocol, type_check_only from xml.sax import xmlreader -version: str +version: Final[str] @type_check_only class _ErrorHandlerProtocol(Protocol): # noqa: Y046 # Protocol is not used @@ -261,20 +261,20 @@ class EntityResolver: to read from. """ -feature_namespaces: str -feature_namespace_prefixes: str -feature_string_interning: str -feature_validation: str -feature_external_ges: str -feature_external_pes: str -all_features: list[str] -property_lexical_handler: Literal["http://xml.org/sax/properties/lexical-handler"] -property_declaration_handler: Literal["http://xml.org/sax/properties/declaration-handler"] -property_dom_node: Literal["http://xml.org/sax/properties/dom-node"] -property_xml_string: Literal["http://xml.org/sax/properties/xml-string"] -property_encoding: Literal["http://www.python.org/sax/properties/encoding"] -property_interning_dict: Literal["http://www.python.org/sax/properties/interning-dict"] -all_properties: list[str] +feature_namespaces: Final = "http://xml.org/sax/features/namespaces" +feature_namespace_prefixes: Final = "http://xml.org/sax/features/namespace-prefixes" +feature_string_interning: Final = "http://xml.org/sax/features/string-interning" +feature_validation: Final = "http://xml.org/sax/features/validation" +feature_external_ges: Final[str] # too long string +feature_external_pes: Final[str] # too long string +all_features: Final[list[str]] +property_lexical_handler: Final = "http://xml.org/sax/properties/lexical-handler" +property_declaration_handler: Final = "http://xml.org/sax/properties/declaration-handler" +property_dom_node: Final = "http://xml.org/sax/properties/dom-node" +property_xml_string: Final = "http://xml.org/sax/properties/xml-string" +property_encoding: Final = "http://www.python.org/sax/properties/encoding" +property_interning_dict: Final[str] # too long string +all_properties: Final[list[str]] if sys.version_info >= (3, 10): class LexicalHandler: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi index 945c3d7365a4f..0389fe1cba78f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/__init__.pyi @@ -217,7 +217,7 @@ class ZipFile: def __init__( self, file: StrPath | _ZipWritable, - mode: Literal["w", "x"] = ..., + mode: Literal["w", "x"], compression: int = 0, allowZip64: bool = True, compresslevel: int | None = None, @@ -229,7 +229,7 @@ class ZipFile: def __init__( self, file: StrPath | _ZipReadableTellable, - mode: Literal["a"] = ..., + mode: Literal["a"], compression: int = 0, allowZip64: bool = True, compresslevel: int | None = None, @@ -268,7 +268,7 @@ class ZipFile: def __init__( self, file: StrPath | _ZipWritable, - mode: Literal["w", "x"] = ..., + mode: Literal["w", "x"], compression: int = 0, allowZip64: bool = True, compresslevel: int | None = None, @@ -279,7 +279,7 @@ class ZipFile: def __init__( self, file: StrPath | _ZipReadableTellable, - mode: Literal["a"] = ..., + mode: Literal["a"], compression: int = 0, allowZip64: bool = True, compresslevel: int | None = None, @@ -417,6 +417,29 @@ class PyZipFile(ZipFile): class ZipInfo: """Class with attributes describing each file in the ZIP archive.""" + __slots__ = ( + "orig_filename", + "filename", + "date_time", + "compress_type", + "compress_level", + "comment", + "extra", + "create_system", + "create_version", + "extract_version", + "reserved", + "flag_bits", + "volume", + "internal_attr", + "external_attr", + "header_offset", + "CRC", + "compress_size", + "file_size", + "_raw_time", + "_end_offset", + ) filename: str date_time: _DateTuple compress_type: int diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/_path/glob.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/_path/glob.pyi index 8722f25246cc3..8c607b19d1d8c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/_path/glob.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/zipfile/_path/glob.pyi @@ -16,7 +16,11 @@ if sys.version_info >= (3, 13): AssertionError: Invalid separators """ - def __init__(self, seps: str = ...) -> None: ... + if sys.platform == "win32": + def __init__(self, seps: str = "\\/") -> None: ... + else: + def __init__(self, seps: str = "/") -> None: ... + def translate(self, pattern: str) -> str: """ Given a glob pattern, produce a regex that matches it. From c5e05df966fe3f5cb6b03a087b39e1f91a4b8008 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 22 Aug 2025 10:20:13 +0200 Subject: [PATCH 089/160] [ty] Cancel background tasks when shutdown is requested (#20039) --- crates/ty_server/src/server/api/requests/shutdown.rs | 7 +++++++ crates/ty_server/src/session.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/ty_server/src/server/api/requests/shutdown.rs b/crates/ty_server/src/server/api/requests/shutdown.rs index 221ff82e09190..77c9e78f9821b 100644 --- a/crates/ty_server/src/server/api/requests/shutdown.rs +++ b/crates/ty_server/src/server/api/requests/shutdown.rs @@ -3,6 +3,7 @@ use crate::server::api::traits::{RequestHandler, SyncRequestHandler}; use crate::session::client::Client; use lsp_types::{WorkspaceDiagnosticReport, WorkspaceDiagnosticReportResult}; +use salsa::Database; pub(crate) struct ShutdownHandler; @@ -28,6 +29,12 @@ impl SyncRequestHandler for ShutdownHandler { session.set_shutdown_requested(true); + // Trigger cancellation for every db to cancel any compute intensive background tasks + // (e.g. workspace diagnostics or workspace symbols). + for db in session.projects_mut() { + db.trigger_cancellation(); + } + Ok(()) } } diff --git a/crates/ty_server/src/session.rs b/crates/ty_server/src/session.rs index 7c13121d1cceb..4c53371c24daa 100644 --- a/crates/ty_server/src/session.rs +++ b/crates/ty_server/src/session.rs @@ -427,7 +427,7 @@ impl Session { /// Returns a mutable iterator over all project databases that have been initialized to this point. /// /// This iterator will only yield the default project database if it has been used. - fn projects_mut(&mut self) -> impl Iterator + '_ { + pub(crate) fn projects_mut(&mut self) -> impl Iterator + '_ { self.project_states_mut().map(|project| &mut project.db) } From 11f521c7683cdad4b26d9116d58a7c8c861ffd4a Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 22 Aug 2025 16:09:22 +0200 Subject: [PATCH 090/160] [ty] Close signature help after `)` (#20017) --- crates/ty_ide/src/signature_help.rs | 118 ++++++++++++++++++++++------ 1 file changed, 95 insertions(+), 23 deletions(-) diff --git a/crates/ty_ide/src/signature_help.rs b/crates/ty_ide/src/signature_help.rs index 4700f7e21be14..e9f775e6d69c8 100644 --- a/crates/ty_ide/src/signature_help.rs +++ b/crates/ty_ide/src/signature_help.rs @@ -12,6 +12,7 @@ use crate::{Db, find_node::covering_node}; use ruff_db::files::File; use ruff_db::parsed::parsed_module; use ruff_python_ast::{self as ast, AnyNodeRef}; +use ruff_python_parser::TokenKind; use ruff_text_size::{Ranged, TextRange, TextSize}; use ty_python_semantic::ResolvedDefinition; use ty_python_semantic::SemanticModel; @@ -25,7 +26,7 @@ use ty_python_semantic::types::{ // associated with the __new__ or __init__ call. /// Information about a function parameter -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ParameterDetails { /// The parameter name (e.g., "param1") pub name: String, @@ -37,7 +38,7 @@ pub struct ParameterDetails { } /// Information about a function signature -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct SignatureDetails { /// Text representation of the full signature (including input parameters and return type). pub label: String, @@ -51,7 +52,7 @@ pub struct SignatureDetails { } /// Signature help information for function calls -#[derive(Debug, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct SignatureHelpInfo { /// Information about each of the signatures for the function call. We /// need to handle multiple because of unions, overloads, and composite @@ -104,22 +105,42 @@ fn get_call_expr( ) -> Option<(&ast::ExprCall, usize)> { let root_node: AnyNodeRef = parsed.syntax().into(); - // Create a range from the offset for the covering_node function. - // Use length 1 if it fits within the root node, otherwise use zero-length range. - let one_char_range = TextRange::at(offset, TextSize::from(1)); - let range = if root_node.range().contains_range(one_char_range) { - one_char_range - } else { - TextRange::at(offset, TextSize::from(0)) - }; + // Find the token under the cursor and use its offset to find the node + let token = parsed + .tokens() + .at_offset(offset) + .max_by_key(|token| match token.kind() { + TokenKind::Name + | TokenKind::String + | TokenKind::Complex + | TokenKind::Float + | TokenKind::Int => 1, + _ => 0, + })?; // Find the covering node at the given position that is a function call. - let covering_node = covering_node(root_node, range) - .find_first(|node| matches!(node, AnyNodeRef::ExprCall(_))) + let call = covering_node(root_node, token.range()) + .find_first(|node| { + if !node.is_expr_call() { + return false; + } + + // Close the signature help if the cursor is at the closing parenthesis + if token.kind() == TokenKind::Rpar && node.end() == token.end() && offset == token.end() + { + return false; + } + + if token.range().is_empty() && node.end() == token.end() { + return false; + } + + true + }) .ok()?; // Get the function call expression. - let AnyNodeRef::ExprCall(call_expr) = covering_node.node() else { + let AnyNodeRef::ExprCall(call_expr) = call.node() else { return None; }; @@ -247,11 +268,11 @@ mod tests { r#" def example_function(param1: str, param2: int) -> str: """This is a docstring for the example function. - + Args: param1: The first parameter as a string param2: The second parameter as an integer - + Returns: A formatted string combining both parameters """ @@ -627,7 +648,7 @@ mod tests { r#" def documented_function(param1: str, param2: int) -> str: """This is a function with parameter documentation. - + Args: param1: The first parameter description param2: The second parameter description @@ -706,6 +727,57 @@ mod tests { assert_eq!(result.active_signature, Some(0)); } + #[test] + fn signature_help_after_closing_paren_at_end_of_file() { + let test = cursor_test( + r#" + def test(a: int) -> int: + return 10 + + test("test")"#, + ); + + // Should not return a signature help + assert_eq!(test.signature_help(), None); + } + + #[test] + fn signature_help_after_closing_paren_in_expression() { + let test = cursor_test( + r#" + def test(a: int) -> int: + return 10 + + test("test") + 10 + "#, + ); + + // Should not return a signature help + assert_eq!(test.signature_help(), None); + } + + #[test] + fn signature_help_after_closing_paren_nested() { + let test = cursor_test( + r#" + def inner(a: int) -> int: + return 10 + + def outer(a: int) -> None: ... + + outer(inner("test") + 10) + "#, + ); + + // Should return the outer signature help + let help = test.signature_help().expect("Should have outer help"); + + assert_eq!(help.signatures.len(), 1); + + let signature = &help.signatures[0]; + assert_eq!(signature.label, "(a: int) -> None"); + } + #[test] fn signature_help_stub_to_implementation_mapping() { // Test that when a function is called from a stub file with no docstring, @@ -714,22 +786,22 @@ mod tests { .source( "main.py", r#" -from lib import func -result = func( + from lib import func + result = func( "#, ) .source( "lib.pyi", r#" -def func() -> str: ... + def func() -> str: ... "#, ) .source( "lib.py", r#" -def func() -> str: - """This function does something.""" - return "" + def func() -> str: + """This function does something.""" + return "" "#, ) .build(); From c22395dbc618e295b7fbd84ca25e32a6256e361f Mon Sep 17 00:00:00 2001 From: Max Mynter <32773644+maxmynter@users.noreply.github.com> Date: Fri, 22 Aug 2025 16:29:42 +0200 Subject: [PATCH 091/160] [`ruff`] Fix false positive for t-strings in `default-factory-kwarg` (`RUF026`) (#20032) Closes #19993 ## Summary Recognize t strings as never being callable to avoid false positives on RUF026. --- crates/ruff_linter/resources/test/fixtures/ruff/RUF026.py | 7 +++++++ .../src/rules/ruff/rules/default_factory_kwarg.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF026.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF026.py index c607b8b1b3dec..384d005e9fb74 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF026.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF026.py @@ -118,3 +118,10 @@ def constant_factory(value): return lambda: value defaultdict(constant_factory("")) + +def func(): + defaultdict(default_factory=t"") # OK + + +def func(): + defaultdict(default_factory=t"hello") # OK diff --git a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs index 355aa47519e14..61f4b3119fc08 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/default_factory_kwarg.rs @@ -123,7 +123,8 @@ fn is_non_callable_value(value: &Expr) -> bool { | Expr::SetComp(_) | Expr::DictComp(_) | Expr::Generator(_) - | Expr::FString(_)) + | Expr::FString(_) + | Expr::TString(_)) } /// Generate an [`Expr`] to replace `defaultdict(default_factory=callable)` with From 8b827c3c6c04307e728ca25fb75f53adfbda13dc Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Fri, 22 Aug 2025 07:40:29 -0700 Subject: [PATCH 092/160] [ty] rename BareTypeAliasType to ManualPEP695TypeAliasType (#20037) ## Summary Rename `TypeAliasType::Bare` to `TypeAliasType::ManualPEP695`, and `BareTypeAliasType` to `ManualPEP695TypeAliasType`. Why? Both existing variants of `TypeAliasType` are specific to features added in PEP 695 (which introduced both the `type` statement and `types.TypeAliasType`), so it doesn't make sense to name one with the name `PEP695` and not the other. A "bare" type alias, in my mind, is a legacy type alias like `IntOrStr = int | str`, which is "bare" in that there is nothing at all distinguishing it as a type alias. I will want to use the "bare" name for this variant, in a future PR. The renamed variant here describes a type alias created with `IntOrStr = types.TypeAliasType("IntOrStr", int | str)`, which is not "bare", it's just "manually" instantiated instead of using the `type` statement syntax sugar. (This is useful when using the `typing_extensions` backport of `TypeAliasType` on older Python versions.) ## Test Plan Pure rename, existing tests pass. --- crates/ty_python_semantic/src/types.rs | 28 +++++++++++--------- crates/ty_python_semantic/src/types/class.rs | 13 ++++----- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index f20412c07396b..a583560192171 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -9231,12 +9231,14 @@ fn value_type_cycle_initial<'db>(_db: &'db dyn Db, _self: PEP695TypeAliasType<'d Type::Never } +/// A PEP 695 `types.TypeAliasType` created by manually calling the constructor. +/// /// # Ordering /// Ordering is based on the type alias's salsa-assigned id and not on its values. /// The id may change between runs, or when the alias was garbage collected and recreated. #[salsa::interned(debug, heap_size=ruff_memory_usage::heap_size)] #[derive(PartialOrd, Ord)] -pub struct BareTypeAliasType<'db> { +pub struct ManualPEP695TypeAliasType<'db> { #[returns(ref)] pub name: ast::name::Name, pub definition: Option>, @@ -9244,17 +9246,17 @@ pub struct BareTypeAliasType<'db> { } // The Salsa heap is tracked separately. -impl get_size2::GetSize for BareTypeAliasType<'_> {} +impl get_size2::GetSize for ManualPEP695TypeAliasType<'_> {} -fn walk_bare_type_alias<'db, V: visitor::TypeVisitor<'db> + ?Sized>( +fn walk_manual_pep_695_type_alias<'db, V: visitor::TypeVisitor<'db> + ?Sized>( db: &'db dyn Db, - type_alias: BareTypeAliasType<'db>, + type_alias: ManualPEP695TypeAliasType<'db>, visitor: &V, ) { visitor.visit_type(db, type_alias.value(db)); } -impl<'db> BareTypeAliasType<'db> { +impl<'db> ManualPEP695TypeAliasType<'db> { fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { Self::new( db, @@ -9272,7 +9274,7 @@ pub enum TypeAliasType<'db> { /// A type alias defined using the PEP 695 `type` statement. PEP695(PEP695TypeAliasType<'db>), /// A type alias defined by manually instantiating the PEP 695 `types.TypeAliasType`. - Bare(BareTypeAliasType<'db>), + ManualPEP695(ManualPEP695TypeAliasType<'db>), } fn walk_type_alias_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( @@ -9284,8 +9286,8 @@ fn walk_type_alias_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( TypeAliasType::PEP695(type_alias) => { walk_pep_695_type_alias(db, type_alias, visitor); } - TypeAliasType::Bare(type_alias) => { - walk_bare_type_alias(db, type_alias, visitor); + TypeAliasType::ManualPEP695(type_alias) => { + walk_manual_pep_695_type_alias(db, type_alias, visitor); } } } @@ -9296,8 +9298,8 @@ impl<'db> TypeAliasType<'db> { TypeAliasType::PEP695(type_alias) => { TypeAliasType::PEP695(type_alias.normalized_impl(db, visitor)) } - TypeAliasType::Bare(type_alias) => { - TypeAliasType::Bare(type_alias.normalized_impl(db, visitor)) + TypeAliasType::ManualPEP695(type_alias) => { + TypeAliasType::ManualPEP695(type_alias.normalized_impl(db, visitor)) } } } @@ -9305,21 +9307,21 @@ impl<'db> TypeAliasType<'db> { pub(crate) fn name(self, db: &'db dyn Db) -> &'db str { match self { TypeAliasType::PEP695(type_alias) => type_alias.name(db), - TypeAliasType::Bare(type_alias) => type_alias.name(db), + TypeAliasType::ManualPEP695(type_alias) => type_alias.name(db), } } pub(crate) fn definition(self, db: &'db dyn Db) -> Option> { match self { TypeAliasType::PEP695(type_alias) => Some(type_alias.definition(db)), - TypeAliasType::Bare(type_alias) => type_alias.definition(db), + TypeAliasType::ManualPEP695(type_alias) => type_alias.definition(db), } } pub(crate) fn value_type(self, db: &'db dyn Db) -> Type<'db> { match self { TypeAliasType::PEP695(type_alias) => type_alias.value_type(db), - TypeAliasType::Bare(type_alias) => type_alias.value(db), + TypeAliasType::ManualPEP695(type_alias) => type_alias.value(db), } } } diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 12a38594cb718..1c736dfc4b6b3 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -28,11 +28,12 @@ use crate::types::infer::nearest_enclosing_class; use crate::types::signatures::{CallableSignature, Parameter, Parameters, Signature}; use crate::types::tuple::{TupleSpec, TupleType}; use crate::types::{ - ApplyTypeMappingVisitor, BareTypeAliasType, Binding, BoundSuperError, BoundSuperType, - CallableType, DataclassParams, DeprecatedInstance, HasRelationToVisitor, IsEquivalentVisitor, - KnownInstanceType, NormalizedVisitor, PropertyInstanceType, StringLiteralType, TypeAliasType, - TypeMapping, TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, - VarianceInferable, declaration_type, infer_definition_types, todo_type, + ApplyTypeMappingVisitor, Binding, BoundSuperError, BoundSuperType, CallableType, + DataclassParams, DeprecatedInstance, HasRelationToVisitor, IsEquivalentVisitor, + KnownInstanceType, ManualPEP695TypeAliasType, NormalizedVisitor, PropertyInstanceType, + StringLiteralType, TypeAliasType, TypeMapping, TypeRelation, TypeVarBoundOrConstraints, + TypeVarInstance, TypeVarKind, VarianceInferable, declaration_type, infer_definition_types, + todo_type, }; use crate::{ Db, FxIndexMap, FxOrderSet, Program, @@ -4935,7 +4936,7 @@ impl KnownClass { return; }; overload.set_return_type(Type::KnownInstance(KnownInstanceType::TypeAliasType( - TypeAliasType::Bare(BareTypeAliasType::new( + TypeAliasType::ManualPEP695(ManualPEP695TypeAliasType::new( db, ast::name::Name::new(name.value(db)), containing_assignment, From 0e9d77e43aef9553c6a57df6844c4d6c08bef9a0 Mon Sep 17 00:00:00 2001 From: Matthew Mckee Date: Fri, 22 Aug 2025 16:12:49 +0100 Subject: [PATCH 093/160] Fix incorrect lsp inlay hint type (#20044) --- crates/ty_ide/src/lib.rs | 2 +- .../src/server/api/requests/inlay_hints.rs | 11 +++++++++-- crates/ty_server/tests/e2e/inlay_hints.rs | 2 +- crates/ty_wasm/src/lib.rs | 19 +++++++++++++++++++ playground/ty/src/Editor/Editor.tsx | 11 +++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index 9395fb7533011..17c9cc56230ad 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -26,7 +26,7 @@ pub use document_symbols::{document_symbols, document_symbols_with_options}; pub use goto::{goto_declaration, goto_definition, goto_type_definition}; pub use goto_references::goto_references; pub use hover::hover; -pub use inlay_hints::{InlayHintSettings, inlay_hints}; +pub use inlay_hints::{InlayHintContent, InlayHintSettings, inlay_hints}; pub use markup::MarkupKind; pub use references::ReferencesMode; pub use rename::{can_rename, rename}; diff --git a/crates/ty_server/src/server/api/requests/inlay_hints.rs b/crates/ty_server/src/server/api/requests/inlay_hints.rs index 3c5e44d2644f2..52a82cd3a2e20 100644 --- a/crates/ty_server/src/server/api/requests/inlay_hints.rs +++ b/crates/ty_server/src/server/api/requests/inlay_hints.rs @@ -9,7 +9,7 @@ use crate::session::client::Client; use lsp_types::request::InlayHintRequest; use lsp_types::{InlayHintParams, Url}; use ruff_db::source::{line_index, source_text}; -use ty_ide::inlay_hints; +use ty_ide::{InlayHintContent, inlay_hints}; use ty_project::ProjectDatabase; pub(crate) struct InlayHintRequestHandler; @@ -56,7 +56,7 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler { .position .to_position(&source, &index, snapshot.encoding()), label: lsp_types::InlayHintLabel::String(hint.display(db).to_string()), - kind: Some(lsp_types::InlayHintKind::TYPE), + kind: Some(inlay_hint_kind(&hint.content)), tooltip: None, padding_left: None, padding_right: None, @@ -70,3 +70,10 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler { } impl RetriableRequestHandler for InlayHintRequestHandler {} + +fn inlay_hint_kind(inlay_hint_content: &InlayHintContent) -> lsp_types::InlayHintKind { + match inlay_hint_content { + InlayHintContent::Type(_) => lsp_types::InlayHintKind::TYPE, + InlayHintContent::CallArgumentName(_) => lsp_types::InlayHintKind::PARAMETER, + } +} diff --git a/crates/ty_server/tests/e2e/inlay_hints.rs b/crates/ty_server/tests/e2e/inlay_hints.rs index 9516bc9d96e35..324c4f1fc62e8 100644 --- a/crates/ty_server/tests/e2e/inlay_hints.rs +++ b/crates/ty_server/tests/e2e/inlay_hints.rs @@ -51,7 +51,7 @@ foo(1) "character": 4 }, "label": "a=", - "kind": 1 + "kind": 2 } ] "#); diff --git a/crates/ty_wasm/src/lib.rs b/crates/ty_wasm/src/lib.rs index ced09a516415f..f835ea911255d 100644 --- a/crates/ty_wasm/src/lib.rs +++ b/crates/ty_wasm/src/lib.rs @@ -455,6 +455,7 @@ impl Workspace { &source, self.position_encoding, ), + kind: hint.content.into(), }) .collect()) } @@ -977,6 +978,22 @@ impl From for CompletionKind { } } +#[wasm_bindgen] +#[derive(Debug, Clone, PartialEq, Eq, Copy)] +pub enum InlayHintKind { + Type, + Parameter, +} + +impl From> for InlayHintKind { + fn from(kind: ty_ide::InlayHintContent) -> Self { + match kind { + ty_ide::InlayHintContent::Type(_) => Self::Type, + ty_ide::InlayHintContent::CallArgumentName(_) => Self::Parameter, + } + } +} + #[wasm_bindgen] #[derive(Debug, Clone, PartialEq, Eq)] pub struct InlayHint { @@ -984,6 +1001,8 @@ pub struct InlayHint { pub markdown: String, pub position: Position, + + pub kind: InlayHintKind, } #[wasm_bindgen] diff --git a/playground/ty/src/Editor/Editor.tsx b/playground/ty/src/Editor/Editor.tsx index 7fd9dbfcec68f..5abcba070554e 100644 --- a/playground/ty/src/Editor/Editor.tsx +++ b/playground/ty/src/Editor/Editor.tsx @@ -27,6 +27,7 @@ import { type FileHandle, DocumentHighlight, DocumentHighlightKind, + InlayHintKind, } from "ty_wasm"; import { FileId, ReadonlyFiles } from "../Playground"; import { isPythonFile } from "./Files"; @@ -405,6 +406,15 @@ class PlaygroundServer return undefined; } + function mapInlayHintKind(kind: InlayHintKind): languages.InlayHintKind { + switch (kind) { + case InlayHintKind.Type: + return languages.InlayHintKind.Type; + case InlayHintKind.Parameter: + return languages.InlayHintKind.Parameter; + } + } + return { dispose: () => {}, hints: inlayHints.map((hint) => ({ @@ -413,6 +423,7 @@ class PlaygroundServer lineNumber: hint.position.line, column: hint.position.column, }, + kind: mapInlayHintKind(hint.kind), })), }; } From 0b6ce1c788bceea13afeac63ec25894a5edd4435 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 22 Aug 2025 10:23:49 -0500 Subject: [PATCH 094/160] [`ruff`] Handle empty t-strings in `unnecessary-empty-iterable-within-deque-call` (`RUF037`) (#20045) Adds a method to `TStringValue` to detect whether the t-string is empty _as an iterable_. Note the subtlety here that, unlike f-strings, an empty t-string is still truthy (i.e. `bool(t"")==True`). Closes #19951 --- .../resources/test/fixtures/ruff/RUF037.py | 5 +++ .../unnecessary_literal_within_deque_call.rs | 1 + ..._rules__ruff__tests__RUF037_RUF037.py.snap | 39 +++++++++++++++++++ crates/ruff_python_ast/src/nodes.rs | 22 ++++++++++- 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py index 3ee96bd2259b0..75818e741bc2e 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF037.py @@ -102,3 +102,8 @@ def f(): deque(b"abc") # OK deque(f"" "a") # OK deque(f"{x}" "") # OK + +# https://github.com/astral-sh/ruff/issues/19951 +deque(t"") +deque(t"" t"") +deque(t"{""}") # OK diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs index 51561e4e1f701..88374119c834b 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_literal_within_deque_call.rs @@ -103,6 +103,7 @@ pub(crate) fn unnecessary_literal_within_deque_call(checker: &Checker, deque: &a Expr::StringLiteral(string) => string.value.is_empty(), Expr::BytesLiteral(bytes) => bytes.value.is_empty(), Expr::FString(fstring) => fstring.value.is_empty_literal(), + Expr::TString(tstring) => tstring.value.is_empty_iterable(), _ => false, }; if !is_empty_literal { diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF037_RUF037.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF037_RUF037.py.snap index f396239316d40..97b71fd4a551e 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF037_RUF037.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF037_RUF037.py.snap @@ -383,3 +383,42 @@ help: Replace with `deque()` 101 101 | deque("abc") # OK 102 102 | deque(b"abc") # OK 103 103 | deque(f"" "a") # OK + +RUF037 [*] Unnecessary empty iterable within a deque call + --> RUF037.py:107:1 + | +106 | # https://github.com/astral-sh/ruff/issues/19951 +107 | deque(t"") + | ^^^^^^^^^^ +108 | deque(t"" t"") +109 | deque(t"{""}") # OK + | +help: Replace with `deque()` + +ℹ Safe fix +104 104 | deque(f"{x}" "") # OK +105 105 | +106 106 | # https://github.com/astral-sh/ruff/issues/19951 +107 |-deque(t"") + 107 |+deque() +108 108 | deque(t"" t"") +109 109 | deque(t"{""}") # OK + +RUF037 [*] Unnecessary empty iterable within a deque call + --> RUF037.py:108:1 + | +106 | # https://github.com/astral-sh/ruff/issues/19951 +107 | deque(t"") +108 | deque(t"" t"") + | ^^^^^^^^^^^^^^^ +109 | deque(t"{""}") # OK + | +help: Replace with `deque()` + +ℹ Safe fix +105 105 | +106 106 | # https://github.com/astral-sh/ruff/issues/19951 +107 107 | deque(t"") +108 |-deque(t"" t"") + 108 |+deque() +109 109 | deque(t"{""}") # OK diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 3e241b82529f6..6de571a86e898 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -515,7 +515,7 @@ impl FStringValue { /// Returns `true` if the node represents an empty f-string literal. /// - /// Noteh that a [`FStringValue`] node will always have >= 1 [`FStringPart`]s inside it. + /// Note that a [`FStringValue`] node will always have >= 1 [`FStringPart`]s inside it. /// This method checks whether the value of the concatenated parts is equal to the empty /// f-string, not whether the f-string has 0 parts inside it. pub fn is_empty_literal(&self) -> bool { @@ -681,6 +681,22 @@ impl TStringValue { pub fn elements(&self) -> impl Iterator { self.iter().flat_map(|tstring| tstring.elements.iter()) } + + /// Returns `true` if the node represents an empty t-string in the + /// sense that `__iter__` returns an empty iterable. + /// + /// Beware that empty t-strings are still truthy, i.e. `bool(t"") == True`. + /// + /// Note that a [`TStringValue`] node will always contain at least one + /// [`TString`] node. This method checks whether each of the constituent + /// t-strings (in an implicitly concatenated t-string) are empty + /// in the above sense. + pub fn is_empty_iterable(&self) -> bool { + match &self.inner { + TStringValueInner::Single(tstring) => tstring.is_empty(), + TStringValueInner::Concatenated(tstrings) => tstrings.iter().all(TString::is_empty), + } + } } impl<'a> IntoIterator for &'a TStringValue { @@ -1182,6 +1198,10 @@ impl TString { pub fn quote_style(&self) -> Quote { self.flags.quote_style() } + + pub fn is_empty(&self) -> bool { + self.elements.is_empty() + } } impl From for Expr { From 5d217b7f461e3fa02900deb7b4c7f4dace43c0b6 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 22 Aug 2025 18:32:53 +0200 Subject: [PATCH 095/160] [ty] Add type as detail to completion items (#20047) ## Summary @BurntSushi was so kind as to find me an easy task to do some coding before I'm off to PTO. This PR adds the type to completion items (see the gray little text at the end of a completion item). https://github.com/user-attachments/assets/c0a86061-fa12-47b4-b43c-3c646771a69d --- crates/ty_server/src/server/api/requests/completion.rs | 1 + crates/ty_wasm/src/lib.rs | 3 +++ playground/ty/src/Editor/Editor.tsx | 1 + 3 files changed, 5 insertions(+) diff --git a/crates/ty_server/src/server/api/requests/completion.rs b/crates/ty_server/src/server/api/requests/completion.rs index 214c04582fae0..e175ed49fec33 100644 --- a/crates/ty_server/src/server/api/requests/completion.rs +++ b/crates/ty_server/src/server/api/requests/completion.rs @@ -71,6 +71,7 @@ impl BackgroundDocumentRequestHandler for CompletionRequestHandler { label: comp.inner.name.into(), kind, sort_text: Some(format!("{i:-max_index_len$}")), + detail: comp.inner.ty.display(db).to_string().into(), documentation: comp .documentation .map(|docstring| Documentation::String(docstring.render_plaintext())), diff --git a/crates/ty_wasm/src/lib.rs b/crates/ty_wasm/src/lib.rs index f835ea911255d..413699866aeed 100644 --- a/crates/ty_wasm/src/lib.rs +++ b/crates/ty_wasm/src/lib.rs @@ -425,6 +425,7 @@ impl Workspace { documentation: completion .documentation .map(|documentation| documentation.render_plaintext()), + detail: completion.inner.ty.display(&self.db).to_string().into(), }) .collect()) } @@ -914,6 +915,8 @@ pub struct Completion { pub kind: Option, #[wasm_bindgen(getter_with_clone)] pub documentation: Option, + #[wasm_bindgen(getter_with_clone)] + pub detail: Option, } #[wasm_bindgen] diff --git a/playground/ty/src/Editor/Editor.tsx b/playground/ty/src/Editor/Editor.tsx index 5abcba070554e..75bcf9d119468 100644 --- a/playground/ty/src/Editor/Editor.tsx +++ b/playground/ty/src/Editor/Editor.tsx @@ -321,6 +321,7 @@ class PlaygroundServer : mapCompletionKind(completion.kind), insertText: completion.name, documentation: completion.documentation, + detail: completion.detail, // TODO(micha): It's unclear why this field is required for monaco but not VS Code. // and omitting it works just fine? The LSP doesn't expose this information right now // which is why we go with undefined for now. From 0be3e1fbbf8f9d0cacf4c784cd75f219511e7342 Mon Sep 17 00:00:00 2001 From: chiri Date: Fri, 22 Aug 2025 20:38:37 +0300 Subject: [PATCH 096/160] [`flake8-use-pathlib`] Add autofix for `PTH211` (#20009) ## Summary Part of https://github.com/astral-sh/ruff/issues/2331 --- .../fixtures/flake8_use_pathlib/PTH211.py | 8 + .../src/checkers/ast/analyze/expression.rs | 3 + crates/ruff_linter/src/codes.rs | 2 +- crates/ruff_linter/src/preview.rs | 5 + .../src/rules/flake8_use_pathlib/mod.rs | 1 + .../src/rules/flake8_use_pathlib/rules/mod.rs | 2 + .../flake8_use_pathlib/rules/os_symlink.rs | 148 ++++++++++++++++++ .../rules/replaceable_by_pathlib.rs | 18 +-- ..._use_pathlib__tests__PTH211_PTH211.py.snap | 58 +++++++ ...lib__tests__preview__PTH211_PTH211.py.snap | 108 +++++++++++++ .../rules/flake8_use_pathlib/violations.rs | 42 ----- 11 files changed, 335 insertions(+), 60 deletions(-) create mode 100644 crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs create mode 100644 crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/PTH211.py b/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/PTH211.py index 5acf2febe27b1..9668d568b4ba2 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/PTH211.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_use_pathlib/PTH211.py @@ -13,3 +13,11 @@ fd = os.open(".", os.O_RDONLY) os.symlink("source.txt", "link.txt", dir_fd=fd) # Ok: dir_fd is not supported by pathlib os.close(fd) + +os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) +os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) + +os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) + +os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) +os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean") diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 51824c3a65692..60d3cce5d6a41 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -1124,6 +1124,9 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { if checker.is_rule_enabled(Rule::OsMakedirs) { flake8_use_pathlib::rules::os_makedirs(checker, call, segments); } + if checker.is_rule_enabled(Rule::OsSymlink) { + flake8_use_pathlib::rules::os_symlink(checker, call, segments); + } if checker.is_rule_enabled(Rule::PathConstructorCurrentDirectory) { flake8_use_pathlib::rules::path_constructor_current_directory( checker, call, segments, diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index d395eed6f287c..bb29e285d744b 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -954,7 +954,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8UsePathlib, "207") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::Glob), (Flake8UsePathlib, "208") => (RuleGroup::Stable, rules::flake8_use_pathlib::violations::OsListdir), (Flake8UsePathlib, "210") => (RuleGroup::Stable, rules::flake8_use_pathlib::rules::InvalidPathlibWithSuffix), - (Flake8UsePathlib, "211") => (RuleGroup::Preview, rules::flake8_use_pathlib::violations::OsSymlink), + (Flake8UsePathlib, "211") => (RuleGroup::Preview, rules::flake8_use_pathlib::rules::OsSymlink), // flake8-logging-format (Flake8LoggingFormat, "001") => (RuleGroup::Stable, rules::flake8_logging_format::violations::LoggingStringFormat), diff --git a/crates/ruff_linter/src/preview.rs b/crates/ruff_linter/src/preview.rs index 64c185989fa08..b7d3b5df7abce 100644 --- a/crates/ruff_linter/src/preview.rs +++ b/crates/ruff_linter/src/preview.rs @@ -169,6 +169,11 @@ pub(crate) const fn is_fix_os_makedirs_enabled(settings: &LinterSettings) -> boo settings.preview.is_enabled() } +// https://github.com/astral-sh/ruff/pull/20009 +pub(crate) const fn is_fix_os_symlink_enabled(settings: &LinterSettings) -> bool { + settings.preview.is_enabled() +} + // https://github.com/astral-sh/ruff/pull/11436 // https://github.com/astral-sh/ruff/pull/11168 pub(crate) const fn is_dunder_init_fix_unused_import_enabled(settings: &LinterSettings) -> bool { diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs index 6042c440e9de0..aa7ca55867d04 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs @@ -129,6 +129,7 @@ mod tests { #[test_case(Rule::OsPathGetatime, Path::new("PTH203.py"))] #[test_case(Rule::OsPathGetmtime, Path::new("PTH204.py"))] #[test_case(Rule::OsPathGetctime, Path::new("PTH205.py"))] + #[test_case(Rule::OsSymlink, Path::new("PTH211.py"))] fn preview_flake8_use_pathlib(rule_code: Rule, path: &Path) -> Result<()> { let snapshot = format!( "preview__{}_{}", diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs index 7c9c180fb62ea..46273bc082438 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/mod.rs @@ -24,6 +24,7 @@ pub(crate) use os_rename::*; pub(crate) use os_replace::*; pub(crate) use os_rmdir::*; pub(crate) use os_sep_split::*; +pub(crate) use os_symlink::*; pub(crate) use os_unlink::*; pub(crate) use path_constructor_current_directory::*; pub(crate) use replaceable_by_pathlib::*; @@ -54,6 +55,7 @@ mod os_rename; mod os_replace; mod os_rmdir; mod os_sep_split; +mod os_symlink; mod os_unlink; mod path_constructor_current_directory; mod replaceable_by_pathlib; diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs new file mode 100644 index 0000000000000..43f5827383de5 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs @@ -0,0 +1,148 @@ +use anyhow::anyhow; +use ruff_diagnostics::{Applicability, Edit, Fix}; +use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::ExprCall; +use ruff_text_size::Ranged; + +use crate::checkers::ast::Checker; +use crate::importer::ImportRequest; +use crate::preview::is_fix_os_symlink_enabled; +use crate::rules::flake8_use_pathlib::helpers::{ + has_unknown_keywords_or_starred_expr, is_keyword_only_argument_non_default, + is_pathlib_path_call, +}; +use crate::{FixAvailability, Violation}; + +/// ## What it does +/// Checks for uses of `os.symlink`. +/// +/// ## Why is this bad? +/// `pathlib` offers a high-level API for path manipulation, as compared to +/// the lower-level API offered by `os.symlink`. +/// +/// ## Example +/// ```python +/// import os +/// +/// os.symlink("usr/bin/python", "tmp/python", target_is_directory=False) +/// ``` +/// +/// Use instead: +/// ```python +/// from pathlib import Path +/// +/// Path("tmp/python").symlink_to("usr/bin/python") +/// ``` +/// +/// ## Known issues +/// While using `pathlib` can improve the readability and type safety of your code, +/// it can be less performant than the lower-level alternatives that work directly with strings, +/// especially on older versions of Python. +/// +/// ## Fix Safety +/// This rule's fix is marked as unsafe if the replacement would remove comments attached to the original expression. +/// +/// ## References +/// - [Python documentation: `Path.symlink_to`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.symlink_to) +/// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) +/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) +#[derive(ViolationMetadata)] +pub(crate) struct OsSymlink; + +impl Violation for OsSymlink { + const FIX_AVAILABILITY: FixAvailability = FixAvailability::Sometimes; + + #[derive_message_formats] + fn message(&self) -> String { + "`os.symlink` should be replaced by `Path.symlink_to`".to_string() + } + + fn fix_title(&self) -> Option { + Some("Replace with `Path(...).symlink_to(...)`".to_string()) + } +} + +/// PTH211 +pub(crate) fn os_symlink(checker: &Checker, call: &ExprCall, segments: &[&str]) { + if segments != ["os", "symlink"] { + return; + } + + // `dir_fd` is not supported by pathlib, so check if there are non-default values. + // Signature as of Python 3.13 (https://docs.python.org/3/library/os.html#os.symlink) + // ```text + // 0 1 2 3 + // os.symlink(src, dst, target_is_directory=False, *, dir_fd=None) + // ``` + if is_keyword_only_argument_non_default(&call.arguments, "dir_fd") { + return; + } + + let range = call.range(); + let mut diagnostic = checker.report_diagnostic(OsSymlink, call.func.range()); + + if !is_fix_os_symlink_enabled(checker.settings()) { + return; + } + + if call.arguments.len() > 3 { + return; + } + + if has_unknown_keywords_or_starred_expr( + &call.arguments, + &["src", "dst", "target_is_directory", "dir_fd"], + ) { + return; + } + + let (Some(src), Some(dst)) = ( + call.arguments.find_argument_value("src", 0), + call.arguments.find_argument_value("dst", 1), + ) else { + return; + }; + + diagnostic.try_set_fix(|| { + let (import_edit, binding) = checker.importer().get_or_import_symbol( + &ImportRequest::import("pathlib", "Path"), + call.start(), + checker.semantic(), + )?; + + let applicability = if checker.comment_ranges().intersects(range) { + Applicability::Unsafe + } else { + Applicability::Safe + }; + + let locator = checker.locator(); + let src_code = locator.slice(src.range()); + let dst_code = locator.slice(dst.range()); + + let target_is_directory = call + .arguments + .find_argument_value("target_is_directory", 2) + .and_then(|expr| { + let code = locator.slice(expr.range()); + expr.as_boolean_literal_expr() + .is_some_and(|bl| !bl.value) + .then_some(format!(", target_is_directory={code}")) + }) + .ok_or_else(|| anyhow!("Non-boolean value passed for `target_is_directory`."))?; + + let replacement = if is_pathlib_path_call(checker, dst) { + format!("{dst_code}.symlink_to({src_code}{target_is_directory})") + } else { + format!("{binding}({dst_code}).symlink_to({src_code}{target_is_directory})") + }; + + Ok(Fix::applicable_edits( + Edit::range_replacement(replacement, range), + [import_edit], + applicability, + )) + }); +} diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs index b35ecd77c1d24..3c3341d3a76a6 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/replaceable_by_pathlib.rs @@ -7,9 +7,7 @@ use crate::rules::flake8_use_pathlib::helpers::{ }; use crate::rules::flake8_use_pathlib::{ rules::Glob, - violations::{ - BuiltinOpen, Joiner, OsListdir, OsPathJoin, OsPathSplitext, OsStat, OsSymlink, PyPath, - }, + violations::{BuiltinOpen, Joiner, OsListdir, OsPathJoin, OsPathSplitext, OsStat, PyPath}, }; pub(crate) fn replaceable_by_pathlib(checker: &Checker, call: &ExprCall) { @@ -62,20 +60,6 @@ pub(crate) fn replaceable_by_pathlib(checker: &Checker, call: &ExprCall) { ), // PTH122 ["os", "path", "splitext"] => checker.report_diagnostic_if_enabled(OsPathSplitext, range), - // PTH211 - ["os", "symlink"] => { - // `dir_fd` is not supported by pathlib, so check if there are non-default values. - // Signature as of Python 3.13 (https://docs.python.org/3/library/os.html#os.symlink) - // ```text - // 0 1 2 3 - // os.symlink(src, dst, target_is_directory=False, *, dir_fd=None) - // ``` - if is_keyword_only_argument_non_default(&call.arguments, "dir_fd") { - return; - } - checker.report_diagnostic_if_enabled(OsSymlink, range) - } - // PTH123 ["" | "builtins", "open"] => { // `closefd` and `opener` are not supported by pathlib, so check if they diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__PTH211_PTH211.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__PTH211_PTH211.py.snap index 69dffd9abbbb3..cd46c1b704b45 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__PTH211_PTH211.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__PTH211_PTH211.py.snap @@ -9,6 +9,7 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` 6 | os.symlink(b"usr/bin/python", b"tmp/python") 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok | +help: Replace with `Path(...).symlink_to(...)` PTH211 `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:6:1 @@ -18,6 +19,7 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | ^^^^^^^^^^ 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok | +help: Replace with `Path(...).symlink_to(...)` PTH211 `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:9:1 @@ -29,6 +31,7 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` 10 | os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True) 11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok | +help: Replace with `Path(...).symlink_to(...)` PTH211 `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:10:1 @@ -38,3 +41,58 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | ^^^^^^^^^^ 11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:17:1 + | +15 | os.close(fd) +16 | +17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) + | ^^^^^^^^^^ +18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:18:1 + | +17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) +18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) + | ^^^^^^^^^^ +19 | +20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:20:1 + | +18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) +19 | +20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) + | ^^^^^^^^^^ +21 | +22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:22:1 + | +20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) +21 | +22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) + | ^^^^^^^^^^ +23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean") + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:23:1 + | +22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) +23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean") + | ^^^^^^^^^^ + | +help: Replace with `Path(...).symlink_to(...)` diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap new file mode 100644 index 0000000000000..9fa340479f97d --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap @@ -0,0 +1,108 @@ +--- +source: crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs +--- +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:5:1 + | +5 | os.symlink("usr/bin/python", "tmp/python") + | ^^^^^^^^^^ +6 | os.symlink(b"usr/bin/python", b"tmp/python") +7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:6:1 + | +5 | os.symlink("usr/bin/python", "tmp/python") +6 | os.symlink(b"usr/bin/python", b"tmp/python") + | ^^^^^^^^^^ +7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:9:1 + | + 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok + 8 | + 9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True) + | ^^^^^^^^^^ +10 | os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True) +11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:10:1 + | + 9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True) +10 | os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True) + | ^^^^^^^^^^ +11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:17:1 + | +15 | os.close(fd) +16 | +17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) + | ^^^^^^^^^^ +18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:18:1 + | +17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) +18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) + | ^^^^^^^^^^ +19 | +20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) + | +help: Replace with `Path(...).symlink_to(...)` + +ℹ Safe fix +15 15 | os.close(fd) +16 16 | +17 17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) +18 |-os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) + 18 |+Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=False) +19 19 | +20 20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) +21 21 | + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:20:1 + | +18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) +19 | +20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) + | ^^^^^^^^^^ +21 | +22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:22:1 + | +20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) +21 | +22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) + | ^^^^^^^^^^ +23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean") + | +help: Replace with `Path(...).symlink_to(...)` + +PTH211 `os.symlink` should be replaced by `Path.symlink_to` + --> PTH211.py:23:1 + | +22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) +23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean") + | ^^^^^^^^^^ + | +help: Replace with `Path(...).symlink_to(...)` diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs index 7a5661aae2f11..a8b424065b9a0 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs @@ -310,45 +310,3 @@ impl Violation for OsListdir { "Use `pathlib.Path.iterdir()` instead.".to_string() } } - -/// ## What it does -/// Checks for uses of `os.symlink`. -/// -/// ## Why is this bad? -/// `pathlib` offers a high-level API for path manipulation, as compared to -/// the lower-level API offered by `os.symlink`. -/// -/// ## Example -/// ```python -/// import os -/// -/// os.symlink("usr/bin/python", "tmp/python", target_is_directory=False) -/// ``` -/// -/// Use instead: -/// ```python -/// from pathlib import Path -/// -/// Path("tmp/python").symlink_to("usr/bin/python") -/// ``` -/// -/// ## Known issues -/// While using `pathlib` can improve the readability and type safety of your code, -/// it can be less performant than the lower-level alternatives that work directly with strings, -/// especially on older versions of Python. -/// -/// ## References -/// - [Python documentation: `Path.symlink_to`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.symlink_to) -/// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) -/// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) -/// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) -#[derive(ViolationMetadata)] -pub(crate) struct OsSymlink; - -impl Violation for OsSymlink { - #[derive_message_formats] - fn message(&self) -> String { - "`os.symlink` should be replaced by `Path.symlink_to`".to_string() - } -} From 5508e8e52868dfdcc9896c110215d08fdae3850d Mon Sep 17 00:00:00 2001 From: Vivek Dasari Date: Fri, 22 Aug 2025 10:49:34 -0700 Subject: [PATCH 097/160] Add testing helper to compare stable vs preview snapshots (#19715) ## Summary This PR implements a diff test helper `assert_diagnostics_diff` as described in #19351. The diff file includes both the settings ( e.g. `+linter.preview = enabled`) and the snapshot data itself. The current implementation looks for each old diagnostic in the new snapshot. This works when the preview behavior adds/removes a couple diagnostics. This implementation does not work well when every diagnostic is modified (e.g. a "fix" is added). https://github.com/astral-sh/ruff/pull/19715#discussion_r2259410763 has ideas for future improvements to this implementation. The example usage in this PR writes the diff to `preview_diff` file instead of `preview` file, which might be a useful convention to keep. ## Test Plan - Included a unit test at: https://github.com/astral-sh/ruff/pull/19715/files#diff-d49487fe3e8a8585529f62c2df2a2b0a4c44267a1f93d1e859dff1d9f8771d36R523 - Example usage of this new test helper: https://github.com/astral-sh/ruff/pull/19715/files#diff-2a33ac11146d1794c01a29549a6041d3af6fb6f9b423a31ade12a88d1951b0c2R1 --- .../src/rules/flake8_commas/mod.rs | 31 +- ...ake8_commas__tests__preview__COM81.py.snap | 1151 ----------------- ...tests__preview__COM81_syntax_error.py.snap | 33 - ...commas__tests__preview_diff__COM81.py.snap | 136 ++ ...__preview_diff__COM81_syntax_error.py.snap | 10 + crates/ruff_linter/src/test.rs | 160 +++ 6 files changed, 324 insertions(+), 1197 deletions(-) delete mode 100644 crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81.py.snap delete mode 100644 crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81_syntax_error.py.snap create mode 100644 crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81.py.snap create mode 100644 crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81_syntax_error.py.snap diff --git a/crates/ruff_linter/src/rules/flake8_commas/mod.rs b/crates/ruff_linter/src/rules/flake8_commas/mod.rs index 97010705a7137..eb7c6e32f9516 100644 --- a/crates/ruff_linter/src/rules/flake8_commas/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_commas/mod.rs @@ -10,7 +10,7 @@ mod tests { use crate::registry::Rule; use crate::test::test_path; - use crate::{assert_diagnostics, settings}; + use crate::{assert_diagnostics, assert_diagnostics_diff, settings}; #[test_case(Path::new("COM81.py"))] #[test_case(Path::new("COM81_syntax_error.py"))] @@ -31,19 +31,24 @@ mod tests { #[test_case(Path::new("COM81.py"))] #[test_case(Path::new("COM81_syntax_error.py"))] fn preview_rules(path: &Path) -> Result<()> { - let snapshot = format!("preview__{}", path.to_string_lossy()); - let diagnostics = test_path( + let snapshot = format!("preview_diff__{}", path.to_string_lossy()); + let rules = vec![ + Rule::MissingTrailingComma, + Rule::TrailingCommaOnBareTuple, + Rule::ProhibitedTrailingComma, + ]; + let settings_before = settings::LinterSettings::for_rules(rules.clone()); + let settings_after = settings::LinterSettings { + preview: crate::settings::types::PreviewMode::Enabled, + ..settings::LinterSettings::for_rules(rules) + }; + + assert_diagnostics_diff!( + snapshot, Path::new("flake8_commas").join(path).as_path(), - &settings::LinterSettings { - preview: crate::settings::types::PreviewMode::Enabled, - ..settings::LinterSettings::for_rules(vec![ - Rule::MissingTrailingComma, - Rule::TrailingCommaOnBareTuple, - Rule::ProhibitedTrailingComma, - ]) - }, - )?; - assert_diagnostics!(snapshot, diagnostics); + &settings_before, + &settings_after + ); Ok(()) } } diff --git a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81.py.snap b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81.py.snap deleted file mode 100644 index 209e784a94bae..0000000000000 --- a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81.py.snap +++ /dev/null @@ -1,1151 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_commas/mod.rs ---- -COM812 [*] Trailing comma missing - --> COM81.py:4:18 - | -2 | bad_function_call( -3 | param1='test', -4 | param2='test' - | ^ -5 | ) -6 | # ==> bad_list.py <== - | -help: Add trailing comma - -ℹ Safe fix -1 1 | # ==> bad_function_call.py <== -2 2 | bad_function_call( -3 3 | param1='test', -4 |- param2='test' - 4 |+ param2='test', -5 5 | ) -6 6 | # ==> bad_list.py <== -7 7 | bad_list = [ - -COM812 [*] Trailing comma missing - --> COM81.py:10:6 - | - 8 | 1, - 9 | 2, -10 | 3 - | ^ -11 | ] - | -help: Add trailing comma - -ℹ Safe fix -7 7 | bad_list = [ -8 8 | 1, -9 9 | 2, -10 |- 3 - 10 |+ 3, -11 11 | ] -12 12 | -13 13 | bad_list_with_comment = [ - -COM812 [*] Trailing comma missing - --> COM81.py:16:6 - | -14 | 1, -15 | 2, -16 | 3 - | ^ -17 | # still needs a comma! -18 | ] - | -help: Add trailing comma - -ℹ Safe fix -13 13 | bad_list_with_comment = [ -14 14 | 1, -15 15 | 2, -16 |- 3 - 16 |+ 3, -17 17 | # still needs a comma! -18 18 | ] -19 19 | - -COM812 [*] Trailing comma missing - --> COM81.py:23:6 - | -21 | 1, -22 | 2, -23 | 3 - | ^ - | -help: Add trailing comma - -ℹ Safe fix -20 20 | bad_list_with_extra_empty = [ -21 21 | 1, -22 22 | 2, -23 |- 3 - 23 |+ 3, -24 24 | -25 25 | -26 26 | - -COM818 Trailing comma on bare tuple prohibited - --> COM81.py:36:8 - | -34 | foo = (1,) -35 | -36 | foo = 1, - | ^ -37 | -38 | bar = 1; foo = bar, - | - -COM818 Trailing comma on bare tuple prohibited - --> COM81.py:38:19 - | -36 | foo = 1, -37 | -38 | bar = 1; foo = bar, - | ^ -39 | -40 | foo = ( - | - -COM818 Trailing comma on bare tuple prohibited - --> COM81.py:45:8 - | -43 | ) -44 | -45 | foo = 3, - | ^ -46 | -47 | class A(object): - | - -COM818 Trailing comma on bare tuple prohibited - --> COM81.py:49:10 - | -47 | class A(object): -48 | foo = 3 -49 | bar = 10, - | ^ -50 | foo_bar = 2 - | - -COM818 Trailing comma on bare tuple prohibited - --> COM81.py:56:32 - | -54 | from foo import bar, baz -55 | -56 | group_by = function_call('arg'), - | ^ -57 | -58 | group_by = ('foobar' * 3), - | - -COM818 Trailing comma on bare tuple prohibited - --> COM81.py:58:26 - | -56 | group_by = function_call('arg'), -57 | -58 | group_by = ('foobar' * 3), - | ^ -59 | -60 | def foo(): - | - -COM818 Trailing comma on bare tuple prohibited - --> COM81.py:61:17 - | -60 | def foo(): -61 | return False, - | ^ -62 | -63 | # ==> callable_before_parenth_form.py <== - | - -COM812 [*] Trailing comma missing - --> COM81.py:70:8 - | -69 | {'foo': foo}['foo']( -70 | bar - | ^ -71 | ) - | -help: Add trailing comma - -ℹ Safe fix -67 67 | pass -68 68 | -69 69 | {'foo': foo}['foo']( -70 |- bar - 70 |+ bar, -71 71 | ) -72 72 | -73 73 | {'foo': foo}['foo']( - -COM812 [*] Trailing comma missing - --> COM81.py:78:8 - | -77 | (foo)( -78 | bar - | ^ -79 | ) - | -help: Add trailing comma - -ℹ Safe fix -75 75 | ) -76 76 | -77 77 | (foo)( -78 |- bar - 78 |+ bar, -79 79 | ) -80 80 | -81 81 | (foo)[0]( - -COM812 [*] Trailing comma missing - --> COM81.py:86:8 - | -85 | [foo][0]( -86 | bar - | ^ -87 | ) - | -help: Add trailing comma - -ℹ Safe fix -83 83 | ) -84 84 | -85 85 | [foo][0]( -86 |- bar - 86 |+ bar, -87 87 | ) -88 88 | -89 89 | [foo][0]( - -COM812 [*] Trailing comma missing - --> COM81.py:152:6 - | -150 | # ==> keyword_before_parenth_form/base_bad.py <== -151 | from x import ( -152 | y - | ^ -153 | ) - | -help: Add trailing comma - -ℹ Safe fix -149 149 | -150 150 | # ==> keyword_before_parenth_form/base_bad.py <== -151 151 | from x import ( -152 |- y - 152 |+ y, -153 153 | ) -154 154 | -155 155 | assert( - -COM812 [*] Trailing comma missing - --> COM81.py:158:11 - | -156 | SyntaxWarning, -157 | ThrownHere, -158 | Anyway - | ^ -159 | ) - | -help: Add trailing comma - -ℹ Safe fix -155 155 | assert( -156 156 | SyntaxWarning, -157 157 | ThrownHere, -158 |- Anyway - 158 |+ Anyway, -159 159 | ) -160 160 | -161 161 | # async await is fine outside an async def - -COM812 [*] Trailing comma missing - --> COM81.py:293:15 - | -291 | # ==> multiline_bad_dict.py <== -292 | multiline_bad_dict = { -293 | "bad": 123 - | ^ -294 | } -295 | # ==> multiline_bad_function_def.py <== - | -help: Add trailing comma - -ℹ Safe fix -290 290 | -291 291 | # ==> multiline_bad_dict.py <== -292 292 | multiline_bad_dict = { -293 |- "bad": 123 - 293 |+ "bad": 123, -294 294 | } -295 295 | # ==> multiline_bad_function_def.py <== -296 296 | def func_good( - -COM812 [*] Trailing comma missing - --> COM81.py:304:14 - | -302 | def func_bad( -303 | a = 3, -304 | b = 2 - | ^ -305 | ): -306 | pass - | -help: Add trailing comma - -ℹ Safe fix -301 301 | -302 302 | def func_bad( -303 303 | a = 3, -304 |- b = 2 - 304 |+ b = 2, -305 305 | ): -306 306 | pass -307 307 | - -COM812 [*] Trailing comma missing - --> COM81.py:310:14 - | -308 | # ==> multiline_bad_function_one_param.py <== -309 | def func( -310 | a = 3 - | ^ -311 | ): -312 | pass - | -help: Add trailing comma - -ℹ Safe fix -307 307 | -308 308 | # ==> multiline_bad_function_one_param.py <== -309 309 | def func( -310 |- a = 3 - 310 |+ a = 3, -311 311 | ): -312 312 | pass -313 313 | - -COM812 [*] Trailing comma missing - --> COM81.py:316:10 - | -315 | func( -316 | a = 3 - | ^ -317 | ) - | -help: Add trailing comma - -ℹ Safe fix -313 313 | -314 314 | -315 315 | func( -316 |- a = 3 - 316 |+ a = 3, -317 317 | ) -318 318 | -319 319 | # ==> multiline_bad_or_dict.py <== - -COM812 [*] Trailing comma missing - --> COM81.py:322:15 - | -320 | multiline_bad_or_dict = { -321 | "good": True or False, -322 | "bad": 123 - | ^ -323 | } - | -help: Add trailing comma - -ℹ Safe fix -319 319 | # ==> multiline_bad_or_dict.py <== -320 320 | multiline_bad_or_dict = { -321 321 | "good": True or False, -322 |- "bad": 123 - 322 |+ "bad": 123, -323 323 | } -324 324 | -325 325 | # ==> multiline_good_dict.py <== - -COM812 [*] Trailing comma missing - --> COM81.py:368:15 - | -366 | multiline_index_access[ -367 | "probably fine", -368 | "not good" - | ^ -369 | ] - | -help: Add trailing comma - -ℹ Safe fix -365 365 | -366 366 | multiline_index_access[ -367 367 | "probably fine", -368 |- "not good" - 368 |+ "not good", -369 369 | ] -370 370 | -371 371 | multiline_index_access[ - -COM812 [*] Trailing comma missing - --> COM81.py:375:15 - | -373 | "fine", -374 | : -375 | "not good" - | ^ -376 | ] - | -help: Add trailing comma - -ℹ Safe fix -372 372 | "fine", -373 373 | "fine", -374 374 | : -375 |- "not good" - 375 |+ "not good", -376 376 | ] -377 377 | -378 378 | # ==> multiline_string.py <== - -COM812 [*] Trailing comma missing - --> COM81.py:404:15 - | -402 | "fine" -403 | : -404 | "not fine" - | ^ -405 | ] - | -help: Add trailing comma - -ℹ Safe fix -401 401 | "fine", -402 402 | "fine" -403 403 | : -404 |- "not fine" - 404 |+ "not fine", -405 405 | ] -406 406 | -407 407 | multiline_index_access[ - -COM812 [*] Trailing comma missing - --> COM81.py:432:15 - | -430 | : -431 | "fine", -432 | "not fine" - | ^ -433 | ] - | -help: Add trailing comma - -ℹ Safe fix -429 429 | "fine" -430 430 | : -431 431 | "fine", -432 |- "not fine" - 432 |+ "not fine", -433 433 | ] -434 434 | -435 435 | multiline_index_access[ - -COM819 [*] Trailing comma prohibited - --> COM81.py:485:21 - | -484 | # ==> prohibited.py <== -485 | foo = ['a', 'b', 'c',] - | ^ -486 | -487 | bar = { a: b,} - | -help: Remove trailing comma - -ℹ Safe fix -482 482 | ) -483 483 | -484 484 | # ==> prohibited.py <== -485 |-foo = ['a', 'b', 'c',] - 485 |+foo = ['a', 'b', 'c'] -486 486 | -487 487 | bar = { a: b,} -488 488 | - -COM819 [*] Trailing comma prohibited - --> COM81.py:487:13 - | -485 | foo = ['a', 'b', 'c',] -486 | -487 | bar = { a: b,} - | ^ -488 | -489 | def bah(ham, spam,): - | -help: Remove trailing comma - -ℹ Safe fix -484 484 | # ==> prohibited.py <== -485 485 | foo = ['a', 'b', 'c',] -486 486 | -487 |-bar = { a: b,} - 487 |+bar = { a: b} -488 488 | -489 489 | def bah(ham, spam,): -490 490 | pass - -COM819 [*] Trailing comma prohibited - --> COM81.py:489:18 - | -487 | bar = { a: b,} -488 | -489 | def bah(ham, spam,): - | ^ -490 | pass - | -help: Remove trailing comma - -ℹ Safe fix -486 486 | -487 487 | bar = { a: b,} -488 488 | -489 |-def bah(ham, spam,): - 489 |+def bah(ham, spam): -490 490 | pass -491 491 | -492 492 | (0,) - -COM819 [*] Trailing comma prohibited - --> COM81.py:494:6 - | -492 | (0,) -493 | -494 | (0, 1,) - | ^ -495 | -496 | foo = ['a', 'b', 'c', ] - | -help: Remove trailing comma - -ℹ Safe fix -491 491 | -492 492 | (0,) -493 493 | -494 |-(0, 1,) - 494 |+(0, 1) -495 495 | -496 496 | foo = ['a', 'b', 'c', ] -497 497 | - -COM819 [*] Trailing comma prohibited - --> COM81.py:496:21 - | -494 | (0, 1,) -495 | -496 | foo = ['a', 'b', 'c', ] - | ^ -497 | -498 | bar = { a: b, } - | -help: Remove trailing comma - -ℹ Safe fix -493 493 | -494 494 | (0, 1,) -495 495 | -496 |-foo = ['a', 'b', 'c', ] - 496 |+foo = ['a', 'b', 'c' ] -497 497 | -498 498 | bar = { a: b, } -499 499 | - -COM819 [*] Trailing comma prohibited - --> COM81.py:498:13 - | -496 | foo = ['a', 'b', 'c', ] -497 | -498 | bar = { a: b, } - | ^ -499 | -500 | def bah(ham, spam, ): - | -help: Remove trailing comma - -ℹ Safe fix -495 495 | -496 496 | foo = ['a', 'b', 'c', ] -497 497 | -498 |-bar = { a: b, } - 498 |+bar = { a: b } -499 499 | -500 500 | def bah(ham, spam, ): -501 501 | pass - -COM819 [*] Trailing comma prohibited - --> COM81.py:500:18 - | -498 | bar = { a: b, } -499 | -500 | def bah(ham, spam, ): - | ^ -501 | pass - | -help: Remove trailing comma - -ℹ Safe fix -497 497 | -498 498 | bar = { a: b, } -499 499 | -500 |-def bah(ham, spam, ): - 500 |+def bah(ham, spam ): -501 501 | pass -502 502 | -503 503 | (0, ) - -COM819 [*] Trailing comma prohibited - --> COM81.py:505:6 - | -503 | (0, ) -504 | -505 | (0, 1, ) - | ^ -506 | -507 | image[:, :, 0] - | -help: Remove trailing comma - -ℹ Safe fix -502 502 | -503 503 | (0, ) -504 504 | -505 |-(0, 1, ) - 505 |+(0, 1 ) -506 506 | -507 507 | image[:, :, 0] -508 508 | - -COM819 [*] Trailing comma prohibited - --> COM81.py:511:10 - | -509 | image[:,] -510 | -511 | image[:,:,] - | ^ -512 | -513 | lambda x, : x - | -help: Remove trailing comma - -ℹ Safe fix -508 508 | -509 509 | image[:,] -510 510 | -511 |-image[:,:,] - 511 |+image[:,:] -512 512 | -513 513 | lambda x, : x -514 514 | - -COM819 [*] Trailing comma prohibited - --> COM81.py:513:9 - | -511 | image[:,:,] -512 | -513 | lambda x, : x - | ^ -514 | -515 | # ==> unpack.py <== - | -help: Remove trailing comma - -ℹ Safe fix -510 510 | -511 511 | image[:,:,] -512 512 | -513 |-lambda x, : x - 513 |+lambda x : x -514 514 | -515 515 | # ==> unpack.py <== -516 516 | def function( - -COM812 [*] Trailing comma missing - --> COM81.py:519:13 - | -517 | foo, -518 | bar, -519 | **kwargs - | ^ -520 | ): -521 | pass - | -help: Add trailing comma - -ℹ Safe fix -516 516 | def function( -517 517 | foo, -518 518 | bar, -519 |- **kwargs - 519 |+ **kwargs, -520 520 | ): -521 521 | pass -522 522 | - -COM812 [*] Trailing comma missing - --> COM81.py:526:10 - | -524 | foo, -525 | bar, -526 | *args - | ^ -527 | ): -528 | pass - | -help: Add trailing comma - -ℹ Safe fix -523 523 | def function( -524 524 | foo, -525 525 | bar, -526 |- *args - 526 |+ *args, -527 527 | ): -528 528 | pass -529 529 | - -COM812 [*] Trailing comma missing - --> COM81.py:534:16 - | -532 | bar, -533 | *args, -534 | extra_kwarg - | ^ -535 | ): -536 | pass - | -help: Add trailing comma - -ℹ Safe fix -531 531 | foo, -532 532 | bar, -533 533 | *args, -534 |- extra_kwarg - 534 |+ extra_kwarg, -535 535 | ): -536 536 | pass -537 537 | - -COM812 [*] Trailing comma missing - --> COM81.py:541:13 - | -539 | foo, -540 | bar, -541 | **kwargs - | ^ -542 | ) - | -help: Add trailing comma - -ℹ Safe fix -538 538 | result = function( -539 539 | foo, -540 540 | bar, -541 |- **kwargs - 541 |+ **kwargs, -542 542 | ) -543 543 | -544 544 | result = function( - -COM812 [*] Trailing comma missing - --> COM81.py:547:24 - | -545 | foo, -546 | bar, -547 | **not_called_kwargs - | ^ -548 | ) - | -help: Add trailing comma - -ℹ Safe fix -544 544 | result = function( -545 545 | foo, -546 546 | bar, -547 |- **not_called_kwargs - 547 |+ **not_called_kwargs, -548 548 | ) -549 549 | -550 550 | def foo( - -COM812 [*] Trailing comma missing - --> COM81.py:554:15 - | -552 | spam, -553 | *args, -554 | kwarg_only - | ^ -555 | ): -556 | pass - | -help: Add trailing comma - -ℹ Safe fix -551 551 | ham, -552 552 | spam, -553 553 | *args, -554 |- kwarg_only - 554 |+ kwarg_only, -555 555 | ): -556 556 | pass -557 557 | - -COM812 [*] Trailing comma missing - --> COM81.py:561:13 - | -560 | foo( -561 | **kwargs - | ^ -562 | ) - | -help: Add trailing comma - -ℹ Safe fix -558 558 | # In python 3.5 if it's not a function def, commas are mandatory. -559 559 | -560 560 | foo( -561 |- **kwargs - 561 |+ **kwargs, -562 562 | ) -563 563 | -564 564 | { - -COM812 [*] Trailing comma missing - --> COM81.py:565:13 - | -564 | { -565 | **kwargs - | ^ -566 | } - | -help: Add trailing comma - -ℹ Safe fix -562 562 | ) -563 563 | -564 564 | { -565 |- **kwargs - 565 |+ **kwargs, -566 566 | } -567 567 | -568 568 | { - -COM812 [*] Trailing comma missing - --> COM81.py:569:10 - | -568 | { -569 | *args - | ^ -570 | } - | -help: Add trailing comma - -ℹ Safe fix -566 566 | } -567 567 | -568 568 | { -569 |- *args - 569 |+ *args, -570 570 | } -571 571 | -572 572 | [ - -COM812 [*] Trailing comma missing - --> COM81.py:573:10 - | -572 | [ -573 | *args - | ^ -574 | ] - | -help: Add trailing comma - -ℹ Safe fix -570 570 | } -571 571 | -572 572 | [ -573 |- *args - 573 |+ *args, -574 574 | ] -575 575 | -576 576 | def foo( - -COM812 [*] Trailing comma missing - --> COM81.py:579:10 - | -577 | ham, -578 | spam, -579 | *args - | ^ -580 | ): -581 | pass - | -help: Add trailing comma - -ℹ Safe fix -576 576 | def foo( -577 577 | ham, -578 578 | spam, -579 |- *args - 579 |+ *args, -580 580 | ): -581 581 | pass -582 582 | - -COM812 [*] Trailing comma missing - --> COM81.py:586:13 - | -584 | ham, -585 | spam, -586 | **kwargs - | ^ -587 | ): -588 | pass - | -help: Add trailing comma - -ℹ Safe fix -583 583 | def foo( -584 584 | ham, -585 585 | spam, -586 |- **kwargs - 586 |+ **kwargs, -587 587 | ): -588 588 | pass -589 589 | - -COM812 [*] Trailing comma missing - --> COM81.py:594:15 - | -592 | spam, -593 | *args, -594 | kwarg_only - | ^ -595 | ): -596 | pass - | -help: Add trailing comma - -ℹ Safe fix -591 591 | ham, -592 592 | spam, -593 593 | *args, -594 |- kwarg_only - 594 |+ kwarg_only, -595 595 | ): -596 596 | pass -597 597 | - -COM812 [*] Trailing comma missing - --> COM81.py:623:20 - | -621 | foo, -622 | bar, -623 | **{'ham': spam} - | ^ -624 | ) - | -help: Add trailing comma - -ℹ Safe fix -620 620 | result = function( -621 621 | foo, -622 622 | bar, -623 |- **{'ham': spam} - 623 |+ **{'ham': spam}, -624 624 | ) -625 625 | -626 626 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error. - -COM812 [*] Trailing comma missing - --> COM81.py:628:42 - | -626 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error. -627 | the_first_one = next( -628 | (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket - | ^ -629 | ) - | -help: Add trailing comma - -ℹ Safe fix -625 625 | -626 626 | # Make sure the COM812 and UP034 rules don't fix simultaneously and cause a syntax error. -627 627 | the_first_one = next( -628 |- (i for i in range(10) if i // 2 == 0) # COM812 fix should include the final bracket - 628 |+ (i for i in range(10) if i // 2 == 0), # COM812 fix should include the final bracket -629 629 | ) -630 630 | -631 631 | foo = namedtuple( - -COM819 [*] Trailing comma prohibited - --> COM81.py:640:46 - | -639 | # F-strings -640 | kwargs.pop("remove", f"this {trailing_comma}",) - | ^ -641 | -642 | raise Exception( - | -help: Remove trailing comma - -ℹ Safe fix -637 637 | ) -638 638 | -639 639 | # F-strings -640 |-kwargs.pop("remove", f"this {trailing_comma}",) - 640 |+kwargs.pop("remove", f"this {trailing_comma}") -641 641 | -642 642 | raise Exception( -643 643 | "first", extra=f"Add trailing comma here ->" - -COM812 [*] Trailing comma missing - --> COM81.py:643:49 - | -642 | raise Exception( -643 | "first", extra=f"Add trailing comma here ->" - | ^ -644 | ) - | -help: Add trailing comma - -ℹ Safe fix -640 640 | kwargs.pop("remove", f"this {trailing_comma}",) -641 641 | -642 642 | raise Exception( -643 |- "first", extra=f"Add trailing comma here ->" - 643 |+ "first", extra=f"Add trailing comma here ->", -644 644 | ) -645 645 | -646 646 | assert False, f"<- This is not a trailing comma" - -COM812 [*] Trailing comma missing - --> COM81.py:655:6 - | -654 | type X[ -655 | T - | ^ -656 | ] = T -657 | def f[ - | -help: Add trailing comma - -ℹ Safe fix -652 652 | }""" -653 653 | -654 654 | type X[ -655 |- T - 655 |+ T, -656 656 | ] = T -657 657 | def f[ -658 658 | T - -COM812 [*] Trailing comma missing - --> COM81.py:658:6 - | -656 | ] = T -657 | def f[ -658 | T - | ^ -659 | ](): pass -660 | class C[ - | -help: Add trailing comma - -ℹ Safe fix -655 655 | T -656 656 | ] = T -657 657 | def f[ -658 |- T - 658 |+ T, -659 659 | ](): pass -660 660 | class C[ -661 661 | T - -COM812 [*] Trailing comma missing - --> COM81.py:661:6 - | -659 | ](): pass -660 | class C[ -661 | T - | ^ -662 | ]: pass - | -help: Add trailing comma - -ℹ Safe fix -658 658 | T -659 659 | ](): pass -660 660 | class C[ -661 |- T - 661 |+ T, -662 662 | ]: pass -663 663 | -664 664 | type X[T,] = T - -COM819 [*] Trailing comma prohibited - --> COM81.py:664:9 - | -662 | ]: pass -663 | -664 | type X[T,] = T - | ^ -665 | def f[T,](): pass -666 | class C[T,]: pass - | -help: Remove trailing comma - -ℹ Safe fix -661 661 | T -662 662 | ]: pass -663 663 | -664 |-type X[T,] = T - 664 |+type X[T] = T -665 665 | def f[T,](): pass -666 666 | class C[T,]: pass - -COM819 [*] Trailing comma prohibited - --> COM81.py:665:8 - | -664 | type X[T,] = T -665 | def f[T,](): pass - | ^ -666 | class C[T,]: pass - | -help: Remove trailing comma - -ℹ Safe fix -662 662 | ]: pass -663 663 | -664 664 | type X[T,] = T -665 |-def f[T,](): pass - 665 |+def f[T](): pass -666 666 | class C[T,]: pass - -COM819 [*] Trailing comma prohibited - --> COM81.py:666:10 - | -664 | type X[T,] = T -665 | def f[T,](): pass -666 | class C[T,]: pass - | ^ - | -help: Remove trailing comma - -ℹ Safe fix -663 663 | -664 664 | type X[T,] = T -665 665 | def f[T,](): pass -666 |-class C[T,]: pass - 666 |+class C[T]: pass diff --git a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81_syntax_error.py.snap b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81_syntax_error.py.snap deleted file mode 100644 index be64c5452f3e5..0000000000000 --- a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview__COM81_syntax_error.py.snap +++ /dev/null @@ -1,33 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/flake8_commas/mod.rs ---- -invalid-syntax: Starred expression cannot be used here - --> COM81_syntax_error.py:3:5 - | -1 | # Check for `flake8-commas` violation for a file containing syntax errors. -2 | ( -3 | *args - | ^^^^^ -4 | ) - | - -invalid-syntax: Type parameter list cannot be empty - --> COM81_syntax_error.py:6:9 - | -4 | ) -5 | -6 | def foo[(param1='test', param2='test',): - | ^ -7 | pass - | - -COM819 Trailing comma prohibited - --> COM81_syntax_error.py:6:38 - | -4 | ) -5 | -6 | def foo[(param1='test', param2='test',): - | ^ -7 | pass - | -help: Remove trailing comma diff --git a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81.py.snap b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81.py.snap new file mode 100644 index 0000000000000..22eb0587e68ec --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81.py.snap @@ -0,0 +1,136 @@ +--- +source: crates/ruff_linter/src/rules/flake8_commas/mod.rs +--- +--- Linter settings --- +-linter.preview = disabled ++linter.preview = enabled + +--- Summary --- +Removed: 0 +Added: 6 + +--- Added --- +COM812 [*] Trailing comma missing + --> COM81.py:655:6 + | +654 | type X[ +655 | T + | ^ +656 | ] = T +657 | def f[ + | +help: Add trailing comma + +ℹ Safe fix +652 652 | }""" +653 653 | +654 654 | type X[ +655 |- T + 655 |+ T, +656 656 | ] = T +657 657 | def f[ +658 658 | T + + +COM812 [*] Trailing comma missing + --> COM81.py:658:6 + | +656 | ] = T +657 | def f[ +658 | T + | ^ +659 | ](): pass +660 | class C[ + | +help: Add trailing comma + +ℹ Safe fix +655 655 | T +656 656 | ] = T +657 657 | def f[ +658 |- T + 658 |+ T, +659 659 | ](): pass +660 660 | class C[ +661 661 | T + + +COM812 [*] Trailing comma missing + --> COM81.py:661:6 + | +659 | ](): pass +660 | class C[ +661 | T + | ^ +662 | ]: pass + | +help: Add trailing comma + +ℹ Safe fix +658 658 | T +659 659 | ](): pass +660 660 | class C[ +661 |- T + 661 |+ T, +662 662 | ]: pass +663 663 | +664 664 | type X[T,] = T + + +COM819 [*] Trailing comma prohibited + --> COM81.py:664:9 + | +662 | ]: pass +663 | +664 | type X[T,] = T + | ^ +665 | def f[T,](): pass +666 | class C[T,]: pass + | +help: Remove trailing comma + +ℹ Safe fix +661 661 | T +662 662 | ]: pass +663 663 | +664 |-type X[T,] = T + 664 |+type X[T] = T +665 665 | def f[T,](): pass +666 666 | class C[T,]: pass + + +COM819 [*] Trailing comma prohibited + --> COM81.py:665:8 + | +664 | type X[T,] = T +665 | def f[T,](): pass + | ^ +666 | class C[T,]: pass + | +help: Remove trailing comma + +ℹ Safe fix +662 662 | ]: pass +663 663 | +664 664 | type X[T,] = T +665 |-def f[T,](): pass + 665 |+def f[T](): pass +666 666 | class C[T,]: pass + + +COM819 [*] Trailing comma prohibited + --> COM81.py:666:10 + | +664 | type X[T,] = T +665 | def f[T,](): pass +666 | class C[T,]: pass + | ^ + | +help: Remove trailing comma + +ℹ Safe fix +663 663 | +664 664 | type X[T,] = T +665 665 | def f[T,](): pass +666 |-class C[T,]: pass + 666 |+class C[T]: pass diff --git a/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81_syntax_error.py.snap b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81_syntax_error.py.snap new file mode 100644 index 0000000000000..d845ec6e9def3 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_commas/snapshots/ruff_linter__rules__flake8_commas__tests__preview_diff__COM81_syntax_error.py.snap @@ -0,0 +1,10 @@ +--- +source: crates/ruff_linter/src/rules/flake8_commas/mod.rs +--- +--- Linter settings --- +-linter.preview = disabled ++linter.preview = enabled + +--- Summary --- +Removed: 0 +Added: 0 diff --git a/crates/ruff_linter/src/test.rs b/crates/ruff_linter/src/test.rs index 2dee7dcbb26ae..5c492a7780a41 100644 --- a/crates/ruff_linter/src/test.rs +++ b/crates/ruff_linter/src/test.rs @@ -2,6 +2,7 @@ //! Helper functions for the tests of rule implementations. use std::borrow::Cow; +use std::fmt; use std::path::Path; #[cfg(not(fuzzing))] @@ -32,6 +33,85 @@ use crate::source_kind::SourceKind; use crate::{Applicability, FixAvailability}; use crate::{Locator, directives}; +/// Represents the difference between two diagnostic runs. +#[derive(Debug)] +pub(crate) struct DiagnosticsDiff { + /// Diagnostics that were removed (present in 'before' but not in 'after') + removed: Vec, + /// Diagnostics that were added (present in 'after' but not in 'before') + added: Vec, + /// Settings used before the change + settings_before: LinterSettings, + /// Settings used after the change + settings_after: LinterSettings, +} + +impl fmt::Display for DiagnosticsDiff { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + writeln!(f, "--- Linter settings ---")?; + let settings_before_str = format!("{}", self.settings_before); + let settings_after_str = format!("{}", self.settings_after); + let diff = similar::TextDiff::from_lines(&settings_before_str, &settings_after_str); + for change in diff.iter_all_changes() { + match change.tag() { + similar::ChangeTag::Delete => write!(f, "-{change}")?, + similar::ChangeTag::Insert => write!(f, "+{change}")?, + similar::ChangeTag::Equal => (), + } + } + writeln!(f)?; + + writeln!(f, "--- Summary ---")?; + writeln!(f, "Removed: {}", self.removed.len())?; + writeln!(f, "Added: {}", self.added.len())?; + writeln!(f)?; + + if !self.removed.is_empty() { + writeln!(f, "--- Removed ---")?; + for diagnostic in &self.removed { + writeln!(f, "{}", print_messages(std::slice::from_ref(diagnostic)))?; + } + writeln!(f)?; + } + + if !self.added.is_empty() { + writeln!(f, "--- Added ---")?; + for diagnostic in &self.added { + writeln!(f, "{}", print_messages(std::slice::from_ref(diagnostic)))?; + } + writeln!(f)?; + } + + Ok(()) + } +} + +/// Compare two sets of diagnostics and return the differences +fn diff_diagnostics( + before: Vec, + after: Vec, + settings_before: &LinterSettings, + settings_after: &LinterSettings, +) -> DiagnosticsDiff { + let mut removed = Vec::new(); + let mut added = after; + + for old_diag in before { + let Some(pos) = added.iter().position(|diag| diag == &old_diag) else { + removed.push(old_diag); + continue; + }; + added.remove(pos); + } + + DiagnosticsDiff { + removed, + added, + settings_before: settings_before.clone(), + settings_after: settings_after.clone(), + } +} + #[cfg(not(fuzzing))] pub(crate) fn test_resource_path(path: impl AsRef) -> std::path::PathBuf { Path::new("./resources/test/").join(path) @@ -49,6 +129,30 @@ pub(crate) fn test_path( Ok(test_contents(&source_kind, &path, settings).0) } +/// Test a file with two different settings and return the differences +#[cfg(not(fuzzing))] +pub(crate) fn test_path_with_settings_diff( + path: impl AsRef, + settings_before: &LinterSettings, + settings_after: &LinterSettings, +) -> Result { + assert!( + format!("{settings_before}") != format!("{settings_after}"), + "Settings must be different for differential testing" + ); + + let diagnostics_before = test_path(&path, settings_before)?; + let diagnostic_after = test_path(&path, settings_after)?; + + let diff = diff_diagnostics( + diagnostics_before, + diagnostic_after, + settings_before, + settings_after, + ); + Ok(diff) +} + #[cfg(not(fuzzing))] pub(crate) struct TestedNotebook { pub(crate) diagnostics: Vec, @@ -400,3 +504,59 @@ macro_rules! assert_diagnostics { }); }}; } + +#[macro_export] +macro_rules! assert_diagnostics_diff { + ($snapshot:expr, $path:expr, $settings_before:expr, $settings_after:expr) => {{ + let diff = $crate::test::test_path_with_settings_diff($path, $settings_before, $settings_after)?; + insta::with_settings!({ omit_expression => true }, { + insta::assert_snapshot!($snapshot, format!("{}", diff)); + }); + }}; +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_diff_diagnostics() -> Result<()> { + use crate::codes::Rule; + use ruff_db::diagnostic::{DiagnosticId, LintName}; + + let settings_before = LinterSettings::for_rule(Rule::Print); + let settings_after = LinterSettings::for_rule(Rule::UnusedImport); + + let test_code = r#" +import sys +import unused_module + +def main(): + print(sys.version) +"#; + + let temp_dir = std::env::temp_dir(); + let test_file = temp_dir.join("test_diff.py"); + std::fs::write(&test_file, test_code)?; + + let diff = + super::test_path_with_settings_diff(&test_file, &settings_before, &settings_after)?; + + assert_eq!(diff.removed.len(), 1, "Should remove 1 print diagnostic"); + assert_eq!( + diff.removed[0].id(), + DiagnosticId::Lint(LintName::of("print")), + "Should remove the print diagnostic" + ); + assert_eq!(diff.added.len(), 1, "Should add 1 unused import diagnostic"); + assert_eq!( + diff.added[0].id(), + DiagnosticId::Lint(LintName::of("unused-import")), + "Should add the unused import diagnostic" + ); + + std::fs::remove_file(test_file)?; + + Ok(()) + } +} From 796819e7a0cc3ecc056797a997d34ffcca76af4a Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 22 Aug 2025 20:13:47 +0200 Subject: [PATCH 098/160] [ty] Disallow std::env and io methods in most ty crates (#20046) ## Summary We use the `System` abstraction in ty to abstract away the host/system on which ty runs. This has a few benefits: * Tests can run in full isolation using a memory system (that uses an in-memory file system) * The LSP has a custom implementation where `read_to_string` returns the content as seen by the editor (e.g. unsaved changes) instead of always returning the content as it is stored on disk * We don't require any file system polyfills for wasm in the browser However, it does require extra care that we don't accidentally use `std::fs` or `std::env` (etc.) methods in ty's code base (which is very easy). This PR sets up Clippy and disallows the most common methods, instead pointing users towards the corresponding `System` methods. The setup is a bit awkward because clippy doesn't support inheriting configurations. That means, a crate can only override the entire workspace configuration or not at all. The approach taken in this PR is: * Configure the disallowed methods at the workspace level * Allow `disallowed_methods` at the workspace level * Enable the lint at the crate level using the warn attribute (in code) The obvious downside is that it won't work if we ever want to disallow other methods, but we can figure that out once we reach that point. What about false positives: Just add an `allow` and move on with your life :) This isn't something that we have to enforce strictly; the goal is to catch accidental misuse. ## Test Plan Clippy found a place where we incorrectly used `std::fs::read_to_string` --- Cargo.toml | 3 + clippy.toml | 17 +++ crates/ruff_db/src/lib.rs | 9 ++ crates/ruff_db/src/system.rs | 4 +- crates/ruff_db/src/system/os.rs | 6 + crates/ruff_db/src/system/test.rs | 11 ++ crates/ty_combine/src/lib.rs | 5 + crates/ty_ide/src/lib.rs | 4 + crates/ty_project/src/lib.rs | 4 + crates/ty_project/src/watch/watcher.rs | 5 + crates/ty_python_semantic/src/lib.rs | 4 + .../src/module_resolver/list.rs | 5 + .../src/module_resolver/resolver.rs | 4 + .../src/module_resolver/typeshed.rs | 5 + .../ty_python_semantic/src/site_packages.rs | 128 ++++++++++++------ crates/ty_server/src/system.rs | 4 + crates/ty_static/src/lib.rs | 4 + crates/ty_test/src/db.rs | 4 + crates/ty_vendored/src/lib.rs | 4 + crates/ty_wasm/src/lib.rs | 4 + 20 files changed, 192 insertions(+), 42 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c7ac8d0596793..d489c9d54ece1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -215,6 +215,8 @@ unexpected_cfgs = { level = "warn", check-cfg = [ [workspace.lints.clippy] pedantic = { level = "warn", priority = -2 } +# Enabled at the crate level +disallowed_methods = "allow" # Allowed pedantic lints char_lit_as_u8 = "allow" collapsible_else_if = "allow" @@ -253,6 +255,7 @@ unused_peekable = "warn" # Diagnostics are not actionable: Enable once https://github.com/rust-lang/rust-clippy/issues/13774 is resolved. large_stack_arrays = "allow" + [profile.release] # Note that we set these explicitly, and these values # were chosen based on a trade-off between compile times diff --git a/clippy.toml b/clippy.toml index 539d63305be5a..c11a535aad663 100644 --- a/clippy.toml +++ b/clippy.toml @@ -24,3 +24,20 @@ ignore-interior-mutability = [ # The expression is read-only. "ruff_python_ast::hashable::HashableExpr", ] + +disallowed-methods = [ + { path = "std::env::var", reason = "Use System::env_var instead in ty crates" }, + { path = "std::env::current_dir", reason = "Use System::current_directory instead in ty crates" }, + { path = "std::fs::read_to_string", reason = "Use System::read_to_string instead in ty crates" }, + { path = "std::fs::metadata", reason = "Use System::path_metadata instead in ty crates" }, + { path = "std::fs::canonicalize", reason = "Use System::canonicalize_path instead in ty crates" }, + { path = "dunce::canonicalize", reason = "Use System::canonicalize_path instead in ty crates" }, + { path = "std::fs::read_dir", reason = "Use System::read_directory instead in ty crates" }, + { path = "std::fs::write", reason = "Use WritableSystem::write_file instead in ty crates" }, + { path = "std::fs::create_dir_all", reason = "Use WritableSystem::create_directory_all instead in ty crates" }, + { path = "std::fs::File::create_new", reason = "Use WritableSystem::create_new_file instead in ty crates" }, + # Path methods that have System trait equivalents + { path = "std::path::Path::exists", reason = "Use System::path_exists instead in ty crates" }, + { path = "std::path::Path::is_dir", reason = "Use System::is_directory instead in ty crates" }, + { path = "std::path::Path::is_file", reason = "Use System::is_file instead in ty crates" }, +] diff --git a/crates/ruff_db/src/lib.rs b/crates/ruff_db/src/lib.rs index 2a152ace72321..efc5b2c974ad5 100644 --- a/crates/ruff_db/src/lib.rs +++ b/crates/ruff_db/src/lib.rs @@ -1,3 +1,8 @@ +#![warn( + clippy::disallowed_methods, + reason = "Prefer System trait methods over std methods" +)] + use crate::files::Files; use crate::system::System; use crate::vendored::VendoredFileSystem; @@ -65,6 +70,10 @@ pub trait Db: salsa::Database { /// to process work in parallel. For example, to index a directory or checking the files of a project. /// ty can still spawn more threads for other tasks, e.g. to wait for a Ctrl+C signal or /// watching the files for changes. +#[expect( + clippy::disallowed_methods, + reason = "We don't have access to System here, but this is also only used by the CLI and the server which always run on a real system." +)] pub fn max_parallelism() -> NonZeroUsize { std::env::var(EnvVars::TY_MAX_PARALLELISM) .or_else(|_| std::env::var(EnvVars::RAYON_NUM_THREADS)) diff --git a/crates/ruff_db/src/system.rs b/crates/ruff_db/src/system.rs index e8b3062f9f862..8448cb9acb40e 100644 --- a/crates/ruff_db/src/system.rs +++ b/crates/ruff_db/src/system.rs @@ -46,7 +46,7 @@ pub type Result = std::io::Result; /// * File watching isn't supported. /// /// Abstracting the system also enables tests to use a more efficient in-memory file system. -pub trait System: Debug { +pub trait System: Debug + Sync + Send { /// Reads the metadata of the file or directory at `path`. /// /// This function will traverse symbolic links to query information about the destination file. @@ -197,6 +197,8 @@ pub trait System: Debug { fn as_any(&self) -> &dyn std::any::Any; fn as_any_mut(&mut self) -> &mut dyn std::any::Any; + + fn dyn_clone(&self) -> Box; } #[derive(Debug, Default, Copy, Clone, Eq, PartialEq)] diff --git a/crates/ruff_db/src/system/os.rs b/crates/ruff_db/src/system/os.rs index dd6a8eea99bab..b9f7e6e3db440 100644 --- a/crates/ruff_db/src/system/os.rs +++ b/crates/ruff_db/src/system/os.rs @@ -1,3 +1,5 @@ +#![allow(clippy::disallowed_methods)] + use super::walk_directory::{ self, DirectoryWalker, WalkDirectoryBuilder, WalkDirectoryConfiguration, WalkDirectoryVisitorBuilder, WalkState, @@ -255,6 +257,10 @@ impl System for OsSystem { fn env_var(&self, name: &str) -> std::result::Result { std::env::var(name) } + + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } } impl OsSystem { diff --git a/crates/ruff_db/src/system/test.rs b/crates/ruff_db/src/system/test.rs index f595aadca7a2f..73a05ba3d58be 100644 --- a/crates/ruff_db/src/system/test.rs +++ b/crates/ruff_db/src/system/test.rs @@ -146,6 +146,10 @@ impl System for TestSystem { fn case_sensitivity(&self) -> CaseSensitivity { self.system().case_sensitivity() } + + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } } impl Default for TestSystem { @@ -394,6 +398,13 @@ impl System for InMemorySystem { fn case_sensitivity(&self) -> CaseSensitivity { CaseSensitivity::CaseSensitive } + + fn dyn_clone(&self) -> Box { + Box::new(Self { + user_config_directory: Mutex::new(self.user_config_directory.lock().unwrap().clone()), + memory_fs: self.memory_fs.clone(), + }) + } } impl WritableSystem for InMemorySystem { diff --git a/crates/ty_combine/src/lib.rs b/crates/ty_combine/src/lib.rs index ab8b7a013b311..d2033cadd520d 100644 --- a/crates/ty_combine/src/lib.rs +++ b/crates/ty_combine/src/lib.rs @@ -1,3 +1,8 @@ +#![warn( + clippy::disallowed_methods, + reason = "Prefer System trait methods over std methods in ty crates" +)] + use std::{collections::HashMap, hash::BuildHasher}; use ordermap::OrderMap; diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index 17c9cc56230ad..922c551ebd7cb 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -1,3 +1,7 @@ +#![warn( + clippy::disallowed_methods, + reason = "Prefer System trait methods over std methods in ty crates" +)] mod completion; mod doc_highlights; mod docstring; diff --git a/crates/ty_project/src/lib.rs b/crates/ty_project/src/lib.rs index f9809541b46bf..53fd6ad3da8ff 100644 --- a/crates/ty_project/src/lib.rs +++ b/crates/ty_project/src/lib.rs @@ -1,3 +1,7 @@ +#![warn( + clippy::disallowed_methods, + reason = "Prefer System trait methods over std methods in ty crates" +)] use crate::glob::{GlobFilterCheckMode, IncludeResult}; use crate::metadata::options::{OptionDiagnostic, ToSettingsError}; use crate::walk::{ProjectFilesFilter, ProjectFilesWalker}; diff --git a/crates/ty_project/src/watch/watcher.rs b/crates/ty_project/src/watch/watcher.rs index f3789a526b9e9..83e10bbedee8b 100644 --- a/crates/ty_project/src/watch/watcher.rs +++ b/crates/ty_project/src/watch/watcher.rs @@ -1,3 +1,8 @@ +#![allow( + clippy::disallowed_methods, + reason = "This implementation is specific to real file systems." +)] + use notify::event::{CreateKind, MetadataKind, ModifyKind, RemoveKind, RenameMode}; use notify::{EventKind, RecommendedWatcher, RecursiveMode, Watcher as _, recommended_watcher}; diff --git a/crates/ty_python_semantic/src/lib.rs b/crates/ty_python_semantic/src/lib.rs index afd61f44caf8f..cf58ab93a6b03 100644 --- a/crates/ty_python_semantic/src/lib.rs +++ b/crates/ty_python_semantic/src/lib.rs @@ -1,3 +1,7 @@ +#![warn( + clippy::disallowed_methods, + reason = "Prefer System trait methods over std methods in ty crates" +)] use std::hash::BuildHasherDefault; use rustc_hash::FxHasher; diff --git a/crates/ty_python_semantic/src/module_resolver/list.rs b/crates/ty_python_semantic/src/module_resolver/list.rs index 2374a242125cf..0d0f95140cf17 100644 --- a/crates/ty_python_semantic/src/module_resolver/list.rs +++ b/crates/ty_python_semantic/src/module_resolver/list.rs @@ -363,6 +363,11 @@ fn is_python_extension(ext: &str) -> bool { #[cfg(test)] mod tests { + #![expect( + clippy::disallowed_methods, + reason = "These are tests, so it's fine to do I/O by-passing System." + )] + use camino::{Utf8Component, Utf8Path}; use ruff_db::Db as _; use ruff_db::files::{File, FilePath, FileRootKind}; diff --git a/crates/ty_python_semantic/src/module_resolver/resolver.rs b/crates/ty_python_semantic/src/module_resolver/resolver.rs index 6779a76042c1b..86e7c9fe59269 100644 --- a/crates/ty_python_semantic/src/module_resolver/resolver.rs +++ b/crates/ty_python_semantic/src/module_resolver/resolver.rs @@ -1115,6 +1115,10 @@ impl fmt::Display for RelaxedModuleName { #[cfg(test)] mod tests { + #![expect( + clippy::disallowed_methods, + reason = "These are tests, so it's fine to do I/O by-passing System." + )] use ruff_db::Db; use ruff_db::files::{File, FilePath, system_path_to_file}; use ruff_db::system::{DbWithTestSystem as _, DbWithWritableSystem as _}; diff --git a/crates/ty_python_semantic/src/module_resolver/typeshed.rs b/crates/ty_python_semantic/src/module_resolver/typeshed.rs index 5b67ae3c77a73..17b85397b4335 100644 --- a/crates/ty_python_semantic/src/module_resolver/typeshed.rs +++ b/crates/ty_python_semantic/src/module_resolver/typeshed.rs @@ -304,6 +304,11 @@ impl fmt::Display for PyVersionRange { #[cfg(test)] mod tests { + #![expect( + clippy::disallowed_methods, + reason = "These are tests, so it's fine to do I/O by-passing System." + )] + use std::fmt::Write as _; use std::num::{IntErrorKind, NonZeroU16}; use std::path::Path; diff --git a/crates/ty_python_semantic/src/site_packages.rs b/crates/ty_python_semantic/src/site_packages.rs index 1e94670365894..f7f84c8d7a948 100644 --- a/crates/ty_python_semantic/src/site_packages.rs +++ b/crates/ty_python_semantic/src/site_packages.rs @@ -211,7 +211,7 @@ impl PythonEnvironment { match VirtualEnvironment::new(path, system) { Ok(venv) => Ok(Self::Virtual(venv)), // If there's not a `pyvenv.cfg` marker, attempt to inspect as a system environment - Err(SitePackagesDiscoveryError::NoPyvenvCfgFile(path, _)) + Err(SitePackagesDiscoveryError::NoPyvenvCfgFile(path, _, _)) if !path.origin.must_be_virtual_env() => { Ok(Self::System(SystemEnvironment::new(path))) @@ -378,7 +378,13 @@ impl VirtualEnvironment { let pyvenv_cfg = match system.read_to_string(&pyvenv_cfg_path) { Ok(pyvenv_cfg) => pyvenv_cfg, - Err(err) => return Err(SitePackagesDiscoveryError::NoPyvenvCfgFile(path, err)), + Err(err) => { + return Err(SitePackagesDiscoveryError::NoPyvenvCfgFile( + path, + err, + system.dyn_clone(), + )); + } }; let parsed_pyvenv_cfg = @@ -833,16 +839,26 @@ impl SystemEnvironment { #[derive(Debug)] pub enum SitePackagesDiscoveryError { /// `site-packages` discovery failed because the provided path couldn't be canonicalized. - CanonicalizationError(SystemPathBuf, SysPrefixPathOrigin, io::Error), + CanonicalizationError( + SystemPathBuf, + SysPrefixPathOrigin, + io::Error, + Box, + ), /// `site-packages` discovery failed because the provided path doesn't appear to point to /// a Python executable or a `sys.prefix` directory. - PathNotExecutableOrDirectory(SystemPathBuf, SysPrefixPathOrigin, Option), + PathNotExecutableOrDirectory( + SystemPathBuf, + SysPrefixPathOrigin, + Option, + Box, + ), /// `site-packages` discovery failed because the [`SysPrefixPathOrigin`] indicated that /// the provided path should point to the `sys.prefix` of a virtual environment, /// but there was no file at `/pyvenv.cfg`. - NoPyvenvCfgFile(SysPrefixPath, io::Error), + NoPyvenvCfgFile(SysPrefixPath, io::Error, Box), /// `site-packages` discovery failed because the `pyvenv.cfg` file could not be parsed. PyvenvCfgParseError(SystemPathBuf, PyvenvCfgParseErrorKind), @@ -852,11 +868,11 @@ pub enum SitePackagesDiscoveryError { /// would be relative to the `sys.prefix` path, and we tried to fallback to iterating /// through the `/lib` directory looking for a `site-packages` directory, /// but we came across some I/O error while trying to do so. - CouldNotReadLibDirectory(SysPrefixPath), + CouldNotReadLibDirectory(SysPrefixPath, Box), /// We looked everywhere we could think of for the `site-packages` directory, /// but none could be found despite our best endeavours. - NoSitePackagesDirFound(SysPrefixPath), + NoSitePackagesDirFound(SysPrefixPath, Box), } /// Enumeration of ways in which stdlib discovery can fail. @@ -864,13 +880,13 @@ pub enum SitePackagesDiscoveryError { pub enum StdlibDiscoveryError { /// We looked everywhere we could think of for the standard library's directory, /// but none could be found despite our best endeavours. - NoStdlibFound(SysPrefixPath), + NoStdlibFound(SysPrefixPath, Box), /// Stdlib discovery failed because we're on a Unix system, /// we weren't able to figure out from the `pyvenv.cfg` file exactly where the stdlib /// would be relative to the `sys.prefix` path, and we tried to fallback to iterating /// through the `/lib` directory looking for a stdlib directory, /// but we came across some I/O error while trying to do so. - CouldNotReadLibDirectory(SysPrefixPath, io::Error), + CouldNotReadLibDirectory(SysPrefixPath, io::Error, Box), /// We failed to resolve the value of `sys.prefix`. NoSysPrefixFound(SystemPathBuf), } @@ -878,14 +894,14 @@ pub enum StdlibDiscoveryError { impl std::error::Error for SitePackagesDiscoveryError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - Self::CanonicalizationError(_, _, io_err) => Some(io_err), - Self::PathNotExecutableOrDirectory(_, _, io_err) => { + Self::CanonicalizationError(_, _, io_err, _) => Some(io_err), + Self::PathNotExecutableOrDirectory(_, _, io_err, _) => { io_err.as_ref().map(|e| e as &dyn std::error::Error) } - Self::NoPyvenvCfgFile(_, io_err) => Some(io_err), + Self::NoPyvenvCfgFile(_, io_err, _) => Some(io_err), Self::PyvenvCfgParseError(_, _) - | Self::CouldNotReadLibDirectory(_) - | Self::NoSitePackagesDirFound(_) => None, + | Self::CouldNotReadLibDirectory(_, _) + | Self::NoSitePackagesDirFound(_, _) => None, } } } @@ -893,10 +909,15 @@ impl std::error::Error for SitePackagesDiscoveryError { impl std::fmt::Display for SitePackagesDiscoveryError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::CanonicalizationError(given_path, origin, _) => { - display_error(f, origin, given_path, "Failed to canonicalize", None) - } - Self::PathNotExecutableOrDirectory(path, origin, _) => { + Self::CanonicalizationError(given_path, origin, _, system) => display_error( + f, + origin, + given_path, + "Failed to canonicalize", + None, + &**system, + ), + Self::PathNotExecutableOrDirectory(path, origin, _, system) => { let thing = if origin.must_point_directly_to_sys_prefix() { "directory on disk" } else { @@ -908,14 +929,16 @@ impl std::fmt::Display for SitePackagesDiscoveryError { path, &format!("Invalid {origin}"), Some(&format!("does not point to a {thing}")), + &**system, ) } - Self::NoPyvenvCfgFile(SysPrefixPath { inner, origin }, _) => display_error( + Self::NoPyvenvCfgFile(SysPrefixPath { inner, origin }, _, system) => display_error( f, origin, inner, &format!("Invalid {origin}"), Some("points to a broken venv with no pyvenv.cfg file"), + &**system, ), Self::PyvenvCfgParseError(path, kind) => { write!( @@ -923,14 +946,17 @@ impl std::fmt::Display for SitePackagesDiscoveryError { "Failed to parse the `pyvenv.cfg` file at `{path}` because {kind}" ) } - Self::CouldNotReadLibDirectory(SysPrefixPath { inner, origin }) => display_error( - f, - origin, - inner, - "Failed to iterate over the contents of the `lib`/`lib64` directories of the Python installation", - None, - ), - Self::NoSitePackagesDirFound(SysPrefixPath { inner, origin }) => display_error( + Self::CouldNotReadLibDirectory(SysPrefixPath { inner, origin }, system) => { + display_error( + f, + origin, + inner, + "Failed to iterate over the contents of the `lib`/`lib64` directories of the Python installation", + None, + &**system, + ) + } + Self::NoSitePackagesDirFound(SysPrefixPath { inner, origin }, system) => display_error( f, origin, inner, @@ -938,6 +964,7 @@ impl std::fmt::Display for SitePackagesDiscoveryError { Some( "Could not find a `site-packages` directory for this Python installation/executable", ), + &**system, ), } } @@ -946,8 +973,8 @@ impl std::fmt::Display for SitePackagesDiscoveryError { impl std::error::Error for StdlibDiscoveryError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - Self::CouldNotReadLibDirectory(_, io_err) => Some(io_err), - Self::NoStdlibFound(_) => None, + Self::CouldNotReadLibDirectory(_, io_err, _) => Some(io_err), + Self::NoStdlibFound(_, _) => None, Self::NoSysPrefixFound(_) => None, } } @@ -962,19 +989,23 @@ impl std::fmt::Display for StdlibDiscoveryError { "Failed to resolve a `sys.prefix` from the `pyvenv.cfg` file at `{path}`" ) } - Self::CouldNotReadLibDirectory(SysPrefixPath { inner, origin }, _) => display_error( - f, - origin, - inner, - "Failed to iterate over the contents of the `lib` directory of the Python installation", - None, - ), - Self::NoStdlibFound(SysPrefixPath { inner, origin }) => display_error( + Self::CouldNotReadLibDirectory(SysPrefixPath { inner, origin }, _, system) => { + display_error( + f, + origin, + inner, + "Failed to iterate over the contents of the `lib` directory of the Python installation", + None, + &**system, + ) + } + Self::NoStdlibFound(SysPrefixPath { inner, origin }, system) => display_error( f, origin, inner, &format!("Invalid {origin}"), Some("Could not find a stdlib directory for this Python installation/executable"), + &**system, ), } } @@ -986,6 +1017,7 @@ fn display_error( given_path: &SystemPath, primary_message: &str, secondary_message: Option<&str>, + system: &dyn System, ) -> std::fmt::Result { let fallback: &mut dyn FnMut() -> std::fmt::Result = &mut || { f.write_str(primary_message)?; @@ -1003,7 +1035,7 @@ fn display_error( return fallback(); }; - let Ok(config_file_source) = std::fs::read_to_string((**config_file_path).as_ref()) else { + let Ok(config_file_source) = system.read_to_string(config_file_path) else { return fallback(); }; @@ -1099,7 +1131,10 @@ fn site_packages_directories_from_sys_prefix( .is_directory(&site_packages) .then(|| SitePackagesPaths::from([site_packages])) .ok_or_else(|| { - SitePackagesDiscoveryError::NoSitePackagesDirFound(sys_prefix_path.to_owned()) + SitePackagesDiscoveryError::NoSitePackagesDirFound( + sys_prefix_path.to_owned(), + system.dyn_clone(), + ) }); } @@ -1206,10 +1241,12 @@ fn site_packages_directories_from_sys_prefix( if found_at_least_one_lib_dir { Err(SitePackagesDiscoveryError::NoSitePackagesDirFound( sys_prefix_path.to_owned(), + system.dyn_clone(), )) } else { Err(SitePackagesDiscoveryError::CouldNotReadLibDirectory( sys_prefix_path.to_owned(), + system.dyn_clone(), )) } } else { @@ -1238,7 +1275,7 @@ fn real_stdlib_directory_from_sys_prefix( if cfg!(target_os = "windows") { let stdlib = sys_prefix_path.join("Lib"); return system.is_directory(&stdlib).then_some(stdlib).ok_or( - StdlibDiscoveryError::NoStdlibFound(sys_prefix_path.to_owned()), + StdlibDiscoveryError::NoStdlibFound(sys_prefix_path.to_owned(), system.dyn_clone()), ); } @@ -1274,7 +1311,11 @@ fn real_stdlib_directory_from_sys_prefix( // must be `lib`, not `lib64`, for the stdlib .read_directory(&sys_prefix_path.join(UnixLibDir::Lib)) .map_err(|io_err| { - StdlibDiscoveryError::CouldNotReadLibDirectory(sys_prefix_path.to_owned(), io_err) + StdlibDiscoveryError::CouldNotReadLibDirectory( + sys_prefix_path.to_owned(), + io_err, + system.dyn_clone(), + ) })? { let Ok(entry) = entry_result else { @@ -1299,6 +1340,7 @@ fn real_stdlib_directory_from_sys_prefix( } Err(StdlibDiscoveryError::NoStdlibFound( sys_prefix_path.to_owned(), + system.dyn_clone(), )) } @@ -1357,6 +1399,7 @@ impl SysPrefixPath { unvalidated_path.to_path_buf(), origin, None, + system.dyn_clone(), )); }; sys_prefix @@ -1376,12 +1419,14 @@ impl SysPrefixPath { unvalidated_path, origin, Some(io_err), + system.dyn_clone(), ) } else { SitePackagesDiscoveryError::CanonicalizationError( unvalidated_path, origin, io_err, + system.dyn_clone(), ) }; return Err(err); @@ -1393,6 +1438,7 @@ impl SysPrefixPath { unvalidated_path.to_path_buf(), origin, None, + system.dyn_clone(), )); } diff --git a/crates/ty_server/src/system.rs b/crates/ty_server/src/system.rs index 7f5ad0cdfc355..46011daa44f82 100644 --- a/crates/ty_server/src/system.rs +++ b/crates/ty_server/src/system.rs @@ -298,6 +298,10 @@ impl System for LSPSystem { fn env_var(&self, name: &str) -> std::result::Result { self.native_system.env_var(name) } + + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } } fn not_a_text_document(path: impl Display) -> std::io::Error { diff --git a/crates/ty_static/src/lib.rs b/crates/ty_static/src/lib.rs index 153591db70828..65a46b624706b 100644 --- a/crates/ty_static/src/lib.rs +++ b/crates/ty_static/src/lib.rs @@ -1,3 +1,7 @@ +#![warn( + clippy::disallowed_methods, + reason = "Prefer System trait methods over std methods in ty crates" +)] pub use env_vars::*; mod env_vars; diff --git a/crates/ty_test/src/db.rs b/crates/ty_test/src/db.rs index 1a47745e1d3b2..100b26b5fb2c8 100644 --- a/crates/ty_test/src/db.rs +++ b/crates/ty_test/src/db.rs @@ -268,6 +268,10 @@ impl System for MdtestSystem { fn as_any_mut(&mut self) -> &mut dyn std::any::Any { self } + + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } } impl WritableSystem for MdtestSystem { diff --git a/crates/ty_vendored/src/lib.rs b/crates/ty_vendored/src/lib.rs index e6fd7e0a0b314..fa054443ff661 100644 --- a/crates/ty_vendored/src/lib.rs +++ b/crates/ty_vendored/src/lib.rs @@ -1,3 +1,7 @@ +#![warn( + clippy::disallowed_methods, + reason = "Prefer System trait methods over std methods in ty crates" +)] use ruff_db::vendored::VendoredFileSystem; use std::sync::LazyLock; diff --git a/crates/ty_wasm/src/lib.rs b/crates/ty_wasm/src/lib.rs index 413699866aeed..7b2c970ea359d 100644 --- a/crates/ty_wasm/src/lib.rs +++ b/crates/ty_wasm/src/lib.rs @@ -1231,6 +1231,10 @@ impl System for WasmSystem { fn as_any_mut(&mut self) -> &mut dyn Any { self } + + fn dyn_clone(&self) -> Box { + Box::new(self.clone()) + } } fn not_found() -> std::io::Error { From bc6ea68733f134dcc69d273a5508c5afdee5648c Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 22 Aug 2025 19:33:08 +0100 Subject: [PATCH 099/160] [ty] Add precise iteration and unpacking inference for string literals and bytes literals (#20023) ## Summary Previously we held off from doing this because we weren't sure that it was worth the added complexity cost. But our code has changed in the months since we made that initial decision, and I think the structure of the code is such that it no longer really leads to much added complexity to add precise inference when unpacking a string literal or a bytes literal. The improved inference we gain from this has real benefits to users (see the mypy_primer report), and this PR doesn't appear to have a performance impact. ## Test plan mdtests --- .../mdtest/exhaustiveness_checking.md | 16 ++ .../resources/mdtest/loops/for.md | 12 ++ .../resources/mdtest/unpacking.md | 142 +++++++++++++++--- crates/ty_python_semantic/src/types.rs | 76 +++++++--- 4 files changed, 203 insertions(+), 43 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/exhaustiveness_checking.md b/crates/ty_python_semantic/resources/mdtest/exhaustiveness_checking.md index 1854967eddb86..974d0be94f96f 100644 --- a/crates/ty_python_semantic/resources/mdtest/exhaustiveness_checking.md +++ b/crates/ty_python_semantic/resources/mdtest/exhaustiveness_checking.md @@ -74,6 +74,22 @@ def match_non_exhaustive(x: Literal[0, 1, "a"]): # this diagnostic is correct: the inferred type of `x` is `Literal[1]` assert_never(x) # error: [type-assertion-failure] + +# This is based on real-world code: +# https://github.com/scipy/scipy/blob/99c0ef6af161a4d8157cae5276a20c30b7677c6f/scipy/linalg/tests/test_lapack.py#L147-L171 +def exhaustiveness_using_containment_checks(): + for norm_str in "Mm1OoIiFfEe": + if norm_str in "FfEe": + return + else: + if norm_str in "Mm": + return + elif norm_str in "1Oo": + return + elif norm_str in "Ii": + return + + assert_never(norm_str) ``` ## Checks on enum literals diff --git a/crates/ty_python_semantic/resources/mdtest/loops/for.md b/crates/ty_python_semantic/resources/mdtest/loops/for.md index fbacb9b6bdbaa..9cc073b91e350 100644 --- a/crates/ty_python_semantic/resources/mdtest/loops/for.md +++ b/crates/ty_python_semantic/resources/mdtest/loops/for.md @@ -755,6 +755,18 @@ def f(never: Never): reveal_type(x) # revealed: Unknown ``` +## Iterating over literals + +```py +from typing import Literal + +for char in "abcde": + reveal_type(char) # revealed: Literal["a", "b", "c", "d", "e"] + +for char in b"abcde": + reveal_type(char) # revealed: Literal[97, 98, 99, 100, 101] +``` + ## A class literal is iterable if it inherits from `Any` A class literal can be iterated over if it has `Any` or `Unknown` in its MRO, since the diff --git a/crates/ty_python_semantic/resources/mdtest/unpacking.md b/crates/ty_python_semantic/resources/mdtest/unpacking.md index ef8cf63519c0e..5944bcc115b8d 100644 --- a/crates/ty_python_semantic/resources/mdtest/unpacking.md +++ b/crates/ty_python_semantic/resources/mdtest/unpacking.md @@ -523,8 +523,8 @@ def f(x: MixedTupleSubclass): ```py a, b = "ab" -reveal_type(a) # revealed: LiteralString -reveal_type(b) # revealed: LiteralString +reveal_type(a) # revealed: Literal["a"] +reveal_type(b) # revealed: Literal["b"] ``` ### Uneven unpacking (1) @@ -570,37 +570,37 @@ reveal_type(d) # revealed: Unknown ```py (a, *b, c) = "ab" -reveal_type(a) # revealed: LiteralString +reveal_type(a) # revealed: Literal["a"] reveal_type(b) # revealed: list[Never] -reveal_type(c) # revealed: LiteralString +reveal_type(c) # revealed: Literal["b"] ``` ### Starred expression (3) ```py (a, *b, c) = "abc" -reveal_type(a) # revealed: LiteralString -reveal_type(b) # revealed: list[LiteralString] -reveal_type(c) # revealed: LiteralString +reveal_type(a) # revealed: Literal["a"] +reveal_type(b) # revealed: list[Literal["b"]] +reveal_type(c) # revealed: Literal["c"] ``` ### Starred expression (4) ```py (a, *b, c, d) = "abcdef" -reveal_type(a) # revealed: LiteralString -reveal_type(b) # revealed: list[LiteralString] -reveal_type(c) # revealed: LiteralString -reveal_type(d) # revealed: LiteralString +reveal_type(a) # revealed: Literal["a"] +reveal_type(b) # revealed: list[Literal["b", "c", "d"]] +reveal_type(c) # revealed: Literal["e"] +reveal_type(d) # revealed: Literal["f"] ``` ### Starred expression (5) ```py (a, b, *c) = "abcd" -reveal_type(a) # revealed: LiteralString -reveal_type(b) # revealed: LiteralString -reveal_type(c) # revealed: list[LiteralString] +reveal_type(a) # revealed: Literal["a"] +reveal_type(b) # revealed: Literal["b"] +reveal_type(c) # revealed: list[Literal["c", "d"]] ``` ### Starred expression (6) @@ -650,8 +650,114 @@ reveal_type(b) # revealed: Unknown ```py (a, b) = "\ud800\udfff" +reveal_type(a) # revealed: Literal["�"] +reveal_type(b) # revealed: Literal["�"] +``` + +### Very long literal + +```py +string = "very long stringgggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg" + +a, *b = string reveal_type(a) # revealed: LiteralString -reveal_type(b) # revealed: LiteralString +reveal_type(b) # revealed: list[LiteralString] +``` + +## Bytes + +### Simple unpacking + +```py +a, b = b"ab" +reveal_type(a) # revealed: Literal[97] +reveal_type(b) # revealed: Literal[98] +``` + +### Uneven unpacking (1) + +```py +# error: [invalid-assignment] "Not enough values to unpack: Expected 3" +a, b, c = b"ab" +reveal_type(a) # revealed: Unknown +reveal_type(b) # revealed: Unknown +reveal_type(c) # revealed: Unknown +``` + +### Uneven unpacking (2) + +```py +# error: [invalid-assignment] "Too many values to unpack: Expected 2" +a, b = b"abc" +reveal_type(a) # revealed: Unknown +reveal_type(b) # revealed: Unknown +``` + +### Starred expression (1) + +```py +# error: [invalid-assignment] "Not enough values to unpack: Expected at least 3" +(a, *b, c, d) = b"ab" +reveal_type(a) # revealed: Unknown +reveal_type(b) # revealed: list[Unknown] +reveal_type(c) # revealed: Unknown +reveal_type(d) # revealed: Unknown +``` + +```py +# error: [invalid-assignment] "Not enough values to unpack: Expected at least 3" +(a, b, *c, d) = b"a" +reveal_type(a) # revealed: Unknown +reveal_type(b) # revealed: Unknown +reveal_type(c) # revealed: list[Unknown] +reveal_type(d) # revealed: Unknown +``` + +### Starred expression (2) + +```py +(a, *b, c) = b"ab" +reveal_type(a) # revealed: Literal[97] +reveal_type(b) # revealed: list[Never] +reveal_type(c) # revealed: Literal[98] +``` + +### Starred expression (3) + +```py +(a, *b, c) = b"abc" +reveal_type(a) # revealed: Literal[97] +reveal_type(b) # revealed: list[Literal[98]] +reveal_type(c) # revealed: Literal[99] +``` + +### Starred expression (4) + +```py +(a, *b, c, d) = b"abcdef" +reveal_type(a) # revealed: Literal[97] +reveal_type(b) # revealed: list[Literal[98, 99, 100]] +reveal_type(c) # revealed: Literal[101] +reveal_type(d) # revealed: Literal[102] +``` + +### Starred expression (5) + +```py +(a, b, *c) = b"abcd" +reveal_type(a) # revealed: Literal[97] +reveal_type(b) # revealed: Literal[98] +reveal_type(c) # revealed: list[Literal[99, 100]] +``` + +### Very long literal + +```py +too_long = b"very long bytes stringggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg" + +a, *b = too_long +reveal_type(a) # revealed: int +reveal_type(b) # revealed: list[int] ``` ## Union @@ -714,7 +820,7 @@ def _(arg: tuple[int, tuple[str, bytes]] | tuple[tuple[int, bytes], Literal["ab" a, (b, c) = arg reveal_type(a) # revealed: int | tuple[int, bytes] reveal_type(b) # revealed: str - reveal_type(c) # revealed: bytes | LiteralString + reveal_type(c) # revealed: bytes | Literal["b"] ``` ### Starred expression @@ -785,8 +891,8 @@ from typing import Literal def _(arg: tuple[int, int] | Literal["ab"]): a, b = arg - reveal_type(a) # revealed: int | LiteralString - reveal_type(b) # revealed: int | LiteralString + reveal_type(a) # revealed: int | Literal["a"] + reveal_type(b) # revealed: int | Literal["b"] ``` ### Custom iterator (1) diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index a583560192171..fe88b3fa7d6b1 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -4917,6 +4917,12 @@ impl<'db> Type<'db> { db: &'db dyn Db, mode: EvaluationMode, ) -> Result>, IterationError<'db>> { + // We will not infer precise heterogeneous tuple specs for literals with lengths above this threshold. + // The threshold here is somewhat arbitrary and conservative; it could be increased if needed. + // However, it's probably very rare to need heterogeneous unpacking inference for long string literals + // or bytes literals, and creating long heterogeneous tuple specs has a performance cost. + const MAX_TUPLE_LENGTH: usize = 128; + if mode.is_async() { let try_call_dunder_anext_on_iterator = |iterator: Type<'db>| -> Result< Result, AwaitError<'db>>, @@ -4972,26 +4978,38 @@ impl<'db> Type<'db> { }; } - match self { - Type::NominalInstance(nominal) => { - if let Some(spec) = nominal.tuple_spec(db) { - return Ok(spec); - } - } + let special_case = match self { + Type::NominalInstance(nominal) => nominal.tuple_spec(db), Type::GenericAlias(alias) if alias.origin(db).is_tuple(db) => { - return Ok(Cow::Owned(TupleSpec::homogeneous(todo_type!( + Some(Cow::Owned(TupleSpec::homogeneous(todo_type!( "*tuple[] annotations" - )))); + )))) } Type::StringLiteral(string_literal_ty) => { - // We could go further and deconstruct to an array of `StringLiteral` - // with each individual character, instead of just an array of - // `LiteralString`, but there would be a cost and it's not clear that - // it's worth it. - return Ok(Cow::Owned(TupleSpec::heterogeneous(std::iter::repeat_n( - Type::LiteralString, - string_literal_ty.python_len(db), - )))); + let string_literal = string_literal_ty.value(db); + let spec = if string_literal.len() < MAX_TUPLE_LENGTH { + TupleSpec::heterogeneous( + string_literal + .chars() + .map(|c| Type::string_literal(db, &c.to_string())), + ) + } else { + TupleSpec::homogeneous(Type::LiteralString) + }; + Some(Cow::Owned(spec)) + } + Type::BytesLiteral(bytes) => { + let bytes_literal = bytes.value(db); + let spec = if bytes_literal.len() < MAX_TUPLE_LENGTH { + TupleSpec::heterogeneous( + bytes_literal + .iter() + .map(|b| Type::IntLiteral(i64::from(*b))), + ) + } else { + TupleSpec::homogeneous(KnownClass::Int.to_instance(db)) + }; + Some(Cow::Owned(spec)) } Type::Never => { // The dunder logic below would have us return `tuple[Never, ...]`, which eagerly @@ -4999,25 +5017,27 @@ impl<'db> Type<'db> { // index into the tuple. Using `tuple[Unknown, ...]` avoids these false positives. // TODO: Consider removing this special case, and instead hide the indexing // diagnostic in unreachable code. - return Ok(Cow::Owned(TupleSpec::homogeneous(Type::unknown()))); + Some(Cow::Owned(TupleSpec::homogeneous(Type::unknown()))) } Type::TypeAlias(alias) => { - return alias.value_type(db).try_iterate_with_mode(db, mode); + Some(alias.value_type(db).try_iterate_with_mode(db, mode)?) } Type::NonInferableTypeVar(tvar) => match tvar.typevar(db).bound_or_constraints(db) { Some(TypeVarBoundOrConstraints::UpperBound(bound)) => { - return bound.try_iterate_with_mode(db, mode); + Some(bound.try_iterate_with_mode(db, mode)?) } // TODO: could we create a "union of tuple specs"...? // (Same question applies to the `Type::Union()` branch lower down) - Some(TypeVarBoundOrConstraints::Constraints(_)) | None => {} + Some(TypeVarBoundOrConstraints::Constraints(_)) | None => None }, Type::TypeVar(_) => unreachable!( "should not be able to iterate over type variable {} in inferable position", self.display(db) ), - Type::Dynamic(_) - | Type::FunctionLiteral(_) + // N.B. These special cases aren't strictly necessary, they're just obvious optimizations + Type::LiteralString | Type::Dynamic(_) => Some(Cow::Owned(TupleSpec::homogeneous(self))), + + Type::FunctionLiteral(_) | Type::GenericAlias(_) | Type::BoundMethod(_) | Type::MethodWrapper(_) @@ -5026,6 +5046,10 @@ impl<'db> Type<'db> { | Type::DataclassTransformer(_) | Type::Callable(_) | Type::ModuleLiteral(_) + // We could infer a precise tuple spec for enum classes with members, + // but it's not clear whether that's worth the added complexity: + // you'd have to check that `EnumMeta.__iter__` is not overridden for it to be sound + // (enums can have `EnumMeta` subclasses as their metaclasses). | Type::ClassLiteral(_) | Type::SubclassOf(_) | Type::ProtocolInstance(_) @@ -5039,11 +5063,13 @@ impl<'db> Type<'db> { | Type::IntLiteral(_) | Type::BooleanLiteral(_) | Type::EnumLiteral(_) - | Type::LiteralString - | Type::BytesLiteral(_) | Type::BoundSuper(_) | Type::TypeIs(_) - | Type::TypedDict(_) => {} + | Type::TypedDict(_) => None + }; + + if let Some(special_case) = special_case { + return Ok(special_case); } let try_call_dunder_getitem = || { From 886c4e477368c1f82745ab919d9c557cd15547b8 Mon Sep 17 00:00:00 2001 From: chiri Date: Fri, 22 Aug 2025 21:35:08 +0300 Subject: [PATCH 100/160] [`flake8-use-pathlib`] Fix `PTH211` autofix (#20049) ## Summary Part of #20009 --- .../flake8_use_pathlib/rules/os_symlink.rs | 17 +++-- ...lib__tests__preview__PTH211_PTH211.py.snap | 72 +++++++++++++++++-- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs index 43f5827383de5..57e068b93faab 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs @@ -1,4 +1,3 @@ -use anyhow::anyhow; use ruff_diagnostics::{Applicability, Edit, Fix}; use ruff_macros::{ViolationMetadata, derive_message_formats}; use ruff_python_ast::ExprCall; @@ -105,6 +104,14 @@ pub(crate) fn os_symlink(checker: &Checker, call: &ExprCall, segments: &[&str]) return; }; + let target_is_directory_arg = call.arguments.find_argument_value("target_is_directory", 2); + + if let Some(expr) = &target_is_directory_arg { + if expr.as_boolean_literal_expr().is_none() { + return; + } + } + diagnostic.try_set_fix(|| { let (import_edit, binding) = checker.importer().get_or_import_symbol( &ImportRequest::import("pathlib", "Path"), @@ -122,16 +129,14 @@ pub(crate) fn os_symlink(checker: &Checker, call: &ExprCall, segments: &[&str]) let src_code = locator.slice(src.range()); let dst_code = locator.slice(dst.range()); - let target_is_directory = call - .arguments - .find_argument_value("target_is_directory", 2) + let target_is_directory = target_is_directory_arg .and_then(|expr| { let code = locator.slice(expr.range()); expr.as_boolean_literal_expr() - .is_some_and(|bl| !bl.value) + .is_none_or(|bl| bl.value) .then_some(format!(", target_is_directory={code}")) }) - .ok_or_else(|| anyhow!("Non-boolean value passed for `target_is_directory`."))?; + .unwrap_or_default(); let replacement = if is_pathlib_path_call(checker, dst) { format!("{dst_code}.symlink_to({src_code}{target_is_directory})") diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap index 9fa340479f97d..d6f0db9f8a2b4 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview__PTH211_PTH211.py.snap @@ -1,7 +1,7 @@ --- source: crates/ruff_linter/src/rules/flake8_use_pathlib/mod.rs --- -PTH211 `os.symlink` should be replaced by `Path.symlink_to` +PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:5:1 | 5 | os.symlink("usr/bin/python", "tmp/python") @@ -11,7 +11,17 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | help: Replace with `Path(...).symlink_to(...)` -PTH211 `os.symlink` should be replaced by `Path.symlink_to` +ℹ Safe fix +2 2 | from pathlib import Path +3 3 | +4 4 | +5 |-os.symlink("usr/bin/python", "tmp/python") + 5 |+Path("tmp/python").symlink_to("usr/bin/python") +6 6 | os.symlink(b"usr/bin/python", b"tmp/python") +7 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok +8 8 | + +PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:6:1 | 5 | os.symlink("usr/bin/python", "tmp/python") @@ -21,7 +31,17 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | help: Replace with `Path(...).symlink_to(...)` -PTH211 `os.symlink` should be replaced by `Path.symlink_to` +ℹ Safe fix +3 3 | +4 4 | +5 5 | os.symlink("usr/bin/python", "tmp/python") +6 |-os.symlink(b"usr/bin/python", b"tmp/python") + 6 |+Path(b"tmp/python").symlink_to(b"usr/bin/python") +7 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok +8 8 | +9 9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True) + +PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:9:1 | 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok @@ -33,7 +53,17 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | help: Replace with `Path(...).symlink_to(...)` -PTH211 `os.symlink` should be replaced by `Path.symlink_to` +ℹ Safe fix +6 6 | os.symlink(b"usr/bin/python", b"tmp/python") +7 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok +8 8 | +9 |-os.symlink("usr/bin/python", "tmp/python", target_is_directory=True) + 9 |+Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) +10 10 | os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True) +11 11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok +12 12 | + +PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:10:1 | 9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True) @@ -43,6 +73,16 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | help: Replace with `Path(...).symlink_to(...)` +ℹ Safe fix +7 7 | Path("tmp/python").symlink_to("usr/bin/python") # Ok +8 8 | +9 9 | os.symlink("usr/bin/python", "tmp/python", target_is_directory=True) +10 |-os.symlink(b"usr/bin/python", b"tmp/python", target_is_directory=True) + 10 |+Path(b"tmp/python").symlink_to(b"usr/bin/python", target_is_directory=True) +11 11 | Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) # Ok +12 12 | +13 13 | fd = os.open(".", os.O_RDONLY) + PTH211 `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:17:1 | @@ -70,12 +110,12 @@ help: Replace with `Path(...).symlink_to(...)` 16 16 | 17 17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) 18 |-os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) - 18 |+Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=False) + 18 |+Path("tmp/python").symlink_to("usr/bin/python") 19 19 | 20 20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) 21 21 | -PTH211 `os.symlink` should be replaced by `Path.symlink_to` +PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:20:1 | 18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) @@ -87,7 +127,17 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | help: Replace with `Path(...).symlink_to(...)` -PTH211 `os.symlink` should be replaced by `Path.symlink_to` +ℹ Safe fix +17 17 | os.symlink(src="usr/bin/python", dst="tmp/python", unknown=True) +18 18 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory=False) +19 19 | +20 |-os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) + 20 |+Path("tmp/python").symlink_to("usr/bin/python") +21 21 | +22 22 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) +23 23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean") + +PTH211 [*] `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:22:1 | 20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) @@ -98,6 +148,14 @@ PTH211 `os.symlink` should be replaced by `Path.symlink_to` | help: Replace with `Path(...).symlink_to(...)` +ℹ Safe fix +19 19 | +20 20 | os.symlink(src="usr/bin/python", dst="tmp/python", dir_fd=None) +21 21 | +22 |-os.symlink("usr/bin/python", dst="tmp/python", target_is_directory= True ) + 22 |+Path("tmp/python").symlink_to("usr/bin/python", target_is_directory=True) +23 23 | os.symlink("usr/bin/python", dst="tmp/python", target_is_directory="nonboolean") + PTH211 `os.symlink` should be replaced by `Path.symlink_to` --> PTH211.py:23:1 | From 7abc41727b93fedb298f917451650fec435fecb7 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Fri, 22 Aug 2025 17:03:22 -0400 Subject: [PATCH 101/160] [ty] Shrink size of `AstNodeRef` (#20028) ## Summary Removes the `module_ptr` field from `AstNodeRef` in release mode, and change `NodeIndex` to a `NonZeroU32` to reduce the size of `Option>` fields. I believe CI runs in debug mode, so this won't show up in the memory report, but this reduces memory by ~2% in release mode. --- crates/ruff_db/src/parsed.rs | 14 +- .../src/rules/flake8_annotations/helpers.rs | 4 +- .../flake8_bugbear/rules/assert_false.rs | 8 +- .../rules/duplicate_exceptions.rs | 2 +- .../rules/setattr_with_constant.rs | 4 +- ...cessary_dict_comprehension_for_iterable.rs | 6 +- .../rules/multiple_starts_ends_with.rs | 12 +- .../rules/duplicate_literal_member.rs | 4 +- .../rules/duplicate_union_member.rs | 4 +- .../src/rules/flake8_pyi/rules/mod.rs | 6 +- .../rules/redundant_none_literal.rs | 6 +- .../rules/redundant_numeric_union.rs | 2 +- .../rules/unnecessary_literal_union.rs | 8 +- .../rules/unnecessary_type_union.rs | 18 +- .../flake8_pytest_style/rules/parametrize.rs | 14 +- .../rules/unittest_assert.rs | 26 +- .../flake8_simplify/rules/ast_bool_op.rs | 18 +- .../rules/flake8_simplify/rules/ast_expr.rs | 2 +- .../rules/flake8_simplify/rules/ast_ifexp.rs | 10 +- .../flake8_simplify/rules/ast_unary_op.rs | 10 +- .../if_else_block_instead_of_dict_get.rs | 14 +- .../rules/if_else_block_instead_of_if_exp.rs | 12 +- .../flake8_simplify/rules/needless_bool.rs | 12 +- .../rules/reimplemented_builtin.rs | 18 +- .../rules/split_static_string.rs | 4 +- .../rules/relative_imports.rs | 2 +- .../src/rules/flake8_type_checking/helpers.rs | 2 +- crates/ruff_linter/src/rules/flynt/helpers.rs | 4 +- .../flynt/rules/static_join_to_fstring.rs | 4 +- .../pycodestyle/rules/lambda_assignment.rs | 6 +- .../rules/pylint/rules/manual_import_from.rs | 4 +- .../src/rules/pylint/rules/nested_min_max.rs | 6 +- .../rules/repeated_equality_comparison.rs | 8 +- .../pylint/rules/unspecified_encoding.rs | 2 +- ...convert_named_tuple_functional_to_class.rs | 12 +- .../convert_typed_dict_functional_to_class.rs | 16 +- .../rules/pyupgrade/rules/native_literals.rs | 8 +- .../rules/pyupgrade/rules/os_error_alias.rs | 4 +- .../src/rules/pyupgrade/rules/pep695/mod.rs | 14 +- .../pyupgrade/rules/timeout_error_alias.rs | 4 +- .../rules/unnecessary_default_type_args.rs | 4 +- .../ruff_linter/src/rules/refurb/helpers.rs | 12 +- .../refurb/rules/check_and_remove_from_set.rs | 8 +- .../src/rules/refurb/rules/read_whole_file.rs | 6 +- .../refurb/rules/reimplemented_starmap.rs | 12 +- .../src/rules/refurb/rules/repeated_append.rs | 10 +- .../refurb/rules/unnecessary_enumerate.rs | 16 +- .../rules/refurb/rules/write_whole_file.rs | 6 +- .../ruff/rules/assert_with_print_message.rs | 16 +- .../rules/collection_literal_concatenation.rs | 6 +- .../src/rules/ruff/rules/implicit_optional.rs | 6 +- .../ruff/rules/legacy_form_pytest_raises.rs | 18 +- .../ruff/rules/mutable_fromkeys_value.rs | 6 +- .../src/rules/ruff/rules/never_union.rs | 4 +- .../ruff/rules/unnecessary_nested_literal.rs | 4 +- .../rules/unnecessary_regular_expression.rs | 10 +- crates/ruff_python_ast/src/helpers.rs | 52 +- crates/ruff_python_ast/src/node_index.rs | 112 +- crates/ruff_python_ast/src/nodes.rs | 10 +- .../src/comments/debug.rs | 4 +- .../src/comments/node_key.rs | 4 +- .../ruff_python_formatter/tests/normalizer.rs | 8 +- crates/ruff_python_parser/src/lib.rs | 2 +- .../src/parser/expression.rs | 130 +- crates/ruff_python_parser/src/parser/mod.rs | 4 +- .../ruff_python_parser/src/parser/pattern.rs | 58 +- ...parser__tests__expr_mode_valid_syntax.snap | 2 +- ...arser__tests__ipython_escape_commands.snap | 114 +- ...arser__parser__tests__unicode_aliases.snap | 8 +- .../src/parser/statement.rs | 86 +- ...arser__string__tests__backspace_alias.snap | 6 +- ...hon_parser__string__tests__bell_alias.snap | 6 +- ..._string__tests__carriage_return_alias.snap | 6 +- ...r_tabulation_with_justification_alias.snap | 6 +- ...n_parser__string__tests__delete_alias.snap | 6 +- ...ests__dont_panic_on_8_in_octal_escape.snap | 8 +- ...er__string__tests__double_quoted_byte.snap | 6 +- ...n_parser__string__tests__escape_alias.snap | 6 +- ...g__tests__escape_char_in_byte_literal.snap | 6 +- ...n_parser__string__tests__escape_octet.snap | 6 +- ...arser__string__tests__form_feed_alias.snap | 6 +- ...string__tests__fstring_constant_range.snap | 20 +- ...ing__tests__fstring_escaped_character.snap | 12 +- ...tring__tests__fstring_escaped_newline.snap | 12 +- ...ing__tests__fstring_line_continuation.snap | 12 +- ...__fstring_parse_self_documenting_base.snap | 10 +- ...ring_parse_self_documenting_base_more.snap | 18 +- ...fstring_parse_self_documenting_format.snap | 14 +- ...ing__tests__fstring_unescaped_newline.snap | 12 +- ...thon_parser__string__tests__hts_alias.snap | 6 +- ...r__string__tests__parse_empty_fstring.snap | 6 +- ...r__string__tests__parse_empty_tstring.snap | 6 +- ...tring__tests__parse_f_string_concat_1.snap | 10 +- ...tring__tests__parse_f_string_concat_2.snap | 10 +- ...tring__tests__parse_f_string_concat_3.snap | 16 +- ...tring__tests__parse_f_string_concat_4.snap | 18 +- ..._parser__string__tests__parse_fstring.snap | 16 +- ...__string__tests__parse_fstring_equals.snap | 14 +- ...ring_nested_concatenation_string_spec.snap | 20 +- ...ing__tests__parse_fstring_nested_spec.snap | 16 +- ...sts__parse_fstring_nested_string_spec.snap | 18 +- ...ring__tests__parse_fstring_not_equals.snap | 14 +- ..._tests__parse_fstring_not_nested_spec.snap | 14 +- ...ts__parse_fstring_self_doc_prec_space.snap | 10 +- ...parse_fstring_self_doc_trailing_space.snap | 10 +- ...ring__tests__parse_fstring_yield_expr.snap | 10 +- ...r__string__tests__parse_string_concat.snap | 8 +- ..._parse_string_triple_quotes_with_kind.snap | 6 +- ..._parser__string__tests__parse_tstring.snap | 16 +- ...__string__tests__parse_tstring_equals.snap | 14 +- ...ring_nested_concatenation_string_spec.snap | 20 +- ...ing__tests__parse_tstring_nested_spec.snap | 16 +- ...sts__parse_tstring_nested_string_spec.snap | 18 +- ...ring__tests__parse_tstring_not_equals.snap | 14 +- ..._tests__parse_tstring_not_nested_spec.snap | 14 +- ...ts__parse_tstring_self_doc_prec_space.snap | 10 +- ...parse_tstring_self_doc_trailing_space.snap | 10 +- ...ring__tests__parse_tstring_yield_expr.snap | 10 +- ...ing__tests__parse_u_f_string_concat_1.snap | 10 +- ...ing__tests__parse_u_f_string_concat_2.snap | 12 +- ...tring__tests__parse_u_string_concat_1.snap | 8 +- ...tring__tests__parse_u_string_concat_2.snap | 8 +- ...er__string__tests__raw_byte_literal_1.snap | 6 +- ...er__string__tests__raw_byte_literal_2.snap | 6 +- ...on_parser__string__tests__raw_fstring.snap | 10 +- ...on_parser__string__tests__raw_tstring.snap | 10 +- ...er__string__tests__single_quoted_byte.snap | 6 +- ..._tests__string_parser_escaped_mac_eol.snap | 6 +- ...tests__string_parser_escaped_unix_eol.snap | 6 +- ...ts__string_parser_escaped_windows_eol.snap | 6 +- ...ing__tests__triple_quoted_raw_fstring.snap | 10 +- ...ing__tests__triple_quoted_raw_tstring.snap | 10 +- ...string__tests__tstring_constant_range.snap | 20 +- ...ing__tests__tstring_escaped_character.snap | 12 +- ...tring__tests__tstring_escaped_newline.snap | 12 +- ...ing__tests__tstring_line_continuation.snap | 12 +- ...__tstring_parse_self_documenting_base.snap | 10 +- ...ring_parse_self_documenting_base_more.snap | 18 +- ...tstring_parse_self_documenting_format.snap | 14 +- ...ing__tests__tstring_unescaped_newline.snap | 12 +- crates/ruff_python_parser/src/string.rs | 16 +- ...ann_assign_stmt_invalid_annotation.py.snap | 44 +- ...tax@ann_assign_stmt_invalid_target.py.snap | 110 +- ...ntax@ann_assign_stmt_invalid_value.py.snap | 54 +- ...syntax@ann_assign_stmt_missing_rhs.py.snap | 8 +- ..._assign_stmt_type_alias_annotation.py.snap | 26 +- ...tax@args_unparenthesized_generator.py.snap | 82 +- .../invalid_syntax@assert_empty_msg.py.snap | 6 +- .../invalid_syntax@assert_empty_test.py.snap | 6 +- ...lid_syntax@assert_invalid_msg_expr.py.snap | 36 +- ...id_syntax@assert_invalid_test_expr.py.snap | 30 +- ..._syntax@assign_stmt_invalid_target.py.snap | 50 +- ...tax@assign_stmt_invalid_value_expr.py.snap | 76 +- ..._syntax@assign_stmt_keyword_target.py.snap | 36 +- ...lid_syntax@assign_stmt_missing_rhs.py.snap | 48 +- ...tax@assign_stmt_starred_expr_value.py.snap | 46 +- ...alid_syntax@async_unexpected_token.py.snap | 48 +- ...tax@aug_assign_stmt_invalid_target.py.snap | 48 +- ...ntax@aug_assign_stmt_invalid_value.py.snap | 64 +- ...syntax@aug_assign_stmt_missing_rhs.py.snap | 30 +- ..._syntax@case_expect_indented_block.py.snap | 22 +- ...nvalid_syntax@class_def_empty_body.py.snap | 18 +- ...alid_syntax@class_def_missing_name.py.snap | 36 +- ...class_def_unclosed_type_param_list.py.snap | 30 +- ...lid_syntax@class_type_params_py311.py.snap | 46 +- ...yntax@clause_expect_indented_block.py.snap | 12 +- ...tax@clause_expect_single_statement.py.snap | 12 +- ...ntax@comma_separated_missing_comma.py.snap | 16 +- ...ted_missing_comma_between_elements.py.snap | 12 +- ...ted_missing_element_between_commas.py.snap | 12 +- ...ma_separated_missing_first_element.py.snap | 12 +- ...prehension_missing_for_after_async.py.snap | 18 +- .../invalid_syntax@debug_shadow_class.py.snap | 24 +- ...valid_syntax@debug_shadow_function.py.snap | 50 +- ...invalid_syntax@debug_shadow_import.py.snap | 34 +- .../invalid_syntax@debug_shadow_match.py.snap | 16 +- .../invalid_syntax@debug_shadow_try.py.snap | 18 +- ...lid_syntax@debug_shadow_type_alias.py.snap | 24 +- .../invalid_syntax@debug_shadow_with.py.snap | 22 +- ...ax@decorator_await_expression_py38.py.snap | 28 +- ...syntax@decorator_dict_literal_py38.py.snap | 22 +- ...d_syntax@decorator_expression_py38.py.snap | 30 +- ...yntax@decorator_float_literal_py38.py.snap | 18 +- ...yntax@decorator_invalid_expression.py.snap | 44 +- ...yntax@decorator_missing_expression.py.snap | 48 +- ...d_syntax@decorator_missing_newline.py.snap | 46 +- ...ax@decorator_named_expression_py37.py.snap | 40 +- ..._non_toplevel_call_expression_py38.py.snap | 30 +- ..._syntax@decorator_unexpected_token.py.snap | 18 +- .../invalid_syntax@del_debug_py39.py.snap | 6 +- ...valid_syntax@del_incomplete_target.py.snap | 30 +- .../invalid_syntax@del_stmt_empty.py.snap | 4 +- ...d_syntax@dotted_name_multiple_dots.py.snap | 22 +- ..._syntax@duplicate_match_class_attr.py.snap | 220 +- ...invalid_syntax@duplicate_match_key.py.snap | 380 +-- ...tax@duplicate_type_parameter_names.py.snap | 178 +- .../invalid_syntax@except_star_py310.py.snap | 32 +- ...tax@except_stmt_invalid_expression.py.snap | 26 +- ...syntax@except_stmt_missing_as_name.py.snap | 18 +- ...ntax@except_stmt_missing_exception.py.snap | 30 +- ...stmt_missing_exception_and_as_name.py.snap | 10 +- ...cept_stmt_unparenthesized_tuple_as.py.snap | 34 +- ..._unparenthesized_tuple_no_as_py313.py.snap | 30 +- ...essions__arguments__double_starred.py.snap | 58 +- ...ments__duplicate_keyword_arguments.py.snap | 40 +- ...ons__arguments__invalid_expression.py.snap | 54 +- ...uments__invalid_keyword_expression.py.snap | 66 +- ...ressions__arguments__invalid_order.py.snap | 84 +- ...sions__arguments__missing_argument.py.snap | 14 +- ...ressions__arguments__missing_comma.py.snap | 14 +- ...ons__arguments__missing_expression.py.snap | 44 +- ...ax@expressions__arguments__starred.py.snap | 50 +- ...expressions__arguments__unclosed_0.py.snap | 20 +- ...expressions__arguments__unclosed_1.py.snap | 22 +- ...expressions__arguments__unclosed_2.py.snap | 22 +- ...essions__attribute__invalid_member.py.snap | 34 +- ...ressions__attribute__multiple_dots.py.snap | 42 +- ...@expressions__attribute__no_member.py.snap | 22 +- ...xpressions__await__no_expression_0.py.snap | 16 +- ...xpressions__await__no_expression_1.py.snap | 18 +- ...syntax@expressions__await__recover.py.snap | 84 +- ...ns__bin_op__invalid_rhs_expression.py.snap | 32 +- ...x@expressions__bin_op__missing_lhs.py.snap | 14 +- ...expressions__bin_op__missing_rhs_0.py.snap | 18 +- ...expressions__bin_op__missing_rhs_1.py.snap | 26 +- ...@expressions__bin_op__multiple_ops.py.snap | 38 +- ...ressions__bin_op__named_expression.py.snap | 30 +- ...ssions__bin_op__starred_expression.py.snap | 22 +- ...s__bool_op__invalid_rhs_expression.py.snap | 32 +- ...@expressions__bool_op__missing_lhs.py.snap | 6 +- ...@expressions__bool_op__missing_rhs.py.snap | 18 +- ...essions__bool_op__named_expression.py.snap | 26 +- ...sions__bool_op__starred_expression.py.snap | 22 +- ...xpressions__compare__invalid_order.py.snap | 36 +- ...s__compare__invalid_rhs_expression.py.snap | 32 +- ...@expressions__compare__missing_lhs.py.snap | 14 +- ...xpressions__compare__missing_rhs_0.py.snap | 18 +- ...xpressions__compare__missing_rhs_1.py.snap | 20 +- ...xpressions__compare__missing_rhs_2.py.snap | 18 +- ...ressions__compare__multiple_equals.py.snap | 22 +- ...essions__compare__named_expression.py.snap | 30 +- ...sions__compare__starred_expression.py.snap | 42 +- ...x@expressions__dict__comprehension.py.snap | 224 +- ...tax@expressions__dict__double_star.py.snap | 124 +- ...s__dict__double_star_comprehension.py.snap | 24 +- ...ons__dict__missing_closing_brace_0.py.snap | 18 +- ...ons__dict__missing_closing_brace_1.py.snap | 14 +- ...ons__dict__missing_closing_brace_2.py.snap | 20 +- ...ressions__dict__named_expression_0.py.snap | 30 +- ...ressions__dict__named_expression_1.py.snap | 30 +- ..._syntax@expressions__dict__recover.py.snap | 104 +- ...tax@expressions__emoji_identifiers.py.snap | 20 +- ...yntax@expressions__emoji_statement.py.snap | 2 +- ...essions__if__missing_orelse_expr_0.py.snap | 22 +- ...essions__if__missing_orelse_expr_1.py.snap | 20 +- ...pressions__if__missing_test_expr_0.py.snap | 22 +- ...pressions__if__missing_test_expr_1.py.snap | 20 +- ...id_syntax@expressions__if__recover.py.snap | 96 +- ...essions__lambda_default_parameters.py.snap | 32 +- ...sions__lambda_duplicate_parameters.py.snap | 110 +- ...x@expressions__list__comprehension.py.snap | 214 +- ...s__list__missing_closing_bracket_0.py.snap | 8 +- ...s__list__missing_closing_bracket_1.py.snap | 12 +- ...s__list__missing_closing_bracket_2.py.snap | 14 +- ...s__list__missing_closing_bracket_3.py.snap | 20 +- ..._syntax@expressions__list__recover.py.snap | 66 +- ...__list__star_expression_precedence.py.snap | 118 +- ...expressions__named__invalid_target.py.snap | 52 +- ...sions__named__missing_expression_0.py.snap | 6 +- ...sions__named__missing_expression_1.py.snap | 10 +- ...sions__named__missing_expression_2.py.snap | 20 +- ...sions__named__missing_expression_3.py.snap | 14 +- ...sions__named__missing_expression_4.py.snap | 18 +- ...ressions__parenthesized__generator.py.snap | 32 +- ...nthesized__missing_closing_paren_0.py.snap | 6 +- ...nthesized__missing_closing_paren_1.py.snap | 10 +- ...nthesized__missing_closing_paren_2.py.snap | 14 +- ...nthesized__missing_closing_paren_3.py.snap | 20 +- ...ions__parenthesized__parenthesized.py.snap | 16 +- ...@expressions__parenthesized__tuple.py.snap | 68 +- ..._parenthesized__tuple_starred_expr.py.snap | 340 ++- ...ax@expressions__set__comprehension.py.snap | 214 +- ...set__missing_closing_curly_brace_0.py.snap | 8 +- ...set__missing_closing_curly_brace_1.py.snap | 12 +- ...set__missing_closing_curly_brace_2.py.snap | 14 +- ...set__missing_closing_curly_brace_3.py.snap | 20 +- ...d_syntax@expressions__set__recover.py.snap | 66 +- ...s__set__star_expression_precedence.py.snap | 118 +- ...__subscript__invalid_slice_element.py.snap | 74 +- ...sions__subscript__unclosed_slice_0.py.snap | 16 +- ...sions__subscript__unclosed_slice_1.py.snap | 22 +- .../invalid_syntax@expressions__unary.py.snap | 12 +- ...pressions__unary__named_expression.py.snap | 22 +- ...xpressions__unary__no_expression_0.py.snap | 16 +- ...xpressions__unary__no_expression_1.py.snap | 16 +- ...pressions__yield__named_expression.py.snap | 26 +- ...xpressions__yield__star_expression.py.snap | 26 +- ...ns__yield_from__starred_expression.py.snap | 22 +- ...sions__yield_from__unparenthesized.py.snap | 38 +- ...ing_conversion_follows_exclamation.py.snap | 32 +- ...d_syntax@f_string_empty_expression.py.snap | 22 +- ...g_invalid_conversion_flag_name_tok.py.snap | 12 +- ..._invalid_conversion_flag_other_tok.py.snap | 22 +- ...ntax@f_string_invalid_starred_expr.py.snap | 44 +- ..._string_lambda_without_parentheses.py.snap | 26 +- ...id_syntax@f_string_unclosed_lbrace.py.snap | 48 +- ...ing_unclosed_lbrace_in_format_spec.py.snap | 32 +- ...nvalid_syntax@for_iter_unpack_py38.py.snap | 52 +- ..._syntax@for_stmt_invalid_iter_expr.py.snap | 42 +- ...lid_syntax@for_stmt_invalid_target.py.snap | 108 +- ...or_stmt_invalid_target_binary_expr.py.snap | 82 +- ...for_stmt_invalid_target_in_keyword.py.snap | 108 +- ...syntax@for_stmt_missing_in_keyword.py.snap | 22 +- ...valid_syntax@for_stmt_missing_iter.py.snap | 14 +- ...lid_syntax@for_stmt_missing_target.py.snap | 12 +- ...id_syntax@from_import_dotted_names.py.snap | 54 +- ...lid_syntax@from_import_empty_names.py.snap | 14 +- ..._syntax@from_import_missing_module.py.snap | 10 +- ...id_syntax@from_import_missing_rpar.py.snap | 42 +- ...@from_import_star_with_other_names.py.snap | 60 +- ...ort_unparenthesized_trailing_comma.py.snap | 32 +- ...lid_syntax@function_def_empty_body.py.snap | 26 +- ...x@function_def_invalid_return_expr.py.snap | 50 +- ...ax@function_def_missing_identifier.py.snap | 28 +- ...x@function_def_missing_return_type.py.snap | 14 +- ...nction_def_unclosed_parameter_list.py.snap | 68 +- ...ction_def_unclosed_type_param_list.py.snap | 46 +- ...n_def_unparenthesized_return_types.py.snap | 36 +- ..._syntax@function_type_params_py311.py.snap | 34 +- .../invalid_syntax@global_stmt_empty.py.snap | 4 +- ...alid_syntax@global_stmt_expression.py.snap | 12 +- ..._syntax@global_stmt_trailing_comma.py.snap | 14 +- ..._syntax@if_stmt_elif_missing_colon.py.snap | 18 +- .../invalid_syntax@if_stmt_empty_body.py.snap | 14 +- ...tax@if_stmt_invalid_elif_test_expr.py.snap | 24 +- ...d_syntax@if_stmt_invalid_test_expr.py.snap | 32 +- ...valid_syntax@if_stmt_missing_colon.py.snap | 18 +- ...nvalid_syntax@if_stmt_missing_test.py.snap | 10 +- ...lid_syntax@if_stmt_misspelled_elif.py.snap | 18 +- ...y_concatenated_unterminated_string.py.snap | 38 +- ...ated_unterminated_string_multiline.py.snap | 46 +- ...syntax@import_alias_missing_asname.py.snap | 8 +- .../invalid_syntax@import_stmt_empty.py.snap | 4 +- ...ax@import_stmt_parenthesized_names.py.snap | 18 +- ...lid_syntax@import_stmt_star_import.py.snap | 26 +- ..._syntax@import_stmt_trailing_comma.py.snap | 14 +- ...id_syntax@invalid_annotation_class.py.snap | 140 +- ...syntax@invalid_annotation_function.py.snap | 478 ++-- ...@invalid_annotation_function_py314.py.snap | 174 +- ...id_syntax@invalid_annotation_py314.py.snap | 52 +- ...ntax@invalid_annotation_type_alias.py.snap | 108 +- ...nvalid_syntax@invalid_byte_literal.py.snap | 20 +- .../invalid_syntax@invalid_del_target.py.snap | 48 +- ...ax@invalid_fstring_literal_element.py.snap | 18 +- ...alid_syntax@invalid_string_literal.py.snap | 14 +- ...id_syntax@irrefutable_case_pattern.py.snap | 110 +- ...lid_syntax@iter_unpack_return_py37.py.snap | 36 +- ...alid_syntax@iter_unpack_yield_py37.py.snap | 66 +- ...ntax@lambda_body_with_starred_expr.py.snap | 84 +- ...syntax@lambda_body_with_yield_expr.py.snap | 38 +- .../invalid_syntax@match_before_py310.py.snap | 14 +- ...d_syntax@match_classify_as_keyword.py.snap | 16 +- ..._classify_as_keyword_or_identifier.py.snap | 16 +- ...nvalid_syntax@match_expected_colon.py.snap | 18 +- ...x@match_stmt_expect_indented_block.py.snap | 14 +- ...tax@match_stmt_expected_case_block.py.snap | 28 +- ...ntax@match_stmt_invalid_guard_expr.py.snap | 56 +- ...ax@match_stmt_invalid_subject_expr.py.snap | 52 +- ...ntax@match_stmt_missing_guard_expr.py.snap | 16 +- ..._syntax@match_stmt_missing_pattern.py.snap | 16 +- ...@match_stmt_no_newline_before_case.py.snap | 14 +- ...@match_stmt_single_starred_subject.py.snap | 16 +- ...mixed_bytes_and_non_bytes_literals.py.snap | 32 +- ...ultiple_assignment_in_case_pattern.py.snap | 208 +- ...ntax@multiple_clauses_on_same_line.py.snap | 82 +- .../invalid_syntax@named_expr_slice.py.snap | 54 +- ...yntax@named_expr_slice_parse_error.py.snap | 20 +- ...x@nested_async_comprehension_py310.py.snap | 240 +- ...nvalid_syntax@node_range_with_gaps.py.snap | 30 +- ...nlocal_declaration_at_module_level.py.snap | 12 +- ...invalid_syntax@nonlocal_stmt_empty.py.snap | 12 +- ...id_syntax@nonlocal_stmt_expression.py.snap | 20 +- ...yntax@nonlocal_stmt_trailing_comma.py.snap | 22 +- ...id_syntax@param_missing_annotation.py.snap | 38 +- ...valid_syntax@param_missing_default.py.snap | 40 +- ...ntax@param_with_invalid_annotation.py.snap | 72 +- ..._syntax@param_with_invalid_default.py.snap | 68 +- ...param_with_invalid_star_annotation.py.snap | 92 +- ...x@param_with_star_annotation_py310.py.snap | 22 +- ...alid_syntax@params_duplicate_names.py.snap | 50 +- ...rams_expected_after_star_separator.py.snap | 78 +- ...@params_kwarg_after_star_separator.py.snap | 18 +- ...alid_syntax@params_multiple_kwargs.py.snap | 24 +- ...ax@params_multiple_slash_separator.py.snap | 56 +- ...tax@params_multiple_star_separator.py.snap | 56 +- ...lid_syntax@params_multiple_varargs.py.snap | 92 +- ..._syntax@params_no_arg_before_slash.py.snap | 32 +- ...x@params_non_default_after_default.py.snap | 36 +- ...lid_syntax@params_star_after_slash.py.snap | 106 +- ...ms_star_separator_after_star_param.py.snap | 64 +- ...ax@params_var_keyword_with_default.py.snap | 40 +- ...params_var_positional_with_default.py.snap | 32 +- ...parenthesized_context_manager_py38.py.snap | 52 +- ...id_syntax@parenthesized_kwarg_py38.py.snap | 44 +- ...valid_syntax@pep701_f_string_py311.py.snap | 190 +- .../invalid_syntax@pos_only_py37.py.snap | 90 +- ...syntax@raise_stmt_from_without_exc.py.snap | 10 +- ...id_syntax@raise_stmt_invalid_cause.py.snap | 28 +- ...alid_syntax@raise_stmt_invalid_exc.py.snap | 22 +- ...e_stmt_unparenthesized_tuple_cause.py.snap | 20 +- ...ise_stmt_unparenthesized_tuple_exc.py.snap | 26 +- ...nvalid_syntax@re_lex_logical_token.py.snap | 210 +- ...yntax@re_lex_logical_token_mac_eol.py.snap | 28 +- ...x@re_lex_logical_token_windows_eol.py.snap | 28 +- ...x@re_lexing__fstring_format_spec_1.py.snap | 76 +- ...tax@re_lexing__line_continuation_1.py.snap | 24 +- ...ing__line_continuation_windows_eol.py.snap | 24 +- ...re_lexing__triple_quoted_fstring_1.py.snap | 14 +- ...re_lexing__triple_quoted_fstring_2.py.snap | 16 +- ...re_lexing__triple_quoted_fstring_3.py.snap | 24 +- ...tax@rebound_comprehension_variable.py.snap | 250 +- ...id_syntax@return_stmt_invalid_expr.py.snap | 38 +- ...ple_and_compound_stmt_on_same_line.py.snap | 16 +- ...ompound_stmt_on_same_line_in_block.py.snap | 26 +- ...d_syntax@simple_stmts_on_same_line.py.snap | 36 +- ...simple_stmts_on_same_line_in_block.py.snap | 16 +- .../invalid_syntax@single_star_for.py.snap | 26 +- .../invalid_syntax@single_star_return.py.snap | 16 +- .../invalid_syntax@single_star_yield.py.snap | 18 +- ...x@single_starred_assignment_target.py.snap | 12 +- .../invalid_syntax@star_index_py310.py.snap | 102 +- .../invalid_syntax@star_slices.py.snap | 18 +- ...atements__function_type_parameters.py.snap | 110 +- ...ents__if_extra_closing_parentheses.py.snap | 8 +- ...syntax@statements__if_extra_indent.py.snap | 24 +- ...ements__invalid_assignment_targets.py.snap | 378 ++- ...nvalid_augmented_assignment_target.py.snap | 358 ++- ...ax@statements__match__as_pattern_0.py.snap | 24 +- ...ax@statements__match__as_pattern_1.py.snap | 18 +- ...ax@statements__match__as_pattern_2.py.snap | 26 +- ...ax@statements__match__as_pattern_3.py.snap | 28 +- ...ax@statements__match__as_pattern_4.py.snap | 24 +- ...ents__match__invalid_class_pattern.py.snap | 114 +- ..._match__invalid_lhs_or_rhs_pattern.py.snap | 284 +- ...ts__match__invalid_mapping_pattern.py.snap | 138 +- ...tements__match__star_pattern_usage.py.snap | 138 +- ...statements__match__unary_add_usage.py.snap | 112 +- ...s__with__ambiguous_lpar_with_items.py.snap | 416 +-- ...statements__with__empty_with_items.py.snap | 16 +- ...nts__with__unclosed_ambiguous_lpar.py.snap | 16 +- ..._with__unclosed_ambiguous_lpar_eof.py.snap | 8 +- ...__with__unparenthesized_with_items.py.snap | 88 +- ...d_syntax@t_string_empty_expression.py.snap | 22 +- ...g_invalid_conversion_flag_name_tok.py.snap | 12 +- ..._invalid_conversion_flag_other_tok.py.snap | 22 +- ...ntax@t_string_invalid_starred_expr.py.snap | 44 +- ..._string_lambda_without_parentheses.py.snap | 26 +- ...id_syntax@t_string_unclosed_lbrace.py.snap | 48 +- ...ing_unclosed_lbrace_in_format_spec.py.snap | 32 +- ...alid_syntax@template_strings_py313.py.snap | 30 +- ...alid_syntax@try_stmt_invalid_order.py.snap | 10 +- ...ax@try_stmt_missing_except_finally.py.snap | 12 +- ..._syntax@try_stmt_misspelled_except.py.snap | 44 +- ..._syntax@try_stmt_mixed_except_kind.py.snap | 54 +- ..._syntax@tuple_context_manager_py38.py.snap | 64 +- ..._syntax@type_alias_incomplete_stmt.py.snap | 20 +- ...ntax@type_alias_invalid_value_expr.py.snap | 36 +- ...id_syntax@type_param_default_py312.py.snap | 82 +- ...ntax@type_param_invalid_bound_expr.py.snap | 68 +- ...id_syntax@type_param_missing_bound.py.snap | 30 +- ...syntax@type_param_param_spec_bound.py.snap | 22 +- ...am_param_spec_invalid_default_expr.py.snap | 84 +- ...e_param_param_spec_missing_default.py.snap | 30 +- ...aram_type_var_invalid_default_expr.py.snap | 102 +- ...ype_param_type_var_missing_default.py.snap | 44 +- ...ax@type_param_type_var_tuple_bound.py.snap | 22 +- ...ype_var_tuple_invalid_default_expr.py.snap | 88 +- ...ram_type_var_tuple_missing_default.py.snap | 30 +- .../invalid_syntax@type_params_empty.py.snap | 26 +- .../invalid_syntax@type_stmt_py311.py.snap | 8 +- ...arenthesized_named_expr_index_py38.py.snap | 14 +- ...nthesized_named_expr_set_comp_py38.py.snap | 24 +- ...esized_named_expr_set_literal_py38.py.snap | 44 +- ...erminated_fstring_newline_recovery.py.snap | 78 +- .../invalid_syntax@walrus_py37.py.snap | 10 +- ...yntax@while_stmt_invalid_test_expr.py.snap | 46 +- ...id_syntax@while_stmt_missing_colon.py.snap | 12 +- ...lid_syntax@while_stmt_missing_test.py.snap | 20 +- ..._items_parenthesized_missing_colon.py.snap | 14 +- ..._items_parenthesized_missing_comma.py.snap | 92 +- ...invalid_syntax@write_to_debug_expr.py.snap | 44 +- ...ntax@all_async_comprehension_py310.py.snap | 42 +- ...iguous_lpar_with_items_binary_expr.py.snap | 110 +- ...@ambiguous_lpar_with_items_if_expr.py.snap | 86 +- ...ntax@ann_assign_stmt_simple_target.py.snap | 34 +- ...tax@args_unparenthesized_generator.py.snap | 90 +- ...tax@assign_stmt_starred_expr_value.py.snap | 40 +- ...d_syntax@assign_targets_terminator.py.snap | 38 +- .../valid_syntax@async_for_statement.py.snap | 12 +- ...d_syntax@async_function_definition.py.snap | 14 +- .../valid_syntax@async_with_statement.py.snap | 12 +- .../valid_syntax@class_def_arguments.py.snap | 20 +- ...ntax@class_keyword_in_case_pattern.py.snap | 26 +- ...lid_syntax@class_type_params_py312.py.snap | 36 +- ..._separated_regular_list_terminator.py.snap | 44 +- .../valid_syntax@debug_rename_import.py.snap | 28 +- ...id_syntax@decorator_async_function.py.snap | 18 +- ...ax@decorator_await_expression_py39.py.snap | 28 +- ...rator_expression_dotted_ident_py38.py.snap | 26 +- ...ecorator_expression_eval_hack_py38.py.snap | 26 +- ...ator_expression_identity_hack_py38.py.snap | 54 +- ...d_syntax@decorator_expression_py39.py.snap | 68 +- .../valid_syntax@del_debug_py38.py.snap | 6 +- ...alid_syntax@del_targets_terminator.py.snap | 30 +- ...ntax@dotted_name_normalized_spaces.py.snap | 14 +- ...id_syntax@duplicate_match_key_attr.py.snap | 34 +- .../valid_syntax@except_star_py311.py.snap | 16 +- ...x@except_stmt_as_name_soft_keyword.py.snap | 38 +- ..._unparenthesized_tuple_no_as_py314.py.snap | 30 +- ...alid_syntax@expressions__arguments.py.snap | 588 ++-- ...alid_syntax@expressions__attribute.py.snap | 82 +- .../valid_syntax@expressions__await.py.snap | 162 +- .../valid_syntax@expressions__bin_op.py.snap | 304 +-- .../valid_syntax@expressions__bool_op.py.snap | 114 +- .../valid_syntax@expressions__call.py.snap | 186 +- .../valid_syntax@expressions__compare.py.snap | 190 +- ...lid_syntax@expressions__dictionary.py.snap | 322 ++- ...ressions__dictionary_comprehension.py.snap | 300 ++- ...valid_syntax@expressions__f_string.py.snap | 656 +++-- ...alid_syntax@expressions__generator.py.snap | 202 +- .../valid_syntax@expressions__if.py.snap | 196 +- .../valid_syntax@expressions__lambda.py.snap | 614 ++--- .../valid_syntax@expressions__list.py.snap | 230 +- ...ax@expressions__list_comprehension.py.snap | 394 ++- .../valid_syntax@expressions__name.py.snap | 38 +- .../valid_syntax@expressions__named.py.snap | 102 +- ...syntax@expressions__number_literal.py.snap | 306 +-- ..._syntax@expressions__parenthesized.py.snap | 78 +- .../valid_syntax@expressions__set.py.snap | 176 +- ...tax@expressions__set_comprehension.py.snap | 226 +- .../valid_syntax@expressions__slice.py.snap | 184 +- .../valid_syntax@expressions__starred.py.snap | 102 +- .../valid_syntax@expressions__string.py.snap | 66 +- ...alid_syntax@expressions__subscript.py.snap | 220 +- ...valid_syntax@expressions__t_string.py.snap | 624 +++-- .../valid_syntax@expressions__tuple.py.snap | 204 +- ...valid_syntax@expressions__unary_op.py.snap | 156 +- .../valid_syntax@expressions__yield.py.snap | 134 +- ...lid_syntax@expressions__yield_from.py.snap | 114 +- ...id_syntax@for_in_target_valid_expr.py.snap | 56 +- .../valid_syntax@for_iter_unpack_py38.py.snap | 52 +- .../valid_syntax@for_iter_unpack_py39.py.snap | 52 +- .../valid_syntax@from_import_no_space.py.snap | 14 +- ...om_import_soft_keyword_module_name.py.snap | 34 +- ...syntax@from_import_stmt_terminator.py.snap | 74 +- ...tax@fstring_format_spec_terminator.py.snap | 36 +- ...yntax@function_def_parameter_range.py.snap | 32 +- ...ion_def_parenthesized_return_types.py.snap | 36 +- ...tax@function_def_valid_return_expr.py.snap | 66 +- ..._syntax@function_type_params_py312.py.snap | 20 +- .../valid_syntax@global_stmt.py.snap | 14 +- ...syntax@import_as_name_soft_keyword.py.snap | 26 +- ...alid_syntax@import_stmt_terminator.py.snap | 40 +- ...ax@irrefutable_case_pattern_at_end.py.snap | 74 +- ...lid_syntax@iter_unpack_return_py37.py.snap | 36 +- ...lid_syntax@iter_unpack_return_py38.py.snap | 36 +- ...alid_syntax@iter_unpack_yield_py37.py.snap | 38 +- ...alid_syntax@iter_unpack_yield_py38.py.snap | 66 +- ...d_syntax@lambda_with_no_parameters.py.snap | 8 +- ...alid_syntax@lambda_with_valid_body.py.snap | 130 +- .../valid_syntax@match_after_py310.py.snap | 14 +- .../valid_syntax@match_as_pattern.py.snap | 28 +- ...ntax@match_as_pattern_soft_keyword.py.snap | 44 +- ...ax@match_attr_pattern_soft_keyword.py.snap | 82 +- ...tax@match_classify_as_identifier_1.py.snap | 10 +- ...tax@match_classify_as_identifier_2.py.snap | 94 +- ...syntax@match_classify_as_keyword_1.py.snap | 182 +- ...syntax@match_classify_as_keyword_2.py.snap | 74 +- ..._classify_as_keyword_or_identifier.py.snap | 86 +- ...nce_pattern_parentheses_terminator.py.snap | 38 +- ...@match_sequence_pattern_terminator.py.snap | 62 +- ...lid_syntax@match_stmt_subject_expr.py.snap | 70 +- ...syntax@match_stmt_valid_guard_expr.py.snap | 90 +- ...ultiple_assignment_in_case_pattern.py.snap | 34 +- ...x@nested_async_comprehension_py310.py.snap | 84 +- ...x@nested_async_comprehension_py311.py.snap | 124 +- ...non_duplicate_type_parameter_names.py.snap | 122 +- ...non_rebound_comprehension_variable.py.snap | 24 +- ...nlocal_declaration_at_module_level.py.snap | 14 +- .../valid_syntax@nonlocal_stmt.py.snap | 22 +- .../valid_syntax@other__atom.py.snap | 18 +- .../valid_syntax@other__decorator.py.snap | 238 +- ...valid_syntax@param_with_annotation.py.snap | 54 +- .../valid_syntax@param_with_default.py.snap | 104 +- ..._syntax@param_with_star_annotation.py.snap | 50 +- ...x@param_with_star_annotation_py310.py.snap | 130 +- ...x@param_with_star_annotation_py311.py.snap | 22 +- ...ntax@params_non_default_after_star.py.snap | 86 +- ...seen_keyword_only_param_after_star.py.snap | 48 +- ...parenthesized_context_manager_py39.py.snap | 52 +- ...id_syntax@parenthesized_kwarg_py37.py.snap | 16 +- ...arenthesized_named_expr_index_py38.py.snap | 14 +- ...ntax@parenthesized_named_expr_py38.py.snap | 38 +- ...tax@parenthesized_star_index_py310.py.snap | 40 +- ...valid_syntax@pep701_f_string_py311.py.snap | 128 +- ...valid_syntax@pep701_f_string_py312.py.snap | 140 +- ...valid_syntax@pep750_t_string_py314.py.snap | 140 +- .../valid_syntax@pos_only_py38.py.snap | 20 +- .../valid_syntax@read_from_debug.py.snap | 16 +- ...valid_syntax@simple_stmts_in_block.py.snap | 36 +- ...yntax@simple_stmts_with_semicolons.py.snap | 28 +- .../valid_syntax@single_star_in_tuple.py.snap | 64 +- ...x@single_starred_assignment_target.py.snap | 38 +- .../valid_syntax@star_index_py311.py.snap | 102 +- ...atement__ambiguous_lpar_with_items.py.snap | 1238 ++++----- ...ax@statement__annotated_assignment.py.snap | 78 +- .../valid_syntax@statement__assert.py.snap | 104 +- ...valid_syntax@statement__assignment.py.snap | 250 +- ...ax@statement__augmented_assignment.py.snap | 136 +- .../valid_syntax@statement__class.py.snap | 408 ++- .../valid_syntax@statement__delete.py.snap | 84 +- .../valid_syntax@statement__for.py.snap | 184 +- ...alid_syntax@statement__from_import.py.snap | 86 +- .../valid_syntax@statement__function.py.snap | 1270 +++++---- .../valid_syntax@statement__if.py.snap | 216 +- .../valid_syntax@statement__import.py.snap | 50 +- .../valid_syntax@statement__match.py.snap | 2366 ++++++++--------- .../valid_syntax@statement__raise.py.snap | 138 +- .../valid_syntax@statement__return.py.snap | 98 +- .../valid_syntax@statement__simple.py.snap | 76 +- .../valid_syntax@statement__try.py.snap | 456 ++-- .../valid_syntax@statement__type.py.snap | 854 +++--- .../valid_syntax@statement__while.py.snap | 142 +- .../valid_syntax@statement__with.py.snap | 126 +- ...alid_syntax@template_strings_py314.py.snap | 30 +- ..._syntax@tuple_context_manager_py38.py.snap | 20 +- ...id_syntax@type_param_default_py313.py.snap | 54 +- ...valid_syntax@type_param_param_spec.py.snap | 62 +- .../valid_syntax@type_param_type_var.py.snap | 92 +- ...d_syntax@type_param_type_var_tuple.py.snap | 78 +- .../valid_syntax@type_stmt_py312.py.snap | 8 +- ...arenthesized_named_expr_index_py39.py.snap | 14 +- ...ax@unparenthesized_named_expr_py39.py.snap | 38 +- ...alid_syntax@valid_annotation_class.py.snap | 76 +- ...ax@valid_annotation_function_py313.py.snap | 174 +- ...alid_syntax@valid_annotation_py313.py.snap | 52 +- .../valid_syntax@walrus_py38.py.snap | 10 +- crates/ty_python_semantic/src/ast_node_ref.rs | 59 +- 648 files changed, 19635 insertions(+), 20358 deletions(-) diff --git a/crates/ruff_db/src/parsed.rs b/crates/ruff_db/src/parsed.rs index 77c71cc51680d..ad241b3ded211 100644 --- a/crates/ruff_db/src/parsed.rs +++ b/crates/ruff_db/src/parsed.rs @@ -92,14 +92,14 @@ impl ParsedModule { self.inner.store(None); } - /// Returns a pointer for this [`ParsedModule`]. + /// Returns the pointer address of this [`ParsedModule`]. /// /// The pointer uniquely identifies the module within the current Salsa revision, /// regardless of whether particular [`ParsedModuleRef`] instances are garbage collected. - pub fn as_ptr(&self) -> *const () { + pub fn addr(&self) -> usize { // Note that the outer `Arc` in `inner` is stable across garbage collection, while the inner // `Arc` within the `ArcSwap` may change. - Arc::as_ptr(&self.inner).cast() + Arc::as_ptr(&self.inner).addr() } } @@ -202,9 +202,13 @@ mod indexed { /// Returns the node at the given index. pub fn get_by_index<'ast>(&'ast self, index: NodeIndex) -> AnyRootNodeRef<'ast> { + let index = index + .as_u32() + .expect("attempted to access uninitialized `NodeIndex`"); + // Note that this method restores the correct lifetime: the nodes are valid for as // long as the reference to `IndexedModule` is alive. - self.index[index.as_usize()] + self.index[index as usize] } } @@ -220,7 +224,7 @@ mod indexed { T: HasNodeIndex + std::fmt::Debug, AnyRootNodeRef<'a>: From<&'a T>, { - node.node_index().set(self.index); + node.node_index().set(NodeIndex::from(self.index)); self.nodes.push(AnyRootNodeRef::from(node)); self.index += 1; } diff --git a/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs b/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs index c0289225f174d..adff541532b2f 100644 --- a/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_annotations/helpers.rs @@ -137,7 +137,7 @@ impl AutoPythonType { let expr = Expr::Name(ast::ExprName { id: Name::from(binding), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, }); Some((expr, vec![no_return_edit])) @@ -204,7 +204,7 @@ fn type_expr(python_type: PythonType) -> Option { Expr::Name(ast::ExprName { id: name.into(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, }) } diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs index 8708e4c487973..d1ba8edcdb164 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/assert_false.rs @@ -52,13 +52,13 @@ impl AlwaysFixableViolation for AssertFalse { fn assertion_error(msg: Option<&Expr>) -> Stmt { Stmt::Raise(ast::StmtRaise { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, exc: Some(Box::new(Expr::Call(ast::ExprCall { func: Box::new(Expr::Name(ast::ExprName { id: "AssertionError".into(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), arguments: Arguments { args: if let Some(msg) = msg { @@ -68,10 +68,10 @@ fn assertion_error(msg: Option<&Expr>) -> Stmt { }, keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }))), cause: None, }) diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs index f753152e4db45..7747f07df78b1 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/duplicate_exceptions.rs @@ -113,7 +113,7 @@ fn type_pattern(elts: Vec<&Expr>) -> Expr { elts: elts.into_iter().cloned().collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, } .into() diff --git a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs index 6244634ffa1fd..7e378a14ba6ae 100644 --- a/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs +++ b/crates/ruff_linter/src/rules/flake8_bugbear/rules/setattr_with_constant.rs @@ -53,11 +53,11 @@ fn assignment(obj: &Expr, name: &str, value: &Expr, generator: Generator) -> Str attr: Identifier::new(name.to_string(), TextRange::default()), ctx: ExprContext::Store, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })], value: Box::new(value.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); generator.stmt(&stmt) } diff --git a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs index 0ae136c25ec90..2618c4765ab22 100644 --- a/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs +++ b/crates/ruff_linter/src/rules/flake8_comprehensions/rules/unnecessary_dict_comprehension_for_iterable.rs @@ -209,18 +209,18 @@ fn fix_unnecessary_dict_comprehension(value: &Expr, generator: &Comprehension) - }, keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; Expr::Call(ExprCall { func: Box::new(Expr::Name(ExprName { id: "dict.fromkeys".into(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), arguments: args, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } diff --git a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs index 27c086833228d..2df842b862fd1 100644 --- a/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs +++ b/crates/ruff_linter/src/rules/flake8_pie/rules/multiple_starts_ends_with.rs @@ -178,21 +178,21 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }); let node1 = Expr::Name(ast::ExprName { id: arg_name.into(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let node2 = Expr::Attribute(ast::ExprAttribute { value: Box::new(node1), attr: Identifier::new(attr_name.to_string(), TextRange::default()), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let node3 = Expr::Call(ast::ExprCall { func: Box::new(node2), @@ -200,10 +200,10 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { args: Box::from([node]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let call = node3; @@ -223,7 +223,7 @@ pub(crate) fn multiple_starts_ends_with(checker: &Checker, expr: &Expr) { }) .collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let bool_op = node; diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs index fea4985036c4f..1f4c6210e4b8b 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_literal_member.rs @@ -92,14 +92,14 @@ pub(crate) fn duplicate_literal_member<'a>(checker: &Checker, expr: &'a Expr) { Expr::Tuple(ast::ExprTuple { elts: unique_nodes.into_iter().cloned().collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, parenthesized: false, }) }), value: subscript.value.clone(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, }); let fix = Fix::applicable_edit( diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs index 2fefb8e01dc7c..47d26ca8502af 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs @@ -187,7 +187,7 @@ fn generate_pep604_fix( op: Operator::BitOr, right: Box::new(right.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })) } else { Some(right.clone()) @@ -202,7 +202,7 @@ fn generate_pep604_fix( } static VIRTUAL_NONE_LITERAL: Expr = Expr::NoneLiteral(ExprNoneLiteral { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::new(TextSize::new(0), TextSize::new(0)), }); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs index 77e902da12476..beba88b70a2f2 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/mod.rs @@ -133,17 +133,17 @@ fn generate_union_fix( // Construct the expression as `Subscript[typing.Union, Tuple[expr, [expr, ...]]]` let new_expr = Expr::Subscript(ExprSubscript { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, value: Box::new(Expr::Name(ExprName { id: Name::new(binding), ctx: ExprContext::Store, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), slice: Box::new(Expr::Tuple(ExprTuple { elts: nodes.into_iter().cloned().collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, parenthesized: false, })), diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs index 12c4b01fb954e..eb188c245dfcf 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_none_literal.rs @@ -205,13 +205,13 @@ fn create_fix( let new_literal_expr = Expr::Subscript(ast::ExprSubscript { value: Box::new(literal_subscript.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, slice: Box::new(if literal_elements.len() > 1 { Expr::Tuple(ast::ExprTuple { elts: literal_elements.into_iter().cloned().collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, parenthesized: true, }) @@ -235,7 +235,7 @@ fn create_fix( UnionKind::BitOr => { let none_expr = Expr::NoneLiteral(ExprNoneLiteral { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let union_expr = pep_604_union(&[new_literal_expr, none_expr]); let content = checker.generator().expr(&union_expr); diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs index b493474929525..1197e70ea6b94 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/redundant_numeric_union.rs @@ -261,7 +261,7 @@ fn generate_pep604_fix( op: Operator::BitOr, right: Box::new(right.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })) } else { Some(right.clone()) diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs index 0765eeb48d0ff..3945afde33928 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_literal_union.rs @@ -140,12 +140,12 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &Checker, expr: &'a Expr) { slice: Box::new(Expr::Tuple(ast::ExprTuple { elts: literal_exprs.into_iter().cloned().collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, parenthesized: true, })), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, }); @@ -164,12 +164,12 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &Checker, expr: &'a Expr) { slice: Box::new(Expr::Tuple(ast::ExprTuple { elts, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, parenthesized: true, })), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, })) } else { diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs index 56d838b950af2..5906e7f4110b2 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/unnecessary_type_union.rs @@ -134,12 +134,12 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &Checker, union: &'a Expr) { id: Name::new_static("type"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), slice: Box::new(pep_604_union(&elts)), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); if other_exprs.is_empty() { @@ -159,7 +159,7 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &Checker, union: &'a Expr) { id: Name::new_static("type"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), slice: Box::new(Expr::Subscript(ast::ExprSubscript { value: subscript.value.clone(), @@ -171,22 +171,22 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &Checker, union: &'a Expr) { id: type_member, ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) }) .collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, })), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); if other_exprs.is_empty() { @@ -202,12 +202,12 @@ pub(crate) fn unnecessary_type_union<'a>(checker: &Checker, union: &'a Expr) { elts: exprs.into_iter().cloned().collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, })), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); checker.generator().expr(&union) diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs index bd3059e430a25..80877303527d9 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/parametrize.rs @@ -301,7 +301,7 @@ fn elts_to_csv(elts: &[Expr], generator: Generator, flags: StringLiteralFlags) - }) .into_boxed_str(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, flags, }); Some(generator.expr(&node)) @@ -367,14 +367,14 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr Expr::from(ast::StringLiteral { value: Box::from(*name), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, flags: checker.default_string_flags(), }) }) .collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( @@ -404,14 +404,14 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr Expr::from(ast::StringLiteral { value: Box::from(*name), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, flags: checker.default_string_flags(), }) }) .collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( checker.generator().expr(&node), @@ -440,7 +440,7 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr elts: elts.clone(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( checker.generator().expr(&node), @@ -485,7 +485,7 @@ fn check_names(checker: &Checker, call: &ExprCall, expr: &Expr, argvalues: &Expr elts: elts.clone(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( diff --git a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs index 650452c6a0f86..6a5f89a6af72d 100644 --- a/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs +++ b/crates/ruff_linter/src/rules/flake8_pytest_style/rules/unittest_assert.rs @@ -166,7 +166,7 @@ fn assert(expr: &Expr, msg: Option<&Expr>) -> Stmt { test: Box::new(expr.clone()), msg: msg.map(|msg| Box::new(msg.clone())), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } @@ -176,7 +176,7 @@ fn compare(left: &Expr, cmp_op: CmpOp, right: &Expr) -> Expr { ops: Box::from([cmp_op]), comparators: Box::from([right.clone()]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } @@ -296,7 +296,7 @@ impl UnittestAssert { op: UnaryOp::Not, operand: Box::new(expr.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }), msg, ) @@ -370,7 +370,7 @@ impl UnittestAssert { }; let node = Expr::NoneLiteral(ast::ExprNoneLiteral { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let expr = compare(expr, cmp_op, &node); Ok(assert(&expr, msg)) @@ -387,7 +387,7 @@ impl UnittestAssert { id: Name::new_static("isinstance"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node1 = ast::ExprCall { func: Box::new(node.into()), @@ -395,10 +395,10 @@ impl UnittestAssert { args: Box::from([(**obj).clone(), (**cls).clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let isinstance = node1.into(); if matches!(self, UnittestAssert::IsInstance) { @@ -408,7 +408,7 @@ impl UnittestAssert { op: UnaryOp::Not, operand: Box::new(isinstance), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let expr = node.into(); Ok(assert(&expr, msg)) @@ -429,14 +429,14 @@ impl UnittestAssert { id: Name::new_static("re"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node1 = ast::ExprAttribute { value: Box::new(node.into()), attr: Identifier::new("search".to_string(), TextRange::default()), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node2 = ast::ExprCall { func: Box::new(node1.into()), @@ -444,10 +444,10 @@ impl UnittestAssert { args: Box::from([(**regex).clone(), (**text).clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let re_search = node2.into(); if matches!(self, UnittestAssert::Regex | UnittestAssert::RegexpMatches) { @@ -457,7 +457,7 @@ impl UnittestAssert { op: UnaryOp::Not, operand: Box::new(re_search), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; Ok(assert(&node.into(), msg)) } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs index 7576c71fc11ba..398bd63860b04 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_bool_op.rs @@ -421,7 +421,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &Checker, expr: &Expr) { .collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }; let isinstance_call = ast::ExprCall { @@ -430,7 +430,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &Checker, expr: &Expr) { id: Name::new_static("isinstance"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -438,10 +438,10 @@ pub(crate) fn duplicate_isinstance_call(checker: &Checker, expr: &Expr) { args: Box::from([target.clone(), tuple.into()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(); @@ -458,7 +458,7 @@ pub(crate) fn duplicate_isinstance_call(checker: &Checker, expr: &Expr) { .chain(after) .collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(); let fixed_source = checker.generator().expr(&bool_op); @@ -552,21 +552,21 @@ pub(crate) fn compare_with_tuple(checker: &Checker, expr: &Expr) { elts: comparators.into_iter().cloned().collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }; let node1 = ast::ExprName { id: id.clone(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node2 = ast::ExprCompare { left: Box::new(node1.into()), ops: Box::from([CmpOp::In]), comparators: Box::from([node.into()]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let in_expr = node2.into(); let mut diagnostic = checker.report_diagnostic( @@ -589,7 +589,7 @@ pub(crate) fn compare_with_tuple(checker: &Checker, expr: &Expr) { op: BoolOp::Or, values: iter::once(in_expr).chain(unmatched).collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; node.into() }; diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs index afc2e88b04169..668dd6920a59c 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_expr.rs @@ -232,7 +232,7 @@ fn check_os_environ_subscript(checker: &Checker, expr: &Expr) { } }), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let new_env_var = node.into(); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs index 7ba5d6410ac72..1f4c12179f9ba 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_ifexp.rs @@ -188,7 +188,7 @@ pub(crate) fn if_expr_with_true_false( id: Name::new_static("bool"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -196,10 +196,10 @@ pub(crate) fn if_expr_with_true_false( args: Box::from([test.clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -227,7 +227,7 @@ pub(crate) fn if_expr_with_false_true( op: UnaryOp::Not, operand: Box::new(test.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -282,7 +282,7 @@ pub(crate) fn twisted_arms_in_ifexpr( body: Box::new(node1), orelse: Box::new(node), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( checker.generator().expr(&node3.into()), diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs index 37f3c16a8e8de..d00393aa664be 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/ast_unary_op.rs @@ -186,7 +186,7 @@ pub(crate) fn negation_with_equal_op(checker: &Checker, expr: &Expr, op: UnaryOp ops: Box::from([CmpOp::NotEq]), comparators: comparators.clone(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( checker.generator().expr(&node.into()), @@ -242,7 +242,7 @@ pub(crate) fn negation_with_not_equal_op( ops: Box::from([CmpOp::Eq]), comparators: comparators.clone(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( checker.generator().expr(&node.into()), @@ -284,7 +284,7 @@ pub(crate) fn double_negation(checker: &Checker, expr: &Expr, op: UnaryOp, opera id: Name::new_static("bool"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node1 = ast::ExprCall { func: Box::new(node.into()), @@ -292,10 +292,10 @@ pub(crate) fn double_negation(checker: &Checker, expr: &Expr, op: UnaryOp, opera args: Box::from([*operand.clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement( checker.generator().expr(&node1.into()), diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs index 505bfe58f75c8..1441c87154d00 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_dict_get.rs @@ -190,7 +190,7 @@ pub(crate) fn if_else_block_instead_of_dict_get(checker: &Checker, stmt_if: &ast attr: Identifier::new("get".to_string(), TextRange::default()), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node3 = ast::ExprCall { func: Box::new(node2.into()), @@ -198,17 +198,17 @@ pub(crate) fn if_else_block_instead_of_dict_get(checker: &Checker, stmt_if: &ast args: Box::from([node1, node]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node4 = expected_var.clone(); let node5 = ast::StmtAssign { targets: vec![node4], value: Box::new(node3.into()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let contents = checker.generator().stmt(&node5.into()); @@ -299,7 +299,7 @@ pub(crate) fn if_exp_instead_of_dict_get( attr: Identifier::new("get".to_string(), TextRange::default()), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let fixed_node = ast::ExprCall { func: Box::new(dict_get_node.into()), @@ -307,10 +307,10 @@ pub(crate) fn if_exp_instead_of_dict_get( args: Box::from([dict_key_node, default_value_node]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let contents = checker.generator().expr(&fixed_node.into()); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs index 97cbcb76ac3c0..db904d6dd1305 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/if_else_block_instead_of_if_exp.rs @@ -266,13 +266,13 @@ fn assignment_ternary( body: Box::new(body_value.clone()), orelse: Box::new(orelse_value.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node1 = ast::StmtAssign { targets: vec![target_var.clone()], value: Box::new(node.into()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; node1.into() } @@ -282,13 +282,13 @@ fn assignment_binary_and(target_var: &Expr, left_value: &Expr, right_value: &Exp op: BoolOp::And, values: vec![left_value.clone(), right_value.clone()], range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node1 = ast::StmtAssign { targets: vec![target_var.clone()], value: Box::new(node.into()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; node1.into() } @@ -296,12 +296,12 @@ fn assignment_binary_and(target_var: &Expr, left_value: &Expr, right_value: &Exp fn assignment_binary_or(target_var: &Expr, left_value: &Expr, right_value: &Expr) -> Stmt { (ast::StmtAssign { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, targets: vec![target_var.clone()], value: Box::new( (ast::ExprBoolOp { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, op: BoolOp::Or, values: vec![left_value.clone(), right_value.clone()], }) diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs index 679797a258301..1d64db5fc82e8 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/needless_bool.rs @@ -256,7 +256,7 @@ pub(crate) fn needless_bool(checker: &Checker, stmt: &Stmt) { left: left.clone(), comparators: Box::new([right.clone()]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })) } @@ -264,7 +264,7 @@ pub(crate) fn needless_bool(checker: &Checker, stmt: &Stmt) { op: ast::UnaryOp::Not, operand: Box::new(if_test.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), } } else if if_test.is_compare_expr() { @@ -277,7 +277,7 @@ pub(crate) fn needless_bool(checker: &Checker, stmt: &Stmt) { id: Name::new_static("bool"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let call_node = ast::ExprCall { func: Box::new(func_node.into()), @@ -285,10 +285,10 @@ pub(crate) fn needless_bool(checker: &Checker, stmt: &Stmt) { args: Box::from([if_test.clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; Some(Expr::Call(call_node)) } else { @@ -301,7 +301,7 @@ pub(crate) fn needless_bool(checker: &Checker, stmt: &Stmt) { Stmt::Return(ast::StmtReturn { value: Some(Box::new(expr.clone())), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) }); diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs index 88e1693d29878..5ad99330e8629 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/reimplemented_builtin.rs @@ -165,7 +165,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) { ops: Box::from([op]), comparators: Box::from([comparator.clone()]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; node.into() } else { @@ -173,7 +173,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) { op: UnaryOp::Not, operand: Box::new(loop_.test.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; node.into() } @@ -182,7 +182,7 @@ pub(crate) fn convert_for_loop_to_any_all(checker: &Checker, stmt: &Stmt) { op: UnaryOp::Not, operand: Box::new(loop_.test.clone()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; node.into() } @@ -406,17 +406,17 @@ fn return_stmt(id: Name, test: &Expr, target: &Expr, iter: &Expr, generator: Gen ifs: vec![], is_async: false, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }], range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: false, }; let node1 = ast::ExprName { id, ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node2 = ast::ExprCall { func: Box::new(node1.into()), @@ -424,15 +424,15 @@ fn return_stmt(id: Name, test: &Expr, target: &Expr, iter: &Expr, generator: Gen args: Box::from([node.into()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let node3 = ast::StmtReturn { value: Some(Box::new(node2.into())), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; generator.stmt(&node3.into()) } diff --git a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs index c8a6f46e03e00..7ab8b12a4f675 100644 --- a/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs +++ b/crates/ruff_linter/src/rules/flake8_simplify/rules/split_static_string.rs @@ -163,14 +163,14 @@ fn construct_replacement(elts: &[&str], flags: StringLiteralFlags) -> Expr { Expr::from(StringLiteral { value: Box::from(*elt), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, flags: element_flags, }) }) .collect(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } diff --git a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs index 1e6ac5e4ca8a5..e88906787be6e 100644 --- a/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs +++ b/crates/ruff_linter/src/rules/flake8_tidy_imports/rules/relative_imports.rs @@ -101,7 +101,7 @@ fn fix_banned_relative_import( names: names.clone(), level: 0, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let content = generator.stmt(&node.into()); Some(Fix::unsafe_edit(Edit::range_replacement( diff --git a/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs b/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs index 6725e2f4b0a5f..6a78d9d16c20d 100644 --- a/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs @@ -436,7 +436,7 @@ impl<'a> QuoteAnnotator<'a> { let annotation = subgenerator.expr(&expr_without_forward_references); generator.expr(&Expr::from(ast::StringLiteral { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, value: annotation.into_boxed_str(), flags: self.flags, })) diff --git a/crates/ruff_linter/src/rules/flynt/helpers.rs b/crates/ruff_linter/src/rules/flynt/helpers.rs index 58137a38165d8..96852d8961941 100644 --- a/crates/ruff_linter/src/rules/flynt/helpers.rs +++ b/crates/ruff_linter/src/rules/flynt/helpers.rs @@ -9,7 +9,7 @@ fn to_interpolated_string_interpolation_element(inner: &Expr) -> ast::Interpolat conversion: ConversionFlag::None, format_spec: None, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } @@ -18,7 +18,7 @@ pub(super) fn to_interpolated_string_literal_element(s: &str) -> ast::Interpolat ast::InterpolatedStringElement::Literal(ast::InterpolatedStringLiteralElement { value: Box::from(s), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } diff --git a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs index 6ac651fb66563..a385b910ec291 100644 --- a/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs +++ b/crates/ruff_linter/src/rules/flynt/rules/static_join_to_fstring.rs @@ -91,7 +91,7 @@ fn build_fstring(joiner: &str, joinees: &[Expr], flags: FStringFlags) -> Option< .into_boxed_str(), flags: flags?, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; return Some(node.into()); } @@ -114,7 +114,7 @@ fn build_fstring(joiner: &str, joinees: &[Expr], flags: FStringFlags) -> Option< let node = ast::FString { elements: f_string_elements.into(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, flags, }; Some(node.into()) diff --git a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs index 24c47e1c7c035..ba14e1ac198e1 100644 --- a/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs +++ b/crates/ruff_linter/src/rules/pycodestyle/rules/lambda_assignment.rs @@ -182,7 +182,7 @@ fn function( ExprEllipsisLiteral::default(), ))), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let parameters = lambda.parameters.as_deref().cloned().unwrap_or_default(); if let Some(annotation) = annotation { @@ -230,7 +230,7 @@ fn function( returns: Some(Box::new(return_type)), type_params: None, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let generated = checker.generator().stmt(&func); @@ -246,7 +246,7 @@ fn function( returns: None, type_params: None, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let generated = checker.generator().stmt(&function); diff --git a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs index 5f5cc9ccc9e17..c53c3c3ddd1c8 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/manual_import_from.rs @@ -72,11 +72,11 @@ pub(crate) fn manual_from_import(checker: &Checker, stmt: &Stmt, alias: &Alias, name: asname.clone(), asname: None, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }], level: 0, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; diagnostic.set_fix(Fix::safe_edit(Edit::range_replacement( checker.generator().stmt(&node.into()), diff --git a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs index b9be519243e0b..8b50510a879be 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/nested_min_max.rs @@ -147,7 +147,7 @@ fn collect_nested_args(min_max: MinMax, args: &[Expr], semantic: &SemanticModel) value: Box::new(arg.clone()), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); new_args.push(new_arg); continue; @@ -204,10 +204,10 @@ pub(crate) fn nested_min_max( args: collect_nested_args(min_max, args, checker.semantic()).into_boxed_slice(), keywords: Box::from(keywords), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement( checker.generator().expr(&flattened_expr), diff --git a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs index 4ac8f3f79f43b..c9c0c00e1c962 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/repeated_equality_comparison.rs @@ -170,13 +170,13 @@ pub(crate) fn repeated_equality_comparison(checker: &Checker, bool_op: &ast::Exp Expr::Set(ast::ExprSet { elts: comparators.iter().copied().cloned().collect(), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } else { Expr::Tuple(ast::ExprTuple { elts: comparators.iter().copied().cloned().collect(), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, ctx: ExprContext::Load, parenthesized: true, }) @@ -194,12 +194,12 @@ pub(crate) fn repeated_equality_comparison(checker: &Checker, bool_op: &ast::Exp }, comparators: Box::from([comparator]), range: bool_op.range(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }))) .chain(after) .collect(), range: bool_op.range(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })), bool_op.range(), ))); diff --git a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs index e6d9e43cc0ab2..a730ffd5674de 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/unspecified_encoding.rs @@ -188,7 +188,7 @@ fn generate_keyword_fix(checker: &Checker, call: &ast::ExprCall) -> Fix { value: Box::from("utf-8"), flags: checker.default_string_flags(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })) ), &call.arguments, diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs index 92f163a57559e..0974d66bb7c19 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_named_tuple_functional_to_class.rs @@ -87,7 +87,7 @@ pub(crate) fn convert_named_tuple_functional_to_class( // Ex) `NamedTuple("MyType")` ([_typename], []) => vec![Stmt::Pass(ast::StmtPass { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })], // Ex) `NamedTuple("MyType", [("a", int), ("b", str)])` ([_typename, fields], []) => { @@ -165,7 +165,7 @@ fn create_field_assignment_stmt(field: Name, annotation: &Expr) -> Stmt { id: field, ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -173,7 +173,7 @@ fn create_field_assignment_stmt(field: Name, annotation: &Expr) -> Stmt { value: None, simple: true, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into() } @@ -184,7 +184,7 @@ fn create_fields_from_fields_arg(fields: &Expr) -> Option> { if fields.is_empty() { let node = Stmt::Pass(ast::StmtPass { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); Some(vec![node]) } else { @@ -236,13 +236,13 @@ fn create_class_def_stmt(typename: &str, body: Vec, base_class: &Expr) -> args: Box::from([base_class.clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), body, type_params: None, decorator_list: vec![], range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into() } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs index 97f16190782ec..28b4b08a8e0f6 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/convert_typed_dict_functional_to_class.rs @@ -150,7 +150,7 @@ fn create_field_assignment_stmt(field: &str, annotation: &Expr) -> Stmt { id: field.into(), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -158,7 +158,7 @@ fn create_field_assignment_stmt(field: &str, annotation: &Expr) -> Stmt { value: None, simple: true, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into() } @@ -179,13 +179,13 @@ fn create_class_def_stmt( None => Box::from([]), }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), body, type_params: None, decorator_list: vec![], range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into() } @@ -194,7 +194,7 @@ fn fields_from_dict_literal(items: &[ast::DictItem]) -> Option> { if items.is_empty() { let node = Stmt::Pass(ast::StmtPass { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); Some(vec![node]) } else { @@ -228,7 +228,7 @@ fn fields_from_dict_call(func: &Expr, keywords: &[Keyword]) -> Option> if keywords.is_empty() { let node = Stmt::Pass(ast::StmtPass { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); Some(vec![node]) } else { @@ -241,7 +241,7 @@ fn fields_from_keywords(keywords: &[Keyword]) -> Option> { if keywords.is_empty() { let node = Stmt::Pass(ast::StmtPass { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); return Some(vec![node]); } @@ -282,7 +282,7 @@ fn match_fields_and_total(arguments: &Arguments) -> Option<(Vec, Option<&K ([_typename], []) => { let node = Stmt::Pass(ast::StmtPass { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); Some((vec![node], None)) } diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs index 4b2bbb1068d2d..0f1a301f1958b 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/native_literals.rs @@ -39,27 +39,27 @@ impl LiteralType { LiteralType::Str => ast::StringLiteral { value: Box::default(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, flags: checker.default_string_flags(), } .into(), LiteralType::Bytes => ast::BytesLiteral { value: Box::default(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, flags: checker.default_bytes_flags(), } .into(), LiteralType::Int => ast::ExprNumberLiteral { value: ast::Number::Int(Int::from(0u8)), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), LiteralType::Float => ast::ExprNumberLiteral { value: ast::Number::Float(0.0), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), LiteralType::Bool => ast::ExprBooleanLiteral::default().into(), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs index c08a49462f141..aeb01069f9c49 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/os_error_alias.rs @@ -116,7 +116,7 @@ fn tuple_diagnostic(checker: &Checker, tuple: &ast::ExprTuple, aliases: &[&Expr] id: Name::new_static("OSError"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; remaining.insert(0, node.into()); } @@ -128,7 +128,7 @@ fn tuple_diagnostic(checker: &Checker, tuple: &ast::ExprTuple, aliases: &[&Expr] elts: remaining, ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }; format!("({})", checker.generator().expr(&node.into())) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs index e364056de37d6..41ae88289fcc7 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/pep695/mod.rs @@ -140,14 +140,14 @@ impl<'a> From<&'a TypeVar<'a>> for TypeParam { TypeParamKind::TypeVar => { TypeParam::TypeVar(TypeParamTypeVar { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, name: Identifier::new(*name, TextRange::default()), bound: match restriction { Some(TypeVarRestriction::Bound(bound)) => Some(Box::new((*bound).clone())), Some(TypeVarRestriction::Constraint(constraints)) => { Some(Box::new(Expr::Tuple(ast::ExprTuple { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, elts: constraints.iter().map(|expr| (*expr).clone()).collect(), ctx: ast::ExprContext::Load, parenthesized: true, @@ -156,17 +156,17 @@ impl<'a> From<&'a TypeVar<'a>> for TypeParam { Some(TypeVarRestriction::AnyStr) => { Some(Box::new(Expr::Tuple(ast::ExprTuple { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, elts: vec![ Expr::Name(ExprName { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, id: Name::from("str"), ctx: ast::ExprContext::Load, }), Expr::Name(ExprName { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, id: Name::from("bytes"), ctx: ast::ExprContext::Load, }), @@ -184,13 +184,13 @@ impl<'a> From<&'a TypeVar<'a>> for TypeParam { } TypeParamKind::TypeVarTuple => TypeParam::TypeVarTuple(TypeParamTypeVarTuple { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, name: Identifier::new(*name, TextRange::default()), default: None, }), TypeParamKind::ParamSpec => TypeParam::ParamSpec(TypeParamParamSpec { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, name: Identifier::new(*name, TextRange::default()), default: None, }), diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs index c5c2e609b62a8..eadfdf8eb8c60 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/timeout_error_alias.rs @@ -130,7 +130,7 @@ fn tuple_diagnostic(checker: &Checker, tuple: &ast::ExprTuple, aliases: &[&Expr] id: Name::new_static("TimeoutError"), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; remaining.insert(0, node.into()); } @@ -142,7 +142,7 @@ fn tuple_diagnostic(checker: &Checker, tuple: &ast::ExprTuple, aliases: &[&Expr] elts: remaining, ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }; format!("({})", checker.generator().expr(&node.into())) diff --git a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs index ed1cba9f53df7..1bfebfe727b8b 100644 --- a/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs +++ b/crates/ruff_linter/src/rules/pyupgrade/rules/unnecessary_default_type_args.rs @@ -127,13 +127,13 @@ pub(crate) fn unnecessary_default_type_args(checker: &Checker, expr: &Expr) { elts: valid_elts, ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }) }), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), expr.range(), ), diff --git a/crates/ruff_linter/src/rules/refurb/helpers.rs b/crates/ruff_linter/src/rules/refurb/helpers.rs index 0c6749af8ce0b..90a624a0553e8 100644 --- a/crates/ruff_linter/src/rules/refurb/helpers.rs +++ b/crates/ruff_linter/src/rules/refurb/helpers.rs @@ -17,7 +17,7 @@ pub(super) fn generate_method_call(name: Name, method: &str, generator: Generato id: name, ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // Construct `name.method`. let attr = ast::ExprAttribute { @@ -25,7 +25,7 @@ pub(super) fn generate_method_call(name: Name, method: &str, generator: Generato attr: ast::Identifier::new(method.to_string(), TextRange::default()), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // Make it into a call `name.method()` let call = ast::ExprCall { @@ -34,16 +34,16 @@ pub(super) fn generate_method_call(name: Name, method: &str, generator: Generato args: Box::from([]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // And finally, turn it into a statement. let stmt = ast::StmtExpr { value: Box::new(call.into()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; generator.stmt(&stmt.into()) } @@ -69,7 +69,7 @@ pub(super) fn replace_with_identity_check( ops: [op].into(), comparators: [ast::ExprNoneLiteral::default().into()].into(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let new_content = generator.expr(&new_expr); diff --git a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs index ed2494f24bfcd..7aa11f94ba255 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/check_and_remove_from_set.rs @@ -185,7 +185,7 @@ fn make_suggestion(set: &ast::ExprName, element: &Expr, generator: Generator) -> attr: ast::Identifier::new("discard".to_string(), TextRange::default()), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // Make the actual call `set.discard(element)` let call = ast::ExprCall { @@ -194,16 +194,16 @@ fn make_suggestion(set: &ast::ExprName, element: &Expr, generator: Generator) -> args: Box::from([element.clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // And finally, turn it into a statement. let stmt = ast::StmtExpr { value: Box::new(call.into()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; generator.stmt(&stmt.into()) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs index cb18f0ff90a1b..af21f4f2472d7 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/read_whole_file.rs @@ -130,7 +130,7 @@ fn make_suggestion(open: &FileOpen<'_>, generator: Generator) -> SourceCodeSnipp id: open.mode.pathlib_method(), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let call = ast::ExprCall { func: Box::new(name.into()), @@ -138,10 +138,10 @@ fn make_suggestion(open: &FileOpen<'_>, generator: Generator) -> SourceCodeSnipp args: Box::from([]), keywords: open.keywords.iter().copied().cloned().collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; SourceCodeSnippet::from_str(&generator.expr(&call.into())) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs index 874e6620d2353..592d7fb7590b9 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/reimplemented_starmap.rs @@ -298,7 +298,7 @@ fn construct_starmap_call(starmap_binding: Name, iter: &Expr, func: &Expr) -> as id: starmap_binding, ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; ast::ExprCall { func: Box::new(starmap.into()), @@ -306,10 +306,10 @@ fn construct_starmap_call(starmap_binding: Name, iter: &Expr, func: &Expr) -> as args: Box::from([func.clone(), iter.clone()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } } @@ -319,7 +319,7 @@ fn wrap_with_call_to(call: ast::ExprCall, func_name: Name) -> ast::ExprCall { id: func_name, ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; ast::ExprCall { func: Box::new(name.into()), @@ -327,10 +327,10 @@ fn wrap_with_call_to(call: ast::ExprCall, func_name: Name) -> ast::ExprCall { args: Box::from([call.into()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } } diff --git a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs index d3c8259ec9d96..aaf7e8883161b 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/repeated_append.rs @@ -342,7 +342,7 @@ fn make_suggestion(group: &AppendGroup, generator: Generator) -> String { elts, ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, }; // Make `var.extend`. @@ -352,7 +352,7 @@ fn make_suggestion(group: &AppendGroup, generator: Generator) -> String { attr: ast::Identifier::new("extend".to_string(), TextRange::default()), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // Make the actual call `var.extend((elt1, elt2, ..., eltN))` let call = ast::ExprCall { @@ -361,16 +361,16 @@ fn make_suggestion(group: &AppendGroup, generator: Generator) -> String { args: Box::from([tuple.into()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // And finally, turn it into a statement. let stmt = ast::StmtExpr { value: Box::new(call.into()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; generator.stmt(&stmt.into()) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs index db8e3fb1c3bc0..4d3ab8268903d 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/unnecessary_enumerate.rs @@ -232,7 +232,7 @@ fn generate_range_len_call(name: Name, generator: Generator) -> String { id: name, ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // Construct `len(name)`. let len = ast::ExprCall { @@ -241,7 +241,7 @@ fn generate_range_len_call(name: Name, generator: Generator) -> String { id: Name::new_static("len"), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -249,10 +249,10 @@ fn generate_range_len_call(name: Name, generator: Generator) -> String { args: Box::from([var.into()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // Construct `range(len(name))`. let range = ast::ExprCall { @@ -261,7 +261,7 @@ fn generate_range_len_call(name: Name, generator: Generator) -> String { id: Name::new_static("range"), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), ), @@ -269,16 +269,16 @@ fn generate_range_len_call(name: Name, generator: Generator) -> String { args: Box::from([len.into()]), keywords: Box::from([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // And finally, turn it into a statement. let stmt = ast::StmtExpr { value: Box::new(range.into()), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; generator.stmt(&stmt.into()) } diff --git a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs index 2440f4236c93e..ab3a3f24806d2 100644 --- a/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs +++ b/crates/ruff_linter/src/rules/refurb/rules/write_whole_file.rs @@ -148,7 +148,7 @@ fn make_suggestion(open: &FileOpen<'_>, arg: &Expr, generator: Generator) -> Sou id: open.mode.pathlib_method(), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let mut arg = arg.clone(); relocate_expr(&mut arg, TextRange::default()); @@ -158,10 +158,10 @@ fn make_suggestion(open: &FileOpen<'_>, arg: &Expr, generator: Generator) -> Sou args: Box::new([arg]), keywords: open.keywords.iter().copied().cloned().collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; SourceCodeSnippet::from_str(&generator.expr(&call.into())) } diff --git a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs index 41f72bbdc5ea7..2d34e63a0c37e 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/assert_with_print_message.rs @@ -68,7 +68,7 @@ pub(crate) fn assert_with_print_message(checker: &Checker, stmt: &ast::StmtAsser test: stmt.test.clone(), msg: print_arguments::to_expr(&call.arguments, checker).map(Box::new), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), // We have to replace the entire statement, // as the `print` could be empty and thus `call.range()` @@ -114,7 +114,7 @@ mod print_arguments { InterpolatedStringElement::Literal(InterpolatedStringLiteralElement { value: part.value.clone(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) }) .collect(), @@ -131,7 +131,7 @@ mod print_arguments { conversion: ConversionFlag::None, format_spec: None, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, )], } @@ -154,7 +154,7 @@ mod print_arguments { value: literal.value.clone(), flags, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); Some(acc) } else { @@ -212,7 +212,7 @@ mod print_arguments { value: combined_string.into(), flags, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })) } @@ -246,10 +246,10 @@ mod print_arguments { elements: InterpolatedStringElements::from(fstring_elements), flags, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })) } @@ -285,7 +285,7 @@ mod print_arguments { vec![InterpolatedStringElement::Literal( InterpolatedStringLiteralElement { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, value: " ".into(), }, )] diff --git a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs index f8cd2b9c36238..8c38154151430 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/collection_literal_concatenation.rs @@ -78,7 +78,7 @@ fn make_splat_elts( value: Box::from(splat_element.clone()), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; let splat = node.into(); if splat_at_left { @@ -166,14 +166,14 @@ fn concatenate_expressions(expr: &Expr) -> Option<(Expr, Type)> { elts: new_elts, ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, } .into(), Type::Tuple => ast::ExprTuple { elts: new_elts, ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, } .into(), diff --git a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs index 83c0065d8bc83..35294f2843c10 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/implicit_optional.rs @@ -140,7 +140,7 @@ fn generate_fix(checker: &Checker, conversion_type: ConversionType, expr: &Expr) op: Operator::BitOr, right: Box::new(Expr::NoneLiteral(ast::ExprNoneLiteral::default())), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); let content = checker.generator().expr(&new_expr); let edit = Edit::range_replacement(content, expr.range()); @@ -160,12 +160,12 @@ fn generate_fix(checker: &Checker, conversion_type: ConversionType, expr: &Expr) let (import_edit, binding) = importer.import(expr.start())?; let new_expr = Expr::Subscript(ast::ExprSubscript { range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, value: Box::new(Expr::Name(ast::ExprName { id: Name::new(binding), ctx: ast::ExprContext::Store, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })), slice: Box::new(expr.clone()), ctx: ast::ExprContext::Load, diff --git a/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs b/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs index 5dc94542dab0d..4e7081a6b4bbe 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/legacy_form_pytest_raises.rs @@ -245,16 +245,16 @@ fn generate_with_statement( }); let context_call = ast::ExprCall { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), func: legacy_call.func.clone(), arguments: ast::Arguments { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), args: expected.cloned().as_slice().into(), keywords: match_arg .map(|expr| ast::Keyword { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, // Take range from the original expression so that the keyword // argument is generated after positional arguments range: expr.range(), @@ -267,11 +267,11 @@ fn generate_with_statement( }; let func_call = ast::ExprCall { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), func: Box::new(func.clone()), arguments: ast::Arguments { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), args: func_args.into(), keywords: func_keywords.into(), @@ -280,25 +280,25 @@ fn generate_with_statement( let body = if let Some(assign_targets) = assign_targets { Stmt::Assign(ast::StmtAssign { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), targets: assign_targets.to_vec(), value: Box::new(func_call.into()), }) } else { Stmt::Expr(StmtExpr { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), value: Box::new(func_call.into()), }) }; Some(StmtWith { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), is_async: false, items: vec![WithItem { - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range: TextRange::default(), context_expr: context_call.into(), optional_vars: optional_vars.map(|var| Box::new(var.clone())), diff --git a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs index 5b60d38c1a7ff..eea779a30eec3 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/mutable_fromkeys_value.rs @@ -102,7 +102,7 @@ fn generate_dict_comprehension(keys: &Expr, value: &Expr, generator: Generator) id: Name::new_static("key"), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; // Construct `key in keys`. let comp = ast::Comprehension { @@ -110,7 +110,7 @@ fn generate_dict_comprehension(keys: &Expr, value: &Expr, generator: Generator) iter: keys.clone(), ifs: vec![], range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, is_async: false, }; // Construct the dict comprehension. @@ -119,7 +119,7 @@ fn generate_dict_comprehension(keys: &Expr, value: &Expr, generator: Generator) value: Box::new(value.clone()), generators: vec![comp], range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }; generator.expr(&dict_comp.into()) } diff --git a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs index 8be1156a0a19c..c06c0545023a7 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/never_union.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/never_union.rs @@ -164,12 +164,12 @@ pub(crate) fn never_union(checker: &Checker, expr: &Expr) { elts: rest, ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, parenthesized: true, })), ctx: ast::ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, })) }, expr.range(), diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs index 8e815c601b6b1..91d384560b2e9 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_nested_literal.rs @@ -116,14 +116,14 @@ pub(crate) fn unnecessary_nested_literal<'a>(checker: &Checker, literal_expr: &' Expr::Tuple(ExprTuple { elts: nodes.into_iter().cloned().collect(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, parenthesized: false, }) }), value: subscript.value.clone(), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, ctx: ExprContext::Load, }); let fix = Fix::applicable_edit( diff --git a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs index 3b9c1a4673fb6..48f2efb2ccaa1 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/unnecessary_regular_expression.rs @@ -303,7 +303,7 @@ impl<'a> ReFunc<'a> { op: UnaryOp::Not, operand: Box::new(expr), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); Some(negated_expr) } @@ -327,7 +327,7 @@ impl<'a> ReFunc<'a> { ops: Box::new([op]), comparators: Box::new([right.clone()]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } @@ -339,7 +339,7 @@ impl<'a> ReFunc<'a> { attr: Identifier::new(method, TextRange::default()), ctx: ExprContext::Load, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }); Expr::Call(ExprCall { func: Box::new(method), @@ -347,10 +347,10 @@ impl<'a> ReFunc<'a> { args: args.into_boxed_slice(), keywords: Box::new([]), range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }, range: TextRange::default(), - node_index: ruff_python_ast::AtomicNodeIndex::dummy(), + node_index: ruff_python_ast::AtomicNodeIndex::NONE, }) } } diff --git a/crates/ruff_python_ast/src/helpers.rs b/crates/ruff_python_ast/src/helpers.rs index 81787601b34d0..bc1195d34728e 100644 --- a/crates/ruff_python_ast/src/helpers.rs +++ b/crates/ruff_python_ast/src/helpers.rs @@ -1489,7 +1489,7 @@ pub fn pep_604_optional(expr: &Expr) -> Expr { op: Operator::BitOr, right: Box::new(Expr::NoneLiteral(ast::ExprNoneLiteral::default())), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } .into() } @@ -1501,7 +1501,7 @@ pub fn pep_604_union(elts: &[Expr]) -> Expr { elts: vec![], ctx: ExprContext::Load, range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, parenthesized: true, }), [Expr::Tuple(ast::ExprTuple { elts, .. })] => pep_604_union(elts), @@ -1511,7 +1511,7 @@ pub fn pep_604_union(elts: &[Expr]) -> Expr { op: Operator::BitOr, right: Box::new(pep_604_union(std::slice::from_ref(elt))), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }), } } @@ -1522,13 +1522,13 @@ pub fn typing_optional(elt: Expr, binding: Name) -> Expr { value: Box::new(Expr::Name(ast::ExprName { id: binding, range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, ctx: ExprContext::Load, })), slice: Box::new(elt), ctx: ExprContext::Load, range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } @@ -1541,19 +1541,19 @@ pub fn typing_union(elts: &[Expr], binding: Name) -> Expr { value: Box::new(Expr::Name(ast::ExprName { id: binding, range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, ctx: ExprContext::Load, })), slice: Box::new(Expr::Tuple(ast::ExprTuple { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, elts: elts.to_vec(), ctx: ExprContext::Load, parenthesized: false, })), ctx: ExprContext::Load, range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } @@ -1686,34 +1686,34 @@ mod tests { let name = Expr::Name(ExprName { id: "x".into(), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, ctx: ExprContext::Load, }); let constant_one = Expr::NumberLiteral(ExprNumberLiteral { value: Number::Int(Int::from(1u8)), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); let constant_two = Expr::NumberLiteral(ExprNumberLiteral { value: Number::Int(Int::from(2u8)), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); let constant_three = Expr::NumberLiteral(ExprNumberLiteral { value: Number::Int(Int::from(3u8)), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); let type_var_one = TypeParam::TypeVar(TypeParamTypeVar { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, bound: Some(Box::new(constant_one.clone())), default: None, name: Identifier::new("x", TextRange::default()), }); let type_var_two = TypeParam::TypeVar(TypeParamTypeVar { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, bound: None, default: Some(Box::new(constant_two.clone())), name: Identifier::new("x", TextRange::default()), @@ -1723,11 +1723,11 @@ mod tests { type_params: Some(Box::new(TypeParams { type_params: vec![type_var_one, type_var_two], range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })), value: Box::new(constant_three.clone()), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); assert!(!any_over_stmt(&type_alias, &|expr| { seen.borrow_mut().push(expr.clone()); @@ -1743,7 +1743,7 @@ mod tests { fn any_over_type_param_type_var() { let type_var_no_bound = TypeParam::TypeVar(TypeParamTypeVar { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, bound: None, default: None, name: Identifier::new("x", TextRange::default()), @@ -1753,12 +1753,12 @@ mod tests { let constant = Expr::NumberLiteral(ExprNumberLiteral { value: Number::Int(Int::ONE), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); let type_var_with_bound = TypeParam::TypeVar(TypeParamTypeVar { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, bound: Some(Box::new(constant.clone())), default: None, name: Identifier::new("x", TextRange::default()), @@ -1776,7 +1776,7 @@ mod tests { let type_var_with_default = TypeParam::TypeVar(TypeParamTypeVar { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, default: Some(Box::new(constant.clone())), bound: None, name: Identifier::new("x", TextRange::default()), @@ -1797,7 +1797,7 @@ mod tests { fn any_over_type_param_type_var_tuple() { let type_var_tuple = TypeParam::TypeVarTuple(TypeParamTypeVarTuple { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, name: Identifier::new("x", TextRange::default()), default: None, }); @@ -1809,12 +1809,12 @@ mod tests { let constant = Expr::NumberLiteral(ExprNumberLiteral { value: Number::Int(Int::ONE), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); let type_var_tuple_with_default = TypeParam::TypeVarTuple(TypeParamTypeVarTuple { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, default: Some(Box::new(constant.clone())), name: Identifier::new("x", TextRange::default()), }); @@ -1834,7 +1834,7 @@ mod tests { fn any_over_type_param_param_spec() { let type_param_spec = TypeParam::ParamSpec(TypeParamParamSpec { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, name: Identifier::new("x", TextRange::default()), default: None, }); @@ -1846,12 +1846,12 @@ mod tests { let constant = Expr::NumberLiteral(ExprNumberLiteral { value: Number::Int(Int::ONE), range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); let param_spec_with_default = TypeParam::TypeVarTuple(TypeParamTypeVarTuple { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, default: Some(Box::new(constant.clone())), name: Identifier::new("x", TextRange::default()), }); diff --git a/crates/ruff_python_ast/src/node_index.rs b/crates/ruff_python_ast/src/node_index.rs index cb8042b04deff..d40a7fc2bb86c 100644 --- a/crates/ruff_python_ast/src/node_index.rs +++ b/crates/ruff_python_ast/src/node_index.rs @@ -1,3 +1,4 @@ +use std::num::NonZeroU32; use std::sync::atomic::{AtomicU32, Ordering}; /// An AST node that has an index. @@ -16,64 +17,82 @@ where } /// A unique index for a node within an AST. -/// -/// This type is interiorly mutable to allow assigning node indices -/// on-demand after parsing. -#[derive(Default)] +#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Copy, Hash)] #[cfg_attr(feature = "get-size", derive(get_size2::GetSize))] -pub struct AtomicNodeIndex(AtomicU32); +pub struct NodeIndex(NonZeroU32); -impl AtomicNodeIndex { - /// Returns a placeholder `AtomicNodeIndex`. - pub const fn dummy() -> AtomicNodeIndex { - AtomicNodeIndex(AtomicU32::new(u32::MAX)) +impl NodeIndex { + /// A placeholder `NodeIndex`. + pub const NONE: NodeIndex = NodeIndex(NonZeroU32::new(NodeIndex::_NONE).unwrap()); + + // Note that the index `u32::MAX` is reserved for the `NonZeroU32` niche, and + // this placeholder also reserves the second highest index. + const _NONE: u32 = u32::MAX - 1; + + /// Returns the index as a `u32`. or `None` for `NodeIndex::NONE`. + pub fn as_u32(self) -> Option { + if self == NodeIndex::NONE { + None + } else { + Some(self.0.get() - 1) + } } +} - /// Load the current value of the `AtomicNodeIndex`. - pub fn load(&self) -> NodeIndex { - NodeIndex(self.0.load(Ordering::Relaxed)) +impl From for NodeIndex { + fn from(value: u32) -> Self { + match NonZeroU32::new(value + 1).map(NodeIndex) { + None | Some(NodeIndex::NONE) => panic!("exceeded maximum `NodeIndex`"), + Some(index) => index, + } } +} - /// Set the value of the `AtomicNodeIndex`. - pub fn set(&self, value: u32) { - self.0.store(value, Ordering::Relaxed); +impl std::fmt::Debug for NodeIndex { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + if *self == Self::NONE { + f.debug_tuple("NodeIndex(None)").finish() + } else { + f.debug_tuple("NodeIndex").field(&self.0).finish() + } } } /// A unique index for a node within an AST. -#[derive(PartialEq, Eq, Debug, PartialOrd, Ord, Clone, Copy, Hash)] +/// +/// This type is interiorly mutable to allow assigning node indices +/// on-demand after parsing. #[cfg_attr(feature = "get-size", derive(get_size2::GetSize))] -pub struct NodeIndex(u32); +pub struct AtomicNodeIndex(AtomicU32); -impl NodeIndex { - pub fn as_usize(self) -> usize { - self.0 as _ - } +#[allow(clippy::declare_interior_mutable_const)] +impl AtomicNodeIndex { + /// A placeholder `AtomicNodeIndex`. + pub const NONE: AtomicNodeIndex = AtomicNodeIndex(AtomicU32::new(NodeIndex::_NONE)); + + /// Load the current value of the `AtomicNodeIndex`. + pub fn load(&self) -> NodeIndex { + let index = NonZeroU32::new(self.0.load(Ordering::Relaxed)) + .expect("value stored was a valid `NodeIndex`"); - pub fn as_u32(self) -> u32 { - self.0 + NodeIndex(index) } -} -impl From for NodeIndex { - fn from(value: u32) -> Self { - NodeIndex(value) + /// Set the value of the `AtomicNodeIndex`. + pub fn set(&self, index: NodeIndex) { + self.0.store(index.0.get(), Ordering::Relaxed); } } -impl From for AtomicNodeIndex { - fn from(value: u32) -> Self { - AtomicNodeIndex(AtomicU32::from(value)) +impl Default for AtomicNodeIndex { + fn default() -> Self { + Self::NONE } } impl std::fmt::Debug for AtomicNodeIndex { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if *self == AtomicNodeIndex::dummy() { - f.debug_tuple("AtomicNodeIndex").finish_non_exhaustive() - } else { - f.debug_tuple("AtomicNodeIndex").field(&self.0).finish() - } + std::fmt::Debug::fmt(&self.load(), f) } } @@ -108,3 +127,26 @@ impl Clone for AtomicNodeIndex { Self(AtomicU32::from(self.0.load(Ordering::Relaxed))) } } + +#[cfg(test)] +mod tests { + use super::{AtomicNodeIndex, NodeIndex}; + + #[test] + fn test_node_index() { + let index = AtomicNodeIndex::NONE; + + assert_eq!(index.load(), NodeIndex::NONE); + assert_eq!(format!("{index:?}"), "NodeIndex(None)"); + + index.set(NodeIndex::from(1)); + assert_eq!(index.load(), NodeIndex::from(1)); + assert_eq!(index.load().as_u32(), Some(1)); + + let index = NodeIndex::from(0); + assert_eq!(index.as_u32(), Some(0)); + + let index = NodeIndex::NONE; + assert_eq!(index.as_u32(), None); + } +} diff --git a/crates/ruff_python_ast/src/nodes.rs b/crates/ruff_python_ast/src/nodes.rs index 6de571a86e898..6a824603bb2b0 100644 --- a/crates/ruff_python_ast/src/nodes.rs +++ b/crates/ruff_python_ast/src/nodes.rs @@ -1602,7 +1602,7 @@ impl StringLiteral { Self { range, value: "".into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, flags: StringLiteralFlags::empty().with_invalid(), } } @@ -1622,7 +1622,7 @@ impl From for Expr { fn from(payload: StringLiteral) -> Self { ExprStringLiteral { range: payload.range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, value: StringLiteralValue::single(payload), } .into() @@ -2001,7 +2001,7 @@ impl BytesLiteral { Self { range, value: Box::new([]), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, flags: BytesLiteralFlags::empty().with_invalid(), } } @@ -2011,7 +2011,7 @@ impl From for Expr { fn from(payload: BytesLiteral) -> Self { ExprBytesLiteral { range: payload.range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, value: BytesLiteralValue::single(payload), } .into() @@ -3545,7 +3545,7 @@ impl Identifier { pub fn new(id: impl Into, range: TextRange) -> Self { Self { id: id.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, range, } } diff --git a/crates/ruff_python_formatter/src/comments/debug.rs b/crates/ruff_python_formatter/src/comments/debug.rs index 8cd374464f4a8..3e4ae7c6bdd9f 100644 --- a/crates/ruff_python_formatter/src/comments/debug.rs +++ b/crates/ruff_python_formatter/src/comments/debug.rs @@ -196,12 +196,12 @@ mod tests { fn debug() { let continue_statement = StmtContinue { range: TextRange::new(TextSize::new(18), TextSize::new(26)), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; let break_statement = StmtBreak { range: TextRange::new(TextSize::new(55), TextSize::new(60)), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; let source = r"# leading comment diff --git a/crates/ruff_python_formatter/src/comments/node_key.rs b/crates/ruff_python_formatter/src/comments/node_key.rs index 4d94ebe092cd5..ec15ced488b02 100644 --- a/crates/ruff_python_formatter/src/comments/node_key.rs +++ b/crates/ruff_python_formatter/src/comments/node_key.rs @@ -69,7 +69,7 @@ mod tests { fn equality() { let continue_statement = StmtContinue { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; let ref_a = NodeRefEqualityKey::from_ref(AnyNodeRef::from(&continue_statement)); @@ -83,7 +83,7 @@ mod tests { fn inequality() { let continue_statement = StmtContinue { range: TextRange::default(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; let boxed = Box::new(continue_statement.clone()); diff --git a/crates/ruff_python_formatter/tests/normalizer.rs b/crates/ruff_python_formatter/tests/normalizer.rs index e5237f8c5f285..2b943948eb995 100644 --- a/crates/ruff_python_formatter/tests/normalizer.rs +++ b/crates/ruff_python_formatter/tests/normalizer.rs @@ -82,7 +82,7 @@ impl Transformer for Normalizer { value: Box::from(string.value.to_str()), range: string.range, flags: StringLiteralFlags::empty(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } } @@ -99,7 +99,7 @@ impl Transformer for Normalizer { value: bytes.value.bytes().collect(), range: bytes.range, flags: BytesLiteralFlags::empty(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } } @@ -143,7 +143,7 @@ impl Transformer for Normalizer { InterpolatedStringLiteralElement { range, value: literal.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }, )); } @@ -185,7 +185,7 @@ impl Transformer for Normalizer { elements: collector.elements.into(), range: fstring.range, flags: FStringFlags::empty(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } } diff --git a/crates/ruff_python_parser/src/lib.rs b/crates/ruff_python_parser/src/lib.rs index c25eea290c25a..46cc082945663 100644 --- a/crates/ruff_python_parser/src/lib.rs +++ b/crates/ruff_python_parser/src/lib.rs @@ -215,7 +215,7 @@ pub fn parse_parenthesized_expression_range( /// value: "'''\n int | str'''".to_string().into_boxed_str(), /// flags: StringLiteralFlags::empty(), /// range: TextRange::new(TextSize::new(0), TextSize::new(16)), -/// node_index: AtomicNodeIndex::dummy() +/// node_index: AtomicNodeIndex::NONE /// }; /// let parsed = parse_string_annotation("'''\n int | str'''", &string); /// assert!(!parsed.is_ok()); diff --git a/crates/ruff_python_parser/src/parser/expression.rs b/crates/ruff_python_parser/src/parser/expression.rs index de9a1bad52f2c..d198441895d0a 100644 --- a/crates/ruff_python_parser/src/parser/expression.rs +++ b/crates/ruff_python_parser/src/parser/expression.rs @@ -304,7 +304,7 @@ impl<'src> Parser<'src> { op: bin_op, right: Box::new(right.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } }; @@ -472,7 +472,7 @@ impl<'src> Parser<'src> { range: identifier.range, id: identifier.id, ctx, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -491,7 +491,7 @@ impl<'src> Parser<'src> { return ast::Identifier { id: name, range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; } @@ -501,7 +501,7 @@ impl<'src> Parser<'src> { return ast::Identifier { id, range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; } @@ -520,7 +520,7 @@ impl<'src> Parser<'src> { ast::Identifier { id, range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } else { self.add_error( @@ -531,7 +531,7 @@ impl<'src> Parser<'src> { ast::Identifier { id: Name::empty(), range: self.missing_node_range(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } } @@ -551,7 +551,7 @@ impl<'src> Parser<'src> { Expr::NumberLiteral(ast::ExprNumberLiteral { value: Number::Float(value), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Complex => { @@ -561,7 +561,7 @@ impl<'src> Parser<'src> { Expr::NumberLiteral(ast::ExprNumberLiteral { value: Number::Complex { real, imag }, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Int => { @@ -571,7 +571,7 @@ impl<'src> Parser<'src> { Expr::NumberLiteral(ast::ExprNumberLiteral { value: Number::Int(value), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::True => { @@ -579,7 +579,7 @@ impl<'src> Parser<'src> { Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: true, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::False => { @@ -587,21 +587,21 @@ impl<'src> Parser<'src> { Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: false, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::None => { self.bump(TokenKind::None); Expr::NoneLiteral(ast::ExprNoneLiteral { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Ellipsis => { self.bump(TokenKind::Ellipsis); Expr::EllipsisLiteral(ast::ExprEllipsisLiteral { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Name => Expr::Name(self.parse_name()), @@ -629,7 +629,7 @@ impl<'src> Parser<'src> { range: self.missing_node_range(), id: Name::empty(), ctx: ExprContext::Invalid, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } } @@ -672,7 +672,7 @@ impl<'src> Parser<'src> { func: Box::new(func), arguments, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -702,7 +702,7 @@ impl<'src> Parser<'src> { arg: None, value: value.expr, range: parser.node_range(argument_start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); seen_keyword_unpacking = true; @@ -767,7 +767,7 @@ impl<'src> Parser<'src> { ast::Identifier { id: ident_expr.id, range: ident_expr.range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } else { // TODO(dhruvmanila): Parser shouldn't drop the `parsed_expr` if it's @@ -780,7 +780,7 @@ impl<'src> Parser<'src> { ast::Identifier { id: Name::empty(), range: parsed_expr.range(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } }; @@ -790,7 +790,7 @@ impl<'src> Parser<'src> { arg: Some(arg), value: value.expr, range: parser.node_range(argument_start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } else { if !parsed_expr.is_unparenthesized_starred_expr() { @@ -815,7 +815,7 @@ impl<'src> Parser<'src> { let arguments = ast::Arguments { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, args: args.into_boxed_slice(), keywords: keywords.into_boxed_slice(), }; @@ -857,11 +857,11 @@ impl<'src> Parser<'src> { range: slice_range, id: Name::empty(), ctx: ExprContext::Invalid, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })), ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; } @@ -881,7 +881,7 @@ impl<'src> Parser<'src> { ctx: ExprContext::Load, range: self.node_range(slice_start), parenthesized: false, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } else if slice.is_starred_expr() { // If the only slice element is a starred expression, that is represented @@ -892,7 +892,7 @@ impl<'src> Parser<'src> { ctx: ExprContext::Load, range: self.node_range(slice_start), parenthesized: false, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } @@ -941,7 +941,7 @@ impl<'src> Parser<'src> { slice: Box::new(slice), ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1035,7 +1035,7 @@ impl<'src> Parser<'src> { Expr::Slice(ast::ExprSlice { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, lower, upper, step, @@ -1066,7 +1066,7 @@ impl<'src> Parser<'src> { op, operand: Box::new(operand.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1091,7 +1091,7 @@ impl<'src> Parser<'src> { attr, ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1135,7 +1135,7 @@ impl<'src> Parser<'src> { values, op, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1215,7 +1215,7 @@ impl<'src> Parser<'src> { ops: operators.into_boxed_slice(), comparators: comparators.into_boxed_slice(), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1285,22 +1285,22 @@ impl<'src> Parser<'src> { StringType::Str(string) => Expr::StringLiteral(ast::ExprStringLiteral { value: ast::StringLiteralValue::single(string), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }), StringType::Bytes(bytes) => Expr::BytesLiteral(ast::ExprBytesLiteral { value: ast::BytesLiteralValue::single(bytes), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }), StringType::FString(fstring) => Expr::FString(ast::ExprFString { value: ast::FStringValue::single(fstring), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }), StringType::TString(tstring) => Expr::TString(ast::ExprTString { value: ast::TStringValue::single(tstring), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }), }, _ => self.handle_implicitly_concatenated_strings(strings, range), @@ -1367,7 +1367,7 @@ impl<'src> Parser<'src> { return Expr::from(ast::ExprBytesLiteral { value: ast::BytesLiteralValue::concatenated(values), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } } @@ -1395,7 +1395,7 @@ impl<'src> Parser<'src> { return Expr::from(ast::ExprTString { value: ast::TStringValue::concatenated(values), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } } @@ -1433,7 +1433,7 @@ impl<'src> Parser<'src> { return Expr::from(ast::ExprStringLiteral { value: ast::StringLiteralValue::concatenated(values), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } @@ -1457,7 +1457,7 @@ impl<'src> Parser<'src> { Expr::from(ast::ExprFString { value: ast::FStringValue::concatenated(parts), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } @@ -1493,7 +1493,7 @@ impl<'src> Parser<'src> { value: Box::new([]), range, flags: ast::BytesLiteralFlags::from(flags).with_invalid(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } else { // test_err invalid_string_literal @@ -1503,7 +1503,7 @@ impl<'src> Parser<'src> { value: "".into(), range, flags: ast::StringLiteralFlags::from(flags).with_invalid(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } } @@ -1677,7 +1677,7 @@ impl<'src> Parser<'src> { ast::InterpolatedStringLiteralElement { value: "".into(), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } }), ) @@ -1846,7 +1846,7 @@ impl<'src> Parser<'src> { Some(Box::new(ast::InterpolatedStringFormatSpec { range: self.node_range(spec_start), elements, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })) } else { None @@ -1898,7 +1898,7 @@ impl<'src> Parser<'src> { conversion, format_spec, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1928,7 +1928,7 @@ impl<'src> Parser<'src> { elts: vec![], ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } @@ -1980,7 +1980,7 @@ impl<'src> Parser<'src> { return Expr::Dict(ast::ExprDict { items: vec![], range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } @@ -2091,7 +2091,7 @@ impl<'src> Parser<'src> { elts: vec![], ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, parenthesized: true, }) .into(); @@ -2180,7 +2180,7 @@ impl<'src> Parser<'src> { elts, ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, parenthesized: parenthesized.is_yes(), } } @@ -2209,7 +2209,7 @@ impl<'src> Parser<'src> { elts, ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2258,7 +2258,7 @@ impl<'src> Parser<'src> { ast::ExprSet { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, elts, } } @@ -2301,7 +2301,7 @@ impl<'src> Parser<'src> { ast::ExprDict { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, items, } } @@ -2369,7 +2369,7 @@ impl<'src> Parser<'src> { ast::Comprehension { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, target: target.expr, iter: iter.expr, ifs, @@ -2399,7 +2399,7 @@ impl<'src> Parser<'src> { elt: Box::new(element), generators, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, parenthesized: parenthesized.is_yes(), } } @@ -2420,7 +2420,7 @@ impl<'src> Parser<'src> { elt: Box::new(element), generators, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2442,7 +2442,7 @@ impl<'src> Parser<'src> { value: Box::new(value), generators, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2462,7 +2462,7 @@ impl<'src> Parser<'src> { elt: Box::new(element), generators, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2499,7 +2499,7 @@ impl<'src> Parser<'src> { value: Box::new(parsed_expr.expr), ctx: ExprContext::Load, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2522,7 +2522,7 @@ impl<'src> Parser<'src> { ast::ExprAwait { value: Box::new(parsed_expr.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2571,7 +2571,7 @@ impl<'src> Parser<'src> { Expr::Yield(ast::ExprYield { value, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } @@ -2611,7 +2611,7 @@ impl<'src> Parser<'src> { Expr::YieldFrom(ast::ExprYieldFrom { value: Box::new(expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } @@ -2652,7 +2652,7 @@ impl<'src> Parser<'src> { target: Box::new(target), value: Box::new(value.expr), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2700,7 +2700,7 @@ impl<'src> Parser<'src> { body: Box::new(body.expr), parameters, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2725,7 +2725,7 @@ impl<'src> Parser<'src> { test: Box::new(test.expr), orelse: Box::new(orelse.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2751,7 +2751,7 @@ impl<'src> Parser<'src> { let command = ast::ExprIpyEscapeCommand { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, kind, value, }; @@ -3010,7 +3010,7 @@ impl From for FString { elements: value.elements, range: value.range, flags: value.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } } @@ -3021,7 +3021,7 @@ impl From for TString { elements: value.elements, range: value.range, flags: value.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } } diff --git a/crates/ruff_python_parser/src/parser/mod.rs b/crates/ruff_python_parser/src/parser/mod.rs index ccd44b2592925..5f35b84b049a9 100644 --- a/crates/ruff_python_parser/src/parser/mod.rs +++ b/crates/ruff_python_parser/src/parser/mod.rs @@ -133,7 +133,7 @@ impl<'src> Parser<'src> { ModExpression { body: Box::new(parsed_expr.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -151,7 +151,7 @@ impl<'src> Parser<'src> { ModModule { body, range: TextRange::new(self.start_offset, self.current_token_range().end()), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } diff --git a/crates/ruff_python_parser/src/parser/pattern.rs b/crates/ruff_python_parser/src/parser/pattern.rs index dd552410db6fa..2839a7dcadf40 100644 --- a/crates/ruff_python_parser/src/parser/pattern.rs +++ b/crates/ruff_python_parser/src/parser/pattern.rs @@ -112,7 +112,7 @@ impl Parser<'_> { lhs = Pattern::MatchOr(ast::PatternMatchOr { range: self.node_range(start), patterns, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } @@ -128,7 +128,7 @@ impl Parser<'_> { range: self.node_range(start), name: Some(ident), pattern: Some(Box::new(lhs)), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } @@ -255,7 +255,7 @@ impl Parser<'_> { keys, patterns, rest, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -279,7 +279,7 @@ impl Parser<'_> { } else { Some(ident) }, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -319,7 +319,7 @@ impl Parser<'_> { return Pattern::MatchSequence(ast::PatternMatchSequence { patterns: vec![], range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } @@ -374,7 +374,7 @@ impl Parser<'_> { ast::PatternMatchSequence { range: self.node_range(start), patterns, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -389,7 +389,7 @@ impl Parser<'_> { Pattern::MatchSingleton(ast::PatternMatchSingleton { value: Singleton::None, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::True => { @@ -397,7 +397,7 @@ impl Parser<'_> { Pattern::MatchSingleton(ast::PatternMatchSingleton { value: Singleton::True, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::False => { @@ -405,7 +405,7 @@ impl Parser<'_> { Pattern::MatchSingleton(ast::PatternMatchSingleton { value: Singleton::False, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::String | TokenKind::FStringStart | TokenKind::TStringStart => { @@ -414,7 +414,7 @@ impl Parser<'_> { Pattern::MatchValue(ast::PatternMatchValue { value: Box::new(str), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Complex => { @@ -427,10 +427,10 @@ impl Parser<'_> { value: Box::new(Expr::NumberLiteral(ast::ExprNumberLiteral { value: Number::Complex { real, imag }, range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Int => { @@ -443,10 +443,10 @@ impl Parser<'_> { value: Box::new(Expr::NumberLiteral(ast::ExprNumberLiteral { value: Number::Int(value), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Float => { @@ -459,10 +459,10 @@ impl Parser<'_> { value: Box::new(Expr::NumberLiteral(ast::ExprNumberLiteral { value: Number::Float(value), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } kind => { @@ -489,7 +489,7 @@ impl Parser<'_> { return Pattern::MatchValue(ast::PatternMatchValue { value: Box::new(Expr::UnaryOp(unary_expr)), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } } @@ -509,7 +509,7 @@ impl Parser<'_> { Pattern::MatchValue(ast::PatternMatchValue { value: Box::new(attribute), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } else { // test_ok match_as_pattern_soft_keyword @@ -530,7 +530,7 @@ impl Parser<'_> { range: ident.range, pattern: None, name: if &ident == "_" { None } else { Some(ident) }, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } } else { @@ -544,12 +544,12 @@ impl Parser<'_> { range: self.missing_node_range(), id: Name::empty(), ctx: ExprContext::Invalid, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); Pattern::MatchValue(ast::PatternMatchValue { range: invalid_node.range(), value: Box::new(invalid_node), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } } @@ -605,10 +605,10 @@ impl Parser<'_> { op: operator, right: rhs_value, range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -648,14 +648,14 @@ impl Parser<'_> { range: ident.range(), id: ident.id, ctx: ExprContext::Load, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })) } else { Box::new(Expr::Name(ast::ExprName { range: ident.range(), id: Name::empty(), ctx: ExprContext::Invalid, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })) } } @@ -707,7 +707,7 @@ impl Parser<'_> { ast::Identifier { id: Name::empty(), range: parser.missing_node_range(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } }; @@ -717,7 +717,7 @@ impl Parser<'_> { attr: key, pattern: value_pattern, range: parser.node_range(pattern_start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); } else { has_seen_pattern = true; @@ -743,10 +743,10 @@ impl Parser<'_> { patterns, keywords, range: self.node_range(arguments_start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } } diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap index ab002c583afa9..714127298bf92 100644 --- a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap +++ b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__expr_mode_valid_syntax.snap @@ -4,7 +4,7 @@ expression: parsed.expr() --- Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, id: Name("first"), ctx: Load, diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap index 8d6fbc000ce9a..f181d200c06c8 100644 --- a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap +++ b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__ipython_escape_commands.snap @@ -4,20 +4,20 @@ expression: parsed.syntax() --- Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..929, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..42, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..40, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("a"), ctx: Load, @@ -26,7 +26,7 @@ Module( op: Mod, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("b"), ctx: Load, @@ -38,7 +38,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..73, kind: Help2, value: "a.foo", @@ -46,7 +46,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..80, kind: Help, value: "a.foo", @@ -54,7 +54,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..88, kind: Help, value: "a.foo", @@ -62,7 +62,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..100, kind: Help2, value: "a.foo()", @@ -70,7 +70,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..128, kind: Magic, value: "timeit a = b", @@ -78,7 +78,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..147, kind: Magic, value: "timeit foo(b) % 3", @@ -86,7 +86,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..176, kind: Magic, value: "alias showPath pwd && ls -a", @@ -94,7 +94,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..205, kind: Magic, value: "timeit a = foo(b); b = 2", @@ -102,7 +102,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..226, kind: Magic, value: "matplotlib --inline", @@ -110,7 +110,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..253, kind: Magic, value: "matplotlib --inline", @@ -118,7 +118,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..309, kind: Shell, value: "pwd && ls -a | sed 's/^/\\ /'", @@ -126,7 +126,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..347, kind: Shell, value: "pwd && ls -a | sed 's/^/\\\\ /'", @@ -134,7 +134,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..393, kind: ShCap, value: "cd /Users/foo/Library/Application\\ Support/", @@ -142,21 +142,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 566..626, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 570..573, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 573..575, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -167,16 +165,16 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 581..626, value: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 598..620, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 598..599, id: Name("a"), ctx: Load, @@ -188,7 +186,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 619..620, id: Name("b"), ctx: Load, @@ -205,7 +203,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 656..664, kind: Paren, value: "foo 1 2", @@ -213,7 +211,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 665..673, kind: Quote2, value: "foo 1 2", @@ -221,7 +219,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 674..682, kind: Quote, value: "foo 1 2", @@ -229,12 +227,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 711..737, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 715..716, id: Name("a"), ctx: Store, @@ -242,11 +240,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 720..728, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 720..725, id: Name("range"), ctx: Load, @@ -254,11 +252,11 @@ Module( ), arguments: Arguments { range: 725..728, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 726..727, value: Int( 5, @@ -273,7 +271,7 @@ Module( body: [ IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 734..737, kind: Shell, value: "ls", @@ -285,12 +283,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 739..748, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 739..741, id: Name("p1"), ctx: Store, @@ -299,7 +297,7 @@ Module( ], value: IpyEscapeCommand( ExprIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 744..748, kind: Shell, value: "pwd", @@ -309,11 +307,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 749..763, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 749..751, id: Name("p2"), ctx: Store, @@ -321,7 +319,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 753..756, id: Name("str"), ctx: Load, @@ -330,7 +328,7 @@ Module( value: Some( IpyEscapeCommand( ExprIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 759..763, kind: Shell, value: "pwd", @@ -342,12 +340,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 764..784, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 764..767, id: Name("foo"), ctx: Store, @@ -356,7 +354,7 @@ Module( ], value: IpyEscapeCommand( ExprIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 770..784, kind: Magic, value: "foo bar", @@ -366,7 +364,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 786..791, kind: Magic, value: " foo", @@ -374,12 +372,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 792..813, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 792..795, id: Name("foo"), ctx: Store, @@ -388,7 +386,7 @@ Module( ], value: IpyEscapeCommand( ExprIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 798..813, kind: Magic, value: "foo # comment", @@ -398,7 +396,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 838..842, kind: Help, value: "foo", @@ -406,7 +404,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 843..852, kind: Help2, value: "foo.bar", @@ -414,7 +412,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 853..865, kind: Help, value: "foo.bar.baz", @@ -422,7 +420,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 866..874, kind: Help2, value: "foo[0]", @@ -430,7 +428,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 875..885, kind: Help, value: "foo[0][1]", @@ -438,7 +436,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 886..905, kind: Help2, value: "foo.bar[0].baz[1]", @@ -446,7 +444,7 @@ Module( ), IpyEscapeCommand( StmtIpyEscapeCommand { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 906..929, kind: Help2, value: "foo.bar[0].baz[2].egg", diff --git a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap index 6ee807fc8c985..2e77ece9434d9 100644 --- a/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap +++ b/crates/ruff_python_parser/src/parser/snapshots/ruff_python_parser__parser__tests__unicode_aliases.snap @@ -5,12 +5,12 @@ expression: suite [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..37, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -19,13 +19,13 @@ expression: suite ], value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..37, value: StringLiteralValue { inner: Single( StringLiteral { range: 4..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{8}another cool trick", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/parser/statement.rs b/crates/ruff_python_parser/src/parser/statement.rs index d738fc78d6592..171cffaa41f08 100644 --- a/crates/ruff_python_parser/src/parser/statement.rs +++ b/crates/ruff_python_parser/src/parser/statement.rs @@ -312,7 +312,7 @@ impl<'src> Parser<'src> { Stmt::Expr(ast::StmtExpr { range: self.node_range(start), value: Box::new(parsed_expr.expr), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } } @@ -368,7 +368,7 @@ impl<'src> Parser<'src> { ast::StmtDelete { targets, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -417,7 +417,7 @@ impl<'src> Parser<'src> { ast::StmtReturn { range: self.node_range(start), value, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -523,7 +523,7 @@ impl<'src> Parser<'src> { range: self.node_range(start), exc, cause, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -564,7 +564,7 @@ impl<'src> Parser<'src> { ast::StmtImport { range: self.node_range(start), names, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -676,7 +676,7 @@ impl<'src> Parser<'src> { names, level: leading_dots, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -693,11 +693,11 @@ impl<'src> Parser<'src> { name: ast::Identifier { id: Name::new_static("*"), range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }, asname: None, range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }; } @@ -730,7 +730,7 @@ impl<'src> Parser<'src> { range: self.node_range(start), name, asname, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -759,7 +759,7 @@ impl<'src> Parser<'src> { ast::Identifier { id: Name::from(dotted_name), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -775,7 +775,7 @@ impl<'src> Parser<'src> { self.bump(TokenKind::Pass); ast::StmtPass { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -791,7 +791,7 @@ impl<'src> Parser<'src> { self.bump(TokenKind::Continue); ast::StmtContinue { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -807,7 +807,7 @@ impl<'src> Parser<'src> { self.bump(TokenKind::Break); ast::StmtBreak { range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -857,7 +857,7 @@ impl<'src> Parser<'src> { test: Box::new(test.expr), msg, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -896,7 +896,7 @@ impl<'src> Parser<'src> { ast::StmtGlobal { range: self.node_range(start), names, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -942,7 +942,7 @@ impl<'src> Parser<'src> { ast::StmtNonlocal { range: self.node_range(start), names, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -995,7 +995,7 @@ impl<'src> Parser<'src> { type_params: type_params.map(Box::new), value: Box::new(value.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1022,7 +1022,7 @@ impl<'src> Parser<'src> { range, kind, value, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1119,7 +1119,7 @@ impl<'src> Parser<'src> { value: value.into_boxed_str(), kind, range: self.node_range(parsed_expr.start()), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1187,7 +1187,7 @@ impl<'src> Parser<'src> { targets, value: Box::new(value.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1267,7 +1267,7 @@ impl<'src> Parser<'src> { value, simple, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1322,7 +1322,7 @@ impl<'src> Parser<'src> { op, value: Box::new(value.expr), range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1378,7 +1378,7 @@ impl<'src> Parser<'src> { body, elif_else_clauses, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1422,7 +1422,7 @@ impl<'src> Parser<'src> { test, body, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1572,7 +1572,7 @@ impl<'src> Parser<'src> { finalbody, is_star, range: self.node_range(try_start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1722,7 +1722,7 @@ impl<'src> Parser<'src> { name, body: except_body, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }), block_kind, ) @@ -1834,7 +1834,7 @@ impl<'src> Parser<'src> { body, orelse, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -1882,7 +1882,7 @@ impl<'src> Parser<'src> { body, orelse, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2012,7 +2012,7 @@ impl<'src> Parser<'src> { is_async: false, returns, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2082,7 +2082,7 @@ impl<'src> Parser<'src> { type_params: type_params.map(Box::new), arguments, body, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2109,7 +2109,7 @@ impl<'src> Parser<'src> { body, is_async: false, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2378,7 +2378,7 @@ impl<'src> Parser<'src> { range: self.node_range(start), context_expr: context_expr.expr, optional_vars, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }, } } @@ -2447,7 +2447,7 @@ impl<'src> Parser<'src> { subject: Box::new(subject), cases, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } TokenKind::Newline if matches!(self.peek2(), (TokenKind::Indent, TokenKind::Case)) => { @@ -2470,7 +2470,7 @@ impl<'src> Parser<'src> { subject: Box::new(subject), cases, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } _ => { @@ -2518,7 +2518,7 @@ impl<'src> Parser<'src> { subject: Box::new(subject), cases, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2697,7 +2697,7 @@ impl<'src> Parser<'src> { guard, body, range: self.node_range(start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -2866,7 +2866,7 @@ impl<'src> Parser<'src> { decorators.push(ast::Decorator { expression: parsed_expr.expr, range: self.node_range(decorator_start), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); // test_err decorator_missing_newline @@ -3080,7 +3080,7 @@ impl<'src> Parser<'src> { range: self.node_range(start), name, annotation, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -3130,7 +3130,7 @@ impl<'src> Parser<'src> { range: self.node_range(start), parameter, default, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -3448,7 +3448,7 @@ impl<'src> Parser<'src> { ast::TypeParams { range: self.node_range(start), type_params, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, } } @@ -3511,7 +3511,7 @@ impl<'src> Parser<'src> { range: self.node_range(start), name, default, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) // test_ok type_param_param_spec @@ -3551,7 +3551,7 @@ impl<'src> Parser<'src> { range: self.node_range(start), name, default, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) // test_ok type_param_type_var // type X[T] = int @@ -3635,7 +3635,7 @@ impl<'src> Parser<'src> { name, bound, default, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } } diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap index 04e5596e74227..9a734b8be4ae8 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__backspace_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{8}", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap index 8f28967afe49c..72fcda7d2a6df 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__bell_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{7}", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap index 258440c8d44d3..3f04c6f2d7b27 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__carriage_return_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\r", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap index 447e6a7e416cd..791588d79457c 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__character_tabulation_with_justification_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..45, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..45, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{89}", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap index ac810427d1e7c..2d53ec0f3d402 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__delete_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{7f}", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap index ccac176830a4d..546f94b9d9232 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__dont_panic_on_8_in_octal_escape.snap @@ -5,12 +5,12 @@ expression: suite [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("bold"), ctx: Store, @@ -19,13 +19,13 @@ expression: suite ], value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..16, value: StringLiteralValue { inner: Single( StringLiteral { range: 7..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{3}8[1m", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap index 59f9b5213b1de..687ce16e1d20f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__double_quoted_byte.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..738, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..738, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 0..738, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 0, 1, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap index 4f706e1fde15d..2cec840d0a572 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{1b}", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap index aad2af989480b..e0ad6cff1b436 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_char_in_byte_literal.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 111, 109, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap index cfc7e3ee09815..80aad9289c0bb 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__escape_octet.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 0..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 35, 97, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap index 21c8747c01ec1..206756607449e 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__form_feed_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{c}", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap index b418df379e042..ed6a838d4e3fb 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_constant_range.snap @@ -5,33 +5,33 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: FStringValue { inner: Single( FString( FString { range: 0..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "aaa", }, ), Interpolation( InterpolatedElement { range: 5..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("bbb"), ctx: Load, @@ -45,17 +45,17 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 10..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "ccc", }, ), Interpolation( InterpolatedElement { range: 13..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("ddd"), ctx: Load, @@ -69,7 +69,7 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 18..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "eee", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap index 8cb891a551b44..990c1d9dad146 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_character.snap @@ -5,33 +5,33 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: FStringValue { inner: Single( FString( FString { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..4, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), Interpolation( InterpolatedElement { range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap index b1df67c78f8f5..7fbfd50e8e1bf 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_escaped_newline.snap @@ -5,33 +5,33 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: FStringValue { inner: Single( FString( FString { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..4, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", }, ), Interpolation( InterpolatedElement { range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap index c3fd51c096ba4..d950371db18fe 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_line_continuation.snap @@ -5,33 +5,33 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: FStringValue { inner: Single( FString( FString { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 3..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\\n", }, ), Interpolation( InterpolatedElement { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap index 35e090916ce47..2955122167560 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FStringValue { inner: Single( FString( FString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, id: Name("user"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap index e05de72bc4655..dc882a8c57c37 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_base_more.snap @@ -5,33 +5,33 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, value: FStringValue { inner: Single( FString( FString { range: 0..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "mix ", }, ), Interpolation( InterpolatedElement { range: 6..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..11, id: Name("user"), ctx: Load, @@ -50,17 +50,17 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 13..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " with text and ", }, ), Interpolation( InterpolatedElement { range: 28..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..35, id: Name("second"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap index 932339c3590d4..da86391550721 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_parse_self_documenting_format.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: FStringValue { inner: Single( FString( FString { range: 0..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, id: Name("user"), ctx: Load, @@ -40,12 +40,12 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 9..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 9..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ">10", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap index f651b99dff099..42fcd75676652 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__fstring_unescaped_newline.snap @@ -5,33 +5,33 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: FStringValue { inner: Single( FString( FString { range: 0..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", }, ), Interpolation( InterpolatedElement { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap index 4d694d9dcaf9c..cdf45c0397749 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__hts_alias.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{88}", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap index 52bb0728d36b3..f865593fb2db4 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_fstring.snap @@ -5,18 +5,18 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: FStringValue { inner: Single( FString( FString { range: 0..3, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_tstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_tstring.snap index 8a95e3a166382..98b1fa3461a19 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_tstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_empty_tstring.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: TStringValue { inner: Single( TString { range: 0..3, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: TStringFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap index 291eb7e8f4f5e..d539cb8deb5e5 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_1.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: FStringValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite Literal( StringLiteral { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -29,12 +29,12 @@ expression: suite FString( FString { range: 9..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 11..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap index 291eb7e8f4f5e..d539cb8deb5e5 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_2.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: FStringValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite Literal( StringLiteral { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -29,12 +29,12 @@ expression: suite FString( FString { range: 9..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 11..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap index 66e0a2cbd93cc..1193adb2e4a4a 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_3.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: FStringValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite Literal( StringLiteral { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -29,28 +29,28 @@ expression: suite FString( FString { range: 9..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 11..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", }, ), Interpolation( InterpolatedElement { range: 16..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: StringLiteralValue { inner: Single( StringLiteral { range: 17..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "!", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap index d7830a63d0ecf..02419e8a00f2a 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_f_string_concat_4.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, value: FStringValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite Literal( StringLiteral { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -29,28 +29,28 @@ expression: suite FString( FString { range: 9..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 11..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", }, ), Interpolation( InterpolatedElement { range: 16..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: StringLiteralValue { inner: Single( StringLiteral { range: 17..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "!", flags: StringLiteralFlags { quote_style: Double, @@ -78,7 +78,7 @@ expression: suite Literal( StringLiteral { range: 23..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "again!", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap index d4d4e01a4afe3..db72a345e0bde 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: FStringValue { inner: Single( FString( FString { range: 0..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("a"), ctx: Load, @@ -38,10 +38,10 @@ expression: suite Interpolation( InterpolatedElement { range: 5..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("b"), ctx: Load, @@ -55,7 +55,7 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 10..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "{foo}", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap index 93333df2aade4..07654a0e227de 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_equals.snap @@ -5,30 +5,30 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: FStringValue { inner: Single( FString( FString { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..11, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..5, value: Int( 42, @@ -41,7 +41,7 @@ expression: suite comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, value: Int( 42, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap index 2e0f5c6474b43..1d8003551577d 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_concatenation_string_spec.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: FStringValue { inner: Single( FString( FString { range: 0..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -35,15 +35,15 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 7..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..13, value: StringLiteralValue { inner: Concatenated( @@ -51,7 +51,7 @@ expression: suite strings: [ StringLiteral { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -61,7 +61,7 @@ expression: suite }, StringLiteral { range: 11..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap index 479ea844b6436..3ed5dbd04be94 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_spec.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: FStringValue { inner: Single( FString( FString { range: 0..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -35,15 +35,15 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 7..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..12, id: Name("spec"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap index c9ef305e708b5..68960eab2543f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_nested_string_spec.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: FStringValue { inner: Single( FString( FString { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -35,21 +35,21 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..10, value: StringLiteralValue { inner: Single( StringLiteral { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap index 42ef942c16787..f3fa222a173f1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_equals.snap @@ -5,30 +5,30 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: FStringValue { inner: Single( FString( FString { range: 0..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..9, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, value: Int( 1, @@ -41,7 +41,7 @@ expression: suite comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 2, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap index 3b428b414876a..2f9be02104542 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_not_nested_spec.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: FStringValue { inner: Single( FString( FString { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -35,12 +35,12 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "spec", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap index 764c3768a4012..e53098fdec837 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_prec_space.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FStringValue { inner: Single( FString( FString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap index 869d7ff2d3984..7de32a7c0c8f3 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_self_doc_trailing_space.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FStringValue { inner: Single( FString( FString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap index 1989651e7ff01..3154dbeff5826 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_fstring_yield_expr.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FStringValue { inner: Single( FString( FString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..8, value: None, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap index c5e7745a97c27..20b0be9eab2c9 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_concat.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: StringLiteralValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite strings: [ StringLiteral { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -27,7 +27,7 @@ expression: suite }, StringLiteral { range: 9..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap index 295d3fd63490f..e37ba3eaf0e67 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_string_triple_quotes_with_kind.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello, world!", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring.snap index f7e45b3308a05..64cb321009132 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: TStringValue { inner: Single( TString { range: 0..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("a"), ctx: Load, @@ -37,10 +37,10 @@ expression: suite Interpolation( InterpolatedElement { range: 5..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("b"), ctx: Load, @@ -54,7 +54,7 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 10..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "{foo}", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_equals.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_equals.snap index 655c257691667..af2754bea45f3 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_equals.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_equals.snap @@ -5,29 +5,29 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: TStringValue { inner: Single( TString { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..11, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..5, value: Int( 42, @@ -40,7 +40,7 @@ expression: suite comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, value: Int( 42, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_concatenation_string_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_concatenation_string_spec.snap index 8b719bdbef416..bfef44ca1a4a1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_concatenation_string_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_concatenation_string_spec.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: TStringValue { inner: Single( TString { range: 0..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -34,15 +34,15 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 7..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..13, value: StringLiteralValue { inner: Concatenated( @@ -50,7 +50,7 @@ expression: suite strings: [ StringLiteral { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -60,7 +60,7 @@ expression: suite }, StringLiteral { range: 11..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_spec.snap index 11102f6346a23..2432a03fea0e5 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_spec.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: TStringValue { inner: Single( TString { range: 0..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -34,15 +34,15 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 7..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..12, id: Name("spec"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_string_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_string_spec.snap index 789ef89073196..4d167f6391c17 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_string_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_nested_string_spec.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: TStringValue { inner: Single( TString { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -34,21 +34,21 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..10, value: StringLiteralValue { inner: Single( StringLiteral { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_equals.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_equals.snap index 151ac16383289..cda9ac63854e0 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_equals.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_equals.snap @@ -5,29 +5,29 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: TStringValue { inner: Single( TString { range: 0..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..9, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, value: Int( 1, @@ -40,7 +40,7 @@ expression: suite comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 2, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_nested_spec.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_nested_spec.snap index 38fb62b089047..607db4621e1aa 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_nested_spec.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_not_nested_spec.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: TStringValue { inner: Single( TString { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("foo"), ctx: Load, @@ -34,12 +34,12 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "spec", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_prec_space.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_prec_space.snap index b1972bb8c223d..82a3532343b8b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_prec_space.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_prec_space.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TStringValue { inner: Single( TString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_trailing_space.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_trailing_space.snap index 0abdf4feeafe3..5b44cbb07eb90 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_trailing_space.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_self_doc_trailing_space.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TStringValue { inner: Single( TString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_yield_expr.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_yield_expr.snap index 2efd41e5a3700..745e1afdf4a62 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_yield_expr.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_tstring_yield_expr.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TStringValue { inner: Single( TString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..8, value: None, }, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap index 0b9244c730362..bfadf93148c0f 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_1.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: FStringValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite Literal( StringLiteral { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -29,12 +29,12 @@ expression: suite FString( FString { range: 10..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 12..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap index 76de944babaf5..31dcb6c17dbc9 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_f_string_concat_2.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: FStringValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite Literal( StringLiteral { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -29,12 +29,12 @@ expression: suite FString( FString { range: 10..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 12..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", }, ), @@ -49,7 +49,7 @@ expression: suite Literal( StringLiteral { range: 19..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "!", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap index b6c48ef5d8ba4..8a8b31c488f01 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_1.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: StringLiteralValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite strings: [ StringLiteral { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -27,7 +27,7 @@ expression: suite }, StringLiteral { range: 9..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap index 7ad459df3f5a8..6dd96bc445dbb 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__parse_u_string_concat_2.snap @@ -5,11 +5,11 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: StringLiteralValue { inner: Concatenated( @@ -17,7 +17,7 @@ expression: suite strings: [ StringLiteral { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello ", flags: StringLiteralFlags { quote_style: Single, @@ -27,7 +27,7 @@ expression: suite }, StringLiteral { range: 10..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap index 8c3cd6bc04657..d90d77f669d4b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_1.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 92, 120, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap index f3a05cb29727f..9dc2e32ae2a00 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_byte_literal_2.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 0..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 92, 92, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap index 7156cd907306f..24540312124b3 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_fstring.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: FStringValue { inner: Single( FString( FString { range: 0..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 3..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_tstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_tstring.snap index 5200cdade1ce2..41f1bac3ab3dc 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_tstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__raw_tstring.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: TStringValue { inner: Single( TString { range: 0..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 3..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap index b85749f0dc0f5..b156356ac7982 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__single_quoted_byte.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..738, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..738, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 0..738, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 0, 1, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap index 432c43fcf4195..c2521fd8ac3f1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_mac_eol.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "text more text", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap index 432c43fcf4195..c2521fd8ac3f1 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_unix_eol.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "text more text", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap index dfaefc86f8ac2..b66b5c37389f3 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__string_parser_escaped_windows_eol.snap @@ -5,17 +5,17 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "text more text", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap index a65a7d4b3945f..3ec5fbae97f9b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_fstring.snap @@ -5,26 +5,26 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: FStringValue { inner: Single( FString( FString { range: 0..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_tstring.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_tstring.snap index 71a7e8c067e0f..bdf91f88e58d2 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_tstring.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__triple_quoted_raw_tstring.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: TStringValue { inner: Single( TString { range: 0..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_constant_range.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_constant_range.snap index d87b9c51f32a6..7460cec091292 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_constant_range.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_constant_range.snap @@ -5,32 +5,32 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: TStringValue { inner: Single( TString { range: 0..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "aaa", }, ), Interpolation( InterpolatedElement { range: 5..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("bbb"), ctx: Load, @@ -44,17 +44,17 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 10..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "ccc", }, ), Interpolation( InterpolatedElement { range: 13..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("ddd"), ctx: Load, @@ -68,7 +68,7 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 18..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "eee", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_character.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_character.snap index 416ad8570abd4..44d783177f808 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_character.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_character.snap @@ -5,32 +5,32 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: TStringValue { inner: Single( TString { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..4, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), Interpolation( InterpolatedElement { range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_newline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_newline.snap index 85e4ce745b24f..d17834c3b1b48 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_newline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_escaped_newline.snap @@ -5,32 +5,32 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: TStringValue { inner: Single( TString { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..4, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", }, ), Interpolation( InterpolatedElement { range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_line_continuation.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_line_continuation.snap index 04ca645b9ec9f..7a142da726bca 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_line_continuation.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_line_continuation.snap @@ -5,32 +5,32 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: TStringValue { inner: Single( TString { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 3..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\\n", }, ), Interpolation( InterpolatedElement { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base.snap index 147b6c7b10e37..81b079ca5e60b 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: TStringValue { inner: Single( TString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, id: Name("user"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base_more.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base_more.snap index 8f098418fc2af..4af3383006240 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base_more.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_base_more.snap @@ -5,32 +5,32 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, value: TStringValue { inner: Single( TString { range: 0..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "mix ", }, ), Interpolation( InterpolatedElement { range: 6..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..11, id: Name("user"), ctx: Load, @@ -49,17 +49,17 @@ expression: suite Literal( InterpolatedStringLiteralElement { range: 13..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " with text and ", }, ), Interpolation( InterpolatedElement { range: 28..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..35, id: Name("second"), ctx: Load, diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_format.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_format.snap index c11b0164f60b3..d8970fbf3a701 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_format.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_parse_self_documenting_format.snap @@ -5,25 +5,25 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: TStringValue { inner: Single( TString { range: 0..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, id: Name("user"), ctx: Load, @@ -39,12 +39,12 @@ expression: suite format_spec: Some( InterpolatedStringFormatSpec { range: 9..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 9..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ">10", }, ), diff --git a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_unescaped_newline.snap b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_unescaped_newline.snap index 728682c92c785..19db8fe2e7b66 100644 --- a/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_unescaped_newline.snap +++ b/crates/ruff_python_parser/src/snapshots/ruff_python_parser__string__tests__tstring_unescaped_newline.snap @@ -5,32 +5,32 @@ expression: suite [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: TStringValue { inner: Single( TString { range: 0..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", }, ), Interpolation( InterpolatedElement { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/src/string.rs b/crates/ruff_python_parser/src/string.rs index 8a0342ded2b4d..45109346858b8 100644 --- a/crates/ruff_python_parser/src/string.rs +++ b/crates/ruff_python_parser/src/string.rs @@ -287,7 +287,7 @@ impl StringParser { return Ok(ast::InterpolatedStringLiteralElement { value: self.source, range: self.range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }); }; @@ -365,7 +365,7 @@ impl StringParser { Ok(ast::InterpolatedStringLiteralElement { value: value.into_boxed_str(), range: self.range, - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, }) } @@ -387,7 +387,7 @@ impl StringParser { value: self.source.into_boxed_bytes(), range: self.range, flags: self.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })); } @@ -397,7 +397,7 @@ impl StringParser { value: self.source.into_boxed_bytes(), range: self.range, flags: self.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })); }; @@ -435,7 +435,7 @@ impl StringParser { value: value.into_boxed_slice(), range: self.range, flags: self.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })) } @@ -446,7 +446,7 @@ impl StringParser { value: self.source, range: self.range, flags: self.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })); } @@ -456,7 +456,7 @@ impl StringParser { value: self.source, range: self.range, flags: self.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })); }; @@ -494,7 +494,7 @@ impl StringParser { value: value.into_boxed_str(), range: self.range, flags: self.flags.into(), - node_index: AtomicNodeIndex::dummy(), + node_index: AtomicNodeIndex::NONE, })) } diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap index 172e4daa89c02..21eb2b1619c5c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_annotation.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_inval ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..63, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -24,11 +24,11 @@ Module( ), annotation: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..7, id: Name("int"), ctx: Load, @@ -40,7 +40,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Int( 1, @@ -53,11 +53,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..26, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, id: Name("x"), ctx: Store, @@ -65,12 +65,12 @@ Module( ), annotation: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..22, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("a"), ctx: Load, @@ -82,7 +82,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 1, @@ -95,11 +95,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..46, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("x"), ctx: Store, @@ -107,11 +107,11 @@ Module( ), annotation: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..42, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("b"), ctx: Load, @@ -122,7 +122,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, value: Int( 1, @@ -135,11 +135,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..51, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -147,7 +147,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, id: Name("y"), ctx: Load, @@ -159,12 +159,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..62, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, id: Name("int"), ctx: Store, @@ -173,7 +173,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap index 4a80fdc2f52b3..74e36dcbcaf1d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_target.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_inval ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..170, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, target: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "abc", flags: StringLiteralFlags { quote_style: Double, @@ -36,7 +36,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, id: Name("str"), ctx: Load, @@ -45,13 +45,13 @@ Module( value: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, value: StringLiteralValue { inner: Single( StringLiteral { range: 13..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "def", flags: StringLiteralFlags { quote_style: Double, @@ -69,15 +69,15 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..37, target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..25, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..23, id: Name("call"), ctx: Load, @@ -85,7 +85,7 @@ Module( ), arguments: Arguments { range: 23..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -93,7 +93,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, id: Name("str"), ctx: Load, @@ -102,13 +102,13 @@ Module( value: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..37, value: StringLiteralValue { inner: Single( StringLiteral { range: 33..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "no", flags: StringLiteralFlags { quote_style: Double, @@ -126,15 +126,15 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..52, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..40, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("x"), ctx: Store, @@ -145,7 +145,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, id: Name("int"), ctx: Load, @@ -154,12 +154,12 @@ Module( value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..52, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, value: Int( 1, @@ -168,7 +168,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 2, @@ -186,16 +186,16 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..83, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..74, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("x"), ctx: Store, @@ -208,7 +208,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, id: Name("int"), ctx: Load, @@ -217,7 +217,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 1, @@ -230,16 +230,16 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..100, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..88, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, id: Name("x"), ctx: Store, @@ -247,7 +247,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, id: Name("y"), ctx: Store, @@ -260,7 +260,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..93, id: Name("int"), ctx: Load, @@ -269,12 +269,12 @@ Module( value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..100, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, value: Int( 1, @@ -283,7 +283,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, value: Int( 2, @@ -301,16 +301,16 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..119, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..107, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("x"), ctx: Store, @@ -318,7 +318,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, id: Name("y"), ctx: Store, @@ -331,7 +331,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, id: Name("int"), ctx: Load, @@ -340,12 +340,12 @@ Module( value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..119, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, value: Int( 1, @@ -354,7 +354,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, value: Int( 2, @@ -372,16 +372,16 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..150, target: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..141, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, id: Name("x"), ctx: Store, @@ -393,7 +393,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..146, id: Name("int"), ctx: Load, @@ -402,7 +402,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, value: Int( 1, @@ -415,16 +415,16 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..169, target: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..157, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..153, id: Name("x"), ctx: Store, @@ -432,7 +432,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..156, id: Name("y"), ctx: Store, @@ -444,7 +444,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..162, id: Name("int"), ctx: Load, @@ -453,12 +453,12 @@ Module( value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..169, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, value: Int( 1, @@ -467,7 +467,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..169, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap index 1d6945367089e..f9ad11979a633 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_invalid_value.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_inval ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..65, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -24,7 +24,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("Any"), ctx: Load, @@ -33,17 +33,17 @@ Module( value: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..17, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..17, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("a"), ctx: Load, @@ -51,7 +51,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("b"), ctx: Load, @@ -69,11 +69,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..28, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("x"), ctx: Store, @@ -81,7 +81,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, id: Name("Any"), ctx: Load, @@ -90,7 +90,7 @@ Module( value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("x"), ctx: Load, @@ -102,11 +102,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 1, @@ -117,11 +117,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..64, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("x"), ctx: Store, @@ -129,7 +129,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..41, id: Name("list"), ctx: Load, @@ -138,12 +138,12 @@ Module( value: Some( List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..64, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, id: Name("x"), ctx: Load, @@ -151,15 +151,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..54, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..54, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("a"), ctx: Load, @@ -168,7 +168,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("b"), ctx: Load, @@ -181,17 +181,17 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..63, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..63, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, id: Name("a"), ctx: Load, @@ -199,7 +199,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap index b1a670039436f..babd3409873a3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_missing_rhs.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -24,7 +24,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap index 957104e6d291b..8c2e51d0cd1fc 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@ann_assign_stmt_type_alias_annotation.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/ann_assign_stmt_type_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..37, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Store, @@ -24,7 +24,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, id: Name("type"), ctx: Load, @@ -36,12 +36,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..15, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("X"), ctx: Store, @@ -50,7 +50,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, id: Name("int"), ctx: Load, @@ -60,16 +60,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..28, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..28, parameters: None, body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, id: Name("type"), ctx: Load, @@ -81,12 +81,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..36, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("X"), ctx: Store, @@ -95,7 +95,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..36, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap index 745c8c8c402f8..13b2bd42923e3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@args_unparenthesized_generator.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/args_unparenthesized_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..92, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, id: Name("sum"), ctx: Load, @@ -28,15 +28,15 @@ Module( ), arguments: Arguments { range: 3..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..24, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, @@ -45,10 +45,10 @@ Module( generators: [ Comprehension { range: 6..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("x"), ctx: Store, @@ -56,11 +56,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..24, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..20, id: Name("range"), ctx: Load, @@ -68,11 +68,11 @@ Module( ), arguments: Arguments { range: 20..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..23, value: Int( 10, @@ -93,7 +93,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, value: Int( 5, @@ -109,15 +109,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..64, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..64, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..34, id: Name("total"), ctx: Load, @@ -125,11 +125,11 @@ Module( ), arguments: Arguments { range: 34..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, value: Int( 1, @@ -138,7 +138,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, value: Int( 2, @@ -147,11 +147,11 @@ Module( ), Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..60, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Load, @@ -160,10 +160,10 @@ Module( generators: [ Comprehension { range: 43..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -171,11 +171,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..60, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..57, id: Name("range"), ctx: Load, @@ -183,11 +183,11 @@ Module( ), arguments: Arguments { range: 57..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, value: Int( 5, @@ -208,7 +208,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, value: Int( 6, @@ -224,15 +224,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..91, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..91, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, id: Name("sum"), ctx: Load, @@ -240,15 +240,15 @@ Module( ), arguments: Arguments { range: 68..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..89, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, id: Name("x"), ctx: Load, @@ -257,10 +257,10 @@ Module( generators: [ Comprehension { range: 71..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("x"), ctx: Store, @@ -268,11 +268,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..89, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..85, id: Name("range"), ctx: Load, @@ -280,11 +280,11 @@ Module( ), arguments: Arguments { range: 85..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..88, value: Int( 10, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap index e4f9844f739ee..fd78d8760b20f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_msg.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/assert_empty_msg.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap index 8722a03c2e652..2c64815756f4f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_empty_test.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/assert_empty_test.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, body: [ Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..6, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap index bfef69718472f..2cc454ed48567 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_msg_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_msg_ex ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..83, body: [ Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..12, value: false, }, @@ -24,11 +24,11 @@ Module( msg: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..16, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("x"), ctx: Load, @@ -42,11 +42,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..30, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..29, value: false, }, @@ -56,11 +56,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..39, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("x"), ctx: Load, @@ -71,11 +71,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..61, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, value: false, }, @@ -83,12 +83,12 @@ Module( msg: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..61, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("x"), ctx: Load, @@ -102,11 +102,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..77, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..74, value: false, }, @@ -114,7 +114,7 @@ Module( msg: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, id: Name("x"), ctx: Load, @@ -125,11 +125,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap index 1f87e7e7b6857..1a843b29c9254 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assert_invalid_test_expr.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/assert_invalid_test_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..55, body: [ Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, test: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..9, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("x"), ctx: Load, @@ -34,11 +34,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..23, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..23, id: Name("assert"), ctx: Load, @@ -49,11 +49,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Load, @@ -63,16 +63,16 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..40, test: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..40, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("x"), ctx: Load, @@ -86,11 +86,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..49, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, id: Name("x"), ctx: Load, @@ -101,11 +101,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap index e317e4b49c9e5..1085de726cb4f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_target.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_invalid_t ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..58, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, targets: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Int( 1, @@ -27,7 +27,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 1, @@ -38,12 +38,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..15, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Store, @@ -51,7 +51,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Int( 1, @@ -61,7 +61,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, value: Int( 2, @@ -72,12 +72,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..33, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("x"), ctx: Store, @@ -85,7 +85,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, value: Int( 1, @@ -94,7 +94,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("y"), ctx: Store, @@ -102,7 +102,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, value: Int( 2, @@ -112,7 +112,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("z"), ctx: Load, @@ -122,23 +122,23 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..57, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..44, elts: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, value: StringLiteralValue { inner: Single( StringLiteral { range: 35..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -152,13 +152,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, value: StringLiteralValue { inner: Single( StringLiteral { range: 40..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b", flags: StringLiteralFlags { quote_style: Double, @@ -177,18 +177,18 @@ Module( ], value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..57, elts: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..51, value: StringLiteralValue { inner: Single( StringLiteral { range: 48..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -202,13 +202,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, value: StringLiteralValue { inner: Single( StringLiteral { range: 53..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap index 65ac6baf43b08..6fe406354b050 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_invalid_value_expr.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_invalid_v ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..90, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -26,22 +26,22 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..15, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..13, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("a"), ctx: Load, @@ -49,7 +49,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, id: Name("b"), ctx: Load, @@ -70,12 +70,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..34, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("x"), ctx: Store, @@ -84,12 +84,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..34, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..23, value: Int( 42, @@ -98,16 +98,16 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..33, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..33, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("x"), ctx: Load, @@ -128,12 +128,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..58, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("x"), ctx: Store, @@ -142,12 +142,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..58, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..42, value: Int( 42, @@ -156,15 +156,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..57, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..57, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Load, @@ -184,12 +184,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..78, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("x"), ctx: Store, @@ -198,35 +198,33 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..78, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..76, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..76, parameters: Some( Parameters { range: 72..73, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -240,7 +238,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("x"), ctx: Load, @@ -260,12 +258,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..84, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, id: Name("x"), ctx: Store, @@ -274,7 +272,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Load, @@ -284,11 +282,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap index 0f58eff527dfa..6264d907b5c46 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_keyword_target.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_keyword_t ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..42, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Store, @@ -25,7 +25,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..8, id: Name("pass"), ctx: Store, @@ -34,7 +34,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("c"), ctx: Load, @@ -44,15 +44,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("a"), ctx: Load, @@ -61,7 +61,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("b"), ctx: Load, @@ -73,12 +73,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..35, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("a"), ctx: Store, @@ -86,7 +86,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("b"), ctx: Store, @@ -94,7 +94,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..31, id: Name("pass"), ctx: Store, @@ -103,7 +103,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("c"), ctx: Load, @@ -113,15 +113,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..41, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..41, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("a"), ctx: Load, @@ -130,7 +130,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap index 6ef39d8045634..8a1f0505336c5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_missing_rhs.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_missing_r ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -26,7 +26,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..3, id: Name(""), ctx: Invalid, @@ -36,15 +36,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 1, @@ -54,7 +54,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 1, @@ -67,12 +67,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..17, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("x"), ctx: Store, @@ -80,7 +80,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("y"), ctx: Store, @@ -89,7 +89,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..17, id: Name(""), ctx: Invalid, @@ -99,15 +99,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..23, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..23, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 2, @@ -117,7 +117,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, value: Int( 2, @@ -130,12 +130,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..31, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Store, @@ -143,7 +143,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..27, id: Name(""), ctx: Store, @@ -152,7 +152,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, id: Name("y"), ctx: Load, @@ -162,15 +162,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..37, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..37, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 3, @@ -180,7 +180,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap index 5af1853e86661..45bda59ff0903 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@assign_stmt_starred_expr_value.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/assign_stmt_starred_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..45, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("_"), ctx: Store, @@ -26,16 +26,16 @@ Module( ], value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..9, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: Int( 42, @@ -53,12 +53,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..19, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("_"), ctx: Store, @@ -67,16 +67,16 @@ Module( ], value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..19, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..19, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..18, value: Int( 42, @@ -93,12 +93,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..31, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("_"), ctx: Store, @@ -107,15 +107,15 @@ Module( ], value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..31, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..31, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..29, id: Name("list"), ctx: Load, @@ -123,7 +123,7 @@ Module( ), arguments: Arguments { range: 29..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -136,12 +136,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..44, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("_"), ctx: Store, @@ -150,15 +150,15 @@ Module( ], value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..44, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..43, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("p"), ctx: Load, @@ -167,7 +167,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, id: Name("q"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap index 7ebaaad4b78a1..7d5b8fd56a576 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@async_unexpected_token.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/inline/err/async_unexpected_toke ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..116, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..20, decorator_list: [], name: Identifier { id: Name("Foo"), range: 12..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, }, ), @@ -40,11 +40,11 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..42, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..37, id: Name("test"), ctx: Load, @@ -53,11 +53,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, }, ), @@ -69,12 +69,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..54, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("x"), ctx: Store, @@ -83,7 +83,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, value: Int( 1, @@ -94,21 +94,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..81, is_async: true, decorator_list: [], name: Identifier { id: Name("foo"), range: 71..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 74..76, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -119,11 +117,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..81, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..81, }, ), @@ -134,11 +132,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..115, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..98, id: Name("test"), ctx: Load, @@ -147,11 +145,11 @@ Module( cases: [ MatchCase { range: 104..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 109..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -160,11 +158,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap index 78da56cda60ce..731d9a39966eb 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_target.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_inval ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..59, body: [ AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Int( 1, @@ -26,7 +26,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -37,17 +37,17 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..17, target: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, value: StringLiteralValue { inner: Single( StringLiteral { range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -62,13 +62,13 @@ Module( op: Add, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, value: StringLiteralValue { inner: Single( StringLiteral { range: 14..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b", flags: StringLiteralFlags { quote_style: Double, @@ -84,15 +84,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..25, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..20, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("x"), ctx: Store, @@ -104,7 +104,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, value: Int( 1, @@ -115,17 +115,17 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..30, }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, value: Int( 1, @@ -136,11 +136,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..45, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("x"), ctx: Store, @@ -149,7 +149,7 @@ Module( op: Add, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..45, id: Name("pass"), ctx: Load, @@ -159,15 +159,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..58, target: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Load, @@ -176,7 +176,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("y"), ctx: Load, @@ -187,7 +187,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap index cfc583f1b86b6..eeec973fc9172 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_invalid_value.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_inval ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..77, body: [ AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -25,17 +25,17 @@ Module( op: Add, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..13, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("a"), ctx: Load, @@ -43,7 +43,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, id: Name("b"), ctx: Load, @@ -59,11 +59,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..27, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("x"), ctx: Store, @@ -72,16 +72,16 @@ Module( op: Add, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..27, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..27, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("x"), ctx: Load, @@ -97,11 +97,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..46, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("x"), ctx: Store, @@ -110,15 +110,15 @@ Module( op: Add, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..46, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..46, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, id: Name("x"), ctx: Load, @@ -133,11 +133,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..64, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -146,30 +146,28 @@ Module( op: Add, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..64, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..64, parameters: Some( Parameters { range: 60..61, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -183,7 +181,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, id: Name("x"), ctx: Load, @@ -198,11 +196,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..71, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("x"), ctx: Store, @@ -211,7 +209,7 @@ Module( op: Add, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("y"), ctx: Load, @@ -221,11 +219,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap index 50e27a1c5e9a7..f367265ec79e8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@aug_assign_stmt_missing_rhs.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/aug_assign_stmt_missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, body: [ AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -25,7 +25,7 @@ Module( op: Add, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..4, id: Name(""), ctx: Invalid, @@ -35,15 +35,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -53,7 +53,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 1, @@ -66,11 +66,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..17, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("x"), ctx: Store, @@ -79,7 +79,7 @@ Module( op: Add, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("y"), ctx: Load, @@ -89,15 +89,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..26, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..26, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, value: Int( 2, @@ -107,7 +107,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap index 0e0305e26b406..99c12452b73c7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@case_expect_indented_block.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/case_expect_indented_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..43, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..42, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,14 +25,14 @@ Module( cases: [ MatchCase { range: 19..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, value: Int( 1, @@ -46,14 +46,14 @@ Module( }, MatchCase { range: 31..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, value: Int( 2, @@ -66,11 +66,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap index 48a479382f0af..b12cc050bf6f1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_empty_body.py.snap @@ -7,18 +7,18 @@ input_file: crates/ruff_python_parser/resources/inline/err/class_def_empty_body. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, decorator_list: [], name: Identifier { id: Name("Foo"), range: 6..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, @@ -27,19 +27,19 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..23, decorator_list: [], name: Identifier { id: Name("Foo"), range: 17..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 20..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -49,12 +49,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..30, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Store, @@ -63,7 +63,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..30, value: Int( 42, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap index 6d68771f17f6f..218b289dc4a4b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_missing_name.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/inline/err/class_def_missing_nam ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, decorator_list: [], name: Identifier { id: Name(""), range: 5..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, }, ), @@ -40,19 +40,19 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..25, decorator_list: [], name: Identifier { id: Name(""), range: 17..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 18..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -60,11 +60,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, }, ), @@ -75,34 +75,34 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..52, decorator_list: [], name: Identifier { id: Name(""), range: 31..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 32..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 33..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("metaclass"), range: 33..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..46, id: Name("ABC"), ctx: Load, @@ -115,11 +115,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap index 17f5d5b106140..6f4c7aa2edef6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unclosed_type_param_list.py.snap @@ -7,32 +7,32 @@ input_file: crates/ruff_python_parser/resources/inline/err/class_def_unclosed_ty ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..33, decorator_list: [], name: Identifier { id: Name("Foo"), range: 6..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 9..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 10..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T1"), range: 10..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -41,11 +41,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 14..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T2"), range: 15..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -56,11 +56,11 @@ Module( arguments: Some( Arguments { range: 17..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("a"), ctx: Load, @@ -68,7 +68,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("b"), ctx: Load, @@ -81,7 +81,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..33, }, ), @@ -90,12 +90,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..40, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("x"), ctx: Store, @@ -104,7 +104,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..40, value: Int( 10, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_type_params_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_type_params_py311.py.snap index 9d91dbf072625..40c8001fee0f7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_type_params_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_type_params_py311.py.snap @@ -7,42 +7,42 @@ input_file: crates/ruff_python_parser/resources/inline/err/class_type_params_py3 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..113, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..95, decorator_list: [], name: Identifier { id: Name("Foo"), range: 50..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 53..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 54..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("S"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..69, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, id: Name("str"), ctx: Load, @@ -50,7 +50,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..68, id: Name("bytes"), ctx: Load, @@ -68,16 +68,16 @@ Module( TypeVar( TypeParamTypeVar { range: 71..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..79, id: Name("float"), ctx: Load, @@ -90,11 +90,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 81..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 82..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -102,11 +102,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 86..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 88..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -118,11 +118,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, }, ), @@ -133,18 +133,18 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..112, decorator_list: [], name: Identifier { id: Name("Foo"), range: 102..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 105..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [], }, ), @@ -152,11 +152,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_indented_block.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_indented_block.py.snap index 52dcef4c1806c..32d4fbf051962 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_indented_block.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_indented_block.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/clause_expect_indente ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..171, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..61, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..60, value: true, }, @@ -27,17 +27,17 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..66, }, ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..170, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..169, value: true, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_single_statement.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_single_statement.py.snap index 0cec1c5726cf5..f43fda3f90545 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_single_statement.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@clause_expect_single_statement.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/clause_expect_single_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: true, }, @@ -27,11 +27,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..22, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..16, value: true, }, @@ -39,7 +39,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..22, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap index 749a5fa1ae447..bf33de094fb73 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, value: Int( 1, @@ -43,11 +43,11 @@ Module( keywords: [ Keyword { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma_between_elements.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma_between_elements.py.snap index 3afc0336c3391..5f39e9451545c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma_between_elements.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_comma_between_elements.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..92, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..91, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..91, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, value: Int( 0, @@ -30,7 +30,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, value: Int( 1, @@ -39,7 +39,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_element_between_commas.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_element_between_commas.py.snap index 0e1f29a3c074e..07e9b5e2725b3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_element_between_commas.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_element_between_commas.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, value: Int( 0, @@ -30,7 +30,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 1, @@ -39,7 +39,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap index 02c89d0035bd8..5f233426139c2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comma_separated_missing_first_element.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/comma_separated_missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap index 636c0bdbac66d..aee9bf70566e9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@comprehension_missing_for_after_async.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/comprehension_missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..6, id: Name("async"), ctx: Load, @@ -26,15 +26,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..27, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..27, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("x"), ctx: Load, @@ -43,10 +43,10 @@ Module( generators: [ Comprehension { range: 11..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("x"), ctx: Store, @@ -54,7 +54,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..26, id: Name("iter"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_class.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_class.py.snap index 91477355a39ee..c69ff0c6931e4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_class.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_class.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/inline/err/debug_shadow_class.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..82, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, decorator_list: [], name: Identifier { id: Name("__debug__"), range: 6..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, }, ), @@ -40,27 +40,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..58, decorator_list: [], name: Identifier { id: Name("C"), range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 42..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 43..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 43..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -73,11 +73,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_function.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_function.py.snap index f31edee08ac34..9dbb166ca4844 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_function.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_function.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/debug_shadow_function ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..125, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, is_async: false, decorator_list: [], name: Identifier { id: Name("__debug__"), range: 4..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 13..15, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,11 +35,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, }, ), @@ -52,28 +50,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..61, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 43..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 44..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 44..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -84,9 +82,7 @@ Module( ), parameters: Parameters { range: 54..56, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -97,11 +93,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), @@ -112,33 +108,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..106, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 89..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 90..101, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 91..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 91..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 91..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -153,11 +147,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..106, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..106, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_import.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_import.py.snap index 380240dd334de..0e59d7d4576a9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_import.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_import.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/debug_shadow_import.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..100, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, names: [ Alias { range: 7..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 7..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -30,22 +30,22 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..42, names: [ Alias { range: 24..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("debug"), range: 24..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("__debug__"), range: 33..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -54,23 +54,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..66, module: Some( Identifier { id: Name("x"), range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 57..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 57..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -80,29 +80,29 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..99, module: Some( Identifier { id: Name("x"), range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 81..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("debug"), range: 81..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("__debug__"), range: 90..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_match.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_match.py.snap index acb6dfcc11b03..16b505fcf939a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_match.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_match.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/debug_shadow_match.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..33, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 13..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 18..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("__debug__"), range: 18..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -44,11 +44,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_try.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_try.py.snap index d638e10acc3e0..1514d68600a06 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_try.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_try.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/debug_shadow_try.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..44, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..43, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, }, ), @@ -32,11 +32,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 9..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..25, id: Name("Exception"), ctx: Load, @@ -47,17 +47,17 @@ Module( Identifier { id: Name("__debug__"), range: 29..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_type_alias.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_type_alias.py.snap index 06bce5209a0cb..a39ffdd665829 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_type_alias.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_type_alias.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/debug_shadow_type_ali ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..95, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..14, id: Name("__debug__"), ctx: Store, @@ -25,11 +25,11 @@ Module( type_params: None, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..26, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..21, id: Name("list"), ctx: Load, @@ -37,7 +37,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, id: Name("int"), ctx: Load, @@ -50,11 +50,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..94, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..77, id: Name("Debug"), ctx: Store, @@ -63,16 +63,16 @@ Module( type_params: Some( TypeParams { range: 77..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 78..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 78..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -83,7 +83,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, id: Name("str"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap index 3d0560bf59c36..0f9a6c4b23515 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@debug_shadow_with.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/inline/err/debug_shadow_with.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..39, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, is_async: false, items: [ WithItem { range: 5..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..20, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..9, id: Name("open"), ctx: Load, @@ -33,17 +33,17 @@ Module( ), arguments: Arguments { range: 9..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..19, value: StringLiteralValue { inner: Single( StringLiteral { range: 10..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo.txt", flags: StringLiteralFlags { quote_style: Double, @@ -63,7 +63,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..33, id: Name("__debug__"), ctx: Store, @@ -75,11 +75,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_await_expression_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_await_expression_py38.py.snap index 9b42c0f68442d..7ca2868d31107 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_await_expression_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_await_expression_py38.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_await_expre ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..96, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..95, is_async: true, decorator_list: [], name: Identifier { id: Name("foo"), range: 55..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 58..60, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,20 +35,20 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..95, is_async: false, decorator_list: [ Decorator { range: 66..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..76, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, id: Name("bar"), ctx: Load, @@ -63,14 +61,12 @@ Module( name: Identifier { id: Name("baz"), range: 85..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 88..90, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -81,11 +77,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_dict_literal_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_dict_literal_py38.py.snap index 0262ed63aae0f..0dd32e14c7e49 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_dict_literal_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_dict_literal_py38.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_dict_litera ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..68, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..67, is_async: false, decorator_list: [ Decorator { range: 45..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..52, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, value: Int( 3, @@ -38,7 +38,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, value: Int( 3, @@ -54,14 +54,12 @@ Module( name: Identifier { id: Name("bar"), range: 57..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 60..62, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -72,11 +70,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_expression_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_expression_py38.py.snap index 5d24f31dd4e87..b277f5a73af3f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_expression_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_expression_py38.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_expression_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..89, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..88, is_async: false, decorator_list: [ Decorator { range: 45..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..72, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..64, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..56, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..53, id: Name("buttons"), ctx: Load, @@ -41,7 +41,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 0, @@ -54,7 +54,7 @@ Module( attr: Identifier { id: Name("clicked"), range: 57..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -62,7 +62,7 @@ Module( attr: Identifier { id: Name("connect"), range: 65..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -72,14 +72,12 @@ Module( name: Identifier { id: Name("spam"), range: 77..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 81..83, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,11 +88,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_float_literal_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_float_literal_py38.py.snap index 666aa7e2baf00..fe245de447767 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_float_literal_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_float_literal_py38.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_float_liter ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..66, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..65, is_async: false, decorator_list: [ Decorator { range: 45..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..50, value: Float( 3.14, @@ -33,14 +33,12 @@ Module( name: Identifier { id: Name("bar"), range: 55..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 58..60, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -51,11 +49,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap index a55f5868c2007..b43a2254b9197 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_invalid_expression.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_invalid_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..56, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..55, is_async: false, decorator_list: [ Decorator { range: 0..3, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..3, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("x"), ctx: Load, @@ -37,14 +37,14 @@ Module( }, Decorator { range: 4..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, @@ -56,14 +56,14 @@ Module( }, Decorator { range: 10..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..15, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("x"), ctx: Load, @@ -75,15 +75,15 @@ Module( }, Decorator { range: 18..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..26, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("x"), ctx: Load, @@ -95,14 +95,14 @@ Module( }, Decorator { range: 27..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..40, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("x"), ctx: Load, @@ -115,14 +115,12 @@ Module( name: Identifier { id: Name("foo"), range: 45..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 48..50, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -133,11 +131,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..55, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..55, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap index 61a1b2b2202fc..2c5bbd3a03610 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_missing_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..51, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..15, target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, id: Name("foo"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), arguments: Arguments { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -36,7 +36,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, }, ), @@ -46,16 +46,16 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..32, is_async: false, decorator_list: [ Decorator { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..17, id: Name(""), ctx: Invalid, @@ -66,14 +66,12 @@ Module( name: Identifier { id: Name("foo"), range: 22..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 25..27, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -84,11 +82,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), @@ -99,20 +97,20 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..50, is_async: false, decorator_list: [ Decorator { range: 33..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..34, id: Name(""), ctx: Invalid, @@ -121,7 +119,7 @@ Module( op: MatMult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..35, id: Name(""), ctx: Invalid, @@ -134,14 +132,12 @@ Module( name: Identifier { id: Name("foo"), range: 40..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 43..45, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -152,11 +148,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..50, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..50, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap index 88a78f186a2f9..948fc24fe2241 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_missing_newline.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_missing_new ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..60, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, is_async: false, decorator_list: [ Decorator { range: 0..2, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("x"), ctx: Load, @@ -32,14 +32,12 @@ Module( name: Identifier { id: Name("foo"), range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 10..12, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -50,11 +48,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, }, ), @@ -65,16 +63,16 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..41, is_async: true, decorator_list: [ Decorator { range: 18..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("x"), ctx: Load, @@ -85,14 +83,12 @@ Module( name: Identifier { id: Name("foo"), range: 31..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 34..36, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -103,11 +99,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, }, ), @@ -118,15 +114,15 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..59, decorator_list: [ Decorator { range: 42..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("x"), ctx: Load, @@ -137,18 +133,18 @@ Module( name: Identifier { id: Name("Foo"), range: 51..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap index 0cbedb39195d6..b852c0911595e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_named_expression_py37.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_named_expre ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..85, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..84, is_async: false, decorator_list: [ Decorator { range: 45..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..69, func: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..63, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -37,26 +37,24 @@ Module( ), value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..63, parameters: Some( Parameters { range: 59..60, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 59..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 59..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 59..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -70,7 +68,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Load, @@ -82,11 +80,11 @@ Module( ), arguments: Arguments { range: 64..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, id: Name("foo"), ctx: Load, @@ -102,14 +100,12 @@ Module( name: Identifier { id: Name("bar"), range: 74..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 77..79, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -120,11 +116,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap index 4172d61656280..2429e4f3fd19e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_non_toplevel_call_expression_py38.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_non_topleve ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..73, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..72, is_async: false, decorator_list: [ Decorator { range: 45..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..57, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..55, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..51, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..49, id: Name("foo"), ctx: Load, @@ -41,7 +41,7 @@ Module( ), arguments: Arguments { range: 49..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -50,14 +50,14 @@ Module( attr: Identifier { id: Name("bar"), range: 52..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 55..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -68,14 +68,12 @@ Module( name: Identifier { id: Name("baz"), range: 62..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -86,11 +84,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..72, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..72, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap index d76a5c7bff80b..a2e7b51517312 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@decorator_unexpected_token.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/decorator_unexpected_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..34, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..22, is_async: true, items: [ WithItem { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("x"), ctx: Load, @@ -33,11 +33,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), @@ -48,12 +48,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..33, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("x"), ctx: Store, @@ -62,7 +62,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_debug_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_debug_py39.py.snap index 40a5517f37278..83f2d82287545 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_debug_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_debug_py39.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/del_debug_py39.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..57, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..56, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, id: Name("__debug__"), ctx: Del, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap index 2e3f2be0afb4e..1ea6b54337ef9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_incomplete_target.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/del_incomplete_target ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Del, @@ -25,11 +25,11 @@ Module( ), Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..9, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("y"), ctx: Load, @@ -38,7 +38,7 @@ Module( attr: Identifier { id: Name(""), range: 9..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Del, }, @@ -48,11 +48,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("z"), ctx: Load, @@ -62,12 +62,12 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..24, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("x"), ctx: Del, @@ -75,11 +75,11 @@ Module( ), Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..23, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("y"), ctx: Load, @@ -87,12 +87,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, lower: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("z"), ctx: Load, @@ -102,7 +102,7 @@ Module( upper: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..23, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_stmt_empty.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_stmt_empty.py.snap index 412384af7c374..a769520c8a394 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_stmt_empty.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@del_stmt_empty.py.snap @@ -7,12 +7,12 @@ input_file: crates/ruff_python_parser/resources/inline/err/del_stmt_empty.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, targets: [], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap index 3614aa08aa440..06b5f87daadbb 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@dotted_name_multiple_dots.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/dotted_name_multiple_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, names: [ Alias { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a..b"), range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -30,16 +30,16 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..20, names: [ Alias { range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -48,11 +48,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, }, ), @@ -60,11 +60,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_class_attr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_class_attr.py.snap index 950b30f63de6e..4a2eefcbc8d4a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_class_attr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_class_attr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/duplicate_match_class ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..231, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..230, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,14 +25,14 @@ Module( cases: [ MatchCase { range: 13..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 18..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..23, id: Name("Class"), ctx: Load, @@ -40,24 +40,24 @@ Module( ), arguments: PatternArguments { range: 23..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, value: Int( 1, @@ -69,19 +69,19 @@ Module( }, PatternKeyword { range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 31..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..32, value: Int( 2, @@ -99,11 +99,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, }, ), @@ -113,19 +113,19 @@ Module( }, MatchCase { range: 43..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 48..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchClass( PatternMatchClass { range: 49..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..54, id: Name("Class"), ctx: Load, @@ -133,24 +133,24 @@ Module( ), arguments: PatternArguments { range: 54..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 55..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 1, @@ -162,19 +162,19 @@ Module( }, PatternKeyword { range: 60..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, value: Int( 2, @@ -195,11 +195,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..70, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..70, }, ), @@ -209,21 +209,21 @@ Module( }, MatchCase { range: 75..113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 80..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, value: StringLiteralValue { inner: Single( StringLiteral { range: 81..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -237,13 +237,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..92, value: StringLiteralValue { inner: Single( StringLiteral { range: 89..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "y", flags: StringLiteralFlags { quote_style: Double, @@ -260,13 +260,13 @@ Module( MatchAs( PatternMatchAs { range: 86..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 86..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -274,10 +274,10 @@ Module( MatchClass( PatternMatchClass { range: 94..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..97, id: Name("Foo"), ctx: Load, @@ -285,24 +285,24 @@ Module( ), arguments: PatternArguments { range: 97..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 98..101, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 100..101, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, value: Int( 1, @@ -314,19 +314,19 @@ Module( }, PatternKeyword { range: 103..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 103..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 105..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, value: Int( 2, @@ -348,11 +348,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..113, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..113, }, ), @@ -362,16 +362,16 @@ Module( }, MatchCase { range: 118..162, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 123..157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchMapping( PatternMatchMapping { range: 124..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -380,17 +380,17 @@ Module( MatchMapping( PatternMatchMapping { range: 128..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..132, value: StringLiteralValue { inner: Single( StringLiteral { range: 129..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -404,13 +404,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..140, value: StringLiteralValue { inner: Single( StringLiteral { range: 137..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "y", flags: StringLiteralFlags { quote_style: Double, @@ -427,13 +427,13 @@ Module( MatchAs( PatternMatchAs { range: 134..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 134..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -441,10 +441,10 @@ Module( MatchClass( PatternMatchClass { range: 142..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..145, id: Name("Foo"), ctx: Load, @@ -452,24 +452,24 @@ Module( ), arguments: PatternArguments { range: 145..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 146..149, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 146..147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 148..149, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..149, value: Int( 1, @@ -481,19 +481,19 @@ Module( }, PatternKeyword { range: 151..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 151..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 153..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..154, value: Int( 2, @@ -518,11 +518,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..162, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..162, }, ), @@ -532,14 +532,14 @@ Module( }, MatchCase { range: 167..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 172..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..177, id: Name("Class"), ctx: Load, @@ -547,24 +547,24 @@ Module( ), arguments: PatternArguments { range: 177..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 178..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 178..179, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 180..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..181, value: Int( 1, @@ -576,26 +576,26 @@ Module( }, PatternKeyword { range: 183..201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("d"), range: 183..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchMapping( PatternMatchMapping { range: 185..201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..189, value: StringLiteralValue { inner: Single( StringLiteral { range: 186..189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -609,13 +609,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..197, value: StringLiteralValue { inner: Single( StringLiteral { range: 194..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -632,10 +632,10 @@ Module( MatchValue( PatternMatchValue { range: 191..192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..192, value: Int( 1, @@ -647,10 +647,10 @@ Module( MatchValue( PatternMatchValue { range: 199..200, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..200, value: Int( 2, @@ -666,19 +666,19 @@ Module( }, PatternKeyword { range: 203..224, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("other"), range: 203..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchClass( PatternMatchClass { range: 209..224, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 209..214, id: Name("Class"), ctx: Load, @@ -686,24 +686,24 @@ Module( ), arguments: PatternArguments { range: 214..224, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 215..218, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 215..216, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 217..218, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..218, value: Int( 1, @@ -715,19 +715,19 @@ Module( }, PatternKeyword { range: 220..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 220..221, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..223, value: Int( 2, @@ -750,11 +750,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..230, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..230, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_key.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_key.py.snap index 4cfbb7011e954..34974c55b06c0 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_key.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_match_key.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/duplicate_match_key.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..533, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..532, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,21 +25,21 @@ Module( cases: [ MatchCase { range: 13..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 18..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: StringLiteralValue { inner: Single( StringLiteral { range: 19..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -53,13 +53,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, value: StringLiteralValue { inner: Single( StringLiteral { range: 27..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -76,10 +76,10 @@ Module( MatchValue( PatternMatchValue { range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, value: Int( 1, @@ -91,10 +91,10 @@ Module( MatchValue( PatternMatchValue { range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 2, @@ -111,11 +111,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, }, ), @@ -125,21 +125,21 @@ Module( }, MatchCase { range: 44..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 49..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..54, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 50..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 120, ], @@ -155,13 +155,13 @@ Module( ), BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..63, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 59..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 120, ], @@ -180,10 +180,10 @@ Module( MatchValue( PatternMatchValue { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, value: Int( 1, @@ -195,10 +195,10 @@ Module( MatchValue( PatternMatchValue { range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 2, @@ -215,11 +215,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..72, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..72, }, ), @@ -229,15 +229,15 @@ Module( }, MatchCase { range: 77..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 82..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 0, @@ -246,7 +246,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 0, @@ -258,10 +258,10 @@ Module( MatchValue( PatternMatchValue { range: 86..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, value: Int( 1, @@ -273,10 +273,10 @@ Module( MatchValue( PatternMatchValue { range: 92..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, value: Int( 2, @@ -293,11 +293,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, }, ), @@ -307,15 +307,15 @@ Module( }, MatchCase { range: 104..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 109..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..113, value: Float( 1.0, @@ -324,7 +324,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..121, value: Float( 1.0, @@ -336,10 +336,10 @@ Module( MatchValue( PatternMatchValue { range: 115..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, value: Int( 1, @@ -351,10 +351,10 @@ Module( MatchValue( PatternMatchValue { range: 123..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..124, value: Int( 2, @@ -371,11 +371,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, }, ), @@ -385,19 +385,19 @@ Module( }, MatchCase { range: 135..171, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 140..166, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..149, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..144, value: Float( 1.0, @@ -407,7 +407,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..149, value: Complex { real: 0.0, @@ -419,11 +419,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..162, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..157, value: Float( 1.0, @@ -433,7 +433,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..162, value: Complex { real: 0.0, @@ -448,10 +448,10 @@ Module( MatchValue( PatternMatchValue { range: 151..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, value: Int( 1, @@ -463,10 +463,10 @@ Module( MatchValue( PatternMatchValue { range: 164..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, value: Int( 2, @@ -483,11 +483,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, }, ), @@ -497,22 +497,22 @@ Module( }, MatchCase { range: 176..204, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 181..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..186, value: true, }, ), BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..195, value: true, }, @@ -522,10 +522,10 @@ Module( MatchValue( PatternMatchValue { range: 188..189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..189, value: Int( 1, @@ -537,10 +537,10 @@ Module( MatchValue( PatternMatchValue { range: 197..198, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, value: Int( 2, @@ -557,11 +557,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..204, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..204, }, ), @@ -571,21 +571,21 @@ Module( }, MatchCase { range: 209..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 214..232, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..219, }, ), NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..228, }, ), @@ -594,10 +594,10 @@ Module( MatchValue( PatternMatchValue { range: 221..222, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..222, value: Int( 1, @@ -609,10 +609,10 @@ Module( MatchValue( PatternMatchValue { range: 230..231, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..231, value: Int( 2, @@ -629,11 +629,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..237, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..237, }, ), @@ -643,21 +643,21 @@ Module( }, MatchCase { range: 242..319, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 247..314, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..277, value: StringLiteralValue { inner: Single( StringLiteral { range: 253..277, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x\n y\n z\n ", flags: StringLiteralFlags { quote_style: Double, @@ -671,13 +671,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..310, value: StringLiteralValue { inner: Single( StringLiteral { range: 286..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x\n y\n z\n ", flags: StringLiteralFlags { quote_style: Double, @@ -694,10 +694,10 @@ Module( MatchValue( PatternMatchValue { range: 279..280, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..280, value: Int( 1, @@ -709,10 +709,10 @@ Module( MatchValue( PatternMatchValue { range: 312..313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..313, value: Int( 2, @@ -729,11 +729,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..319, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..319, }, ), @@ -743,21 +743,21 @@ Module( }, MatchCase { range: 324..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 329..353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 330..333, value: StringLiteralValue { inner: Single( StringLiteral { range: 330..333, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -771,13 +771,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 338..341, value: StringLiteralValue { inner: Single( StringLiteral { range: 338..341, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -791,13 +791,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 346..349, value: StringLiteralValue { inner: Single( StringLiteral { range: 346..349, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -814,10 +814,10 @@ Module( MatchValue( PatternMatchValue { range: 335..336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..336, value: Int( 1, @@ -829,10 +829,10 @@ Module( MatchValue( PatternMatchValue { range: 343..344, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..344, value: Int( 2, @@ -844,10 +844,10 @@ Module( MatchValue( PatternMatchValue { range: 351..352, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..352, value: Int( 3, @@ -864,11 +864,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 355..358, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 355..358, }, ), @@ -878,15 +878,15 @@ Module( }, MatchCase { range: 363..401, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 368..396, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 369..370, value: Int( 0, @@ -895,13 +895,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 375..378, value: StringLiteralValue { inner: Single( StringLiteral { range: 375..378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -915,7 +915,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..384, value: Int( 0, @@ -924,13 +924,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 389..392, value: StringLiteralValue { inner: Single( StringLiteral { range: 389..392, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -947,10 +947,10 @@ Module( MatchValue( PatternMatchValue { range: 372..373, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 372..373, value: Int( 1, @@ -962,10 +962,10 @@ Module( MatchValue( PatternMatchValue { range: 380..381, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 380..381, value: Int( 1, @@ -977,10 +977,10 @@ Module( MatchValue( PatternMatchValue { range: 386..387, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..387, value: Int( 2, @@ -992,10 +992,10 @@ Module( MatchValue( PatternMatchValue { range: 394..395, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 394..395, value: Int( 2, @@ -1012,11 +1012,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 398..401, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 398..401, }, ), @@ -1026,26 +1026,26 @@ Module( }, MatchCase { range: 406..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 411..429, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchMapping( PatternMatchMapping { range: 412..428, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 413..416, value: StringLiteralValue { inner: Single( StringLiteral { range: 413..416, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -1059,13 +1059,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..424, value: StringLiteralValue { inner: Single( StringLiteral { range: 421..424, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -1082,10 +1082,10 @@ Module( MatchValue( PatternMatchValue { range: 418..419, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 418..419, value: Int( 1, @@ -1097,10 +1097,10 @@ Module( MatchValue( PatternMatchValue { range: 426..427, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 426..427, value: Int( 2, @@ -1120,11 +1120,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 431..434, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 431..434, }, ), @@ -1134,14 +1134,14 @@ Module( }, MatchCase { range: 439..477, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 444..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 444..447, id: Name("Foo"), ctx: Load, @@ -1149,24 +1149,24 @@ Module( ), arguments: PatternArguments { range: 447..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 448..451, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 448..449, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 450..451, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 450..451, value: Int( 1, @@ -1178,26 +1178,26 @@ Module( }, PatternKeyword { range: 453..471, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 453..454, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchMapping( PatternMatchMapping { range: 455..471, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 456..459, value: StringLiteralValue { inner: Single( StringLiteral { range: 456..459, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -1211,13 +1211,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..467, value: StringLiteralValue { inner: Single( StringLiteral { range: 464..467, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -1234,10 +1234,10 @@ Module( MatchValue( PatternMatchValue { range: 461..462, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 461..462, value: Int( 1, @@ -1249,10 +1249,10 @@ Module( MatchValue( PatternMatchValue { range: 469..470, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 469..470, value: Int( 2, @@ -1274,11 +1274,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 474..477, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 474..477, }, ), @@ -1288,19 +1288,19 @@ Module( }, MatchCase { range: 482..532, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 487..527, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchClass( PatternMatchClass { range: 488..496, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 488..491, id: Name("Foo"), ctx: Load, @@ -1308,24 +1308,24 @@ Module( ), arguments: PatternArguments { range: 491..496, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 492..495, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 492..493, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 494..495, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 494..495, value: Int( 1, @@ -1342,10 +1342,10 @@ Module( MatchClass( PatternMatchClass { range: 498..526, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..501, id: Name("Foo"), ctx: Load, @@ -1353,24 +1353,24 @@ Module( ), arguments: PatternArguments { range: 501..526, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 502..505, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 502..503, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 504..505, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 504..505, value: Int( 1, @@ -1382,26 +1382,26 @@ Module( }, PatternKeyword { range: 507..525, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 507..508, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchMapping( PatternMatchMapping { range: 509..525, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 510..513, value: StringLiteralValue { inner: Single( StringLiteral { range: 510..513, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -1415,13 +1415,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 518..521, value: StringLiteralValue { inner: Single( StringLiteral { range: 518..521, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Double, @@ -1438,10 +1438,10 @@ Module( MatchValue( PatternMatchValue { range: 515..516, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 515..516, value: Int( 1, @@ -1453,10 +1453,10 @@ Module( MatchValue( PatternMatchValue { range: 523..524, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 523..524, value: Int( 2, @@ -1481,11 +1481,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 529..532, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 529..532, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_type_parameter_names.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_type_parameter_names.py.snap index 55e020ad84b15..852f2656e05d0 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_type_parameter_names.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@duplicate_type_parameter_names.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/duplicate_type_parame ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..261, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, id: Name("Alias"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 10..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -43,11 +43,11 @@ Module( TypeVar( TypeParamTypeVar { range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -58,7 +58,7 @@ Module( ), value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), @@ -66,28 +66,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..45, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 28..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -96,11 +96,11 @@ Module( TypeVar( TypeParamTypeVar { range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -111,26 +111,24 @@ Module( ), parameters: Parameters { range: 34..40, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 35..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 35..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("t"), range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("T"), ctx: Load, @@ -149,11 +147,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, }, ), @@ -164,27 +162,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..64, decorator_list: [], name: Identifier { id: Name("C"), range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 53..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -193,11 +191,11 @@ Module( TypeVar( TypeParamTypeVar { range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -210,11 +208,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..64, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..64, }, ), @@ -225,11 +223,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..132, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..75, id: Name("Alias"), ctx: Store, @@ -238,16 +236,16 @@ Module( type_params: Some( TypeParams { range: 75..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 76..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 76..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -256,16 +254,16 @@ Module( TypeVar( TypeParamTypeVar { range: 79..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 79..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, id: Name("str"), ctx: Load, @@ -278,21 +276,21 @@ Module( TypeVar( TypeParamTypeVar { range: 87..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("V"), range: 87..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..102, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, id: Name("str"), ctx: Load, @@ -300,7 +298,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..101, id: Name("bytes"), ctx: Load, @@ -318,11 +316,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 104..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 105..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -330,11 +328,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 109..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 111..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -342,17 +340,17 @@ Module( TypeVar( TypeParamTypeVar { range: 114..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 114..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..125, id: Name("default"), ctx: Load, @@ -366,7 +364,7 @@ Module( ), value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..132, }, ), @@ -374,28 +372,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..154, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 137..138, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 138..147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 139..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 139..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -404,11 +402,11 @@ Module( TypeVar( TypeParamTypeVar { range: 142..143, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 142..143, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -417,11 +415,11 @@ Module( TypeVar( TypeParamTypeVar { range: 145..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 145..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -432,9 +430,7 @@ Module( ), parameters: Parameters { range: 147..149, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -445,11 +441,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..154, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..154, }, ), @@ -460,28 +456,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..188, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 174..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 175..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 175..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -490,11 +486,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 178..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 179..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -504,9 +500,7 @@ Module( ), parameters: Parameters { range: 181..183, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -517,11 +511,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..188, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..188, }, ), @@ -532,28 +526,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..238, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 223..231, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 224..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 224..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -562,11 +556,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 227..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 229..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -576,9 +570,7 @@ Module( ), parameters: Parameters { range: 231..233, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -589,11 +581,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..238, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..238, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_star_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_star_py310.py.snap index 0530c751f8c98..668f37596bfac 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_star_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_star_py310.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/except_star_py310.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..126, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..125, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, }, ), @@ -32,11 +32,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 53..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..71, id: Name("ValueError"), ctx: Load, @@ -47,11 +47,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, }, ), @@ -63,11 +63,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 77..98, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..93, id: Name("KeyError"), ctx: Load, @@ -78,11 +78,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..98, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..98, }, ), @@ -94,11 +94,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 99..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..120, id: Name("Error"), ctx: Load, @@ -109,11 +109,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..125, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..125, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap index fb1f2b6181124..475b5a7e2caed 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_invalid_expression.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_invalid_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..74, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -26,16 +26,16 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 14..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..28, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("x"), ctx: Load, @@ -49,7 +49,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..38, }, ), @@ -64,12 +64,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..73, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..52, }, ), @@ -78,15 +78,15 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 53..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..63, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Load, @@ -100,7 +100,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..73, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap index b9b370d139a81..bdc389bfcd5e4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_as_name.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_a ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..73, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..72, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -26,11 +26,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 14..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..30, id: Name("Exception"), ctx: Load, @@ -41,7 +41,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..43, }, ), @@ -51,11 +51,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 44..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..60, id: Name("Exception"), ctx: Load, @@ -66,7 +66,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..72, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap index fa14993f7942b..e3f602dd2463e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..166, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..37, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -26,19 +26,19 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 14..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: Some( Identifier { id: Name("exc"), range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..37, }, ), @@ -53,12 +53,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..165, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..105, }, ), @@ -67,13 +67,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 106..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..123, }, ), @@ -83,13 +83,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 124..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..140, }, ), @@ -99,19 +99,19 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 141..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: Some( Identifier { id: Name("exc"), range: 152..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..165, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception_and_as_name.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception_and_as_name.py.snap index fc9b78dde0110..fe8b15dd88aea 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception_and_as_name.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_missing_exception_and_as_name.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_missing_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..34, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..33, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -26,13 +26,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 14..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..33, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_as.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_as.py.snap index ddc722c8922ea..153f50e02ed8e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_as.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_as.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_unparenth ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..86, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..42, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -26,16 +26,16 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 14..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..25, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("x"), ctx: Load, @@ -43,7 +43,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("y"), ctx: Load, @@ -59,13 +59,13 @@ Module( Identifier { id: Name("exc"), range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..42, }, ), @@ -80,12 +80,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..85, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..56, }, ), @@ -94,16 +94,16 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 57..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..69, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("x"), ctx: Load, @@ -111,7 +111,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("y"), ctx: Load, @@ -127,13 +127,13 @@ Module( Identifier { id: Name("eg"), range: 73..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..85, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_no_as_py313.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_no_as_py313.py.snap index 848e2c129955f..671eed373c07d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_no_as_py313.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@except_stmt_unparenthesized_tuple_no_as_py313.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/except_stmt_unparenth ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..117, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..79, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..57, }, ), @@ -26,16 +26,16 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 58..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..69, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("x"), ctx: Load, @@ -43,7 +43,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("y"), ctx: Load, @@ -59,7 +59,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..79, }, ), @@ -74,12 +74,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..116, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..93, }, ), @@ -88,16 +88,16 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 94..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..106, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("x"), ctx: Load, @@ -105,7 +105,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, id: Name("y"), ctx: Load, @@ -121,7 +121,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..116, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap index 0637b78f081a1..e3f633b879464 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__double_starred.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/do ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..55, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,21 +28,21 @@ Module( ), arguments: Arguments { range: 4..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 5..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..14, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("x"), ctx: Load, @@ -60,15 +60,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..27, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..27, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..20, id: Name("call"), ctx: Load, @@ -76,20 +76,20 @@ Module( ), arguments: Arguments { range: 20..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 21..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..26, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("x"), ctx: Load, @@ -107,15 +107,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..38, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..38, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..32, id: Name("call"), ctx: Load, @@ -123,20 +123,20 @@ Module( ), arguments: Arguments { range: 32..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 33..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..37, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("x"), ctx: Load, @@ -154,15 +154,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..54, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..54, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..44, id: Name("call"), ctx: Load, @@ -170,11 +170,11 @@ Module( ), arguments: Arguments { range: 44..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, value: Int( 1, @@ -185,11 +185,11 @@ Module( keywords: [ Keyword { range: 45..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap index 6e6e7699e23bc..9f5a0cfa41675 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__duplicate_keyword_arguments.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/du ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, id: Name("foo"), ctx: Load, @@ -28,22 +28,22 @@ Module( ), arguments: Arguments { range: 3..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("a"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: Int( 1, @@ -53,17 +53,17 @@ Module( }, Keyword { range: 9..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("b"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Int( 2, @@ -73,17 +73,17 @@ Module( }, Keyword { range: 14..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("c"), range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, value: Int( 3, @@ -93,17 +93,17 @@ Module( }, Keyword { range: 19..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("b"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, value: Int( 4, @@ -113,17 +113,17 @@ Module( }, Keyword { range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("a"), range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, value: Int( 5, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap index e517103c145d9..1e7f4b61921f8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/in ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..67, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,22 +28,22 @@ Module( ), arguments: Arguments { range: 4..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 5..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name(""), range: 5..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 1, @@ -59,15 +59,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..32, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..32, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..20, id: Name("call"), ctx: Load, @@ -75,22 +75,22 @@ Module( ), arguments: Arguments { range: 20..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 21..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name(""), range: 21..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, value: Int( 1, @@ -106,15 +106,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..47, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..47, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..38, id: Name("call"), ctx: Load, @@ -122,16 +122,16 @@ Module( ), arguments: Arguments { range: 38..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..46, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, id: Name("x"), ctx: Load, @@ -149,15 +149,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..66, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..66, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..52, id: Name("call"), ctx: Load, @@ -165,15 +165,15 @@ Module( ), arguments: Arguments { range: 52..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..65, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap index 99643af80e05f..00502dd67916e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_keyword_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/in ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..69, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,27 +28,27 @@ Module( ), arguments: Arguments { range: 4..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 5..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..16, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("y"), ctx: Load, @@ -66,15 +66,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..40, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..40, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..22, id: Name("call"), ctx: Load, @@ -82,26 +82,26 @@ Module( ), arguments: Arguments { range: 22..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 23..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..39, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("y"), ctx: Load, @@ -118,15 +118,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..53, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..53, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..45, id: Name("call"), ctx: Load, @@ -134,26 +134,26 @@ Module( ), arguments: Arguments { range: 45..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 46..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..52, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("y"), ctx: Load, @@ -171,15 +171,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..68, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..68, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..58, id: Name("call"), ctx: Load, @@ -187,26 +187,26 @@ Module( ), arguments: Arguments { range: 58..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 59..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 59..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..66, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap index 2b60be9235fb7..90c44de37ccd4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__invalid_order.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/in ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..100, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("x"), ctx: Load, @@ -42,11 +42,11 @@ Module( keywords: [ Keyword { range: 5..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..13, id: Name("kwargs"), ctx: Load, @@ -61,15 +61,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..30, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..30, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..22, id: Name("call"), ctx: Load, @@ -77,11 +77,11 @@ Module( ), arguments: Arguments { range: 22..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("y"), ctx: Load, @@ -91,17 +91,17 @@ Module( keywords: [ Keyword { range: 23..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 1, @@ -117,15 +117,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..53, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..53, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..35, id: Name("call"), ctx: Load, @@ -133,11 +133,11 @@ Module( ), arguments: Arguments { range: 35..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("y"), ctx: Load, @@ -147,17 +147,17 @@ Module( keywords: [ Keyword { range: 36..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, value: Int( 1, @@ -167,11 +167,11 @@ Module( }, Keyword { range: 41..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..49, id: Name("kwargs"), ctx: Load, @@ -186,15 +186,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..75, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..75, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..58, id: Name("call"), ctx: Load, @@ -202,15 +202,15 @@ Module( ), arguments: Arguments { range: 58..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..74, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..74, id: Name("args"), ctx: Load, @@ -223,11 +223,11 @@ Module( keywords: [ Keyword { range: 59..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..67, id: Name("kwargs"), ctx: Load, @@ -242,15 +242,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..99, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..99, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..80, id: Name("call"), ctx: Load, @@ -258,15 +258,15 @@ Module( ), arguments: Arguments { range: 80..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..97, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..97, id: Name("args"), ctx: Load, @@ -279,11 +279,11 @@ Module( keywords: [ Keyword { range: 81..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..89, id: Name("kwargs"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap index bade10dafee52..42fd265361af0 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_argument.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/mi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, @@ -40,7 +40,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap index a17128ef2c7f4..37e891b89a404 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_comma.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/mi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, @@ -40,7 +40,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap index 1b515e8f95efa..83e062828f786 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__missing_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/mi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 1, @@ -48,15 +48,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..21, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..21, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..15, id: Name("call"), ctx: Load, @@ -64,22 +64,22 @@ Module( ), arguments: Arguments { range: 15..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 16..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..19, id: Name(""), ctx: Invalid, @@ -94,15 +94,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..32, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..32, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..26, id: Name("call"), ctx: Load, @@ -110,15 +110,15 @@ Module( ), arguments: Arguments { range: 26..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..28, id: Name(""), ctx: Invalid, @@ -129,7 +129,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, id: Name("y"), ctx: Load, @@ -144,11 +144,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..37, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..37, id: Name("foo"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap index d9a820dcd8fbd..d4e877372689d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__starred.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/st ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..64, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,19 +28,19 @@ Module( ), arguments: Arguments { range: 4..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..27, elt: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..10, id: Name("data"), ctx: Load, @@ -52,10 +52,10 @@ Module( generators: [ Comprehension { range: 11..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..19, id: Name("data"), ctx: Store, @@ -63,7 +63,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..27, id: Name("iter"), ctx: Load, @@ -85,15 +85,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..43, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..43, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..33, id: Name("call"), ctx: Load, @@ -101,20 +101,20 @@ Module( ), arguments: Arguments { range: 33..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..42, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..42, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Load, @@ -135,15 +135,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..63, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..63, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..48, id: Name("call"), ctx: Load, @@ -151,19 +151,19 @@ Module( ), arguments: Arguments { range: 48..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..62, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..62, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap index 6eab95404964d..655f45ed241bd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_0.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/un ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), arguments: Arguments { range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -38,21 +38,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..26, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 11..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 14..16, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -63,7 +61,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..26, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap index d60f2bf8710a4..99e0e4fbcd521 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/un ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, @@ -47,21 +47,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..27, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 12..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 15..17, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -72,7 +70,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..27, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap index ee3456db28520..2b4270bf2cbc4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__arguments__unclosed_2.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/arguments/un ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, @@ -47,21 +47,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..28, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 13..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 16..18, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -72,7 +70,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap index f2eec9b2cb912..67ca493c7d65f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__invalid_member.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/in ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -26,11 +26,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..3, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..3, value: Float( 0.1, @@ -41,11 +41,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, @@ -55,11 +55,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..7, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..7, value: Float( 0.1, @@ -70,11 +70,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..9, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..9, value: Float( 0.0, @@ -85,19 +85,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..15, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..15, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..12, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("x"), ctx: Load, @@ -106,14 +106,14 @@ Module( attr: Identifier { id: Name(""), range: 12..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 0, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap index efa04a319e7bf..cbbf28892ac5f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__multiple_dots.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/mu ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..46, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, id: Name("extra"), ctx: Load, @@ -33,7 +33,7 @@ Module( attr: Identifier { id: Name(""), range: 6..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -41,7 +41,7 @@ Module( attr: Identifier { id: Name("dot"), range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -50,11 +50,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..19, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..19, id: Name("multiple"), ctx: Load, @@ -64,22 +64,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..27, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..27, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), attr: Identifier { id: Name("dots"), range: 23..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -88,11 +88,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..36, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..36, id: Name("multiple"), ctx: Load, @@ -102,26 +102,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..45, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..45, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..40, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, }, ), attr: Identifier { id: Name(""), range: 40..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -129,7 +129,7 @@ Module( attr: Identifier { id: Name("dots"), range: 41..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap index 69af9f8041b7d..04634b6766d0c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__attribute__no_member.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/attribute/no ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..141, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..93, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..93, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..92, id: Name("first"), ctx: Load, @@ -29,7 +29,7 @@ Module( attr: Identifier { id: Name(""), range: 93..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -38,11 +38,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..100, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..100, id: Name("second"), ctx: Load, @@ -52,15 +52,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..141, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..141, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..140, id: Name("last"), ctx: Load, @@ -69,7 +69,7 @@ Module( attr: Identifier { id: Name(""), range: 141..141, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap index f1e8020d1a8cb..f9683c9fe628d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_0.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/await/no_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..73, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..66, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..66, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..66, id: Name(""), ctx: Invalid, @@ -32,15 +32,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..73, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..73, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -49,7 +49,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap index cf7d31d11b5e7..10da259bcc75b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__no_expression_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/await/no_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..85, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..64, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..64, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..64, id: Name(""), ctx: Invalid, @@ -32,21 +32,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..85, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 70..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 73..75, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -57,7 +55,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..85, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap index 029e1723d9b72..3eb34793946a5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__await__recover.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/await/recove ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..284, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..130, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..130, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..130, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("x"), ctx: Load, @@ -38,19 +38,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..162, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..162, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..162, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, id: Name("x"), ctx: Load, @@ -65,19 +65,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..173, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..173, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..172, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("x"), ctx: Load, @@ -92,20 +92,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..227, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..227, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..227, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..227, id: Name("x"), ctx: Load, @@ -120,34 +120,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..245, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..245, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..245, parameters: Some( Parameters { range: 241..242, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 241..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 241..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 241..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -161,7 +159,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..245, id: Name("x"), ctx: Load, @@ -175,20 +173,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..254, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..254, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..254, op: UAdd, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..254, id: Name("x"), ctx: Load, @@ -202,20 +200,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..263, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..263, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..263, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..263, id: Name("x"), ctx: Load, @@ -229,20 +227,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..272, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..272, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..272, op: Invert, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..272, id: Name("x"), ctx: Load, @@ -256,20 +254,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 273..284, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 273..284, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..284, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 283..284, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap index fa628602c101c..41d9904805118 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__invalid_rhs_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/inval ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -29,26 +29,24 @@ Module( op: Add, right: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..15, parameters: Some( Parameters { range: 11..12, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -62,7 +60,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("y"), ctx: Load, @@ -76,15 +74,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..28, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..28, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("x"), ctx: Load, @@ -93,12 +91,12 @@ Module( op: Sub, right: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..28, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap index b9bd494cd7f6b..1ba50a5e827f1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_lhs.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("y"), ctx: Load, @@ -26,15 +26,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -44,7 +44,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap index ab67484feb3a6..baf12f2136939 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_0.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Int( 0, @@ -30,7 +30,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..3, id: Name(""), ctx: Invalid, @@ -42,15 +42,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -60,7 +60,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap index 9357c59dc3aa4..1b39f2bac0dba 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__missing_rhs_1.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/missi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Int( 1, @@ -34,7 +34,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 2, @@ -46,11 +46,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 3, @@ -60,7 +60,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..11, id: Name(""), ctx: Invalid, @@ -74,15 +74,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 4, @@ -92,7 +92,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, value: Int( 5, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap index 41adb471bfeb4..cf81983e851c7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__multiple_ops.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/multi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -29,12 +29,12 @@ Module( op: Add, right: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, op: UAdd, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..3, id: Name(""), ctx: Invalid, @@ -48,15 +48,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 1, @@ -66,7 +66,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 2, @@ -79,15 +79,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("x"), ctx: Load, @@ -96,12 +96,12 @@ Module( op: Sub, right: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..13, id: Name(""), ctx: Invalid, @@ -115,15 +115,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..19, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..19, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, value: Int( 1, @@ -133,7 +133,7 @@ Module( op: Sub, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap index 475add5dc262c..8293f4b759d26 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__named_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/named ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -29,7 +29,7 @@ Module( op: Sub, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("y"), ctx: Load, @@ -41,16 +41,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..15, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..15, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Int( 1, @@ -59,7 +59,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 2, @@ -75,15 +75,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..21, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..21, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("x"), ctx: Load, @@ -92,7 +92,7 @@ Module( op: Div, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("y"), ctx: Load, @@ -104,11 +104,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap index 3fc18497c4ce5..5080466f7f07e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bin_op__starred_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bin_op/starr ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -29,11 +29,11 @@ Module( op: Add, right: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..6, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("y"), ctx: Load, @@ -48,15 +48,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..14, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..14, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, @@ -65,11 +65,11 @@ Module( op: Pow, right: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..14, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap index a3515f3a7fa6d..8f10231161e6e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__invalid_rhs_expression.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/inva ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -30,26 +30,24 @@ Module( ), Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..17, parameters: Some( Parameters { range: 13..14, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 13..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 13..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 13..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -63,7 +61,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("y"), ctx: Load, @@ -78,17 +76,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..31, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..31, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("x"), ctx: Load, @@ -96,12 +94,12 @@ Module( ), Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..31, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap index 68ff71e827417..7becb2d219913 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_lhs.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/miss ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap index 85ad8a317f91d..d40859437fe92 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__missing_rhs.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/miss ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -30,7 +30,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..5, id: Name(""), ctx: Invalid, @@ -43,15 +43,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..12, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..12, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Int( 1, @@ -61,7 +61,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap index e06f08171688b..c599119ee6c2f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__named_expression.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/name ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -30,7 +30,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("a"), ctx: Load, @@ -43,11 +43,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("b"), ctx: Load, @@ -57,17 +57,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..19, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..19, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("x"), ctx: Load, @@ -75,7 +75,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("a"), ctx: Load, @@ -88,11 +88,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap index 5369e4e69bd79..a63aa3e1776d1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__bool_op__starred_expression.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/bool_op/star ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -30,11 +30,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("y"), ctx: Load, @@ -50,17 +50,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..16, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..16, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("x"), ctx: Load, @@ -68,11 +68,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..16, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap index a64df1f7b321f..419cc7854b1d6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_order.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/inva ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..131, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -32,12 +32,12 @@ Module( comparators: [ UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("y"), ctx: Load, @@ -52,12 +52,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..41, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("x"), ctx: Store, @@ -66,11 +66,11 @@ Module( ], value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..38, id: Name(""), ctx: Invalid, @@ -82,7 +82,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("y"), ctx: Load, @@ -95,11 +95,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, id: Name("x"), ctx: Load, @@ -109,16 +109,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..128, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..128, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..128, id: Name("is"), ctx: Load, @@ -130,11 +130,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap index a118b221db5f8..22a228bba8f38 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__invalid_rhs_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/inva ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..34, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -32,26 +32,24 @@ Module( comparators: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..20, parameters: Some( Parameters { range: 16..17, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -65,7 +63,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("y"), ctx: Load, @@ -80,15 +78,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..34, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..34, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -100,12 +98,12 @@ Module( comparators: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..34, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap index a38a989312cb1..4ca152d200eef 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_lhs.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/miss ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("y"), ctx: Load, @@ -26,15 +26,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -44,7 +44,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap index b41171207cb07..b40badc953b11 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_0.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/miss ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -32,7 +32,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..3, id: Name(""), ctx: Invalid, @@ -45,15 +45,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -63,7 +63,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap index e58c0025af0d0..d51319b5b9d2a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_1.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/miss ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..71, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("x"), ctx: Load, @@ -26,16 +26,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..64, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..64, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..64, id: Name(""), ctx: Invalid, @@ -47,15 +47,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..71, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..71, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, value: Int( 1, @@ -65,7 +65,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap index f02148c958940..a9019dc09ea8c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__missing_rhs_2.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/miss ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -32,7 +32,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..8, id: Name(""), ctx: Invalid, @@ -45,15 +45,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..15, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..15, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Int( 1, @@ -63,7 +63,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap index 023e710c958e2..38297d62dac51 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__multiple_equals.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/mult ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..32, targets: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..29, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("x"), ctx: Load, @@ -33,7 +33,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..29, id: Name(""), ctx: Invalid, @@ -45,7 +45,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..32, id: Name("y"), ctx: Load, @@ -55,16 +55,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..40, targets: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..37, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, id: Name("x"), ctx: Load, @@ -76,7 +76,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..37, id: Name(""), ctx: Invalid, @@ -88,7 +88,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap index fdeafe1b4d71f..3bdec1455cbb1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__named_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/name ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -32,7 +32,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("y"), ctx: Load, @@ -45,16 +45,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..20, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..20, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, value: Int( 1, @@ -63,7 +63,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 2, @@ -79,15 +79,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..26, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..26, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("x"), ctx: Load, @@ -99,7 +99,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("y"), ctx: Load, @@ -112,11 +112,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap index 90dd6b20562a6..0de6ae37e0904 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__compare__starred_expression.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/compare/star ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..39, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -32,11 +32,11 @@ Module( comparators: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..7, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("y"), ctx: Load, @@ -52,15 +52,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..19, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..19, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("x"), ctx: Load, @@ -72,11 +72,11 @@ Module( comparators: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..19, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("y"), ctx: Load, @@ -92,19 +92,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..27, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..27, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..27, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -116,7 +116,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("y"), ctx: Load, @@ -132,19 +132,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..39, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..39, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..39, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Load, @@ -156,7 +156,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap index 7a000174912f1..6c72721b03f04 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__comprehension.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/compreh ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..362, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..34, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..34, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("x"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("y"), ctx: Load, @@ -37,10 +37,10 @@ Module( generators: [ Comprehension { range: 23..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, value: Int( 1, @@ -49,7 +49,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("y"), ctx: Load, @@ -65,15 +65,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..54, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..54, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("x"), ctx: Load, @@ -81,7 +81,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("y"), ctx: Load, @@ -90,16 +90,16 @@ Module( generators: [ Comprehension { range: 41..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..48, value: StringLiteralValue { inner: Single( StringLiteral { range: 45..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Single, @@ -113,7 +113,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, id: Name("y"), ctx: Load, @@ -129,15 +129,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..77, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..77, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Load, @@ -145,7 +145,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("y"), ctx: Load, @@ -154,14 +154,14 @@ Module( generators: [ Comprehension { range: 61..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..71, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..69, id: Name("call"), ctx: Load, @@ -169,7 +169,7 @@ Module( ), arguments: Arguments { range: 69..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -177,7 +177,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("y"), ctx: Load, @@ -193,15 +193,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..100, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..100, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, id: Name("x"), ctx: Load, @@ -209,7 +209,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("y"), ctx: Load, @@ -218,15 +218,15 @@ Module( generators: [ Comprehension { range: 84..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..94, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("a"), ctx: Load, @@ -234,7 +234,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, id: Name("b"), ctx: Load, @@ -245,7 +245,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("y"), ctx: Load, @@ -261,15 +261,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..135, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..135, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, id: Name("x"), ctx: Load, @@ -277,7 +277,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..122, id: Name("y"), ctx: Load, @@ -286,10 +286,10 @@ Module( generators: [ Comprehension { range: 123..134, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("x"), ctx: Store, @@ -297,11 +297,11 @@ Module( ), iter: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..134, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..134, id: Name("y"), ctx: Load, @@ -320,15 +320,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..159, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..159, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("x"), ctx: Load, @@ -336,7 +336,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, id: Name("y"), ctx: Load, @@ -345,10 +345,10 @@ Module( generators: [ Comprehension { range: 142..158, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("x"), ctx: Store, @@ -356,12 +356,12 @@ Module( ), iter: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..158, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, id: Name("y"), ctx: Load, @@ -380,15 +380,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..188, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..188, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, id: Name("x"), ctx: Load, @@ -396,7 +396,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, id: Name("y"), ctx: Load, @@ -405,10 +405,10 @@ Module( generators: [ Comprehension { range: 166..187, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, id: Name("x"), ctx: Store, @@ -416,11 +416,11 @@ Module( ), iter: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..187, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..187, id: Name("y"), ctx: Load, @@ -438,15 +438,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..216, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..216, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..191, id: Name("x"), ctx: Load, @@ -454,7 +454,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, id: Name("y"), ctx: Load, @@ -463,10 +463,10 @@ Module( generators: [ Comprehension { range: 195..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..200, id: Name("x"), ctx: Store, @@ -474,26 +474,24 @@ Module( ), iter: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..215, parameters: Some( Parameters { range: 211..212, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -507,7 +505,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("y"), ctx: Load, @@ -525,15 +523,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..257, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..257, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..233, id: Name("x"), ctx: Load, @@ -541,7 +539,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..236, id: Name("y"), ctx: Load, @@ -550,10 +548,10 @@ Module( generators: [ Comprehension { range: 237..256, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, id: Name("x"), ctx: Store, @@ -561,7 +559,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..250, id: Name("data"), ctx: Load, @@ -570,11 +568,11 @@ Module( ifs: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..256, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..256, id: Name("y"), ctx: Load, @@ -593,15 +591,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..289, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..289, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..260, id: Name("x"), ctx: Load, @@ -609,7 +607,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..263, id: Name("y"), ctx: Load, @@ -618,10 +616,10 @@ Module( generators: [ Comprehension { range: 264..288, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 268..269, id: Name("x"), ctx: Store, @@ -629,7 +627,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 273..277, id: Name("data"), ctx: Load, @@ -638,12 +636,12 @@ Module( ifs: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..288, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..288, id: Name("y"), ctx: Load, @@ -662,15 +660,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..326, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..326, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 291..292, id: Name("x"), ctx: Load, @@ -678,7 +676,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 294..295, id: Name("y"), ctx: Load, @@ -687,10 +685,10 @@ Module( generators: [ Comprehension { range: 296..325, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..301, id: Name("x"), ctx: Store, @@ -698,7 +696,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 305..309, id: Name("data"), ctx: Load, @@ -707,11 +705,11 @@ Module( ifs: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..325, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..325, id: Name("y"), ctx: Load, @@ -729,15 +727,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..362, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..362, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..329, id: Name("x"), ctx: Load, @@ -745,7 +743,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..332, id: Name("y"), ctx: Load, @@ -754,10 +752,10 @@ Module( generators: [ Comprehension { range: 333..361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 337..338, id: Name("x"), ctx: Store, @@ -765,7 +763,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..346, id: Name("data"), ctx: Load, @@ -774,26 +772,24 @@ Module( ifs: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 350..361, parameters: Some( Parameters { range: 357..358, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 357..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 357..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 357..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -807,7 +803,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 360..361, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap index 2375e262a6783..a579afac89c0c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/double_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..278, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..135, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..135, items: [ DictItem { key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("x"), ctx: Load, @@ -34,7 +34,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..134, value: Int( 1, @@ -44,7 +44,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..134, id: Name(""), ctx: Invalid, @@ -58,18 +58,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..162, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..162, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("a"), ctx: Load, @@ -78,7 +78,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, value: Int( 1, @@ -90,18 +90,18 @@ Module( key: None, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..161, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..154, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..146, id: Name("x"), ctx: Load, @@ -109,7 +109,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, id: Name("y"), ctx: Load, @@ -125,37 +125,35 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..184, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..184, items: [ DictItem { key: None, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..177, parameters: Some( Parameters { range: 173..174, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -169,7 +167,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..177, id: Name("x"), ctx: Load, @@ -182,7 +180,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, id: Name("b"), ctx: Load, @@ -191,7 +189,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..183, value: Int( 2, @@ -206,18 +204,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..201, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..201, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..187, id: Name("a"), ctx: Load, @@ -226,7 +224,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, value: Int( 1, @@ -238,13 +236,13 @@ Module( key: None, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..200, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..195, id: Name("x"), ctx: Load, @@ -252,7 +250,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..200, id: Name("y"), ctx: Load, @@ -269,24 +267,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..219, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..219, items: [ DictItem { key: None, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..212, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..206, id: Name("x"), ctx: Load, @@ -294,7 +292,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, id: Name("y"), ctx: Load, @@ -308,7 +306,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("b"), ctx: Load, @@ -317,7 +315,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..218, value: Int( 2, @@ -332,18 +330,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..241, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..241, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..222, id: Name("a"), ctx: Load, @@ -352,7 +350,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..225, value: Int( 1, @@ -364,12 +362,12 @@ Module( key: None, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..234, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..234, id: Name("x"), ctx: Load, @@ -382,7 +380,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("b"), ctx: Load, @@ -391,7 +389,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, value: Int( 2, @@ -406,22 +404,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..252, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..252, items: [ DictItem { key: None, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..251, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, id: Name("x"), ctx: Load, @@ -433,7 +431,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..251, id: Name("y"), ctx: Load, @@ -450,22 +448,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..267, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..267, items: [ DictItem { key: None, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 256..266, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 256..257, id: Name("x"), ctx: Load, @@ -477,7 +475,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..266, id: Name("y"), ctx: Load, @@ -494,22 +492,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 268..277, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 268..277, items: [ DictItem { key: None, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..276, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..272, id: Name("x"), ctx: Load, @@ -521,7 +519,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 275..276, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap index 22ca3a3d362a7..9c0cde63d3919 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__double_star_comprehension.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/double_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..358, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..147, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..147, items: [ DictItem { key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..126, id: Name("x"), ctx: Load, @@ -34,7 +34,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("y"), ctx: Load, @@ -43,7 +43,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..133, id: Name("for"), ctx: Load, @@ -54,7 +54,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, id: Name("x"), ctx: Load, @@ -63,7 +63,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..135, id: Name(""), ctx: Invalid, @@ -74,11 +74,11 @@ Module( key: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..146, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("y"), ctx: Load, @@ -90,7 +90,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..146, id: Name("data"), ctx: Load, @@ -102,7 +102,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..146, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap index 3b205a80f1463..99d310bc874e4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_0.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("x"), ctx: Load, @@ -32,7 +32,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, id: Name("def"), ctx: Load, @@ -43,11 +43,11 @@ Module( key: Some( Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, id: Name("foo"), ctx: Load, @@ -55,7 +55,7 @@ Module( ), arguments: Arguments { range: 12..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -64,7 +64,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..24, id: Name("pass"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap index 487654f51db0e..c53bcf8e92c69 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_1.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("x"), ctx: Load, @@ -32,11 +32,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -46,7 +46,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap index 474f5b303833a..a5a08be0be579 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__missing_closing_brace_2.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("x"), ctx: Load, @@ -32,7 +32,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 1, @@ -47,21 +47,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..27, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 12..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 15..17, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -72,7 +70,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..27, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap index a6bcfaa62163d..5db7a61381c4c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_0.py.snap @@ -7,27 +7,27 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/named_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..84, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..77, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..77, items: [ DictItem { key: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..62, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Store, @@ -35,7 +35,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, value: Int( 1, @@ -47,7 +47,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, id: Name("y"), ctx: Load, @@ -58,7 +58,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("z"), ctx: Load, @@ -67,7 +67,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..68, id: Name(""), ctx: Invalid, @@ -78,7 +78,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, value: Int( 2, @@ -88,7 +88,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("a"), ctx: Load, @@ -102,15 +102,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..84, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..84, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, id: Name("x"), ctx: Load, @@ -119,7 +119,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap index 47c76d0afcc71..58509cc935c7d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__named_expression_1.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/named_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..86, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..79, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..79, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("x"), ctx: Load, @@ -32,7 +32,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, id: Name("y"), ctx: Load, @@ -43,7 +43,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, value: Int( 1, @@ -53,7 +53,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..67, id: Name(""), ctx: Invalid, @@ -64,7 +64,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, id: Name("z"), ctx: Load, @@ -73,7 +73,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("a"), ctx: Load, @@ -84,7 +84,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, value: Int( 2, @@ -94,7 +94,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..78, id: Name(""), ctx: Invalid, @@ -108,15 +108,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..86, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..86, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, id: Name("x"), ctx: Load, @@ -125,7 +125,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..86, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap index ecfb8d7b9a15d..c4c4f242c8001 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__dict__recover.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/dict/recover ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..346, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..91, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..91, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..89, id: Name(""), ctx: Invalid, @@ -34,18 +34,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..105, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..105, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..95, value: Int( 1, @@ -55,7 +55,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, value: Int( 2, @@ -67,7 +67,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, value: Int( 3, @@ -77,7 +77,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..104, value: Int( 4, @@ -92,18 +92,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..115, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..115, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, value: Int( 1, @@ -113,7 +113,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, value: Int( 2, @@ -128,18 +128,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..144, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..144, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, value: Int( 1, @@ -149,7 +149,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, value: Int( 2, @@ -161,7 +161,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, value: Int( 3, @@ -171,7 +171,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..143, value: Int( 4, @@ -186,18 +186,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..162, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..162, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, value: Int( 1, @@ -207,7 +207,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..160, id: Name(""), ctx: Invalid, @@ -221,18 +221,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..205, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..205, items: [ DictItem { key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..204, id: Name(""), ctx: Invalid, @@ -246,18 +246,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..222, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..222, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..208, id: Name("x"), ctx: Load, @@ -266,7 +266,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..211, id: Name("y"), ctx: Load, @@ -277,7 +277,7 @@ Module( key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..215, id: Name(""), ctx: Invalid, @@ -288,7 +288,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..218, id: Name("a"), ctx: Load, @@ -297,7 +297,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..221, id: Name("b"), ctx: Load, @@ -311,22 +311,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..330, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..330, items: [ DictItem { key: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 311..313, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..313, id: Name("x"), ctx: Load, @@ -338,7 +338,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..316, id: Name("y"), ctx: Load, @@ -349,7 +349,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..319, id: Name("z"), ctx: Load, @@ -358,7 +358,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..322, id: Name("a"), ctx: Load, @@ -369,11 +369,11 @@ Module( key: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..326, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 325..326, id: Name("b"), ctx: Load, @@ -385,7 +385,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..329, id: Name("c"), ctx: Load, @@ -399,18 +399,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..345, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..345, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 332..333, id: Name("x"), ctx: Load, @@ -419,11 +419,11 @@ Module( ), value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..337, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..337, id: Name("y"), ctx: Load, @@ -437,7 +437,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..340, id: Name("z"), ctx: Load, @@ -446,11 +446,11 @@ Module( ), value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..344, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..344, id: Name("a"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap index bf215d18b6919..ba444eb9597ab 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_identifiers.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/emoji_identi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..64, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Store, @@ -26,7 +26,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..5, id: Name(""), ctx: Invalid, @@ -36,12 +36,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..37, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("a"), ctx: Store, @@ -50,7 +50,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..37, id: Name(""), ctx: Invalid, @@ -60,16 +60,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, op: UAdd, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..43, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_statement.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_statement.py.snap index d4c139b3cc46e..20d9f0812e8b4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_statement.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__emoji_statement.py.snap @@ -7,7 +7,7 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/emoji_statem ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, body: [], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap index b480e99948aa3..766ec9bebc257 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_0.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_o ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..88, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..67, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..67, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..62, id: Name("expr"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("x"), ctx: Load, @@ -36,7 +36,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..67, id: Name(""), ctx: Invalid, @@ -48,21 +48,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..88, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 73..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 76..78, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -73,7 +71,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..88, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap index beec6bcb14994..20584cc80bbae 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_orelse_expr_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_o ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..76, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..69, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..69, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..64, id: Name("expr"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, id: Name("x"), ctx: Load, @@ -36,7 +36,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..69, id: Name(""), ctx: Invalid, @@ -48,15 +48,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..76, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..76, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, value: Int( 1, @@ -66,7 +66,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap index d3c32935800bd..38246f51553da 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_0.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_t ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..76, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..55, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..55, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..55, id: Name(""), ctx: Invalid, @@ -28,7 +28,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("x"), ctx: Load, @@ -36,7 +36,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..55, id: Name(""), ctx: Invalid, @@ -48,21 +48,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..76, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 61..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 64..66, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -73,7 +71,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..76, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap index 39ddb5266add8..9ea573657dae3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__missing_test_expr_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/if/missing_t ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..64, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..57, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..57, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..57, id: Name(""), ctx: Invalid, @@ -28,7 +28,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("x"), ctx: Load, @@ -36,7 +36,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..57, id: Name(""), ctx: Invalid, @@ -48,15 +48,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..64, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..64, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, value: Int( 1, @@ -66,7 +66,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap index e62779397c09c..38a8d3c530737 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__if__recover.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/if/recover.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..215, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..43, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..43, test: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..36, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..36, id: Name("expr"), ctx: Load, @@ -35,7 +35,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("x"), ctx: Load, @@ -43,7 +43,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, id: Name("y"), ctx: Load, @@ -55,34 +55,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..67, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..67, test: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..60, parameters: Some( Parameters { range: 56..57, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -96,7 +94,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("x"), ctx: Load, @@ -106,7 +104,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("x"), ctx: Load, @@ -114,7 +112,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("y"), ctx: Load, @@ -126,20 +124,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..87, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..87, test: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..80, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, id: Name("x"), ctx: Load, @@ -150,7 +148,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -158,7 +156,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, id: Name("y"), ctx: Load, @@ -170,19 +168,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..112, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..112, test: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..105, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("x"), ctx: Load, @@ -192,7 +190,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, id: Name("x"), ctx: Load, @@ -200,7 +198,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, id: Name("y"), ctx: Load, @@ -212,15 +210,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..164, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..164, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..151, id: Name("expr"), ctx: Load, @@ -228,7 +226,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..143, id: Name("x"), ctx: Load, @@ -236,11 +234,11 @@ Module( ), orelse: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..164, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..164, id: Name("orelse"), ctx: Load, @@ -255,15 +253,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..187, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..187, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..174, id: Name("expr"), ctx: Load, @@ -271,7 +269,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, id: Name("x"), ctx: Load, @@ -279,12 +277,12 @@ Module( ), orelse: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..187, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..187, id: Name("y"), ctx: Load, @@ -299,15 +297,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..215, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..215, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..197, id: Name("expr"), ctx: Load, @@ -315,7 +313,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..189, id: Name("x"), ctx: Load, @@ -323,11 +321,11 @@ Module( ), orelse: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..215, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap index ac95e6aff76d7..7d2bfdb631b07 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_default_parameters.py.snap @@ -7,35 +7,33 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/lambda_defau ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, parameters: Some( Parameters { range: 7..17, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -43,21 +41,21 @@ Module( }, ParameterWithDefault { range: 10..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..14, value: Int( 20, @@ -68,14 +66,14 @@ Module( }, ParameterWithDefault { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -89,7 +87,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap index 30e3bf68b1f18..986a07de03f87 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__lambda_duplicate_parameters.py.snap @@ -7,35 +7,33 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/lambda_dupli ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..91, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, parameters: Some( Parameters { range: 7..11, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -43,14 +41,14 @@ Module( }, ParameterWithDefault { range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -64,7 +62,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 1, @@ -77,30 +75,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..33, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..33, parameters: Some( Parameters { range: 23..30, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -111,14 +107,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -130,7 +126,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 1, @@ -143,30 +139,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..52, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..52, parameters: Some( Parameters { range: 42..49, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -174,21 +168,21 @@ Module( }, ParameterWithDefault { range: 45..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 45..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 45..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..49, value: Int( 20, @@ -205,7 +199,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 1, @@ -218,30 +212,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..69, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..69, parameters: Some( Parameters { range: 61..66, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -251,11 +243,11 @@ Module( vararg: Some( Parameter { range: 64..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -266,7 +258,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, value: Int( 1, @@ -279,30 +271,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..90, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..90, parameters: Some( Parameters { range: 78..87, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 78..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 78..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 78..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -314,11 +304,11 @@ Module( kwarg: Some( Parameter { range: 84..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 86..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -327,7 +317,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap index 110db0cba9fa1..80f0ed10de200 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__comprehension.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/list/compreh ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..376, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..48, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..48, elt: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..36, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("x"), ctx: Load, @@ -36,10 +36,10 @@ Module( generators: [ Comprehension { range: 37..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Store, @@ -47,7 +47,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("y"), ctx: Load, @@ -63,15 +63,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..81, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..81, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -80,10 +80,10 @@ Module( generators: [ Comprehension { range: 70..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, value: Int( 1, @@ -92,7 +92,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, id: Name("y"), ctx: Load, @@ -108,15 +108,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..98, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..98, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Load, @@ -125,16 +125,16 @@ Module( generators: [ Comprehension { range: 85..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..92, value: StringLiteralValue { inner: Single( StringLiteral { range: 89..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Single, @@ -148,7 +148,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("y"), ctx: Load, @@ -164,15 +164,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..118, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..118, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("x"), ctx: Load, @@ -181,14 +181,14 @@ Module( generators: [ Comprehension { range: 102..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..112, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..110, id: Name("call"), ctx: Load, @@ -196,7 +196,7 @@ Module( ), arguments: Arguments { range: 110..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -204,7 +204,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, id: Name("y"), ctx: Load, @@ -220,15 +220,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..138, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..138, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, id: Name("x"), ctx: Load, @@ -237,15 +237,15 @@ Module( generators: [ Comprehension { range: 122..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..132, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("a"), ctx: Load, @@ -253,7 +253,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..131, id: Name("b"), ctx: Load, @@ -264,7 +264,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..137, id: Name("y"), ctx: Load, @@ -280,15 +280,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..170, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..170, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("x"), ctx: Load, @@ -297,10 +297,10 @@ Module( generators: [ Comprehension { range: 158..169, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..163, id: Name("x"), ctx: Store, @@ -308,11 +308,11 @@ Module( ), iter: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..169, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..169, id: Name("y"), ctx: Load, @@ -331,15 +331,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..191, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..191, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..173, id: Name("x"), ctx: Load, @@ -348,10 +348,10 @@ Module( generators: [ Comprehension { range: 174..190, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("x"), ctx: Store, @@ -359,12 +359,12 @@ Module( ), iter: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..190, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("y"), ctx: Load, @@ -383,15 +383,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..217, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..217, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, id: Name("x"), ctx: Load, @@ -400,10 +400,10 @@ Module( generators: [ Comprehension { range: 195..216, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..200, id: Name("x"), ctx: Store, @@ -411,11 +411,11 @@ Module( ), iter: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..216, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..216, id: Name("y"), ctx: Load, @@ -433,15 +433,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..242, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..242, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..220, id: Name("x"), ctx: Load, @@ -450,10 +450,10 @@ Module( generators: [ Comprehension { range: 221..241, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..226, id: Name("x"), ctx: Store, @@ -461,26 +461,24 @@ Module( ), iter: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..241, parameters: Some( Parameters { range: 237..238, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -494,7 +492,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..241, id: Name("y"), ctx: Load, @@ -512,15 +510,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..280, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..280, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..259, id: Name("x"), ctx: Load, @@ -529,10 +527,10 @@ Module( generators: [ Comprehension { range: 260..279, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..265, id: Name("x"), ctx: Store, @@ -540,7 +538,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..273, id: Name("data"), ctx: Load, @@ -549,11 +547,11 @@ Module( ifs: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..279, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..279, id: Name("y"), ctx: Load, @@ -572,15 +570,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..309, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..309, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..283, id: Name("x"), ctx: Load, @@ -589,10 +587,10 @@ Module( generators: [ Comprehension { range: 284..308, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 288..289, id: Name("x"), ctx: Store, @@ -600,7 +598,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 293..297, id: Name("data"), ctx: Load, @@ -609,12 +607,12 @@ Module( ifs: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..308, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 307..308, id: Name("y"), ctx: Load, @@ -633,15 +631,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..343, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..343, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 311..312, id: Name("x"), ctx: Load, @@ -650,10 +648,10 @@ Module( generators: [ Comprehension { range: 313..342, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..318, id: Name("x"), ctx: Store, @@ -661,7 +659,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 322..326, id: Name("data"), ctx: Load, @@ -670,11 +668,11 @@ Module( ifs: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 330..342, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 341..342, id: Name("y"), ctx: Load, @@ -692,15 +690,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..376, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..376, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..346, id: Name("x"), ctx: Load, @@ -709,10 +707,10 @@ Module( generators: [ Comprehension { range: 347..375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..352, id: Name("x"), ctx: Store, @@ -720,7 +718,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 356..360, id: Name("data"), ctx: Load, @@ -729,26 +727,24 @@ Module( ifs: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..375, parameters: Some( Parameters { range: 371..372, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 371..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 371..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 371..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -762,7 +758,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..375, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap index 04f72aae2310f..27415fde73536 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_0.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..43, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..43, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap index da496ea1cd9c4..d53b5a82915e3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_1.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..133, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..133, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..133, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..133, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("x"), ctx: Load, @@ -34,7 +34,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap index c65c7f3f8f7f5..3bfaaa689ef92 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_2.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..141, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..141, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..141, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, value: Int( 1, @@ -30,11 +30,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..141, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..137, id: Name("x"), ctx: Load, @@ -43,7 +43,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap index 833765842b84f..4f21ca4ddf237 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__missing_closing_bracket_3.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/list/missing ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..140, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..119, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..119, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, value: Int( 1, @@ -30,7 +30,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, value: Int( 2, @@ -45,21 +45,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..140, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 125..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 128..130, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -70,7 +68,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..140, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap index e3535344a6505..3b1ba32aac392 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__recover.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/list/recover ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..208, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..83, id: Name(""), ctx: Invalid, @@ -35,16 +35,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..93, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..93, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, value: Int( 1, @@ -53,7 +53,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, value: Int( 2, @@ -68,16 +68,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..100, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..100, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, value: Int( 1, @@ -92,16 +92,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Int( 1, @@ -110,7 +110,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..122, value: Int( 2, @@ -125,16 +125,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..162, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..162, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, value: Int( 1, @@ -143,7 +143,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, value: Int( 2, @@ -158,16 +158,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..194, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..194, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..187, value: Int( 1, @@ -176,11 +176,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..192, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("x"), ctx: Load, @@ -189,7 +189,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..192, id: Name(""), ctx: Invalid, @@ -205,16 +205,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..202, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..202, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, value: Int( 1, @@ -223,7 +223,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..201, value: Int( 2, @@ -238,20 +238,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..207, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..207, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..206, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..206, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap index caa6a5a30d193..064ab37b92761 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__list__star_expression_precedence.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/list/star_ex ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..200, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..93, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..93, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..88, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, id: Name("x"), ctx: Load, @@ -36,7 +36,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, id: Name("y"), ctx: Load, @@ -50,24 +50,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..106, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..106, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..102, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..102, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("x"), ctx: Load, @@ -79,7 +79,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, id: Name("y"), ctx: Load, @@ -93,7 +93,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("z"), ctx: Load, @@ -107,25 +107,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..118, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..118, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..114, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..114, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("x"), ctx: Load, @@ -138,7 +138,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, id: Name("z"), ctx: Load, @@ -152,26 +152,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..132, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..132, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..128, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..128, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..122, id: Name("x"), ctx: Load, @@ -179,7 +179,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("y"), ctx: Load, @@ -193,7 +193,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..131, id: Name("z"), ctx: Load, @@ -207,26 +207,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..145, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..145, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..141, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..141, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, id: Name("x"), ctx: Load, @@ -234,7 +234,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, id: Name("y"), ctx: Load, @@ -248,7 +248,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..144, id: Name("z"), ctx: Load, @@ -262,31 +262,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..168, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..168, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..164, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..164, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..157, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..149, id: Name("x"), ctx: Load, @@ -294,7 +294,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, id: Name("y"), ctx: Load, @@ -307,7 +307,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("z"), ctx: Load, @@ -321,39 +321,37 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..186, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..186, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..182, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..182, parameters: Some( Parameters { range: 178..179, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 178..179, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 178..179, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 178..179, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -367,7 +365,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..182, id: Name("x"), ctx: Load, @@ -380,7 +378,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..185, id: Name("z"), ctx: Load, @@ -394,24 +392,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..199, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..199, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..195, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..190, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("x"), ctx: Store, @@ -422,7 +420,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..195, value: Int( 2, @@ -433,7 +431,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap index e19733fe68916..80c4345b88149 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__invalid_target.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/named/invali ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..109, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..68, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..67, target: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("x"), ctx: Load, @@ -33,14 +33,14 @@ Module( attr: Identifier { id: Name("y"), range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, value: Int( 1, @@ -53,19 +53,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..80, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..79, target: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..74, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("x"), ctx: Load, @@ -73,7 +73,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("y"), ctx: Load, @@ -84,7 +84,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 1, @@ -97,19 +97,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..90, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..89, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..84, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Store, @@ -120,7 +120,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, value: Int( 1, @@ -133,20 +133,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..109, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..108, target: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..98, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("x"), ctx: Store, @@ -154,7 +154,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("y"), ctx: Store, @@ -166,12 +166,12 @@ Module( ), value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..108, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..104, value: Int( 1, @@ -180,7 +180,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..107, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap index 8015e50f6a7c0..d434114a508d9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_0.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missin ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..75, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap index af8dfa521093d..d37bcfe97a45e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missin ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..33, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..33, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..33, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Store, @@ -28,7 +28,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..33, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap index aaa227cdfe103..884fb234b2936 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_2.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missin ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..87, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..71, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..71, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Store, @@ -28,7 +28,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, id: Name("def"), ctx: Load, @@ -40,15 +40,15 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..87, target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..77, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..75, id: Name("foo"), ctx: Load, @@ -56,7 +56,7 @@ Module( ), arguments: Arguments { range: 75..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -64,7 +64,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..87, id: Name("pass"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap index e7e25c0972136..181c17c668dfd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_3.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missin ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..112, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..112, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..112, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, id: Name("x"), ctx: Store, @@ -28,11 +28,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..112, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..108, id: Name("x"), ctx: Load, @@ -41,7 +41,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap index dc699731cef50..ee4effd12c812 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__named__missing_expression_4.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/named/missin ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..78, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..71, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..69, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("x"), ctx: Store, @@ -28,7 +28,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..69, id: Name(""), ctx: Invalid, @@ -40,15 +40,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..78, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..78, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("x"), ctx: Load, @@ -57,7 +57,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap index 3ac0c1bdffc2c..3e8a85dc97555 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__generator.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..36, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, elt: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..3, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("x"), ctx: Load, @@ -36,10 +36,10 @@ Module( generators: [ Comprehension { range: 4..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("x"), ctx: Store, @@ -47,7 +47,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("y"), ctx: Load, @@ -64,20 +64,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..24, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..24, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..23, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("x"), ctx: Store, @@ -85,7 +85,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, value: Int( 1, @@ -103,12 +103,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..35, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Store, @@ -116,7 +116,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap index 1b1d87fe6d091..ed9f13abc614d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_0.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..47, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..47, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap index 5dee13a8a2d29..80fe213fc24f6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..137, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..137, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..137, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("x"), ctx: Load, @@ -29,7 +29,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..137, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap index b5721df9676f0..fa0cdaade8253 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_2.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..146, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..146, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..146, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, value: Int( 1, @@ -30,11 +30,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..146, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, id: Name("x"), ctx: Load, @@ -43,7 +43,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..146, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap index bbf1fb9749f30..b98aae283e6d4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__missing_closing_paren_3.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..144, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Int( 1, @@ -30,7 +30,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 2, @@ -46,21 +46,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..144, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 129..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 132..134, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -71,7 +69,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..144, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap index 9012f3e1bef88..2dc3440241eb7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__parenthesized.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..125, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..70, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..69, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -33,11 +33,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, id: Name("x"), ctx: Load, @@ -47,11 +47,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..125, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..125, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap index a44a6fc0663a4..768381c483f8b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..267, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..84, id: Name(""), ctx: Invalid, @@ -36,16 +36,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..94, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..94, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 1, @@ -54,7 +54,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, value: Int( 2, @@ -70,16 +70,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..101, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..101, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, value: Int( 1, @@ -95,11 +95,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..121, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, value: Int( 1, @@ -110,11 +110,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 2, @@ -125,11 +125,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..162, target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, value: Int( 1, @@ -138,7 +138,7 @@ Module( ), annotation: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, value: Int( 2, @@ -151,16 +151,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..195, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..195, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..188, value: Int( 1, @@ -169,11 +169,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..193, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..191, id: Name("x"), ctx: Load, @@ -182,7 +182,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..193, id: Name(""), ctx: Invalid, @@ -199,11 +199,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..199, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..199, value: Int( 1, @@ -214,11 +214,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: Int( 2, @@ -229,16 +229,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..267, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..267, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..256, id: Name("x"), ctx: Load, @@ -246,7 +246,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..259, id: Name("y"), ctx: Load, @@ -254,7 +254,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..264, value: Int( 2, @@ -263,7 +263,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..267, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap index b566c6a594853..da92fa1991d3a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__parenthesized__tuple_starred_expr.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/parenthesize ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..532, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..178, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..178, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..165, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..165, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..160, id: Name("x"), ctx: Load, @@ -41,7 +41,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, id: Name("y"), ctx: Load, @@ -55,7 +55,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, id: Name("z"), ctx: Load, @@ -63,15 +63,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..177, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..177, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("x"), ctx: Load, @@ -83,7 +83,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..177, id: Name("y"), ctx: Load, @@ -104,25 +104,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..198, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..198, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..186, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..186, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..186, id: Name("x"), ctx: Load, @@ -135,7 +135,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..189, id: Name("z"), ctx: Load, @@ -143,16 +143,16 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..197, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..197, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..197, id: Name("x"), ctx: Load, @@ -172,26 +172,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..222, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..222, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..208, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..208, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, id: Name("x"), ctx: Load, @@ -199,7 +199,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..208, id: Name("y"), ctx: Load, @@ -213,7 +213,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..211, id: Name("z"), ctx: Load, @@ -221,17 +221,17 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..221, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..221, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("x"), ctx: Load, @@ -239,7 +239,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..221, id: Name("y"), ctx: Load, @@ -260,26 +260,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..244, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..244, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..231, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..231, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..226, id: Name("x"), ctx: Load, @@ -287,7 +287,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..231, id: Name("y"), ctx: Load, @@ -301,7 +301,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..234, id: Name("z"), ctx: Load, @@ -309,17 +309,17 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..243, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..243, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..238, id: Name("x"), ctx: Load, @@ -327,7 +327,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..243, id: Name("y"), ctx: Load, @@ -348,31 +348,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..286, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..286, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..263, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 247..263, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..256, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 247..248, id: Name("x"), ctx: Load, @@ -380,7 +380,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..263, id: Name("y"), ctx: Load, @@ -393,7 +393,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..266, id: Name("z"), ctx: Load, @@ -401,22 +401,22 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 268..285, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..285, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..278, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..270, id: Name("x"), ctx: Load, @@ -424,7 +424,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..285, id: Name("y"), ctx: Load, @@ -444,39 +444,37 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..318, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..318, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 288..300, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..300, parameters: Some( Parameters { range: 296..297, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 296..297, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 296..297, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 296..297, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -490,7 +488,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..300, id: Name("x"), ctx: Load, @@ -503,7 +501,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..303, id: Name("z"), ctx: Load, @@ -511,30 +509,28 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 305..317, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..317, parameters: Some( Parameters { range: 313..314, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 313..314, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 313..314, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 313..314, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -548,7 +544,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..317, id: Name("x"), ctx: Load, @@ -568,24 +564,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..340, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..340, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 320..327, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 320..322, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..322, id: Name("x"), ctx: Store, @@ -596,7 +592,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 326..327, value: Int( 2, @@ -607,7 +603,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..330, id: Name("z"), ctx: Load, @@ -615,15 +611,15 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 332..339, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 332..334, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..334, id: Name("x"), ctx: Store, @@ -634,7 +630,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 338..339, value: Int( 2, @@ -652,24 +648,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 363..382, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 363..382, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 363..370, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..370, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..365, id: Name("x"), ctx: Load, @@ -681,7 +677,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 369..370, id: Name("y"), ctx: Load, @@ -695,7 +691,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 372..373, id: Name("z"), ctx: Load, @@ -703,15 +699,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 375..382, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..382, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..377, id: Name("x"), ctx: Load, @@ -723,7 +719,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 381..382, id: Name("y"), ctx: Load, @@ -744,25 +740,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..400, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..400, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..389, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 384..389, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 388..389, id: Name("x"), ctx: Load, @@ -775,7 +771,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 391..392, id: Name("z"), ctx: Load, @@ -783,16 +779,16 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 394..400, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..400, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 399..400, id: Name("x"), ctx: Load, @@ -812,26 +808,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..422, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..422, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..409, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 402..409, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 402..403, id: Name("x"), ctx: Load, @@ -839,7 +835,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 408..409, id: Name("y"), ctx: Load, @@ -853,7 +849,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 411..412, id: Name("z"), ctx: Load, @@ -861,17 +857,17 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 414..422, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 415..422, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 415..416, id: Name("x"), ctx: Load, @@ -879,7 +875,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..422, id: Name("y"), ctx: Load, @@ -900,26 +896,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 423..442, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 423..442, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 423..430, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 424..430, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 424..425, id: Name("x"), ctx: Load, @@ -927,7 +923,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 429..430, id: Name("y"), ctx: Load, @@ -941,7 +937,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 432..433, id: Name("z"), ctx: Load, @@ -949,17 +945,17 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 435..442, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 436..442, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 436..437, id: Name("x"), ctx: Load, @@ -967,7 +963,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..442, id: Name("y"), ctx: Load, @@ -988,31 +984,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..482, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..482, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..460, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 444..460, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 449..453, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 444..445, id: Name("x"), ctx: Load, @@ -1020,7 +1016,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 459..460, id: Name("y"), ctx: Load, @@ -1033,7 +1029,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 462..463, id: Name("z"), ctx: Load, @@ -1041,22 +1037,22 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 465..482, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 466..482, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 471..475, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 466..467, id: Name("x"), ctx: Load, @@ -1064,7 +1060,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 481..482, id: Name("y"), ctx: Load, @@ -1084,39 +1080,37 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 483..512, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 483..512, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 483..495, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 484..495, parameters: Some( Parameters { range: 491..492, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 491..492, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 491..492, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 491..492, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1130,7 +1124,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 494..495, id: Name("x"), ctx: Load, @@ -1143,7 +1137,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 497..498, id: Name("z"), ctx: Load, @@ -1151,30 +1145,28 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 500..512, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 501..512, parameters: Some( Parameters { range: 508..509, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 508..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 508..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 508..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1188,7 +1180,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 511..512, id: Name("x"), ctx: Load, @@ -1208,15 +1200,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..515, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..515, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 514..515, id: Name("x"), ctx: Load, @@ -1229,16 +1221,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 519..532, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 519..532, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 519..520, value: Int( 2, @@ -1247,7 +1239,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 522..523, id: Name("z"), ctx: Load, @@ -1255,11 +1247,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 525..527, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 526..527, id: Name("x"), ctx: Load, @@ -1270,7 +1262,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 531..532, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap index abf42e4b03000..08cad0598c913 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__comprehension.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/set/comprehe ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..377, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..48, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..48, elt: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..36, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("x"), ctx: Load, @@ -36,10 +36,10 @@ Module( generators: [ Comprehension { range: 37..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Store, @@ -47,7 +47,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("y"), ctx: Load, @@ -63,15 +63,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..81, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..81, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -80,10 +80,10 @@ Module( generators: [ Comprehension { range: 70..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, value: Int( 1, @@ -92,7 +92,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, id: Name("y"), ctx: Load, @@ -108,15 +108,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..98, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..98, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Load, @@ -125,16 +125,16 @@ Module( generators: [ Comprehension { range: 85..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..92, value: StringLiteralValue { inner: Single( StringLiteral { range: 89..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Single, @@ -148,7 +148,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("y"), ctx: Load, @@ -164,15 +164,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..118, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..118, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("x"), ctx: Load, @@ -181,14 +181,14 @@ Module( generators: [ Comprehension { range: 102..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..112, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..110, id: Name("call"), ctx: Load, @@ -196,7 +196,7 @@ Module( ), arguments: Arguments { range: 110..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -204,7 +204,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, id: Name("y"), ctx: Load, @@ -220,15 +220,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..138, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..138, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, id: Name("x"), ctx: Load, @@ -237,15 +237,15 @@ Module( generators: [ Comprehension { range: 122..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..132, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("a"), ctx: Load, @@ -253,7 +253,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..131, id: Name("b"), ctx: Load, @@ -264,7 +264,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..137, id: Name("y"), ctx: Load, @@ -280,15 +280,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..170, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..170, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("x"), ctx: Load, @@ -297,10 +297,10 @@ Module( generators: [ Comprehension { range: 158..169, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..163, id: Name("x"), ctx: Store, @@ -308,11 +308,11 @@ Module( ), iter: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..169, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..169, id: Name("y"), ctx: Load, @@ -331,15 +331,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..191, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..191, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..173, id: Name("x"), ctx: Load, @@ -348,10 +348,10 @@ Module( generators: [ Comprehension { range: 174..190, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("x"), ctx: Store, @@ -359,12 +359,12 @@ Module( ), iter: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..190, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("y"), ctx: Load, @@ -383,15 +383,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..217, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..217, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, id: Name("x"), ctx: Load, @@ -400,10 +400,10 @@ Module( generators: [ Comprehension { range: 195..216, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..200, id: Name("x"), ctx: Store, @@ -411,11 +411,11 @@ Module( ), iter: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..216, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..216, id: Name("y"), ctx: Load, @@ -433,15 +433,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..242, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..242, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..220, id: Name("x"), ctx: Load, @@ -450,10 +450,10 @@ Module( generators: [ Comprehension { range: 221..241, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..226, id: Name("x"), ctx: Store, @@ -461,26 +461,24 @@ Module( ), iter: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..241, parameters: Some( Parameters { range: 237..238, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -494,7 +492,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..241, id: Name("y"), ctx: Load, @@ -512,15 +510,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..280, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..280, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..259, id: Name("x"), ctx: Load, @@ -529,10 +527,10 @@ Module( generators: [ Comprehension { range: 260..279, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..265, id: Name("x"), ctx: Store, @@ -540,7 +538,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..273, id: Name("data"), ctx: Load, @@ -549,11 +547,11 @@ Module( ifs: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..279, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..279, id: Name("y"), ctx: Load, @@ -572,15 +570,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..309, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..309, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..283, id: Name("x"), ctx: Load, @@ -589,10 +587,10 @@ Module( generators: [ Comprehension { range: 284..308, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 288..289, id: Name("x"), ctx: Store, @@ -600,7 +598,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 293..297, id: Name("data"), ctx: Load, @@ -609,12 +607,12 @@ Module( ifs: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..308, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 307..308, id: Name("y"), ctx: Load, @@ -633,15 +631,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..343, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..343, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 311..312, id: Name("x"), ctx: Load, @@ -650,10 +648,10 @@ Module( generators: [ Comprehension { range: 313..342, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..318, id: Name("x"), ctx: Store, @@ -661,7 +659,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 322..326, id: Name("data"), ctx: Load, @@ -670,11 +668,11 @@ Module( ifs: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 330..342, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 341..342, id: Name("y"), ctx: Load, @@ -692,15 +690,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..376, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..376, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..346, id: Name("x"), ctx: Load, @@ -709,10 +707,10 @@ Module( generators: [ Comprehension { range: 347..375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..352, id: Name("x"), ctx: Store, @@ -720,7 +718,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 356..360, id: Name("data"), ctx: Load, @@ -729,26 +727,24 @@ Module( ifs: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..375, parameters: Some( Parameters { range: 371..372, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 371..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 371..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 371..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -762,7 +758,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..375, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap index 43438af0b7046..759f2c99c0dcf 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_0.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..47, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..47, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap index b1a51ec0e1580..01bfdf4692112 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_1.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..136, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..136, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..136, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..136, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, id: Name("x"), ctx: Load, @@ -34,7 +34,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap index ee7e0553f36db..ead70d568e997 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_2.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..144, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..144, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..144, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, value: Int( 1, @@ -30,11 +30,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..144, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, id: Name("x"), ctx: Load, @@ -43,7 +43,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..144, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap index dd12017d4f61c..311eaae5306ef 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__missing_closing_curly_brace_3.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/set/missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..144, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Int( 1, @@ -30,7 +30,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 2, @@ -44,21 +44,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..144, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 129..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 132..134, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -69,7 +67,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..144, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap index fd02629ffdc7f..b489b1c64fe1e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__recover.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/set/recover. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..323, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..200, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..200, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..198, id: Name(""), ctx: Invalid, @@ -34,16 +34,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..208, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..208, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..204, value: Int( 1, @@ -52,7 +52,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..207, value: Int( 2, @@ -66,16 +66,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..215, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..215, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, value: Int( 1, @@ -89,16 +89,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..238, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..238, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..235, value: Int( 1, @@ -107,7 +107,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, value: Int( 2, @@ -121,18 +121,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..277, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..277, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..273, value: Int( 1, @@ -142,7 +142,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 275..276, value: Int( 2, @@ -157,16 +157,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..309, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..309, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..302, value: Int( 1, @@ -175,11 +175,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..307, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..305, id: Name("x"), ctx: Load, @@ -188,7 +188,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 307..307, id: Name(""), ctx: Invalid, @@ -203,16 +203,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 311..317, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 311..317, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..313, value: Int( 1, @@ -221,7 +221,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..316, value: Int( 2, @@ -235,20 +235,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..322, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..322, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 320..321, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..321, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap index 18fb551839be9..d3c23a0ec3909 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__set__star_expression_precedence.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/set/star_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..198, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..92, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..92, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..87, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, id: Name("x"), ctx: Load, @@ -36,7 +36,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("y"), ctx: Load, @@ -49,24 +49,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..105, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..105, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..101, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..101, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..96, id: Name("x"), ctx: Load, @@ -78,7 +78,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("y"), ctx: Load, @@ -92,7 +92,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..104, id: Name("z"), ctx: Load, @@ -105,25 +105,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..117, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..117, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..113, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..113, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, id: Name("x"), ctx: Load, @@ -136,7 +136,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, id: Name("z"), ctx: Load, @@ -149,26 +149,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..131, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..131, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..127, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..127, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, id: Name("x"), ctx: Load, @@ -176,7 +176,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, id: Name("y"), ctx: Load, @@ -190,7 +190,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("z"), ctx: Load, @@ -203,26 +203,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..144, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..144, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..140, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..140, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, id: Name("x"), ctx: Load, @@ -230,7 +230,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, id: Name("y"), ctx: Load, @@ -244,7 +244,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..143, id: Name("z"), ctx: Load, @@ -257,31 +257,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..167, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..167, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..163, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..163, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..156, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..148, id: Name("x"), ctx: Load, @@ -289,7 +289,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..163, id: Name("y"), ctx: Load, @@ -302,7 +302,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, id: Name("z"), ctx: Load, @@ -315,39 +315,37 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..185, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..185, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..181, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..181, parameters: Some( Parameters { range: 177..178, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -361,7 +359,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..181, id: Name("x"), ctx: Load, @@ -374,7 +372,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..184, id: Name("z"), ctx: Load, @@ -387,24 +385,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..198, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..198, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..194, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..189, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..189, id: Name("x"), ctx: Store, @@ -415,7 +413,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, value: Int( 2, @@ -426,7 +424,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..197, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap index 133fc59208017..2e4321abd9be7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__invalid_slice_element.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/subscript/in ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..133, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -28,16 +28,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..9, lower: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..8, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("x"), ctx: Store, @@ -45,7 +45,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Int( 1, @@ -66,15 +66,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..39, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..39, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, id: Name("x"), ctx: Load, @@ -82,16 +82,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, lower: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..37, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("x"), ctx: Load, @@ -112,15 +112,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..46, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..46, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("x"), ctx: Load, @@ -128,17 +128,17 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, lower: None, upper: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..45, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("x"), ctx: Load, @@ -158,15 +158,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..54, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..54, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Load, @@ -174,18 +174,18 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..53, lower: None, upper: None, step: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..53, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, id: Name("x"), ctx: Load, @@ -204,15 +204,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("x"), ctx: Load, @@ -220,7 +220,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name(""), ctx: Invalid, @@ -233,15 +233,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..133, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..133, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..124, id: Name("x"), ctx: Load, @@ -249,15 +249,15 @@ Module( ), slice: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..132, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..127, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, id: Name("x"), ctx: Store, @@ -268,7 +268,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap index 734e357a4ab3d..b8b02d2973f32 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_0.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/subscript/un ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -28,17 +28,17 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..10, lower: None, upper: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, @@ -47,7 +47,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap index 0d95577060488..d3e57ddfc0d62 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__subscript__unclosed_slice_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/subscript/un ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Load, @@ -28,14 +28,14 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..9, lower: None, upper: None, step: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("def"), ctx: Load, @@ -51,15 +51,15 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..25, target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..15, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, id: Name("foo"), ctx: Load, @@ -67,7 +67,7 @@ Module( ), arguments: Arguments { range: 13..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -75,7 +75,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..25, id: Name("pass"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap index f024ef0b37aa4..b8f917a7ddba4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/unary.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, @@ -33,11 +33,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap index 952700a605f50..45a740ba23683 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__named_expression.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/unary/named_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..2, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..2, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("x"), ctx: Load, @@ -33,11 +33,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: Int( 1, @@ -48,16 +48,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..13, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..13, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, id: Name("x"), ctx: Load, @@ -69,11 +69,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap index 90fbf1bd9f05b..b11ca386f946b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_0.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/unary/no_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..3, id: Name(""), ctx: Invalid, @@ -33,15 +33,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, @@ -50,7 +50,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap index 2b9353fc3b7a7..48f2e1e00ffd4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__unary__no_expression_1.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/unary/no_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, op: UAdd, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..1, id: Name(""), ctx: Invalid, @@ -33,15 +33,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..8, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..8, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, @@ -50,7 +50,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap index 73536890eca5f..5feebcc55f505 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__named_expression.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/yield/named_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..85, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..59, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..59, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("x"), ctx: Load, @@ -34,11 +34,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, value: Int( 1, @@ -49,21 +49,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..84, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..84, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..84, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, value: Int( 1, @@ -72,7 +72,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("x"), ctx: Load, @@ -80,7 +80,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, value: Int( 2, @@ -89,7 +89,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap index 6bd430e889b2c..4238df7e8c799 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield__star_expression.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/yield/star_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..67, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..47, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..47, value: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..46, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, id: Name("x"), ctx: Load, @@ -41,31 +41,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..66, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..66, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..66, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..63, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..63, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Load, @@ -73,7 +73,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("y"), ctx: Load, @@ -87,7 +87,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap index 72433f9e7736f..719d563ed29af 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__starred_expression.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/yield_from/s ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..100, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..83, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..83, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..83, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("x"), ctx: Load, @@ -39,24 +39,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..100, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..100, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..100, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..97, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("x"), ctx: Load, @@ -67,7 +67,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap index a14264ccfbb3b..d521191aa7c85 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@expressions__yield_from__unparenthesized.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/expressions/yield_from/u ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..192, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..47, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..47, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("x"), ctx: Load, @@ -32,11 +32,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 1, @@ -47,20 +47,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..104, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..104, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..104, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("x"), ctx: Load, @@ -68,7 +68,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..104, id: Name("y"), ctx: Load, @@ -85,20 +85,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..192, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..192, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..192, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..181, id: Name("x"), ctx: Load, @@ -106,17 +106,17 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..191, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..191, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..185, id: Name("x"), ctx: Load, @@ -124,7 +124,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..191, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_conversion_follows_exclamation.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_conversion_follows_exclamation.py.snap index ac3df9565884d..0deb7be86aa48 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_conversion_follows_exclamation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_conversion_follows_exclamation.py.snap @@ -7,31 +7,31 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_conversion_f ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..30, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: FStringValue { inner: Single( FString( FString { range: 0..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, @@ -58,25 +58,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..19, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..19, value: TStringValue { inner: Single( TString { range: 10..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 12..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("x"), ctx: Load, @@ -102,26 +102,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..29, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..29, value: FStringValue { inner: Single( FString( FString { range: 20..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 22..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap index 42acb3033d9a7..b336a9531bb07 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_empty_expression.py.snap @@ -7,31 +7,31 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_empty_expres ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: FStringValue { inner: Single( FString( FString { range: 0..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..4, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..3, id: Name(""), ctx: Invalid, @@ -58,26 +58,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, value: FStringValue { inner: Single( FString( FString { range: 6..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 8..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..9, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap index 0858ce958d9d1..acb9c88e025c6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_name_tok.py.snap @@ -7,31 +7,31 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_invalid_conv ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: FStringValue { inner: Single( FString( FString { range: 0..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap index 165a659e99d4d..28624a678ed67 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_conversion_flag_other_tok.py.snap @@ -7,31 +7,31 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_invalid_conv ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: FStringValue { inner: Single( FString( FString { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, @@ -58,26 +58,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..21, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..21, value: FStringValue { inner: Single( FString( FString { range: 11..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 13..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap index acdb317e91fe5..a6920bde706f1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_invalid_starred_expr.py.snap @@ -7,35 +7,35 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_invalid_star ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..112, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..83, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..83, value: FStringValue { inner: Single( FString( FString { range: 77..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 79..82, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..81, id: Name(""), ctx: Invalid, @@ -65,36 +65,36 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..97, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..97, value: FStringValue { inner: Single( FString( FString { range: 84..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 86..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..95, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..95, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, id: Name("x"), ctx: Load, @@ -102,7 +102,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..95, id: Name("y"), ctx: Load, @@ -135,35 +135,35 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..111, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..111, value: FStringValue { inner: Single( FString( FString { range: 98..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 100..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..109, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..109, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap index 3610b8d114a23..2c4c6ee355304 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_lambda_without_parentheses.py.snap @@ -7,50 +7,48 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_lambda_witho ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: FStringValue { inner: Single( FString( FString { range: 0..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..12, parameters: Some( Parameters { range: 10..11, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -64,7 +62,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..12, id: Name(""), ctx: Invalid, @@ -80,7 +78,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 12..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " x", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap index 62c1efddfb713..9f85f5551df55 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace.py.snap @@ -7,31 +7,31 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_unclosed_lbr ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, value: FStringValue { inner: Single( FString( FString { range: 0..4, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2..3, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..3, id: Name(""), ctx: Invalid, @@ -58,26 +58,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..14, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..14, value: FStringValue { inner: Single( FString( FString { range: 5..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 7..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, id: Name("foo"), ctx: Load, @@ -104,26 +104,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..23, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..23, value: FStringValue { inner: Single( FString( FString { range: 15..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 17..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, id: Name("foo"), ctx: Load, @@ -155,11 +155,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..37, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..37, value: FStringValue { inner: Concatenated( @@ -167,15 +167,15 @@ Module( FString( FString { range: 24..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..27, id: Name(""), ctx: Invalid, @@ -197,15 +197,15 @@ Module( FString( FString { range: 29..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..34, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap index 9d97896c805f1..796a9745ea670 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@f_string_unclosed_lbrace_in_format_spec.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/err/f_string_unclosed_lbr ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: FStringValue { inner: Single( FString( FString { range: 0..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 8..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("x"), ctx: Load, @@ -49,7 +49,7 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 11..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], }, ), @@ -71,33 +71,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..28, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..28, value: FStringValue { inner: Single( FString( FString { range: 13..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 15..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 21..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -108,12 +108,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_iter_unpack_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_iter_unpack_py38.py.snap index cf2cb1c90be85..36e244899b1d4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_iter_unpack_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_iter_unpack_py38.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_iter_unpack_py38. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..106, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..63, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -25,16 +25,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..58, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..54, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("a"), ctx: Load, @@ -45,7 +45,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, id: Name("b"), ctx: Load, @@ -59,11 +59,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, }, ), @@ -75,12 +75,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..84, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Store, @@ -88,12 +88,12 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..79, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("a"), ctx: Load, @@ -101,11 +101,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..79, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, id: Name("b"), ctx: Load, @@ -122,11 +122,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, }, ), @@ -138,12 +138,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..105, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("x"), ctx: Store, @@ -151,16 +151,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..100, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..96, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..96, id: Name("a"), ctx: Load, @@ -171,11 +171,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..100, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("b"), ctx: Load, @@ -192,11 +192,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..105, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..105, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap index 2520538fcc2f7..907c07e8ce283 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_iter_expr.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_iter ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..71, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Store, @@ -25,17 +25,17 @@ Module( ), iter: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..17, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..17, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("a"), ctx: Load, @@ -43,7 +43,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("b"), ctx: Load, @@ -58,11 +58,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), @@ -74,12 +74,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..44, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("x"), ctx: Store, @@ -87,12 +87,12 @@ Module( ), iter: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..39, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("a"), ctx: Load, @@ -104,11 +104,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..44, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..44, }, ), @@ -120,12 +120,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..60, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..55, id: Name("target"), ctx: Store, @@ -133,7 +133,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("x"), ctx: Load, @@ -145,11 +145,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..70, target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, value: Int( 1, @@ -158,7 +158,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..70, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap index 491fd41a42e14..2ee9ae9293a70 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_targ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..154, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, is_async: false, target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 1, @@ -26,7 +26,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("x"), ctx: Load, @@ -35,11 +35,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, }, ), @@ -51,18 +51,18 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..33, is_async: false, target: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, value: StringLiteralValue { inner: Single( StringLiteral { range: 20..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -76,7 +76,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("x"), ctx: Load, @@ -85,11 +85,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..33, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..33, }, ), @@ -101,22 +101,22 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..56, is_async: false, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..46, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..46, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("x"), ctx: Load, @@ -124,7 +124,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, id: Name("y"), ctx: Load, @@ -138,7 +138,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, id: Name("z"), ctx: Load, @@ -147,11 +147,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, }, ), @@ -163,20 +163,20 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..77, is_async: false, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..67, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..67, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Load, @@ -185,7 +185,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("y"), ctx: Load, @@ -198,7 +198,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, id: Name("z"), ctx: Load, @@ -207,11 +207,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..77, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..77, }, ), @@ -223,16 +223,16 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..99, is_async: false, target: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..89, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, id: Name("x"), ctx: Load, @@ -242,7 +242,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("z"), ctx: Load, @@ -251,11 +251,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, }, ), @@ -267,21 +267,21 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..121, is_async: false, target: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..116, value: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..116, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..111, id: Name("x"), ctx: Load, @@ -293,7 +293,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, id: Name("y"), ctx: Load, @@ -307,7 +307,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..116, id: Name(""), ctx: Invalid, @@ -316,11 +316,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..121, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..121, }, ), @@ -332,17 +332,17 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..153, is_async: false, target: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..143, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("x"), ctx: Store, @@ -350,7 +350,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..131, value: Int( 1, @@ -359,7 +359,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..134, id: Name("y"), ctx: Store, @@ -367,22 +367,22 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..142, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..142, elts: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..141, value: StringLiteralValue { inner: Single( StringLiteral { range: 138..141, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -407,7 +407,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..148, id: Name("z"), ctx: Load, @@ -416,11 +416,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..153, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..153, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap index cb545e9b38b35..72cac3d156409 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_binary_expr.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_targ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..124, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, is_async: false, target: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..14, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, @@ -33,7 +33,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("y"), ctx: Load, @@ -44,7 +44,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("z"), ctx: Load, @@ -53,11 +53,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, }, ), @@ -69,16 +69,16 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..45, is_async: false, target: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..35, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Load, @@ -90,7 +90,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("y"), ctx: Load, @@ -101,7 +101,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("z"), ctx: Load, @@ -110,11 +110,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, }, ), @@ -126,18 +126,18 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..66, is_async: false, target: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..56, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, id: Name("x"), ctx: Load, @@ -145,7 +145,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, id: Name("y"), ctx: Load, @@ -156,7 +156,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("z"), ctx: Load, @@ -165,11 +165,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..66, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..66, }, ), @@ -181,17 +181,17 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..83, is_async: false, target: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..73, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("x"), ctx: Store, @@ -201,7 +201,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("y"), ctx: Load, @@ -210,11 +210,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, }, ), @@ -226,17 +226,17 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..103, is_async: false, target: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..93, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, id: Name("x"), ctx: Store, @@ -246,7 +246,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, id: Name("y"), ctx: Load, @@ -255,11 +255,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..103, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..103, }, ), @@ -271,16 +271,16 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..123, is_async: false, target: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..113, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("x"), ctx: Load, @@ -289,7 +289,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, id: Name("y"), ctx: Load, @@ -299,7 +299,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..118, id: Name("z"), ctx: Load, @@ -308,11 +308,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..123, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..123, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap index 185ab4b7a7426..d219ca921c9e6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_invalid_target_in_keyword.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_invalid_targ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..170, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..13, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("d"), ctx: Load, @@ -29,15 +29,15 @@ Module( ), arguments: Arguments { range: 5..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..12, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -49,7 +49,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("y"), ctx: Load, @@ -65,7 +65,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..23, id: Name("target"), ctx: Load, @@ -74,11 +74,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -90,20 +90,20 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..56, is_async: false, target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..43, func: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..40, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("x"), ctx: Load, @@ -115,7 +115,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("y"), ctx: Load, @@ -126,7 +126,7 @@ Module( ), arguments: Arguments { range: 41..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -134,7 +134,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..51, id: Name("iter"), ctx: Load, @@ -143,11 +143,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, }, ), @@ -159,16 +159,16 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..82, is_async: false, target: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..68, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Load, @@ -180,7 +180,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("y"), ctx: Load, @@ -191,7 +191,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..77, id: Name("iter"), ctx: Load, @@ -200,11 +200,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..82, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..82, }, ), @@ -216,21 +216,21 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..111, is_async: false, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..98, elts: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..94, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, id: Name("x"), ctx: Load, @@ -242,7 +242,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("y"), ctx: Load, @@ -253,7 +253,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("z"), ctx: Store, @@ -266,7 +266,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..106, id: Name("iter"), ctx: Load, @@ -275,11 +275,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, }, ), @@ -291,21 +291,21 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..140, is_async: false, target: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..127, elts: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..123, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..118, id: Name("x"), ctx: Load, @@ -317,7 +317,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, id: Name("y"), ctx: Load, @@ -328,7 +328,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..126, id: Name("z"), ctx: Store, @@ -340,7 +340,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..135, id: Name("iter"), ctx: Load, @@ -349,11 +349,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..140, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..140, }, ), @@ -365,21 +365,21 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..169, is_async: false, target: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..156, elts: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..152, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("x"), ctx: Load, @@ -391,7 +391,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, id: Name("y"), ctx: Load, @@ -402,7 +402,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..155, id: Name("z"), ctx: Load, @@ -413,7 +413,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..164, id: Name("iter"), ctx: Load, @@ -422,11 +422,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..169, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..169, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap index d16e1ec4bc4f3..8052c314b5acd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_in_keyword.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_missing_in_k ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("a"), ctx: Store, @@ -25,7 +25,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("b"), ctx: Load, @@ -34,11 +34,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, }, ), @@ -50,12 +50,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..23, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("a"), ctx: Store, @@ -63,7 +63,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..18, id: Name(""), ctx: Invalid, @@ -72,11 +72,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap index d258342309078..f9640e450af6f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_iter.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_missing_iter ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Store, @@ -25,7 +25,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..8, id: Name(""), ctx: Invalid, @@ -34,12 +34,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..19, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("a"), ctx: Store, @@ -48,7 +48,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap index 42ea10ed9f812..84d8b4f8cd479 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@for_stmt_missing_target.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/for_stmt_missing_targ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..6, id: Name("in"), ctx: Store, @@ -25,7 +25,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, @@ -34,11 +34,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap index 2c98db482e7a7..2520cfbe493e7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_dotted_names.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/inline/err/from_import_dotted_na ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..67, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, module: Some( Identifier { id: Name("x"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -38,33 +38,33 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..34, module: Some( Identifier { id: Name("x"), range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 31..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 31..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -74,83 +74,83 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..66, module: Some( Identifier { id: Name("x"), range: 40..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("g"), range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap index b84eb9a41acc9..6534394ab29e8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_empty_names.py.snap @@ -7,18 +7,18 @@ input_file: crates/ruff_python_parser/resources/inline/err/from_import_empty_nam ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..48, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, module: Some( Identifier { id: Name("x"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [], @@ -27,13 +27,13 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..30, module: Some( Identifier { id: Name("x"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [], @@ -42,13 +42,13 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..47, module: Some( Identifier { id: Name("x"), range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [], diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap index 9e3cbe4994892..7f405b3edfdbd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_module.py.snap @@ -7,12 +7,12 @@ input_file: crates/ruff_python_parser/resources/inline/err/from_import_missing_m ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, module: None, names: [], @@ -21,17 +21,17 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..18, module: None, names: [ Alias { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap index 761cbc2a7ec69..f53eb5aeff546 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_missing_rpar.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/err/from_import_missing_r ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, module: Some( Identifier { id: Name("x"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 15..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 15..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -48,15 +48,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..25, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..25, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, value: Int( 1, @@ -66,7 +66,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, value: Int( 1, @@ -79,33 +79,33 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..46, module: Some( Identifier { id: Name("x"), range: 31..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 44..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 44..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -115,15 +115,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, value: Int( 2, @@ -133,7 +133,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap index 0c0d1ff705ec8..616bb3d4c5f5d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_star_with_other_names.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/err/from_import_star_with ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..87, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, module: Some( Identifier { id: Name("x"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("*"), range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -48,43 +48,43 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..40, module: Some( Identifier { id: Name("x"), range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("*"), range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -94,39 +94,39 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..64, module: Some( Identifier { id: Name("x"), range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("*"), range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 58..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 58..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("b"), range: 63..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -136,43 +136,43 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..86, module: Some( Identifier { id: Name("x"), range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 79..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("*"), range: 79..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 82..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("*"), range: 82..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 85..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 85..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap index 4708a3d670bb1..778e7d23814f2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@from_import_unparenthesized_trailing_comma.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/inline/err/from_import_unparenth ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..59, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, module: Some( Identifier { id: Name("a"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -38,29 +38,29 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..38, module: Some( Identifier { id: Name("a"), range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 31..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 31..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("c"), range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -70,33 +70,33 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..58, module: Some( Identifier { id: Name("a"), range: 44..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap index 2b793eb3a0723..8774db9904042 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_empty_body.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_def_empty_bo ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..36, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..9, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -39,21 +37,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..28, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 15..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 18..20, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -63,7 +59,7 @@ Module( returns: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, id: Name("int"), ctx: Load, @@ -75,12 +71,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..35, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Store, @@ -89,7 +85,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..35, value: Int( 42, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap index 630b9274b75a8..a3bef4f4b931a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_invalid_return_expr.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_def_invalid_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..74, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..9, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -36,11 +34,11 @@ Module( returns: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -53,11 +51,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), @@ -68,21 +66,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..47, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 27..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 30..32, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -92,11 +88,11 @@ Module( returns: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..41, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, id: Name("int"), ctx: Load, @@ -109,11 +105,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, }, ), @@ -124,21 +120,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..73, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 52..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 55..57, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -148,12 +142,12 @@ Module( returns: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..68, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("x"), ctx: Load, @@ -166,11 +160,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap index 6b3b63253fdbd..1ee0f8c743ce4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_identifier.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_def_missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, is_async: false, decorator_list: [], name: Identifier { id: Name(""), range: 3..3, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 4..6, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,11 +35,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, }, ), @@ -52,21 +50,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..30, is_async: false, decorator_list: [], name: Identifier { id: Name(""), range: 15..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 16..18, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -76,7 +72,7 @@ Module( returns: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, id: Name("int"), ctx: Load, @@ -86,11 +82,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap index e8b2fbeeac6bd..36593a9900dcf 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_missing_return_type.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_def_missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..9, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,11 +35,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..18, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..18, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap index f3b024f7e5ad8..9028296eeb9c1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_parameter_list.py.snap @@ -7,43 +7,41 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_def_unclosed ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..74, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..18, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, id: Name("int"), ctx: Load, @@ -55,14 +53,14 @@ Module( }, ParameterWithDefault { range: 16..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 16..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -79,21 +77,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..43, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 23..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 26..28, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -104,12 +100,12 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..43, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..43, value: Int( 42, @@ -124,38 +120,36 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..74, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 48..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 51..74, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 52..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 52..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, id: Name("int"), ctx: Load, @@ -167,19 +161,19 @@ Module( }, ParameterWithDefault { range: 60..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 60..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..66, id: Name("str"), ctx: Load, @@ -191,21 +185,21 @@ Module( }, ParameterWithDefault { range: 67..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 67..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 67..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..73, value: Int( 10, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap index f8ef4f81691b6..78bc5e9f73808 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unclosed_type_param_list.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_def_unclosed ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..47, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..39, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 7..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T1"), range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -42,11 +42,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 12..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T2"), range: 13..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -56,21 +56,19 @@ Module( ), parameters: Parameters { range: 15..21, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -78,14 +76,14 @@ Module( }, ParameterWithDefault { range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -100,16 +98,16 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..39, value: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..39, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("a"), ctx: Load, @@ -118,7 +116,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("b"), ctx: Load, @@ -134,12 +132,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..46, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("x"), ctx: Store, @@ -148,7 +146,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..46, value: Int( 10, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap index a2e19de94c776..fc72f4209f88e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_def_unparenthesized_return_types.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_def_unparent ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..50, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..9, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -36,12 +34,12 @@ Module( returns: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, id: Name("int"), ctx: Load, @@ -56,11 +54,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), @@ -71,21 +69,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..49, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 27..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 30..32, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -95,12 +91,12 @@ Module( returns: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..44, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, id: Name("int"), ctx: Load, @@ -108,7 +104,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..44, id: Name("str"), ctx: Load, @@ -123,11 +119,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..49, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..49, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_type_params_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_type_params_py311.py.snap index 18039d0ce0948..259c43f1e3150 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_type_params_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@function_type_params_py311.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/err/function_type_params_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..79, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..61, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 48..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 51..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -44,9 +44,7 @@ Module( ), parameters: Parameters { range: 54..56, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -57,11 +55,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), @@ -72,27 +70,25 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..78, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 66..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 69..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [], }, ), parameters: Parameters { range: 71..73, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -103,11 +99,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_empty.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_empty.py.snap index 6255c8fe595fc..5971aa62c7163 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_empty.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_empty.py.snap @@ -7,12 +7,12 @@ input_file: crates/ruff_python_parser/resources/inline/err/global_stmt_empty.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, body: [ Global( StmtGlobal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, names: [], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap index d179c96eef2bb..c80bc045056b8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_expression.py.snap @@ -7,34 +7,34 @@ input_file: crates/ruff_python_parser/resources/inline/err/global_stmt_expressio ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, body: [ Global( StmtGlobal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, names: [ Identifier { id: Name("x"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap index 232acca04ddcc..689169704255e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@global_stmt_trailing_comma.py.snap @@ -7,43 +7,43 @@ input_file: crates/ruff_python_parser/resources/inline/err/global_stmt_trailing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, body: [ Global( StmtGlobal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, names: [], }, ), Global( StmtGlobal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..18, names: [ Identifier { id: Name("x"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, ), Global( StmtGlobal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..31, names: [ Identifier { id: Name("x"), range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, Identifier { id: Name("y"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap index 888e539c24195..d8ac7c86beba3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_elif_missing_colon.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_elif_missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..46, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..45, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, @@ -25,7 +25,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..14, }, ), @@ -33,11 +33,11 @@ Module( elif_else_clauses: [ ElifElseClause { range: 15..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("y"), ctx: Load, @@ -47,7 +47,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..30, }, ), @@ -55,12 +55,12 @@ Module( }, ElifElseClause { range: 31..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..45, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_empty_body.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_empty_body.py.snap index 0b8fecc04863b..1d74c36f4867c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_empty_body.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_empty_body.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_empty_body.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: true, }, @@ -27,15 +27,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 1, @@ -45,7 +45,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap index ee46056de5836..356e404b04586 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_elif_test_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_invalid_elif_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..56, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..55, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, @@ -25,7 +25,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..14, }, ), @@ -33,15 +33,15 @@ Module( elif_else_clauses: [ ElifElseClause { range: 15..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..22, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("x"), ctx: Load, @@ -54,7 +54,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..32, }, ), @@ -62,16 +62,16 @@ Module( }, ElifElseClause { range: 33..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..45, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("x"), ctx: Load, @@ -84,7 +84,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..55, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap index 0562b031f9beb..c06836fcdb8ff 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_invalid_test_expr.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_invalid_test_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..48, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, test: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..5, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, @@ -32,11 +32,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, }, ), @@ -48,16 +48,16 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..26, test: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..21, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("x"), ctx: Load, @@ -69,11 +69,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, }, ), @@ -85,15 +85,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..47, test: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..42, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Load, @@ -104,11 +104,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap index 091fe218f51a6..8092bc7d7cb69 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_colon.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_missing_colon ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("x"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..18, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("x"), ctx: Load, @@ -41,7 +41,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..18, }, ), @@ -51,12 +51,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..24, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("a"), ctx: Store, @@ -65,7 +65,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap index 13cacd4b1073d..421ce18c82153 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_missing_test.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_missing_test. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..2, id: Name(""), ctx: Invalid, @@ -25,11 +25,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap index bef4a1b8523e6..e932a526c41fd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@if_stmt_misspelled_elif.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/if_stmt_misspelled_el ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..47, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: true, }, @@ -24,7 +24,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, }, ), @@ -34,11 +34,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..22, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, id: Name("elf"), ctx: Store, @@ -46,7 +46,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..22, id: Name(""), ctx: Invalid, @@ -58,13 +58,13 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..31, }, ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..46, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap index 887ae67220567..a883b9e411c2c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/inline/err/implicitly_concatenat ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..47, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello", flags: StringLiteralFlags { quote_style: Single, @@ -38,15 +38,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..20, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..20, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, value: Int( 1, @@ -56,7 +56,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, value: Int( 1, @@ -69,11 +69,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..40, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..40, value: FStringValue { inner: Concatenated( @@ -81,7 +81,7 @@ Module( Literal( StringLiteral { range: 21..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello", flags: StringLiteralFlags { quote_style: Single, @@ -93,22 +93,22 @@ Module( FString( FString { range: 29..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 31..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world ", }, ), Interpolation( InterpolatedElement { range: 37..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("x"), ctx: Load, @@ -136,15 +136,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..46, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..46, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, value: Int( 2, @@ -154,7 +154,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap index 59016cc425c23..58734d3b8f417 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@implicitly_concatenated_unterminated_string_multiline.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/implicitly_concatenat ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..85, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..31, value: FStringValue { inner: Concatenated( @@ -24,7 +24,7 @@ Module( Literal( StringLiteral { range: 6..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello", flags: StringLiteralFlags { quote_style: Single, @@ -36,22 +36,22 @@ Module( FString( FString { range: 18..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 20..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world ", }, ), Interpolation( InterpolatedElement { range: 26..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("x"), ctx: Load, @@ -79,15 +79,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..37, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..37, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 1, @@ -97,7 +97,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, value: Int( 1, @@ -110,17 +110,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..51, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..51, value: StringLiteralValue { inner: Single( StringLiteral { range: 44..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "first", flags: StringLiteralFlags { quote_style: Single, @@ -136,23 +136,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..76, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..76, value: FStringValue { inner: Single( FString( FString { range: 68..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 70..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "third", }, ), @@ -172,15 +172,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..84, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..84, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 2, @@ -190,7 +190,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap index 23ff8ca3c45b8..33c7bf11e6c4a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_alias_missing_asname.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/import_alias_missing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, names: [ Alias { range: 7..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_empty.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_empty.py.snap index b198a714774b8..74adfe2d5274d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_empty.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_empty.py.snap @@ -7,12 +7,12 @@ input_file: crates/ruff_python_parser/resources/inline/err/import_stmt_empty.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, names: [], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap index dedb2fd84b90d..2db170e781c12 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_parenthesized_names.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/inline/err/import_stmt_parenthes ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, names: [], }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("a"), ctx: Load, @@ -33,23 +33,23 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..17, names: [], }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..24, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..24, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("a"), ctx: Load, @@ -57,7 +57,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap index 81439cdee2229..84de08d9600a7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_star_import.py.snap @@ -7,27 +7,27 @@ input_file: crates/ruff_python_parser/resources/inline/err/import_stmt_star_impo ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, names: [], }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..8, id: Name(""), ctx: Invalid, @@ -40,16 +40,16 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..18, names: [ Alias { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -58,20 +58,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..23, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..23, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..20, id: Name(""), ctx: Invalid, @@ -82,7 +82,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap index d9ea1890a59a8..5179defd2f641 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@import_stmt_trailing_comma.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/err/import_stmt_trailing_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, names: [], }, ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..21, names: [ Alias { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap index 815e9022559ca..87faffde66fbf 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_class.py.snap @@ -7,32 +7,32 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_annotation_cl ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..247, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, decorator_list: [], name: Identifier { id: Name("F"), range: 6..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -44,15 +44,15 @@ Module( arguments: Some( Arguments { range: 10..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..20, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("y"), ctx: Store, @@ -60,7 +60,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..20, id: Name("list"), ctx: Load, @@ -75,11 +75,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, }, ), @@ -90,27 +90,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..53, decorator_list: [], name: Identifier { id: Name("I"), range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 34..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -122,16 +122,16 @@ Module( arguments: Some( Arguments { range: 37..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..46, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, value: Int( 1, @@ -148,11 +148,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, }, ), @@ -163,27 +163,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..85, decorator_list: [], name: Identifier { id: Name("J"), range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 61..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -195,15 +195,15 @@ Module( arguments: Some( Arguments { range: 64..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..78, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, value: Int( 1, @@ -219,11 +219,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, }, ), @@ -234,37 +234,37 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..112, decorator_list: [], name: Identifier { id: Name("K"), range: 92..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 93..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 94..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..105, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, value: Int( 1, @@ -285,11 +285,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, }, ), @@ -300,36 +300,36 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..162, decorator_list: [], name: Identifier { id: Name("L"), range: 143..144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 144..157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 145..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 145..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..155, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, id: Name("x"), ctx: Store, @@ -337,7 +337,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..155, value: Int( 1, @@ -357,11 +357,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..162, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..162, }, ), @@ -372,27 +372,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..219, decorator_list: [], name: Identifier { id: Name("M"), range: 199..200, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 200..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 201..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 201..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -404,15 +404,15 @@ Module( arguments: Some( Arguments { range: 203..214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..212, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, value: Int( 1, @@ -428,11 +428,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..219, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..219, }, ), @@ -443,36 +443,36 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..246, decorator_list: [], name: Identifier { id: Name("N"), range: 226..227, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 227..241, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 228..240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 228..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..239, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..239, value: Int( 1, @@ -492,11 +492,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..246, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..246, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function.py.snap index 2953a62e5533c..7f6d5bbebf419 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_annotation_fu ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..987, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, decorator_list: [], name: Identifier { id: Name("d"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 5..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 6..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 6..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -44,9 +44,7 @@ Module( ), parameters: Parameters { range: 8..10, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -56,11 +54,11 @@ Module( returns: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..22, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, value: Int( 1, @@ -73,11 +71,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -88,28 +86,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..58, is_async: false, decorator_list: [], name: Identifier { id: Name("e"), range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 34..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -120,30 +118,28 @@ Module( ), parameters: Parameters { range: 37..53, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 38..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 38..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 38..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..51, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, value: Int( 1, @@ -165,11 +161,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, }, ), @@ -180,28 +176,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..86, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 63..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 64..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -212,9 +208,7 @@ Module( ), parameters: Parameters { range: 67..69, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -224,11 +218,11 @@ Module( returns: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..80, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("y"), ctx: Store, @@ -236,7 +230,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 3, @@ -249,11 +243,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, }, ), @@ -264,28 +258,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..115, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 91..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 92..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 93..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 93..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -296,30 +290,28 @@ Module( ), parameters: Parameters { range: 95..110, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 96..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 96..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 96..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..108, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("x"), ctx: Store, @@ -327,7 +319,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..108, value: Int( 1, @@ -349,11 +341,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, }, ), @@ -364,28 +356,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..143, is_async: false, decorator_list: [], name: Identifier { id: Name("h"), range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 121..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 122..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 122..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -396,31 +388,29 @@ Module( ), parameters: Parameters { range: 124..138, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 125..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 125..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 125..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..136, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, value: Int( 1, @@ -443,11 +433,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..143, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..143, }, ), @@ -458,28 +448,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..172, is_async: false, decorator_list: [], name: Identifier { id: Name("j"), range: 148..149, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 149..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 150..151, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 150..151, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -490,9 +480,7 @@ Module( ), parameters: Parameters { range: 152..154, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -502,12 +490,12 @@ Module( returns: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..166, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, value: Int( 1, @@ -521,11 +509,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..172, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..172, }, ), @@ -536,28 +524,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..205, is_async: false, decorator_list: [], name: Identifier { id: Name("l"), range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 178..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 179..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 179..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -568,30 +556,28 @@ Module( ), parameters: Parameters { range: 181..200, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 182..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 182..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 182..183, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..198, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, value: Int( 1, @@ -613,11 +599,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..205, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..205, }, ), @@ -628,28 +614,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..239, is_async: false, decorator_list: [], name: Identifier { id: Name("n"), range: 210..211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 211..214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 212..213, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 212..213, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -660,9 +646,7 @@ Module( ), parameters: Parameters { range: 214..216, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -672,11 +656,11 @@ Module( returns: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..233, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..233, value: Int( 1, @@ -689,11 +673,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..239, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..239, }, ), @@ -704,38 +688,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..266, is_async: false, decorator_list: [], name: Identifier { id: Name("p"), range: 244..245, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 245..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 246..258, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 246..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..257, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 256..257, value: Int( 1, @@ -754,9 +738,7 @@ Module( ), parameters: Parameters { range: 259..261, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -767,11 +749,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..266, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..266, }, ), @@ -782,39 +764,39 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 297..324, is_async: false, decorator_list: [], name: Identifier { id: Name("q"), range: 301..302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 302..317, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 303..316, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 303..304, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..315, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..315, value: Int( 1, @@ -832,9 +814,7 @@ Module( ), parameters: Parameters { range: 317..319, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -845,11 +825,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..324, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..324, }, ), @@ -860,38 +840,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 356..385, is_async: false, decorator_list: [], name: Identifier { id: Name("r"), range: 360..361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 361..378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 362..377, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 363..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 369..376, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 375..376, value: Int( 1, @@ -909,9 +889,7 @@ Module( ), parameters: Parameters { range: 378..380, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -922,11 +900,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 382..385, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 382..385, }, ), @@ -937,38 +915,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..450, is_async: false, decorator_list: [], name: Identifier { id: Name("s"), range: 424..425, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 425..443, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 426..442, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 428..430, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 434..441, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 440..441, value: Int( 1, @@ -986,9 +964,7 @@ Module( ), parameters: Parameters { range: 443..445, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -999,11 +975,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 447..450, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 447..450, }, ), @@ -1014,37 +990,37 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 481..506, is_async: false, decorator_list: [], name: Identifier { id: Name("t"), range: 485..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 486..499, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 487..498, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 487..488, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 491..497, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 491..492, id: Name("x"), ctx: Store, @@ -1052,7 +1028,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 496..497, value: Int( 1, @@ -1070,9 +1046,7 @@ Module( ), parameters: Parameters { range: 499..501, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1083,11 +1057,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 503..506, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 503..506, }, ), @@ -1098,38 +1072,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 543..569, is_async: false, decorator_list: [], name: Identifier { id: Name("u"), range: 547..548, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 548..562, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 549..561, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 549..550, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 554..560, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 554..555, id: Name("x"), ctx: Store, @@ -1137,7 +1111,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 559..560, value: Int( 1, @@ -1154,9 +1128,7 @@ Module( ), parameters: Parameters { range: 562..564, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1167,11 +1139,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 566..569, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 566..569, }, ), @@ -1182,37 +1154,37 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 607..635, is_async: false, decorator_list: [], name: Identifier { id: Name("v"), range: 611..612, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 612..628, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 613..627, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 614..616, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 620..626, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 620..621, id: Name("x"), ctx: Store, @@ -1220,7 +1192,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 625..626, value: Int( 1, @@ -1237,9 +1209,7 @@ Module( ), parameters: Parameters { range: 628..630, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1250,11 +1220,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 632..635, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 632..635, }, ), @@ -1265,37 +1235,37 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 676..705, is_async: false, decorator_list: [], name: Identifier { id: Name("w"), range: 680..681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 681..698, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 682..697, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 684..686, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 690..696, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 690..691, id: Name("x"), ctx: Store, @@ -1303,7 +1273,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 695..696, value: Int( 1, @@ -1320,9 +1290,7 @@ Module( ), parameters: Parameters { range: 698..700, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1333,11 +1301,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 702..705, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 702..705, }, ), @@ -1348,37 +1316,37 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 742..768, is_async: false, decorator_list: [], name: Identifier { id: Name("t"), range: 746..747, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 747..761, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 748..760, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 748..749, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 752..759, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 758..759, value: Int( 1, @@ -1396,9 +1364,7 @@ Module( ), parameters: Parameters { range: 761..763, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1409,11 +1375,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 765..768, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 765..768, }, ), @@ -1424,38 +1390,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 800..827, is_async: false, decorator_list: [], name: Identifier { id: Name("u"), range: 804..805, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 805..820, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 806..819, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 806..807, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 811..818, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 817..818, value: Int( 1, @@ -1472,9 +1438,7 @@ Module( ), parameters: Parameters { range: 820..822, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1485,11 +1449,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 824..827, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 824..827, }, ), @@ -1500,37 +1464,37 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 860..889, is_async: false, decorator_list: [], name: Identifier { id: Name("v"), range: 864..865, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 865..882, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 866..881, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 867..869, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 873..880, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 879..880, value: Int( 1, @@ -1547,9 +1511,7 @@ Module( ), parameters: Parameters { range: 882..884, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1560,11 +1522,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 886..889, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 886..889, }, ), @@ -1575,37 +1537,37 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 925..955, is_async: false, decorator_list: [], name: Identifier { id: Name("w"), range: 929..930, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 930..948, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 931..947, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 933..935, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 939..946, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 945..946, value: Int( 1, @@ -1622,9 +1584,7 @@ Module( ), parameters: Parameters { range: 948..950, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -1635,11 +1595,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 952..955, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 952..955, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function_py314.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function_py314.py.snap index 81e3240ff76ab..132507c7c768a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function_py314.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_function_py314.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_annotation_fu ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..316, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..68, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 49..51, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -36,11 +34,11 @@ Module( returns: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..62, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("y"), ctx: Store, @@ -48,7 +46,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, value: Int( 3, @@ -61,11 +59,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, }, ), @@ -76,42 +74,40 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..94, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 73..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 74..89, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 75..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 75..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 75..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..87, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, id: Name("x"), ctx: Store, @@ -119,7 +115,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, value: Int( 1, @@ -141,11 +137,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, }, ), @@ -156,21 +152,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..235, is_async: false, decorator_list: [], name: Identifier { id: Name("outer"), range: 99..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 104..106, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -181,43 +175,41 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..136, is_async: false, decorator_list: [], name: Identifier { id: Name("i"), range: 116..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 117..131, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 118..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 118..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 118..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..129, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, value: Int( 1, @@ -240,11 +232,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..136, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..136, }, ), @@ -255,21 +247,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..166, is_async: false, decorator_list: [], name: Identifier { id: Name("k"), range: 145..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 146..148, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -279,12 +269,12 @@ Module( returns: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..160, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..160, value: Int( 1, @@ -298,11 +288,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..166, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..166, }, ), @@ -313,42 +303,40 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..200, is_async: false, decorator_list: [], name: Identifier { id: Name("m"), range: 175..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 176..195, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 177..194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 177..194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..193, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, value: Int( 1, @@ -370,11 +358,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..200, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..200, }, ), @@ -385,21 +373,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..235, is_async: false, decorator_list: [], name: Identifier { id: Name("o"), range: 209..210, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 210..212, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -409,11 +395,11 @@ Module( returns: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..229, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..229, value: Int( 1, @@ -426,11 +412,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..235, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..235, }, ), @@ -444,21 +430,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..315, is_async: true, decorator_list: [], name: Identifier { id: Name("outer"), range: 246..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 251..253, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -469,21 +453,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..284, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 263..264, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 264..266, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -493,11 +475,11 @@ Module( returns: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..278, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..278, value: Int( 1, @@ -510,11 +492,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..284, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..284, }, ), @@ -525,42 +507,40 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..315, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 293..294, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 294..310, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 295..309, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 295..309, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 295..298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..308, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 307..308, value: Int( 1, @@ -582,11 +562,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..315, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..315, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_py314.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_py314.py.snap index 78ac67583b03b..f3fdd11ffe868 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_py314.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_py314.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_annotation_py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..144, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..55, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("a"), ctx: Store, @@ -24,11 +24,11 @@ Module( ), annotation: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..54, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, id: Name("x"), ctx: Store, @@ -36,7 +36,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, value: Int( 1, @@ -51,21 +51,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..107, is_async: false, decorator_list: [], name: Identifier { id: Name("outer"), range: 60..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -76,11 +74,11 @@ Module( body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..85, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("b"), ctx: Store, @@ -88,12 +86,12 @@ Module( ), annotation: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..84, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 1, @@ -109,11 +107,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..107, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("c"), ctx: Store, @@ -121,11 +119,11 @@ Module( ), annotation: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..106, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, value: Int( 1, @@ -143,21 +141,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..143, is_async: true, decorator_list: [], name: Identifier { id: Name("outer"), range: 118..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 123..125, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -168,11 +164,11 @@ Module( body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..143, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, id: Name("d"), ctx: Store, @@ -180,11 +176,11 @@ Module( ), annotation: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..142, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_type_alias.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_type_alias.py.snap index 10e387a20bc1f..61e633131dc39 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_type_alias.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_annotation_type_alias.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_annotation_ty ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..406, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,26 +25,26 @@ Module( type_params: Some( TypeParams { range: 6..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 7..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..18, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, value: Int( 1, @@ -63,7 +63,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, id: Name("int"), ctx: Load, @@ -73,11 +73,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..75, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("X"), ctx: Store, @@ -86,27 +86,27 @@ Module( type_params: Some( TypeParams { range: 54..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 55..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..67, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, value: Int( 1, @@ -124,7 +124,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..75, id: Name("int"), ctx: Load, @@ -134,11 +134,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..127, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..104, id: Name("X"), ctx: Store, @@ -147,26 +147,26 @@ Module( type_params: Some( TypeParams { range: 104..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 105..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 106..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..119, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, value: Int( 1, @@ -184,7 +184,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..127, id: Name("int"), ctx: Load, @@ -194,11 +194,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..183, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, id: Name("X"), ctx: Store, @@ -207,26 +207,26 @@ Module( type_params: Some( TypeParams { range: 159..177, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 160..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 162..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..175, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..175, value: Int( 1, @@ -244,7 +244,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..183, id: Name("int"), ctx: Load, @@ -254,11 +254,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..223, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..211, id: Name("Y"), ctx: Store, @@ -267,12 +267,12 @@ Module( type_params: None, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..222, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..222, value: Int( 1, @@ -286,11 +286,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..271, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..260, id: Name("Y"), ctx: Store, @@ -299,11 +299,11 @@ Module( type_params: None, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..270, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..265, id: Name("x"), ctx: Store, @@ -311,7 +311,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..270, value: Int( 1, @@ -324,11 +324,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..334, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..314, id: Name("Y"), ctx: Store, @@ -337,25 +337,25 @@ Module( type_params: Some( TypeParams { range: 314..328, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 315..327, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 315..316, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..326, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 325..326, value: Int( 1, @@ -373,7 +373,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..334, id: Name("int"), ctx: Load, @@ -383,11 +383,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..375, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 362..363, id: Name("Y"), ctx: Store, @@ -396,11 +396,11 @@ Module( type_params: None, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..374, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 373..374, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_byte_literal.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_byte_literal.py.snap index 67b56f461720f..635e860d01094 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_byte_literal.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_byte_literal.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_byte_literal. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..44, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 0..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [], flags: BytesLiteralFlags { quote_style: Single, @@ -38,17 +38,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..26, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..26, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 13..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [], flags: BytesLiteralFlags { quote_style: Double, @@ -66,17 +66,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..43, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..43, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 27..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [], flags: BytesLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap index 444e3dd9792a1..f214888ea38e6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_del_target.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_del_target.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..75, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, targets: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Load, @@ -30,7 +30,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 1, @@ -44,25 +44,25 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..22, targets: [ Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..22, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..18, value: StringLiteralValue { inner: Single( StringLiteral { range: 15..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Single, @@ -77,7 +77,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, value: Int( 1, @@ -93,23 +93,23 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..37, targets: [ Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..37, elts: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, value: StringLiteralValue { inner: Single( StringLiteral { range: 28..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Single, @@ -123,13 +123,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..36, value: StringLiteralValue { inner: Single( StringLiteral { range: 33..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "y", flags: StringLiteralFlags { quote_style: Single, @@ -149,32 +149,32 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..74, targets: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..46, }, ), BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..52, value: true, }, ), BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..59, value: false, }, ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, value: Int( 1, @@ -183,7 +183,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, value: Float( 1.0, @@ -192,13 +192,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..74, value: StringLiteralValue { inner: Single( StringLiteral { range: 69..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "abc", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_fstring_literal_element.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_fstring_literal_element.py.snap index d401ee2d55219..88875b56f9b8c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_fstring_literal_element.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_fstring_literal_element.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_fstring_liter ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..58, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, value: FStringValue { inner: Single( FString( FString { range: 0..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", }, ), @@ -48,23 +48,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..57, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..57, value: FStringValue { inner: Single( FString( FString { range: 27..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 31..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_string_literal.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_string_literal.py.snap index 93f0879fae1ae..0dbe2ee507cb3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_string_literal.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@invalid_string_literal.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/inline/err/invalid_string_litera ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..56, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -38,17 +38,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..55, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..55, value: StringLiteralValue { inner: Single( StringLiteral { range: 26..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@irrefutable_case_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@irrefutable_case_pattern.py.snap index 3853b04afdb87..678ef97091e30 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@irrefutable_case_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@irrefutable_case_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/irrefutable_case_patt ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..317, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..61, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 13..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 18..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("var"), range: 18..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -44,11 +44,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, }, ), @@ -58,14 +58,14 @@ Module( }, MatchCase { range: 50..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, value: Int( 2, @@ -78,11 +78,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), @@ -95,11 +95,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..102, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -108,11 +108,11 @@ Module( cases: [ MatchCase { range: 75..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 80..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -121,11 +121,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, }, ), @@ -135,14 +135,14 @@ Module( }, MatchCase { range: 91..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 96..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, value: Int( 2, @@ -155,11 +155,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..102, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..102, }, ), @@ -172,11 +172,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..222, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, id: Name("x"), ctx: Load, @@ -185,22 +185,22 @@ Module( cases: [ MatchCase { range: 138..160, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 143..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchAs( PatternMatchAs { range: 143..147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("var1"), range: 143..147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -210,7 +210,7 @@ Module( Identifier { id: Name("var2"), range: 151..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -219,11 +219,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..160, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..160, }, ), @@ -233,14 +233,14 @@ Module( }, MatchCase { range: 211..222, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 216..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..217, value: Int( 2, @@ -253,11 +253,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..222, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..222, }, ), @@ -270,11 +270,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..316, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..230, id: Name("x"), ctx: Load, @@ -283,23 +283,23 @@ Module( cases: [ MatchCase { range: 236..264, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 241..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 241..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..253, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..245, id: Name("enum"), ctx: Load, @@ -308,7 +308,7 @@ Module( attr: Identifier { id: Name("variant"), range: 246..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -318,13 +318,13 @@ Module( MatchAs( PatternMatchAs { range: 256..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("var"), range: 256..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -336,11 +336,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..264, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..264, }, ), @@ -350,14 +350,14 @@ Module( }, MatchCase { range: 305..316, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 310..311, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..311, value: Int( 2, @@ -370,11 +370,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..316, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..316, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_return_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_return_py37.py.snap index 305adc1eeaced..cc4ffef040282 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_return_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_return_py37.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/iter_unpack_return_py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..91, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, id: Name("rest"), ctx: Store, @@ -26,12 +26,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..59, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 4, @@ -40,7 +40,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 5, @@ -49,7 +49,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 6, @@ -65,21 +65,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..90, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,17 +88,17 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..90, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..90, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, value: Int( 1, @@ -109,7 +107,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 2, @@ -118,7 +116,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 3, @@ -127,11 +125,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..90, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..90, id: Name("rest"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_yield_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_yield_py37.py.snap index f3e6ac63aa8ad..09bb35556958b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_yield_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@iter_unpack_yield_py37.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/iter_unpack_yield_py3 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..128, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, id: Name("rest"), ctx: Store, @@ -26,12 +26,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..59, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 4, @@ -40,7 +40,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 5, @@ -49,7 +49,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 6, @@ -65,21 +65,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..89, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,21 +88,21 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..89, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..89, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..89, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 1, @@ -113,7 +111,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 2, @@ -122,7 +120,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: Int( 3, @@ -131,11 +129,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..89, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..89, id: Name("rest"), ctx: Load, @@ -159,21 +157,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..127, is_async: false, decorator_list: [], name: Identifier { id: Name("h"), range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 95..97, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -184,21 +180,21 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..127, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..127, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..127, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, value: Int( 1, @@ -207,17 +203,17 @@ Module( ), Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..123, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..123, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, value: Int( 2, @@ -226,11 +222,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..123, id: Name("rest"), ctx: Load, @@ -249,7 +245,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap index 920e8ab7d7d32..a438ef9c4614b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_starred_expr.py.snap @@ -7,35 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/err/lambda_body_with_star ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..62, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, parameters: Some( Parameters { range: 7..8, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -49,11 +47,11 @@ Module( ), body: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..12, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("y"), ctx: Load, @@ -68,35 +66,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..26, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..26, elts: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..25, parameters: Some( Parameters { range: 20..21, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -110,11 +106,11 @@ Module( ), body: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..25, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("y"), ctx: Load, @@ -134,35 +130,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..42, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..42, elts: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..39, parameters: Some( Parameters { range: 34..35, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 34..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 34..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 34..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -176,11 +170,11 @@ Module( ), body: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..39, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("y"), ctx: Load, @@ -193,7 +187,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("z"), ctx: Load, @@ -208,30 +202,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..61, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..61, parameters: Some( Parameters { range: 50..51, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -245,17 +237,17 @@ Module( ), body: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..61, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..61, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("y"), ctx: Load, @@ -263,7 +255,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap index 1b3cd9547258f..50eb38666e6b7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@lambda_body_with_yield_expr.py.snap @@ -7,35 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/err/lambda_body_with_yiel ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, parameters: Some( Parameters { range: 7..8, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -49,12 +47,12 @@ Module( ), body: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..17, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("y"), ctx: Load, @@ -69,30 +67,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..40, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..40, parameters: Some( Parameters { range: 25..26, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -106,11 +102,11 @@ Module( ), body: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..40, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_before_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_before_py310.py.snap index f4cf349ddd2b0..ee6bbd4bd024f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_before_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_before_py310.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_before_py310.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..79, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..78, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 2, @@ -26,14 +26,14 @@ Module( cases: [ MatchCase { range: 58..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 63..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, value: Int( 1, @@ -46,7 +46,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..78, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap index e4e0b0db63713..f30f13e7be3cc 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_classify_as_key ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..33, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, subject: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..15, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, id: Name("foo"), ctx: Load, @@ -33,11 +33,11 @@ Module( cases: [ MatchCase { range: 21..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -46,11 +46,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap index 5ce94bf138ca1..531219c2b7da7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_classify_as_keyword_or_identifier.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_classify_as_key ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..39, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, subject: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, id: Name("foo"), ctx: Load, @@ -32,11 +32,11 @@ Module( cases: [ MatchCase { range: 27..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -45,11 +45,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..38, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_expected_colon.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_expected_colon.py.snap index 6415f9724a551..a3b0a5de38015 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_expected_colon.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_expected_colon.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_expected_colon. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, subject: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..12, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Int( 1, @@ -30,7 +30,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Int( 2, @@ -44,11 +44,11 @@ Module( cases: [ MatchCase { range: 17..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -57,11 +57,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap index 273c444e53840..3f165716fdb25 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expect_indented_block.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_expect_ind ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("foo"), ctx: Load, @@ -25,11 +25,11 @@ Module( cases: [ MatchCase { range: 11..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -38,11 +38,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap index 528b87d4e7afe..491b24261160e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_expected_case_block.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_expected_c ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..61, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -27,12 +27,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("x"), ctx: Store, @@ -41,7 +41,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, value: Int( 1, @@ -52,11 +52,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..32, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("x"), ctx: Load, @@ -67,11 +67,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..60, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("y"), ctx: Load, @@ -80,11 +80,11 @@ Module( cases: [ MatchCase { range: 49..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -93,11 +93,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap index 0f5a1d34f4894..73bce3400e319 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_guard_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_invalid_gu ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..100, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..30, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 13..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -43,11 +43,11 @@ Module( guard: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..25, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("a"), ctx: Load, @@ -60,11 +60,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, }, ), @@ -77,11 +77,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..63, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, id: Name("x"), ctx: Load, @@ -90,17 +90,17 @@ Module( cases: [ MatchCase { range: 44..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -108,11 +108,11 @@ Module( guard: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..57, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("a"), ctx: Load, @@ -125,11 +125,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, }, ), @@ -142,11 +142,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..99, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("x"), ctx: Load, @@ -155,17 +155,17 @@ Module( cases: [ MatchCase { range: 77..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 82..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 82..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -173,12 +173,12 @@ Module( guard: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..94, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("x"), ctx: Load, @@ -191,11 +191,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap index 13285ab3c48f5..1db01735fb2e7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_invalid_subject_expr.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_invalid_su ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..131, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, subject: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..9, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("x"), ctx: Load, @@ -32,11 +32,11 @@ Module( cases: [ MatchCase { range: 16..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -45,11 +45,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, }, ), @@ -62,26 +62,26 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..99, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..82, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..79, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..79, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("x"), ctx: Load, @@ -89,7 +89,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, id: Name("y"), ctx: Load, @@ -103,7 +103,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, id: Name("z"), ctx: Load, @@ -117,11 +117,11 @@ Module( cases: [ MatchCase { range: 88..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 93..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -130,11 +130,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, }, ), @@ -147,16 +147,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..130, subject: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..113, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, id: Name("x"), ctx: Load, @@ -168,11 +168,11 @@ Module( cases: [ MatchCase { range: 119..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -181,11 +181,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap index bda3c6e5c3692..ebaf34464bb06 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_guard_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_missing_gu ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 13..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -44,11 +44,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap index 3b604f0505f19..ddc7872be1454 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_missing_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_missing_pa ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,14 +25,14 @@ Module( cases: [ MatchCase { range: 13..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 17..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..17, id: Name(""), ctx: Invalid, @@ -44,11 +44,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap index f22cb551fca4d..b904a97ae4e25 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_no_newline_before_case.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_no_newline ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("foo"), ctx: Load, @@ -25,11 +25,11 @@ Module( cases: [ MatchCase { range: 11..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -38,11 +38,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap index 1bfa4ac064cd6..8ad5469d41744 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@match_stmt_single_starred_subject.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/match_stmt_single_sta ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, subject: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, id: Name("foo"), ctx: Load, @@ -32,11 +32,11 @@ Module( cases: [ MatchCase { range: 16..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -45,11 +45,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@mixed_bytes_and_non_bytes_literals.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@mixed_bytes_and_non_bytes_literals.py.snap index 192d87e0b5485..f79a6c04788b1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@mixed_bytes_and_non_bytes_literals.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@mixed_bytes_and_non_bytes_literals.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/mixed_bytes_and_non_b ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..64, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: StringLiteralValue { inner: Concatenated( @@ -24,7 +24,7 @@ Module( strings: [ StringLiteral { range: 0..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "first", flags: StringLiteralFlags { quote_style: Single, @@ -34,7 +34,7 @@ Module( }, StringLiteral { range: 8..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -53,11 +53,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..36, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..36, value: FStringValue { inner: Concatenated( @@ -65,12 +65,12 @@ Module( FString( FString { range: 18..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 20..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "first", }, ), @@ -85,7 +85,7 @@ Module( Literal( StringLiteral { range: 27..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -103,11 +103,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..63, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..63, value: FStringValue { inner: Concatenated( @@ -115,7 +115,7 @@ Module( Literal( StringLiteral { range: 37..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "first", flags: StringLiteralFlags { quote_style: Single, @@ -127,12 +127,12 @@ Module( FString( FString { range: 45..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 47..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "second", }, ), @@ -147,7 +147,7 @@ Module( Literal( StringLiteral { range: 55..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_assignment_in_case_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_assignment_in_case_pattern.py.snap index c3e7a8341c213..fbedd8e0ee78b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_assignment_in_case_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_assignment_in_case_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/multiple_assignment_i ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..456, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..444, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: Int( 2, @@ -26,22 +26,22 @@ Module( cases: [ MatchCase { range: 13..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 18..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -49,13 +49,13 @@ Module( MatchAs( PatternMatchAs { range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -63,13 +63,13 @@ Module( MatchAs( PatternMatchAs { range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -81,11 +81,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), @@ -95,22 +95,22 @@ Module( }, MatchCase { range: 54..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 59..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -118,13 +118,13 @@ Module( MatchAs( PatternMatchAs { range: 63..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 63..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -132,12 +132,12 @@ Module( MatchStar( PatternMatchStar { range: 66..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("y"), range: 67..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -149,11 +149,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..74, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..74, }, ), @@ -163,22 +163,22 @@ Module( }, MatchCase { range: 96..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 101..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 102..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 102..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -186,13 +186,13 @@ Module( MatchAs( PatternMatchAs { range: 105..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 105..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -200,13 +200,13 @@ Module( MatchAs( PatternMatchAs { range: 108..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 108..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -218,11 +218,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, }, ), @@ -232,15 +232,15 @@ Module( }, MatchCase { range: 146..168, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 151..163, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..153, value: Int( 1, @@ -249,7 +249,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, value: Int( 2, @@ -261,13 +261,13 @@ Module( MatchAs( PatternMatchAs { range: 155..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 155..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -275,13 +275,13 @@ Module( MatchAs( PatternMatchAs { range: 161..162, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 161..162, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -294,11 +294,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..168, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..168, }, ), @@ -308,15 +308,15 @@ Module( }, MatchCase { range: 207..228, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 212..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..214, value: Int( 1, @@ -328,13 +328,13 @@ Module( MatchAs( PatternMatchAs { range: 216..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 216..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -344,7 +344,7 @@ Module( Identifier { id: Name("x"), range: 221..222, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -353,11 +353,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..228, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..228, }, ), @@ -367,14 +367,14 @@ Module( }, MatchCase { range: 269..290, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 274..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..279, id: Name("Class"), ctx: Load, @@ -382,18 +382,18 @@ Module( ), arguments: PatternArguments { range: 279..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 280..281, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 280..281, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -401,13 +401,13 @@ Module( MatchAs( PatternMatchAs { range: 283..284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 283..284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -421,11 +421,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..290, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..290, }, ), @@ -435,14 +435,14 @@ Module( }, MatchCase { range: 320..345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 325..340, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 325..330, id: Name("Class"), ctx: Load, @@ -450,27 +450,27 @@ Module( ), arguments: PatternArguments { range: 330..340, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 331..334, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 331..332, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchAs( PatternMatchAs { range: 333..334, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 333..334, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -478,22 +478,22 @@ Module( }, PatternKeyword { range: 336..339, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("z"), range: 336..337, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchAs( PatternMatchAs { range: 338..339, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 338..339, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -507,11 +507,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..345, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..345, }, ), @@ -521,27 +521,27 @@ Module( }, MatchCase { range: 372..412, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 377..407, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 377..380, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 378..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 378..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -552,11 +552,11 @@ Module( MatchMapping( PatternMatchMapping { range: 383..389, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 384..385, value: Int( 1, @@ -568,13 +568,13 @@ Module( MatchAs( PatternMatchAs { range: 387..388, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 387..388, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -586,10 +586,10 @@ Module( MatchClass( PatternMatchClass { range: 392..407, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..397, id: Name("Class"), ctx: Load, @@ -597,27 +597,27 @@ Module( ), arguments: PatternArguments { range: 397..407, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 398..401, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 398..399, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchAs( PatternMatchAs { range: 400..401, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 400..401, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -625,22 +625,22 @@ Module( }, PatternKeyword { range: 403..406, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("z"), range: 403..404, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchAs( PatternMatchAs { range: 405..406, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 405..406, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -657,11 +657,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..412, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..412, }, ), @@ -671,22 +671,22 @@ Module( }, MatchCase { range: 428..444, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 433..439, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchAs( PatternMatchAs { range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -696,7 +696,7 @@ Module( Identifier { id: Name("x"), range: 438..439, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -705,11 +705,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..444, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..444, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap index e7bbeb557a229..0fb6c83f4661d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@multiple_clauses_on_same_line.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/multiple_clauses_on_s ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..258, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: true, }, @@ -24,7 +24,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -32,11 +32,11 @@ Module( elif_else_clauses: [ ElifElseClause { range: 14..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..24, value: false, }, @@ -45,7 +45,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..30, }, ), @@ -53,12 +53,12 @@ Module( }, ElifElseClause { range: 31..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..41, }, ), @@ -69,11 +69,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..85, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..49, value: true, }, @@ -81,7 +81,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..55, }, ), @@ -89,11 +89,11 @@ Module( elif_else_clauses: [ ElifElseClause { range: 57..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..67, value: false, }, @@ -102,7 +102,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..73, }, ), @@ -110,12 +110,12 @@ Module( }, ElifElseClause { range: 75..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..85, }, ), @@ -126,12 +126,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..117, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("x"), ctx: Store, @@ -139,7 +139,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..99, id: Name("iter"), ctx: Load, @@ -148,7 +148,7 @@ Module( body: [ Break( StmtBreak { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..106, }, ), @@ -156,7 +156,7 @@ Module( orelse: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..117, }, ), @@ -165,12 +165,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..150, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, id: Name("x"), ctx: Store, @@ -178,7 +178,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..131, id: Name("iter"), ctx: Load, @@ -187,7 +187,7 @@ Module( body: [ Break( StmtBreak { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..138, }, ), @@ -195,7 +195,7 @@ Module( orelse: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..150, }, ), @@ -204,12 +204,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..202, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..160, }, ), @@ -218,11 +218,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 161..177, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, id: Name("exc"), ctx: Load, @@ -233,7 +233,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..177, }, ), @@ -244,7 +244,7 @@ Module( orelse: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..188, }, ), @@ -252,7 +252,7 @@ Module( finalbody: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..202, }, ), @@ -262,12 +262,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..257, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..212, }, ), @@ -276,11 +276,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 214..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..224, id: Name("exc"), ctx: Load, @@ -291,7 +291,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..230, }, ), @@ -302,7 +302,7 @@ Module( orelse: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..242, }, ), @@ -310,7 +310,7 @@ Module( finalbody: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..257, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice.py.snap index 0e70f2a74ac12..d521c935f4d2c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/named_expr_slice.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..119, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..92, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..92, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, id: Name("lst"), ctx: Load, @@ -28,16 +28,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..91, lower: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..88, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, id: Name("x"), ctx: Store, @@ -45,7 +45,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, value: Int( 1, @@ -58,12 +58,12 @@ Module( upper: Some( UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..91, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, value: Int( 1, @@ -83,15 +83,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..100, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..100, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, id: Name("lst"), ctx: Load, @@ -99,12 +99,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..100, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, value: Int( 1, @@ -115,7 +115,7 @@ Module( upper: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("x"), ctx: Load, @@ -132,11 +132,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, value: Int( 1, @@ -147,15 +147,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..114, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..114, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..108, id: Name("lst"), ctx: Load, @@ -163,12 +163,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..114, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..110, value: Int( 1, @@ -179,7 +179,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, value: Int( 3, @@ -190,7 +190,7 @@ Module( step: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("x"), ctx: Load, @@ -206,11 +206,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice_parse_error.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice_parse_error.py.snap index 044df9bbb71cf..e282dc0cab1aa 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice_parse_error.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@named_expr_slice_parse_error.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/named_expr_slice_pars ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..130, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..129, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..129, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, id: Name("lst"), ctx: Load, @@ -28,16 +28,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..128, lower: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..125, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..122, id: Name("x"), ctx: Store, @@ -45,7 +45,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..125, value: Int( 1, @@ -58,12 +58,12 @@ Module( upper: Some( UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..128, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap index 9d6245421f2e9..310c7d5336f6b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nested_async_comprehension_py310.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/nested_async_comprehe ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..467, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..111, is_async: true, decorator_list: [], name: Identifier { id: Name("f"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 55..57, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,20 +35,20 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..111, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..111, elt: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..92, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -59,10 +57,10 @@ Module( generators: [ Comprehension { range: 70..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, id: Name("x"), ctx: Store, @@ -70,11 +68,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..91, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, id: Name("foo"), ctx: Load, @@ -82,11 +80,11 @@ Module( ), arguments: Arguments { range: 88..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("n"), ctx: Load, @@ -106,10 +104,10 @@ Module( generators: [ Comprehension { range: 93..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, id: Name("n"), ctx: Store, @@ -117,11 +115,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..110, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..107, id: Name("range"), ctx: Load, @@ -129,11 +127,11 @@ Module( ), arguments: Arguments { range: 107..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, value: Int( 3, @@ -159,21 +157,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..192, is_async: true, decorator_list: [], name: Identifier { id: Name("g"), range: 132..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 133..135, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -184,20 +180,20 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..192, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..192, elt: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..173, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("x"), ctx: Load, @@ -205,7 +201,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, value: Int( 1, @@ -215,10 +211,10 @@ Module( generators: [ Comprehension { range: 151..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, id: Name("x"), ctx: Store, @@ -226,11 +222,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..172, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..169, id: Name("foo"), ctx: Load, @@ -238,11 +234,11 @@ Module( ), arguments: Arguments { range: 169..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, id: Name("n"), ctx: Load, @@ -262,10 +258,10 @@ Module( generators: [ Comprehension { range: 174..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("n"), ctx: Store, @@ -273,11 +269,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..191, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..188, id: Name("range"), ctx: Load, @@ -285,11 +281,11 @@ Module( ), arguments: Arguments { range: 188..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, value: Int( 3, @@ -315,21 +311,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..267, is_async: true, decorator_list: [], name: Identifier { id: Name("h"), range: 210..211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 211..213, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -340,20 +334,20 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..267, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..267, elt: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..248, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..225, id: Name("x"), ctx: Load, @@ -362,10 +356,10 @@ Module( generators: [ Comprehension { range: 226..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("x"), ctx: Store, @@ -373,11 +367,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..247, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..244, id: Name("foo"), ctx: Load, @@ -385,11 +379,11 @@ Module( ), arguments: Arguments { range: 244..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, id: Name("n"), ctx: Load, @@ -409,10 +403,10 @@ Module( generators: [ Comprehension { range: 249..266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..254, id: Name("n"), ctx: Store, @@ -420,11 +414,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..266, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..263, id: Name("range"), ctx: Load, @@ -432,11 +426,11 @@ Module( ), arguments: Arguments { range: 263..266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..265, value: Int( 3, @@ -462,21 +456,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..371, is_async: true, decorator_list: [], name: Identifier { id: Name("i"), range: 287..288, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 288..290, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -487,25 +479,25 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 292..371, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..371, elt: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..352, elts: [ ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..328, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..303, id: Name("y"), ctx: Load, @@ -514,10 +506,10 @@ Module( generators: [ Comprehension { range: 304..327, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..315, id: Name("y"), ctx: Store, @@ -525,11 +517,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..327, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..324, id: Name("range"), ctx: Load, @@ -537,11 +529,11 @@ Module( ), arguments: Arguments { range: 324..327, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 325..326, value: Int( 1, @@ -561,11 +553,11 @@ Module( ), ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 330..351, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..332, id: Name("z"), ctx: Load, @@ -574,10 +566,10 @@ Module( generators: [ Comprehension { range: 333..350, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 337..338, id: Name("z"), ctx: Store, @@ -585,11 +577,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..350, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..347, id: Name("range"), ctx: Load, @@ -597,11 +589,11 @@ Module( ), arguments: Arguments { range: 347..350, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..349, value: Int( 2, @@ -627,10 +619,10 @@ Module( generators: [ Comprehension { range: 353..370, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..358, id: Name("x"), ctx: Store, @@ -638,11 +630,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 362..370, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 362..367, id: Name("range"), ctx: Load, @@ -650,11 +642,11 @@ Module( ), arguments: Arguments { range: 367..370, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 368..369, value: Int( 5, @@ -680,21 +672,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 372..466, is_async: true, decorator_list: [], name: Identifier { id: Name("j"), range: 382..383, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 383..385, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -705,25 +695,25 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 387..466, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 394..466, elt: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..447, elts: [ ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 396..417, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 397..398, id: Name("y"), ctx: Load, @@ -732,10 +722,10 @@ Module( generators: [ Comprehension { range: 399..416, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..404, id: Name("y"), ctx: Store, @@ -743,11 +733,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 408..416, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 408..413, id: Name("range"), ctx: Load, @@ -755,11 +745,11 @@ Module( ), arguments: Arguments { range: 413..416, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 414..415, value: Int( 1, @@ -779,11 +769,11 @@ Module( ), ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 419..446, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..421, id: Name("z"), ctx: Load, @@ -792,10 +782,10 @@ Module( generators: [ Comprehension { range: 422..445, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 432..433, id: Name("z"), ctx: Store, @@ -803,11 +793,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 437..445, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 437..442, id: Name("range"), ctx: Load, @@ -815,11 +805,11 @@ Module( ), arguments: Arguments { range: 442..445, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..444, value: Int( 2, @@ -845,10 +835,10 @@ Module( generators: [ Comprehension { range: 448..465, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 452..453, id: Name("x"), ctx: Store, @@ -856,11 +846,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 457..465, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 457..462, id: Name("range"), ctx: Load, @@ -868,11 +858,11 @@ Module( ), arguments: Arguments { range: 462..465, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 463..464, value: Int( 5, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap index 95c44e302d5e4..c3a8cdca25ae4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@node_range_with_gaps.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/node_range_with_gaps. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -39,21 +37,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..32, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 22..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 25..27, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -64,11 +60,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), @@ -79,21 +75,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..40, is_async: false, decorator_list: [], name: Identifier { id: Name("baz"), range: 37..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 40..40, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_declaration_at_module_level.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_declaration_at_module_level.py.snap index d49417620bdb0..ecfbbe06d22aa 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_declaration_at_module_level.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_declaration_at_module_level.py.snap @@ -7,36 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/nonlocal_declaration_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, body: [ Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, names: [ Identifier { id: Name("x"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, ), Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..24, names: [ Identifier { id: Name("x"), range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, Identifier { id: Name("y"), range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_empty.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_empty.py.snap index dde2775dc31d2..e7c4c552bd7b2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_empty.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_empty.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/nonlocal_stmt_empty.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, is_async: false, decorator_list: [], name: Identifier { id: Name("_"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,7 +35,7 @@ Module( body: [ Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..21, names: [], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap index 739b49643a708..f82316bd46709 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_expression.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/nonlocal_stmt_express ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, is_async: false, decorator_list: [], name: Identifier { id: Name("_"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,29 +35,29 @@ Module( body: [ Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..23, names: [ Identifier { id: Name("x"), range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap index 10cedaf7ba326..d749245b986ac 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@nonlocal_stmt_trailing_comma.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/nonlocal_stmt_trailin ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..59, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..58, is_async: false, decorator_list: [], name: Identifier { id: Name("_"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,38 +35,38 @@ Module( body: [ Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..23, names: [], }, ), Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..39, names: [ Identifier { id: Name("x"), range: 37..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, ), Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..58, names: [ Identifier { id: Name("x"), range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, Identifier { id: Name("y"), range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap index f23ebd2f93cc2..16efd0233ed09 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_annotation.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/param_missing_annotat ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..35, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..11, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -53,11 +51,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, }, ), @@ -68,33 +66,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..34, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 21..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 24..29, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 25..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 25..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -109,11 +105,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap index ee03c9a0a6a56..fcb763f0a12dc 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_missing_default.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/param_missing_default ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..11, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -53,11 +51,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, }, ), @@ -68,38 +66,36 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..40, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 21..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 24..35, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 25..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 25..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, id: Name("int"), ctx: Load, @@ -118,11 +114,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..40, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..40, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap index 779f868a448ae..149cc7b4ce3a9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_annotation.py.snap @@ -7,47 +7,45 @@ input_file: crates/ruff_python_parser/resources/inline/err/param_with_invalid_an ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..81, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..18, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 8..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -69,11 +67,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, }, ), @@ -84,43 +82,41 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..52, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 28..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 31..47, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 32..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 32..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 32..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..46, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..46, id: Name("int"), ctx: Load, @@ -142,11 +138,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, }, ), @@ -157,38 +153,36 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..80, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 57..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 60..75, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 61..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 61..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 61..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("x"), ctx: Load, @@ -200,14 +194,14 @@ Module( }, ParameterWithDefault { range: 71..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 71..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("int"), range: 71..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -222,11 +216,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..80, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..80, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap index bec69b1894bed..fcc9686845a00 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_default.py.snap @@ -7,49 +7,47 @@ input_file: crates/ruff_python_parser/resources/inline/err/param_with_invalid_de ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..68, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..15, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..14, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, id: Name("int"), ctx: Load, @@ -69,11 +67,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, }, ), @@ -84,44 +82,42 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..43, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 25..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 28..38, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 29..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..36, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..36, id: Name("int"), ctx: Load, @@ -141,11 +137,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, }, ), @@ -156,45 +152,43 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..67, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 48..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 51..62, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 52..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..61, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("y"), ctx: Load, @@ -214,11 +208,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap index 9360cfde290d9..c8ace07b1fba3 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_invalid_star_annotation.py.snap @@ -7,45 +7,43 @@ input_file: crates/ruff_python_parser/resources/inline/err/param_with_invalid_st ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..150, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..17, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 8..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 9..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..16, id: Name(""), ctx: Invalid, @@ -64,11 +62,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), @@ -79,44 +77,42 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..57, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 27..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 30..52, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 31..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 32..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..50, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..50, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..45, id: Name("tuple"), ctx: Load, @@ -124,7 +120,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..49, id: Name("int"), ctx: Load, @@ -146,11 +142,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, }, ), @@ -161,46 +157,44 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..90, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 62..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..85, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 66..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 67..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..84, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..84, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..77, id: Name("int"), ctx: Load, @@ -208,7 +202,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, id: Name("str"), ctx: Load, @@ -230,11 +224,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..90, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..90, }, ), @@ -245,45 +239,43 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..120, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 95..98, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 98..115, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 99..114, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 100..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..114, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..114, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("x"), ctx: Load, @@ -305,11 +297,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_star_annotation_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_star_annotation_py310.py.snap index 224824a9e7325..0add20fe0e03b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_star_annotation_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@param_with_star_annotation_py310.py.snap @@ -7,45 +7,43 @@ input_file: crates/ruff_python_parser/resources/inline/err/param_with_star_annot ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..69, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..68, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 48..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 51..63, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 52..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 53..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..62, id: Name("Ts"), ctx: Load, @@ -64,11 +62,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap index 9e0f94fdad06f..54ade04fb2941 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_duplicate_names.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_duplicate_name ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..42, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..36, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -46,21 +44,21 @@ Module( }, ParameterWithDefault { range: 11..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..15, value: Int( 10, @@ -73,11 +71,11 @@ Module( vararg: Some( Parameter { range: 17..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -85,14 +83,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -100,19 +98,19 @@ Module( }, ParameterWithDefault { range: 24..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 24..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, id: Name("str"), ctx: Load, @@ -126,11 +124,11 @@ Module( kwarg: Some( Parameter { range: 32..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 34..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -140,11 +138,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap index c2fdb7f4d5043..b1d8bdaa922ce 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_expected_after_star_separator.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_expected_after ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..98, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..10, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,11 +35,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, }, ), @@ -52,21 +50,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..32, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 20..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 23..27, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -77,11 +73,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), @@ -92,33 +88,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..51, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 37..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 40..46, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -133,11 +127,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..51, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..51, }, ), @@ -148,33 +142,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..71, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 56..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 59..66, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 60..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -189,11 +181,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, }, ), @@ -204,21 +196,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..97, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 76..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 79..92, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -226,11 +216,11 @@ Module( kwarg: Some( Parameter { range: 83..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 85..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -240,11 +230,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..97, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..97, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap index 71846f8fc78c2..324b7246ea810 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_kwarg_after_star_separator.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_kwarg_after_st ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..20, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -34,11 +32,11 @@ Module( kwarg: Some( Parameter { range: 11..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 13..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -48,11 +46,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap index f26f826c50ebb..156a962746633 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_kwargs.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_kwarg ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..37, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..32, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -50,11 +48,11 @@ Module( kwarg: Some( Parameter { range: 22..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs2"), range: 24..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -64,11 +62,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..37, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..37, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap index 5bbcc79890345..21a9f2882093c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_slash_separator.py.snap @@ -7,37 +7,35 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_slash ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..19, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -47,14 +45,14 @@ Module( args: [ ParameterWithDefault { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -69,11 +67,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, }, ), @@ -84,32 +82,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..52, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 32..47, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -119,14 +115,14 @@ Module( args: [ ParameterWithDefault { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -134,14 +130,14 @@ Module( }, ParameterWithDefault { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -156,11 +152,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap index 9e2ccfb2c9a61..4daa7f27f272e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_star_separator.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_star_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..19, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -49,14 +47,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -69,11 +67,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, }, ), @@ -84,33 +82,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..52, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 32..47, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -121,14 +117,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -136,14 +132,14 @@ Module( }, ParameterWithDefault { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -156,11 +152,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap index a8a26d73bc2c0..8fb783b1c13e2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_multiple_varargs.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_multiple_varar ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..136, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..23, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -48,11 +46,11 @@ Module( vararg: Some( Parameter { range: 14..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 15..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -60,14 +58,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -80,11 +78,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -95,33 +93,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..97, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 67..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 70..92, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -131,11 +127,11 @@ Module( vararg: Some( Parameter { range: 74..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args1"), range: 75..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -143,14 +139,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -163,11 +159,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..97, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..97, }, ), @@ -178,33 +174,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..135, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 102..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 105..130, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 106..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 106..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 106..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -214,11 +208,11 @@ Module( vararg: Some( Parameter { range: 109..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args1"), range: 110..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -226,14 +220,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 117..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 117..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 117..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -241,14 +235,14 @@ Module( }, ParameterWithDefault { range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -261,11 +255,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..135, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..135, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap index be7f6b1b35253..7444c8148adc7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_no_arg_before_slash.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_no_arg_before_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..35, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..10, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,11 +35,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, }, ), @@ -52,33 +50,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..34, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 20..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 23..29, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -93,11 +89,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap index 4e01047ebb876..4d23c7dde97cd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_non_default_after_default.py.snap @@ -7,45 +7,43 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_non_default_af ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..30, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..24, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..12, value: Int( 10, @@ -56,14 +54,14 @@ Module( }, ParameterWithDefault { range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -71,19 +69,19 @@ Module( }, ParameterWithDefault { range: 17..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 17..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, id: Name("int"), ctx: Load, @@ -102,11 +100,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap index c2db1084e7780..2015f10090653 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_after_slash.py.snap @@ -7,36 +7,34 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_star_after_sla ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..105, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..14, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -48,11 +46,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..19, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..19, }, ), @@ -63,32 +61,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..48, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 27..43, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -99,11 +95,11 @@ Module( vararg: Some( Parameter { range: 31..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 32..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -111,14 +107,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 38..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 38..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 38..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -131,11 +127,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..48, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..48, }, ), @@ -146,32 +142,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..73, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 53..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 56..68, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -183,14 +177,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 66..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 66..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 66..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -203,11 +197,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, }, ), @@ -218,32 +212,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..104, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 78..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 81..99, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 82..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 82..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 82..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -255,14 +247,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 88..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 88..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 88..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -270,14 +262,14 @@ Module( }, ParameterWithDefault { range: 91..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 91..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 91..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -285,14 +277,14 @@ Module( }, ParameterWithDefault { range: 97..98, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 97..98, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 97..98, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -305,11 +297,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..104, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..104, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap index aa5149155a8f3..fb13bd6095a1d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_star_separator_after_star_param.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_star_separator ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..61, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..23, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -48,11 +46,11 @@ Module( vararg: Some( Parameter { range: 11..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 12..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -60,14 +58,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -80,11 +78,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -95,33 +93,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..60, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 33..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 36..55, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 37..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 37..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 37..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -131,11 +127,11 @@ Module( vararg: Some( Parameter { range: 40..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 41..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -143,14 +139,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 47..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 47..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 47..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -158,14 +154,14 @@ Module( }, ParameterWithDefault { range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -178,11 +174,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap index f56f7d96abdc1..85f48fc80f1d2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_keyword_with_default.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_var_keyword_wi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..43, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..36, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..20, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -50,11 +48,11 @@ Module( kwarg: Some( Parameter { range: 11..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 13..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -64,24 +62,24 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..36, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..36, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, value: StringLiteralValue { inner: Single( StringLiteral { range: 21..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b", flags: StringLiteralFlags { quote_style: Single, @@ -96,7 +94,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, value: Int( 1, @@ -108,13 +106,13 @@ Module( key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: StringLiteralValue { inner: Single( StringLiteral { range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "c", flags: StringLiteralFlags { quote_style: Single, @@ -129,7 +127,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, value: Int( 2, @@ -147,11 +145,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap index 5ca631e7d1f50..1e84abfa40101 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@params_var_positional_with_default.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/err/params_var_positional ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..30, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..17, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -48,11 +46,11 @@ Module( vararg: Some( Parameter { range: 11..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 12..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -64,16 +62,16 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..23, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..23, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 1, @@ -82,7 +80,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, value: Int( 2, @@ -101,11 +99,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_context_manager_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_context_manager_py38.py.snap index ca32f57b18313..c9fce5f0817d4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_context_manager_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_context_manager_py38.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/parenthesized_context ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..126, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..73, is_async: false, items: [ WithItem { range: 49..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, id: Name("foo"), ctx: Load, @@ -30,7 +30,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Store, @@ -40,10 +40,10 @@ Module( }, WithItem { range: 59..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, id: Name("bar"), ctx: Load, @@ -52,7 +52,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("y"), ctx: Store, @@ -64,11 +64,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, }, ), @@ -79,16 +79,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..99, is_async: false, items: [ WithItem { range: 80..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, id: Name("foo"), ctx: Load, @@ -98,10 +98,10 @@ Module( }, WithItem { range: 85..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, id: Name("bar"), ctx: Load, @@ -110,7 +110,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, id: Name("y"), ctx: Store, @@ -122,11 +122,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, }, ), @@ -137,16 +137,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..125, is_async: false, items: [ WithItem { range: 106..114, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..109, id: Name("foo"), ctx: Load, @@ -155,7 +155,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("x"), ctx: Store, @@ -165,10 +165,10 @@ Module( }, WithItem { range: 116..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..119, id: Name("bar"), ctx: Load, @@ -180,11 +180,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..125, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..125, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap index 90fb2c97daf10..149fba6e356a9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@parenthesized_kwarg_py38.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/parenthesized_kwarg_p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..77, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..51, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..51, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("f"), ctx: Load, @@ -28,22 +28,22 @@ Module( ), arguments: Arguments { range: 44..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 45..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("a"), range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, value: Int( 1, @@ -59,15 +59,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..62, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..62, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, id: Name("f"), ctx: Load, @@ -75,22 +75,22 @@ Module( ), arguments: Arguments { range: 53..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 54..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("a"), range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, value: Int( 1, @@ -106,15 +106,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..76, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..76, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, id: Name("f"), ctx: Load, @@ -122,22 +122,22 @@ Module( ), arguments: Arguments { range: 64..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 66..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("a"), range: 68..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap index 78be042c66925..0361caff9b61b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pep701_f_string_py311.py.snap @@ -7,42 +7,42 @@ input_file: crates/ruff_python_parser/resources/inline/err/pep701_f_string_py311 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..549, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..74, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..74, value: FStringValue { inner: Single( FString( FString { range: 44..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 46..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Magic wand: ", }, ), Interpolation( InterpolatedElement { range: 58..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..71, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, id: Name("bag"), ctx: Load, @@ -50,13 +50,13 @@ Module( ), slice: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..70, value: StringLiteralValue { inner: Single( StringLiteral { range: 64..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "wand", flags: StringLiteralFlags { quote_style: Single, @@ -92,40 +92,40 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..112, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..112, value: FStringValue { inner: Single( FString( FString { range: 95..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 97..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..110, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..107, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..102, value: StringLiteralValue { inner: Single( StringLiteral { range: 98..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", flags: StringLiteralFlags { quote_style: Single, @@ -140,18 +140,18 @@ Module( attr: Identifier { id: Name("join"), range: 103..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 107..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("a"), ctx: Load, @@ -183,37 +183,37 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..220, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..220, value: FStringValue { inner: Single( FString( FString { range: 148..220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 152..169, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "A complex trick: ", }, ), Interpolation( InterpolatedElement { range: 169..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..185, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..178, id: Name("bag"), ctx: Load, @@ -221,13 +221,13 @@ Module( ), slice: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..184, value: StringLiteralValue { inner: Single( StringLiteral { range: 179..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bag", flags: StringLiteralFlags { quote_style: Single, @@ -263,105 +263,105 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..254, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..254, value: FStringValue { inner: Single( FString( FString { range: 221..254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 223..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..252, value: FStringValue { inner: Single( FString( FString { range: 224..252, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 226..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..250, value: FStringValue { inner: Single( FString( FString { range: 227..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 229..249, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..248, value: FStringValue { inner: Single( FString( FString { range: 230..248, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 232..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..246, value: FStringValue { inner: Single( FString( FString { range: 233..246, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 235..245, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..244, value: FStringValue { inner: Single( FString( FString { range: 236..244, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 238..243, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..242, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, value: Int( 1, @@ -371,7 +371,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, value: Int( 1, @@ -486,47 +486,47 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..310, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..310, value: FStringValue { inner: Single( FString( FString { range: 276..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 278..303, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..302, value: FStringValue { inner: Single( FString( FString { range: 279..302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 283..293, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..292, value: StringLiteralValue { inner: Single( StringLiteral { range: 284..292, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "nested", flags: StringLiteralFlags { quote_style: Double, @@ -546,7 +546,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 293..299, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " inner", }, ), @@ -570,7 +570,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 303..309, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " outer", }, ), @@ -590,33 +590,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..359, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..359, value: FStringValue { inner: Single( FString( FString { range: 336..359, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 338..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "test ", }, ), Interpolation( InterpolatedElement { range: 343..353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..345, id: Name("a"), ctx: Load, @@ -630,7 +630,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 353..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " more", }, ), @@ -650,41 +650,41 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..422, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..422, value: FStringValue { inner: Single( FString( FString { range: 403..422, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 407..419, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 408..418, value: FStringValue { inner: Single( FString( FString { range: 408..418, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 412..415, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 413..414, id: Name("x"), ctx: Load, @@ -728,40 +728,40 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 468..502, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 468..502, value: FStringValue { inner: Single( FString( FString { range: 468..502, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 470..501, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 471..500, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 471..480, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 471..475, value: StringLiteralValue { inner: Single( StringLiteral { range: 471..475, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", flags: StringLiteralFlags { quote_style: Single, @@ -776,29 +776,29 @@ Module( attr: Identifier { id: Name("join"), range: 476..480, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 480..500, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 481..499, elts: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 482..486, value: StringLiteralValue { inner: Single( StringLiteral { range: 482..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\t", flags: StringLiteralFlags { quote_style: Single, @@ -812,13 +812,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 488..492, value: StringLiteralValue { inner: Single( StringLiteral { range: 488..492, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\u{b}", flags: StringLiteralFlags { quote_style: Single, @@ -832,13 +832,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 494..498, value: StringLiteralValue { inner: Single( StringLiteral { range: 494..498, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\r", flags: StringLiteralFlags { quote_style: Single, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pos_only_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pos_only_py37.py.snap index 6e1bdfaf6e122..f6650bb5d9e47 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pos_only_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@pos_only_py37.py.snap @@ -7,37 +7,35 @@ input_file: crates/ruff_python_parser/resources/inline/err/pos_only_py37.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..136, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..61, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 47..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 50..56, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -53,11 +51,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), @@ -68,32 +66,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..86, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 66..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 69..81, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -103,14 +99,14 @@ Module( args: [ ParameterWithDefault { range: 76..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 76..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 76..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -125,11 +121,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, }, ), @@ -140,32 +136,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..115, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 91..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 94..110, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 95..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 95..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 95..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -176,11 +170,11 @@ Module( vararg: Some( Parameter { range: 98..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 99..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -188,14 +182,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 108..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 108..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 108..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -208,11 +202,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..115, }, ), @@ -223,33 +217,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..135, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 120..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 123..130, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -264,11 +256,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..135, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..135, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_from_without_exc.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_from_without_exc.py.snap index d6a06bfe2f1e5..4e9bad06a48ff 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_from_without_exc.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_from_without_exc.py.snap @@ -7,18 +7,18 @@ input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_from_witho ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, exc: None, cause: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, id: Name("exc"), ctx: Load, @@ -29,13 +29,13 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..30, exc: None, cause: Some( NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..30, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap index 969eb0b526af8..c9559c557f600 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_cause.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_invalid_ca ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..57, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -27,11 +27,11 @@ Module( cause: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..15, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("y"), ctx: Load, @@ -45,12 +45,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..36, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -60,12 +60,12 @@ Module( cause: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..36, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("y"), ctx: Load, @@ -79,12 +79,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..51, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("x"), ctx: Load, @@ -94,7 +94,7 @@ Module( cause: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, id: Name("y"), ctx: Load, @@ -105,11 +105,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap index fc1d86ea861a4..6886f22badb49 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_invalid_exc.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_invalid_ex ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..36, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, exc: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, @@ -36,17 +36,17 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..22, exc: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..22, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("x"), ctx: Load, @@ -61,12 +61,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..30, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Load, @@ -78,11 +78,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap index d25483b1bc1e2..40dc442afdf02 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_cause.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_unparenthe ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..34, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -27,12 +27,12 @@ Module( cause: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..15, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("y"), ctx: Load, @@ -48,12 +48,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..33, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -63,12 +63,12 @@ Module( cause: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..33, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("y"), ctx: Load, @@ -76,7 +76,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap index 36f4db810c864..34510782dc372 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@raise_stmt_unparenthesized_tuple_exc.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/inline/err/raise_stmt_unparenthe ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..38, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, exc: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -39,17 +39,17 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..19, exc: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..19, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("x"), ctx: Load, @@ -57,7 +57,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("y"), ctx: Load, @@ -74,17 +74,17 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..37, exc: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..30, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("x"), ctx: Load, @@ -92,7 +92,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("y"), ctx: Load, @@ -107,7 +107,7 @@ Module( cause: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap index aec52e3b459e7..5864cb2b05250 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..979, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..59, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..59, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..55, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 55..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, id: Name("foo"), ctx: Load, @@ -49,21 +49,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..79, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 64..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 67..69, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -74,7 +72,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..79, }, ), @@ -83,15 +81,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..152, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..124, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..120, id: Name("call"), ctx: Load, @@ -99,11 +97,11 @@ Module( ), arguments: Arguments { range: 120..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..124, id: Name("foo"), ctx: Load, @@ -117,21 +115,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..152, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 133..136, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 136..138, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -142,7 +138,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..152, }, ), @@ -155,15 +151,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..269, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..239, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..235, id: Name("call"), ctx: Load, @@ -171,11 +167,11 @@ Module( ), arguments: Arguments { range: 235..239, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..239, id: Name("foo"), ctx: Load, @@ -189,21 +185,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..269, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 250..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 253..255, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -214,7 +208,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..269, }, ), @@ -227,15 +221,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..392, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 347..355, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 347..351, id: Name("call"), ctx: Load, @@ -243,11 +237,11 @@ Module( ), arguments: Arguments { range: 351..355, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 352..355, id: Name("foo"), ctx: Load, @@ -261,21 +255,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 369..392, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 373..376, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 376..378, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -286,7 +278,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 388..392, }, ), @@ -299,15 +291,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 453..499, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 456..472, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 456..460, id: Name("call"), ctx: Load, @@ -315,11 +307,11 @@ Module( ), arguments: Arguments { range: 460..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 461..464, id: Name("foo"), ctx: Load, @@ -327,12 +319,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 466..471, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 467..468, id: Name("a"), ctx: Load, @@ -340,7 +332,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 470..471, id: Name("b"), ctx: Load, @@ -358,21 +350,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 476..499, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 480..483, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 483..485, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -383,7 +373,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 495..499, }, ), @@ -396,15 +386,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 564..611, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..583, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..571, id: Name("call"), ctx: Load, @@ -412,11 +402,11 @@ Module( ), arguments: Arguments { range: 571..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..575, id: Name("foo"), ctx: Load, @@ -424,12 +414,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 577..582, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 578..579, id: Name("a"), ctx: Load, @@ -437,7 +427,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 581..582, id: Name("b"), ctx: Load, @@ -455,21 +445,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 588..611, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 592..595, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 595..597, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -480,7 +468,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 607..611, }, ), @@ -493,15 +481,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 772..824, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 775..796, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 775..779, id: Name("call"), ctx: Load, @@ -509,11 +497,11 @@ Module( ), arguments: Arguments { range: 779..796, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 780..783, id: Name("foo"), ctx: Load, @@ -521,12 +509,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 785..794, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 786..787, id: Name("a"), ctx: Load, @@ -534,7 +522,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 793..794, id: Name("b"), ctx: Load, @@ -552,21 +540,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 801..824, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 805..808, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 808..810, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -577,7 +563,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 820..824, }, ), @@ -590,15 +576,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 887..933, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 890..905, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 890..894, id: Name("call"), ctx: Load, @@ -606,33 +592,33 @@ Module( ), arguments: Arguments { range: 894..905, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 895..905, value: FStringValue { inner: Single( FString( FString { range: 895..905, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 897..903, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 903..905, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 904..905, id: Name("x"), ctx: Load, @@ -663,21 +649,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 910..933, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 914..917, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 917..919, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -688,7 +672,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 929..933, }, ), @@ -701,15 +685,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 936..956, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 939..956, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 939..943, id: Name("call"), ctx: Load, @@ -717,18 +701,18 @@ Module( ), arguments: Arguments { range: 943..956, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 944..951, value: FStringValue { inner: Single( FString( FString { range: 944..951, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Double, @@ -752,21 +736,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 956..979, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 960..963, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 963..965, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -777,7 +759,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 975..979, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap index 065645a7ac3f2..d9082066b8ee9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_mac_eol.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token_mac ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..46, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..46, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..19, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 7..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, id: Name("foo"), ctx: Load, @@ -40,12 +40,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("a"), ctx: Load, @@ -53,7 +53,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("b"), ctx: Load, @@ -71,21 +71,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..46, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 27..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 30..32, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -96,7 +94,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..46, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap index 37943705bb106..c3b23f4fbdd41 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lex_logical_token_windows_eol.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lex_logical_token_win ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..50, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..48, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..20, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 7..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, id: Name("foo"), ctx: Load, @@ -40,12 +40,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..18, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("a"), ctx: Load, @@ -53,7 +53,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("b"), ctx: Load, @@ -71,21 +71,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..48, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 28..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 31..33, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -96,7 +94,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..48, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap index 4cb5587c2a4d6..b14f005e9ccbb 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__fstring_format_spec_1.py.snap @@ -7,44 +7,44 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lexing/fstring_format ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..298, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..192, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..192, value: FStringValue { inner: Single( FString( FString { range: 162..192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 164..171, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "middle ", }, ), Interpolation( InterpolatedElement { range: 171..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..180, value: StringLiteralValue { inner: Single( StringLiteral { range: 172..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "string", flags: StringLiteralFlags { quote_style: Single, @@ -61,12 +61,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 181..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 181..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), @@ -91,11 +91,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..198, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..198, id: Name("format"), ctx: Load, @@ -105,11 +105,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..203, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..203, id: Name("spec"), ctx: Load, @@ -119,39 +119,39 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..228, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..228, value: FStringValue { inner: Single( FString( FString { range: 207..228, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 209..216, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "middle ", }, ), Interpolation( InterpolatedElement { range: 216..228, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..225, value: StringLiteralValue { inner: Single( StringLiteral { range: 217..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "string", flags: StringLiteralFlags { quote_style: Single, @@ -168,7 +168,7 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 226..228, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], }, ), @@ -190,17 +190,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..250, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..250, value: StringLiteralValue { inner: Single( StringLiteral { range: 237..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "format spec", flags: StringLiteralFlags { quote_style: Single, @@ -216,39 +216,39 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..285, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..285, value: FStringValue { inner: Single( FString( FString { range: 253..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 255..262, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "middle ", }, ), Interpolation( InterpolatedElement { range: 262..284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..271, value: StringLiteralValue { inner: Single( StringLiteral { range: 263..271, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "string", flags: StringLiteralFlags { quote_style: Single, @@ -265,12 +265,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 272..284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 272..284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\ ", }, ), @@ -295,11 +295,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 285..291, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 285..291, id: Name("format"), ctx: Load, @@ -309,11 +309,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 292..296, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 292..296, id: Name("spec"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap index ae9e10591970e..54c66a5216a74 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lexing/line_continuat ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..36, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("a"), ctx: Load, @@ -40,7 +40,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("b"), ctx: Load, @@ -55,21 +55,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..35, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 20..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 23..25, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -80,7 +78,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..35, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap index 97fbdf8b65be5..f1ae6a18c9a02 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__line_continuation_windows_eol.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lexing/line_continuat ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..46, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("call"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 4..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("a"), ctx: Load, @@ -40,7 +40,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("b"), ctx: Load, @@ -55,21 +55,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..46, is_async: false, decorator_list: [], name: Identifier { id: Name("bar"), range: 30..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 33..35, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -80,7 +78,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..46, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap index 4aa6298cabfae..81e700a1d24a9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_1.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lexing/triple_quoted_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..198, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..178, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..178, value: FStringValue { inner: Single( FString( FString { range: 166..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 170..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 176..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..178, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap index 6a553051a5cb6..599be8b78db41 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_2.py.snap @@ -7,31 +7,31 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lexing/triple_quoted_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..183, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..183, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..183, value: FStringValue { inner: Single( FString( FString { range: 167..183, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 171..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..175, id: Name("foo"), ctx: Load, @@ -42,12 +42,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 176..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 176..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f\n", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap index 2db1a776b19cc..ce80ab0705ee8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@re_lexing__triple_quoted_fstring_3.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/invalid/re_lexing/triple_quoted_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..262, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..262, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..253, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..238, id: Name("call"), ctx: Load, @@ -28,26 +28,26 @@ Module( ), arguments: Arguments { range: 238..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..253, value: FStringValue { inner: Single( FString( FString { range: 239..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 243..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..245, id: Name("x"), ctx: Load, @@ -58,12 +58,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 246..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 246..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f\n", }, ), @@ -92,7 +92,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..262, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap index e14ea1a654330..589ef950bff7b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@rebound_comprehension_variable.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/rebound_comprehension ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..342, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..8, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("a"), ctx: Store, @@ -32,7 +32,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Int( 0, @@ -44,10 +44,10 @@ Module( generators: [ Comprehension { range: 10..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("a"), ctx: Store, @@ -55,11 +55,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..27, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..24, id: Name("range"), ctx: Load, @@ -67,11 +67,11 @@ Module( ), arguments: Arguments { range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 0, @@ -93,19 +93,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..57, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..57, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..37, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..32, id: Name("a"), ctx: Store, @@ -113,7 +113,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, value: Int( 0, @@ -125,10 +125,10 @@ Module( generators: [ Comprehension { range: 39..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("a"), ctx: Store, @@ -136,11 +136,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..56, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..53, id: Name("range"), ctx: Load, @@ -148,11 +148,11 @@ Module( ), arguments: Arguments { range: 53..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 0, @@ -174,19 +174,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..91, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..91, key: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..66, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("a"), ctx: Store, @@ -194,7 +194,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 0, @@ -205,7 +205,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..72, id: Name("val"), ctx: Load, @@ -214,10 +214,10 @@ Module( generators: [ Comprehension { range: 73..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("a"), ctx: Store, @@ -225,11 +225,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..90, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..87, id: Name("range"), ctx: Load, @@ -237,11 +237,11 @@ Module( ), arguments: Arguments { range: 87..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, value: Int( 0, @@ -263,15 +263,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..125, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..125, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, id: Name("key"), ctx: Load, @@ -279,11 +279,11 @@ Module( ), value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..105, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("a"), ctx: Store, @@ -291,7 +291,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, value: Int( 0, @@ -303,10 +303,10 @@ Module( generators: [ Comprehension { range: 107..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, id: Name("a"), ctx: Store, @@ -314,11 +314,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..124, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..121, id: Name("range"), ctx: Load, @@ -326,11 +326,11 @@ Module( ), arguments: Arguments { range: 121..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 0, @@ -352,19 +352,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..154, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..154, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..134, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("a"), ctx: Store, @@ -372,7 +372,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..134, value: Int( 0, @@ -384,10 +384,10 @@ Module( generators: [ Comprehension { range: 136..153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, id: Name("a"), ctx: Store, @@ -395,11 +395,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..153, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..150, id: Name("range"), ctx: Load, @@ -407,11 +407,11 @@ Module( ), arguments: Arguments { range: 150..153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, value: Int( 0, @@ -434,24 +434,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..185, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..185, elt: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..166, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..164, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, id: Name("a"), ctx: Store, @@ -459,7 +459,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, value: Int( 0, @@ -475,10 +475,10 @@ Module( generators: [ Comprehension { range: 167..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("a"), ctx: Store, @@ -486,11 +486,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..184, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..181, id: Name("range"), ctx: Load, @@ -498,11 +498,11 @@ Module( ), arguments: Arguments { range: 181..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..183, value: Int( 0, @@ -524,19 +524,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..233, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..233, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..194, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..189, id: Name("a"), ctx: Store, @@ -544,7 +544,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, value: Int( 0, @@ -556,10 +556,10 @@ Module( generators: [ Comprehension { range: 196..214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..201, id: Name("b"), ctx: Store, @@ -567,11 +567,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..214, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..210, id: Name("range"), ctx: Load, @@ -579,11 +579,11 @@ Module( ), arguments: Arguments { range: 211..214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..213, value: Int( 0, @@ -600,10 +600,10 @@ Module( }, Comprehension { range: 215..232, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..220, id: Name("a"), ctx: Store, @@ -611,11 +611,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..232, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..229, id: Name("range"), ctx: Load, @@ -623,11 +623,11 @@ Module( ), arguments: Arguments { range: 229..232, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..231, value: Int( 0, @@ -649,19 +649,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..281, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..281, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..242, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("a"), ctx: Store, @@ -669,7 +669,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, value: Int( 0, @@ -681,10 +681,10 @@ Module( generators: [ Comprehension { range: 244..262, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 248..249, id: Name("a"), ctx: Store, @@ -692,11 +692,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..262, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..258, id: Name("range"), ctx: Load, @@ -704,11 +704,11 @@ Module( ), arguments: Arguments { range: 259..262, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..261, value: Int( 0, @@ -725,10 +725,10 @@ Module( }, Comprehension { range: 263..280, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 267..268, id: Name("b"), ctx: Store, @@ -736,11 +736,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..280, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..277, id: Name("range"), ctx: Load, @@ -748,11 +748,11 @@ Module( ), arguments: Arguments { range: 277..280, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..279, value: Int( 0, @@ -774,24 +774,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..341, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..341, elt: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 283..303, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 285..291, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 285..286, id: Name("a"), ctx: Store, @@ -799,7 +799,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..291, value: Int( 0, @@ -810,11 +810,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..301, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..296, id: Name("b"), ctx: Store, @@ -822,7 +822,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..301, value: Int( 1, @@ -839,10 +839,10 @@ Module( generators: [ Comprehension { range: 304..322, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..309, id: Name("a"), ctx: Store, @@ -850,11 +850,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..322, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..318, id: Name("range"), ctx: Load, @@ -862,11 +862,11 @@ Module( ), arguments: Arguments { range: 319..322, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 320..321, value: Int( 0, @@ -883,10 +883,10 @@ Module( }, Comprehension { range: 323..340, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..328, id: Name("b"), ctx: Store, @@ -894,11 +894,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 332..340, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 332..337, id: Name("range"), ctx: Load, @@ -906,11 +906,11 @@ Module( ), arguments: Arguments { range: 337..340, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 338..339, value: Int( 0, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap index b93edc683b61d..c6e921af8335f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@return_stmt_invalid_expr.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/return_stmt_invalid_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..74, body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, value: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..8, id: Name(""), ctx: Invalid, @@ -35,17 +35,17 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..23, value: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..23, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -59,16 +59,16 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..43, value: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..43, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, id: Name("x"), ctx: Load, @@ -81,12 +81,12 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("x"), ctx: Load, @@ -97,11 +97,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, value: Int( 1, @@ -112,22 +112,22 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..73, value: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..73, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..73, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("x"), ctx: Load, @@ -135,7 +135,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap index 208ce1f1b0370..fe0e953b6837d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/simple_and_compound_s ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Load, @@ -26,11 +26,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..16, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("b"), ctx: Load, @@ -39,17 +39,17 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line_in_block.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line_in_block.py.snap index 5c6e1ab082a41..9364793f007b9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line_in_block.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_and_compound_stmt_on_same_line_in_block.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/simple_and_compound_s ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..59, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: true, }, @@ -24,7 +24,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -34,11 +34,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..28, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..22, value: false, }, @@ -46,7 +46,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, }, ), @@ -56,11 +56,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..42, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..36, value: true, }, @@ -68,7 +68,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..42, }, ), @@ -78,11 +78,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..58, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, value: false, }, @@ -90,7 +90,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..58, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap index 3e2eb8febcd1b..2fdd57a51a6fe 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/simple_stmts_on_same_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Load, @@ -26,11 +26,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("b"), ctx: Load, @@ -40,15 +40,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..9, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("a"), ctx: Load, @@ -57,7 +57,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("b"), ctx: Load, @@ -69,15 +69,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..15, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..15, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("c"), ctx: Load, @@ -86,7 +86,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("d"), ctx: Load, @@ -98,31 +98,31 @@ Module( ), Break( StmtBreak { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..21, }, ), Continue( StmtContinue { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..31, }, ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..36, }, ), Continue( StmtContinue { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..46, }, ), Break( StmtBreak { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line_in_block.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line_in_block.py.snap index 0e424616ad651..99af157a8ee65 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line_in_block.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@simple_stmts_on_same_line_in_block.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/simple_stmts_on_same_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..46, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..45, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: true, }, @@ -24,31 +24,31 @@ Module( body: [ Break( StmtBreak { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, }, ), Continue( StmtContinue { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..24, }, ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..29, }, ), Continue( StmtContinue { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..39, }, ), Break( StmtBreak { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..45, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_for.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_for.py.snap index 75ce9e03204f3..ad76a4b9a2a71 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_for.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_for.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/single_star_for.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..35, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("_"), ctx: Store, @@ -25,11 +25,11 @@ Module( ), iter: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("x"), ctx: Load, @@ -41,11 +41,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, }, ), @@ -57,16 +57,16 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..34, is_async: false, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..23, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Store, @@ -77,7 +77,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..29, id: Name("xs"), ctx: Load, @@ -86,11 +86,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_return.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_return.py.snap index 8c08d4f66c828..c9515b946ec96 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_return.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_return.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/single_star_return.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,16 +35,16 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..18, value: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..18, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_yield.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_yield.py.snap index 273bb6dd53ccd..e4eaafb75c034 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_yield.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_star_yield.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/single_star_yield.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,20 +35,20 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..17, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..17, value: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..17, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_starred_assignment_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_starred_assignment_target.py.snap index fd275c3a2ed14..c619b3d4151d7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_starred_assignment_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@single_starred_assignment_target.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/single_starred_assign ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, targets: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..2, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("a"), ctx: Store, @@ -33,12 +33,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..9, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap index 2f547ff272313..23e829c3841ef 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_index_py310.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/star_index_py310.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..293, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..55, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..55, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, id: Name("lst"), ctx: Load, @@ -28,16 +28,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..54, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..54, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..54, id: Name("index"), ctx: Load, @@ -58,27 +58,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..112, decorator_list: [], name: Identifier { id: Name("Array"), range: 78..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 83..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..106, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..91, id: Name("Generic"), ctx: Load, @@ -86,12 +86,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..105, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..97, id: Name("DType"), ctx: Load, @@ -99,11 +99,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..105, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..105, id: Name("Shape"), ctx: Load, @@ -127,11 +127,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, }, ), @@ -142,15 +142,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..161, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..161, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..151, id: Name("lst"), ctx: Load, @@ -158,12 +158,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..160, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..153, id: Name("a"), ctx: Load, @@ -171,11 +171,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..157, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("b"), ctx: Load, @@ -186,7 +186,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..160, id: Name("c"), ctx: Load, @@ -204,15 +204,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..198, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..198, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..188, id: Name("lst"), ctx: Load, @@ -220,12 +220,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..197, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("a"), ctx: Load, @@ -233,7 +233,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, id: Name("b"), ctx: Load, @@ -241,11 +241,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 195..197, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..197, id: Name("c"), ctx: Load, @@ -266,15 +266,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..233, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..233, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..225, id: Name("lst"), ctx: Load, @@ -282,16 +282,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..232, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..228, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..228, id: Name("a"), ctx: Load, @@ -302,11 +302,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..232, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..232, id: Name("b"), ctx: Load, @@ -327,15 +327,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..271, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..271, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..259, id: Name("array"), ctx: Load, @@ -343,17 +343,17 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..270, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..263, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..261, value: Int( 3, @@ -364,7 +364,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..263, value: Int( 5, @@ -377,11 +377,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..270, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..270, id: Name("idxs"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_slices.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_slices.py.snap index 4f9cc982f6ee7..d4d9df070fccd 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_slices.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@star_slices.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/star_slices.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, id: Name("array"), ctx: Load, @@ -28,16 +28,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..17, lower: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..12, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..12, id: Name("start"), ctx: Load, @@ -50,11 +50,11 @@ Module( upper: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("end"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap index 5853cdff0029f..bafb792f6a86a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__function_type_parameters.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/function_type ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..988, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 796..824, is_async: false, decorator_list: [], name: Identifier { id: Name("keyword"), range: 800..807, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 807..817, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 808..809, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("A"), range: 808..809, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -42,11 +42,11 @@ Module( TypeVar( TypeParamTypeVar { range: 811..816, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("await"), range: 811..816, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -57,9 +57,7 @@ Module( ), parameters: Parameters { range: 817..819, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -70,11 +68,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 821..824, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 821..824, }, ), @@ -85,28 +83,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 826..862, is_async: false, decorator_list: [], name: Identifier { id: Name("not_a_type_param"), range: 830..846, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 846..855, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 847..848, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("A"), range: 847..848, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -115,11 +113,11 @@ Module( TypeVar( TypeParamTypeVar { range: 853..854, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("B"), range: 853..854, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -130,9 +128,7 @@ Module( ), parameters: Parameters { range: 855..857, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -143,11 +139,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 859..862, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 859..862, }, ), @@ -158,28 +154,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 864..896, is_async: false, decorator_list: [], name: Identifier { id: Name("multiple_commas"), range: 868..883, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 883..889, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 884..885, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("A"), range: 884..885, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -188,11 +184,11 @@ Module( TypeVar( TypeParamTypeVar { range: 887..888, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("B"), range: 887..888, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -203,9 +199,7 @@ Module( ), parameters: Parameters { range: 889..891, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -216,11 +210,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 893..896, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 893..896, }, ), @@ -231,28 +225,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 898..938, is_async: false, decorator_list: [], name: Identifier { id: Name("multiple_trailing_commas"), range: 902..926, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 926..931, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 927..928, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("A"), range: 927..928, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -263,9 +257,7 @@ Module( ), parameters: Parameters { range: 931..933, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -276,11 +268,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 935..938, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 935..938, }, ), @@ -291,28 +283,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 940..979, is_async: false, decorator_list: [], name: Identifier { id: Name("multiple_commas_and_recovery"), range: 944..972, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 972..976, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 973..974, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("A"), range: 973..974, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -323,9 +315,7 @@ Module( ), parameters: Parameters { range: 976..976, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -336,11 +326,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 976..979, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 976..979, value: Int( 100, @@ -354,11 +344,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 980..987, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 980..982, elts: [], ctx: Store, @@ -367,7 +357,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 984..987, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_closing_parentheses.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_closing_parentheses.py.snap index 5ca66592b10f3..886c21590cab8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_closing_parentheses.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_closing_parentheses.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/if_extra_clos ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..110, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..97, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..97, value: true, }, @@ -27,7 +27,7 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..109, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap index 0a04441bbbf1b..6a36fcb277c90 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__if_extra_indent.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/if_extra_inde ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..153, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..134, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..110, value: true, }, @@ -24,21 +24,21 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..120, }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..134, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..134, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("a"), ctx: Load, @@ -47,7 +47,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..134, id: Name("b"), ctx: Load, @@ -63,18 +63,18 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..144, }, ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..152, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("a"), ctx: Store, @@ -83,7 +83,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..152, value: Int( 10, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap index 26643d505d71a..6920a94c5381f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_assignment_targets.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/invalid_assig ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..788, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..206, targets: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: Int( 5, @@ -27,7 +27,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..206, value: Int( 3, @@ -38,11 +38,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..214, target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..209, value: Int( 5, @@ -52,7 +52,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..214, value: Int( 3, @@ -63,11 +63,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..228, target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..218, value: Int( 5, @@ -76,7 +76,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..224, id: Name("int"), ctx: Load, @@ -85,7 +85,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..228, value: Int( 3, @@ -98,18 +98,18 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..314, targets: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..309, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..304, id: Name("x"), ctx: Load, @@ -117,7 +117,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..309, id: Name("y"), ctx: Load, @@ -129,7 +129,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..314, value: Int( 42, @@ -140,16 +140,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..328, targets: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..322, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..317, id: Name("x"), ctx: Store, @@ -157,7 +157,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..322, value: Int( 5, @@ -169,7 +169,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 326..328, value: Int( 42, @@ -180,16 +180,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..339, targets: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..334, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..330, id: Name("x"), ctx: Load, @@ -198,7 +198,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..334, id: Name("y"), ctx: Load, @@ -209,7 +209,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 337..339, value: Int( 42, @@ -220,17 +220,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..347, targets: [ UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..342, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 341..342, id: Name("x"), ctx: Store, @@ -241,7 +241,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..347, value: Int( 42, @@ -252,31 +252,29 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..366, targets: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..360, parameters: Some( Parameters { range: 356..357, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 356..357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 356..357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("_"), range: 356..357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -290,7 +288,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 359..360, value: Int( 1, @@ -302,7 +300,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..366, value: Int( 42, @@ -313,16 +311,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..385, targets: [ If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..380, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 372..373, id: Name("b"), ctx: Load, @@ -330,7 +328,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..368, id: Name("a"), ctx: Load, @@ -338,7 +336,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 379..380, id: Name("c"), ctx: Load, @@ -349,7 +347,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..385, value: Int( 42, @@ -360,25 +358,25 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..399, targets: [ Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..394, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 387..390, value: StringLiteralValue { inner: Single( StringLiteral { range: 387..390, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -393,7 +391,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..393, value: Int( 5, @@ -407,7 +405,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 397..399, value: Int( 42, @@ -418,17 +416,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..408, targets: [ Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..403, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..402, id: Name("a"), ctx: Load, @@ -440,7 +438,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 406..408, value: Int( 42, @@ -451,16 +449,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..429, targets: [ ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..424, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 410..411, id: Name("x"), ctx: Load, @@ -469,10 +467,10 @@ Module( generators: [ Comprehension { range: 412..423, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 416..417, id: Name("x"), ctx: Store, @@ -480,7 +478,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..423, id: Name("xs"), ctx: Load, @@ -495,7 +493,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 427..429, value: Int( 42, @@ -506,16 +504,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..450, targets: [ SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..445, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 431..432, id: Name("x"), ctx: Load, @@ -524,10 +522,10 @@ Module( generators: [ Comprehension { range: 433..444, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 437..438, id: Name("x"), ctx: Store, @@ -535,7 +533,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 442..444, id: Name("xs"), ctx: Load, @@ -550,7 +548,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 448..450, value: Int( 42, @@ -561,16 +559,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 451..478, targets: [ DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 451..473, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 452..453, id: Name("x"), ctx: Load, @@ -578,11 +576,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 455..460, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 455..456, id: Name("x"), ctx: Load, @@ -591,7 +589,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 459..460, value: Int( 2, @@ -603,10 +601,10 @@ Module( generators: [ Comprehension { range: 461..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 465..466, id: Name("x"), ctx: Store, @@ -614,7 +612,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 470..472, id: Name("xs"), ctx: Load, @@ -629,7 +627,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 476..478, value: Int( 42, @@ -640,16 +638,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 479..499, targets: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 479..494, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 480..481, id: Name("x"), ctx: Load, @@ -658,10 +656,10 @@ Module( generators: [ Comprehension { range: 482..493, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 486..487, id: Name("x"), ctx: Store, @@ -669,7 +667,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 491..493, id: Name("xs"), ctx: Load, @@ -685,7 +683,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 497..499, value: Int( 42, @@ -696,16 +694,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 500..512, targets: [ Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 500..507, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 506..507, id: Name("x"), ctx: Load, @@ -716,7 +714,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 510..512, value: Int( 42, @@ -727,17 +725,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..527, targets: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 514..521, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 520..521, id: Name("x"), ctx: Load, @@ -749,7 +747,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 525..527, value: Int( 42, @@ -760,16 +758,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 528..548, targets: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 529..542, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 540..542, id: Name("xs"), ctx: Load, @@ -780,7 +778,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 546..548, value: Int( 42, @@ -791,16 +789,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 549..563, targets: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 549..558, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 549..550, id: Name("a"), ctx: Load, @@ -813,7 +811,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 553..554, id: Name("b"), ctx: Load, @@ -821,7 +819,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 557..558, id: Name("c"), ctx: Load, @@ -833,7 +831,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 561..563, value: Int( 42, @@ -844,16 +842,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 564..574, targets: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 564..569, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 564..567, id: Name("foo"), ctx: Load, @@ -861,7 +859,7 @@ Module( ), arguments: Arguments { range: 567..569, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -870,7 +868,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..574, value: Int( 42, @@ -881,27 +879,27 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 576..590, targets: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 576..585, value: FStringValue { inner: Single( FString( FString { range: 576..585, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 578..584, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 579..583, id: Name("quux"), ctx: Load, @@ -927,7 +925,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 588..590, value: Int( 42, @@ -938,27 +936,27 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 591..614, targets: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 591..609, value: FStringValue { inner: Single( FString( FString { range: 591..609, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 593..598, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 594..597, id: Name("foo"), ctx: Load, @@ -972,17 +970,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 598..603, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " and ", }, ), Interpolation( InterpolatedElement { range: 603..608, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 604..607, id: Name("bar"), ctx: Load, @@ -1008,7 +1006,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 612..614, value: Int( 42, @@ -1019,18 +1017,18 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 616..626, targets: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 616..621, value: StringLiteralValue { inner: Single( StringLiteral { range: 616..621, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -1045,7 +1043,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 624..626, value: Int( 42, @@ -1056,18 +1054,18 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 627..638, targets: [ BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 627..633, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 627..633, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 102, 111, @@ -1086,7 +1084,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 636..638, value: Int( 42, @@ -1097,12 +1095,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 639..647, targets: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 639..642, value: Int( 123, @@ -1112,7 +1110,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 645..647, value: Int( 42, @@ -1123,12 +1121,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 648..657, targets: [ BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 648..652, value: true, }, @@ -1136,7 +1134,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 655..657, value: Int( 42, @@ -1147,19 +1145,19 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..667, targets: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..662, }, ), ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 665..667, value: Int( 42, @@ -1170,19 +1168,19 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 668..676, targets: [ EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 668..671, }, ), ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 674..676, value: Int( 42, @@ -1193,20 +1191,20 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 677..688, targets: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 677..683, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 678..683, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 678..681, id: Name("foo"), ctx: Load, @@ -1214,7 +1212,7 @@ Module( ), arguments: Arguments { range: 681..683, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1226,7 +1224,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..688, value: Int( 42, @@ -1237,17 +1235,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 689..717, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 689..702, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 690..691, id: Name("x"), ctx: Store, @@ -1255,11 +1253,11 @@ Module( ), Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 693..698, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 693..696, id: Name("foo"), ctx: Load, @@ -1267,7 +1265,7 @@ Module( ), arguments: Arguments { range: 696..698, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1275,7 +1273,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..701, id: Name("y"), ctx: Store, @@ -1288,12 +1286,12 @@ Module( ], value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 705..717, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 706..708, value: Int( 42, @@ -1302,7 +1300,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..712, value: Int( 42, @@ -1311,7 +1309,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 714..716, value: Int( 42, @@ -1326,22 +1324,22 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 718..758, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 718..737, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 719..725, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 720..721, id: Name("a"), ctx: Store, @@ -1349,7 +1347,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 723..724, id: Name("b"), ctx: Store, @@ -1361,17 +1359,17 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 727..733, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 728..732, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 729..731, value: Int( 42, @@ -1388,7 +1386,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 735..736, id: Name("d"), ctx: Store, @@ -1401,17 +1399,17 @@ Module( ], value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 740..758, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 741..747, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 742..743, value: Int( 1, @@ -1420,7 +1418,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 745..746, value: Int( 2, @@ -1433,17 +1431,17 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 749..754, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 750..753, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 751..752, value: Int( 3, @@ -1460,7 +1458,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 756..757, value: Int( 4, @@ -1475,17 +1473,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 759..787, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 759..772, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 760..761, id: Name("x"), ctx: Store, @@ -1493,11 +1491,11 @@ Module( ), Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 763..768, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 763..766, id: Name("foo"), ctx: Load, @@ -1505,7 +1503,7 @@ Module( ), arguments: Arguments { range: 766..768, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1513,7 +1511,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 770..771, id: Name("y"), ctx: Store, @@ -1527,12 +1525,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 775..787, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 776..778, value: Int( 42, @@ -1541,7 +1539,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 780..782, value: Int( 42, @@ -1550,7 +1548,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 784..786, value: Int( 42, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap index 788a678251bd2..1ac04383c539e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__invalid_augmented_assignment_target.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/invalid_augme ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..611, body: [ AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..109, target: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..103, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, id: Name("x"), ctx: Load, @@ -30,7 +30,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("y"), ctx: Load, @@ -42,7 +42,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..109, value: Int( 42, @@ -53,15 +53,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..124, target: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..117, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, id: Name("x"), ctx: Store, @@ -69,7 +69,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, value: Int( 5, @@ -81,7 +81,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..124, value: Int( 42, @@ -92,15 +92,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..136, target: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..130, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..126, id: Name("x"), ctx: Load, @@ -109,7 +109,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("y"), ctx: Load, @@ -120,7 +120,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..136, value: Int( 42, @@ -131,16 +131,16 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..145, target: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..139, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..139, id: Name("x"), ctx: Store, @@ -151,7 +151,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..145, value: Int( 42, @@ -162,30 +162,28 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..165, target: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..158, parameters: Some( Parameters { range: 154..155, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 154..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 154..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("_"), range: 154..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -199,7 +197,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, value: Int( 1, @@ -211,7 +209,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..165, value: Int( 42, @@ -222,15 +220,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..185, target: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..179, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("b"), ctx: Load, @@ -238,7 +236,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("a"), ctx: Load, @@ -246,7 +244,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("c"), ctx: Load, @@ -257,7 +255,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..185, value: Int( 42, @@ -268,24 +266,24 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..200, target: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..194, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..190, value: StringLiteralValue { inner: Single( StringLiteral { range: 187..190, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -300,7 +298,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, value: Int( 5, @@ -314,7 +312,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..200, value: Int( 42, @@ -325,16 +323,16 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..210, target: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..204, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..203, id: Name("a"), ctx: Load, @@ -346,7 +344,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..210, value: Int( 42, @@ -357,15 +355,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..232, target: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..226, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..213, id: Name("x"), ctx: Load, @@ -374,10 +372,10 @@ Module( generators: [ Comprehension { range: 214..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..219, id: Name("x"), ctx: Store, @@ -385,7 +383,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..225, id: Name("xs"), ctx: Load, @@ -400,7 +398,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..232, value: Int( 42, @@ -411,15 +409,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..254, target: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..248, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..235, id: Name("x"), ctx: Load, @@ -428,10 +426,10 @@ Module( generators: [ Comprehension { range: 236..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..241, id: Name("x"), ctx: Store, @@ -439,7 +437,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..247, id: Name("xs"), ctx: Load, @@ -454,7 +452,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..254, value: Int( 42, @@ -465,15 +463,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..283, target: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..277, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 256..257, id: Name("x"), ctx: Load, @@ -481,11 +479,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..264, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..260, id: Name("x"), ctx: Load, @@ -494,7 +492,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..264, value: Int( 2, @@ -506,10 +504,10 @@ Module( generators: [ Comprehension { range: 265..276, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..270, id: Name("x"), ctx: Store, @@ -517,7 +515,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..276, id: Name("xs"), ctx: Load, @@ -532,7 +530,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..283, value: Int( 42, @@ -543,15 +541,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..305, target: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..299, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 285..286, id: Name("x"), ctx: Load, @@ -560,10 +558,10 @@ Module( generators: [ Comprehension { range: 287..298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 291..292, id: Name("x"), ctx: Store, @@ -571,7 +569,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..298, id: Name("xs"), ctx: Load, @@ -587,7 +585,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..305, value: Int( 42, @@ -598,15 +596,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..319, target: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..313, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..313, id: Name("x"), ctx: Load, @@ -617,7 +615,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..319, value: Int( 42, @@ -628,16 +626,16 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 320..335, target: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..328, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..328, id: Name("x"), ctx: Load, @@ -649,7 +647,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..335, value: Int( 42, @@ -660,15 +658,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..357, target: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 337..350, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..350, id: Name("xs"), ctx: Load, @@ -679,7 +677,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 355..357, value: Int( 42, @@ -690,15 +688,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 358..373, target: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 358..367, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 358..359, id: Name("a"), ctx: Load, @@ -711,7 +709,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 362..363, id: Name("b"), ctx: Load, @@ -719,7 +717,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 366..367, id: Name("c"), ctx: Load, @@ -731,7 +729,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 371..373, value: Int( 42, @@ -742,15 +740,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..385, target: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..379, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..377, id: Name("foo"), ctx: Load, @@ -758,7 +756,7 @@ Module( ), arguments: Arguments { range: 377..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -767,7 +765,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..385, value: Int( 42, @@ -778,26 +776,26 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 387..402, target: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 387..396, value: FStringValue { inner: Single( FString( FString { range: 387..396, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 389..395, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..394, id: Name("quux"), ctx: Load, @@ -823,7 +821,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..402, value: Int( 42, @@ -834,26 +832,26 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..427, target: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..421, value: FStringValue { inner: Single( FString( FString { range: 403..421, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 405..410, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 406..409, id: Name("foo"), ctx: Load, @@ -867,17 +865,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 410..415, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " and ", }, ), Interpolation( InterpolatedElement { range: 415..420, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 416..419, id: Name("bar"), ctx: Load, @@ -903,7 +901,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 425..427, value: Int( 42, @@ -914,17 +912,17 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 429..440, target: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 429..434, value: StringLiteralValue { inner: Single( StringLiteral { range: 429..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -939,7 +937,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 438..440, value: Int( 42, @@ -950,17 +948,17 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..453, target: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..447, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 441..447, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 102, 111, @@ -979,7 +977,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 451..453, value: Int( 42, @@ -990,11 +988,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 454..463, target: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 454..457, value: Int( 123, @@ -1004,7 +1002,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 461..463, value: Int( 42, @@ -1015,11 +1013,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..474, target: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..468, value: true, }, @@ -1027,7 +1025,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 472..474, value: Int( 42, @@ -1038,18 +1036,18 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 475..485, target: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 475..479, }, ), op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 483..485, value: Int( 42, @@ -1060,18 +1058,18 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 486..495, target: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 486..489, }, ), op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 493..495, value: Int( 42, @@ -1082,19 +1080,19 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 496..508, target: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 496..502, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 497..502, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 497..500, id: Name("foo"), ctx: Load, @@ -1102,7 +1100,7 @@ Module( ), arguments: Arguments { range: 500..502, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1114,7 +1112,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 506..508, value: Int( 42, @@ -1125,16 +1123,16 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 509..538, target: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 509..522, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 510..511, id: Name("x"), ctx: Store, @@ -1142,11 +1140,11 @@ Module( ), Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..518, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..516, id: Name("foo"), ctx: Load, @@ -1154,7 +1152,7 @@ Module( ), arguments: Arguments { range: 516..518, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1162,7 +1160,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 520..521, id: Name("y"), ctx: Store, @@ -1175,12 +1173,12 @@ Module( op: Add, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 526..538, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 527..529, value: Int( 42, @@ -1189,7 +1187,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 531..533, value: Int( 42, @@ -1198,7 +1196,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 535..537, value: Int( 42, @@ -1213,21 +1211,21 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 539..580, target: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 539..558, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 540..546, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 541..542, id: Name("a"), ctx: Store, @@ -1235,7 +1233,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 544..545, id: Name("b"), ctx: Store, @@ -1247,17 +1245,17 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 548..554, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 549..553, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 550..552, value: Int( 42, @@ -1274,7 +1272,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 556..557, id: Name("d"), ctx: Store, @@ -1287,17 +1285,17 @@ Module( op: Add, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 562..580, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 563..569, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 564..565, value: Int( 1, @@ -1306,7 +1304,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..568, value: Int( 2, @@ -1319,17 +1317,17 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 571..576, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..575, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 573..574, value: Int( 3, @@ -1346,7 +1344,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 578..579, value: Int( 4, @@ -1361,16 +1359,16 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 581..610, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 581..594, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 582..583, id: Name("x"), ctx: Store, @@ -1378,11 +1376,11 @@ Module( ), Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 585..590, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 585..588, id: Name("foo"), ctx: Load, @@ -1390,7 +1388,7 @@ Module( ), arguments: Arguments { range: 588..590, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1398,7 +1396,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 592..593, id: Name("y"), ctx: Store, @@ -1412,12 +1410,12 @@ Module( op: Add, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 598..610, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 599..601, value: Int( 42, @@ -1426,7 +1424,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 603..605, value: Int( 42, @@ -1435,7 +1433,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 607..609, value: Int( 42, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap index 58087f43bd7e8..27c349f705c1b 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_0.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_patt ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..198, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..197, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,14 +25,14 @@ Module( cases: [ MatchCase { range: 127..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 132..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..139, id: Name(""), ctx: Invalid, @@ -40,18 +40,18 @@ Module( ), arguments: PatternArguments { range: 140..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 141..142, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 141..142, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -59,13 +59,13 @@ Module( MatchAs( PatternMatchAs { range: 144..145, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("b"), range: 144..145, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -79,7 +79,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..197, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap index c33ba5de9a3bd..4ef2b99dcf28e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_1.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_patt ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..210, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..209, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,18 +25,18 @@ Module( cases: [ MatchCase { range: 140..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 145..158, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..158, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..152, id: Name(""), ctx: Invalid, @@ -45,7 +45,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..158, value: Complex { real: 0.0, @@ -61,7 +61,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..209, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap index 056268c64d25f..b649717bab809 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_2.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_patt ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..190, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..176, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,22 +25,22 @@ Module( cases: [ MatchCase { range: 159..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 164..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchAs( PatternMatchAs { range: 164..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 164..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -50,7 +50,7 @@ Module( Identifier { id: Name("y"), range: 169..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -59,16 +59,16 @@ Module( body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..176, target: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..175, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..175, value: Complex { real: 0.0, @@ -80,7 +80,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..176, id: Name(""), ctx: Invalid, @@ -97,7 +97,7 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..189, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap index 6ebf0be44b9fc..74014165fd03a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_3.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_patt ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..136, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..120, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,37 +25,37 @@ Module( cases: [ MatchCase { range: 103..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 108..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, items: [], }, ), arguments: PatternArguments { range: 109..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 110..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchAs( PatternMatchAs { range: 110..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 110..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -65,7 +65,7 @@ Module( Identifier { id: Name("y"), range: 115..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -79,11 +79,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Int( 1, @@ -99,7 +99,7 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..135, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap index 6d705cce3a44d..4ec3c135117b9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__as_pattern_4.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/as_patt ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..187, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..186, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,15 +25,15 @@ Module( cases: [ MatchCase { range: 156..186, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 161..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..163, id: Name("x"), ctx: Store, @@ -41,7 +41,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, id: Name("y"), ctx: Store, @@ -52,13 +52,13 @@ Module( MatchAs( PatternMatchAs { range: 164..166, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("as"), range: 164..166, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -66,10 +66,10 @@ Module( MatchValue( PatternMatchValue { range: 170..171, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, value: Int( 1, @@ -86,7 +86,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..186, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap index 1687f42248ed8..e5f771dfd8b27 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_class_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/invalid ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..383, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..285, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..57, id: Name("subject"), ctx: Load, @@ -25,14 +25,14 @@ Module( cases: [ MatchCase { range: 63..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 68..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, id: Name("Foo"), ctx: Load, @@ -40,24 +40,24 @@ Module( ), arguments: PatternArguments { range: 71..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 72..82, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name(""), range: 80..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 81..82, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: Int( 1, @@ -75,7 +75,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..97, }, ), @@ -83,14 +83,14 @@ Module( }, MatchCase { range: 102..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 107..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..110, id: Name("Foo"), ctx: Load, @@ -98,24 +98,24 @@ Module( ), arguments: PatternArguments { range: 110..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 111..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name(""), range: 118..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 119..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Int( 1, @@ -133,7 +133,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..135, }, ), @@ -141,14 +141,14 @@ Module( }, MatchCase { range: 140..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 145..160, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..148, id: Name("Foo"), ctx: Load, @@ -156,24 +156,24 @@ Module( ), arguments: PatternArguments { range: 148..160, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 149..159, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name(""), range: 157..157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 158..159, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, value: Int( 1, @@ -191,7 +191,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..174, }, ), @@ -199,14 +199,14 @@ Module( }, MatchCase { range: 179..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 184..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..187, id: Name("Foo"), ctx: Load, @@ -214,24 +214,24 @@ Module( ), arguments: PatternArguments { range: 187..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 188..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name(""), range: 200..200, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 201..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: Int( 1, @@ -249,7 +249,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..217, }, ), @@ -257,14 +257,14 @@ Module( }, MatchCase { range: 222..249, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 227..235, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..230, id: Name("Foo"), ctx: Load, @@ -272,24 +272,24 @@ Module( ), arguments: PatternArguments { range: 230..235, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 231..234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name(""), range: 233..233, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 233..234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..234, value: Int( 1, @@ -307,7 +307,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..249, }, ), @@ -315,14 +315,14 @@ Module( }, MatchCase { range: 254..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 259..271, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..262, id: Name("Foo"), ctx: Load, @@ -330,24 +330,24 @@ Module( ), arguments: PatternArguments { range: 262..271, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 263..270, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name(""), range: 269..269, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 269..270, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..270, value: Int( 1, @@ -365,7 +365,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..285, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap index abf680ec652dd..978a1633e1ad6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_lhs_or_rhs_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/invalid ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..695, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..332, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..25, id: Name("invalid_lhs_pattern"), ctx: Load, @@ -25,22 +25,22 @@ Module( cases: [ MatchCase { range: 31..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 36..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..46, left: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..41, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, id: Name("Foo"), ctx: Load, @@ -48,7 +48,7 @@ Module( ), arguments: Arguments { range: 39..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -57,7 +57,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..46, value: Complex { real: 0.0, @@ -73,7 +73,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..60, }, ), @@ -81,18 +81,18 @@ Module( }, MatchCase { range: 65..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 70..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..76, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("x"), ctx: Store, @@ -101,7 +101,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..76, value: Complex { real: 0.0, @@ -117,7 +117,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..90, }, ), @@ -125,18 +125,18 @@ Module( }, MatchCase { range: 95..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 100..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..106, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("_"), ctx: Store, @@ -145,7 +145,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..106, value: Complex { real: 0.0, @@ -161,7 +161,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..120, }, ), @@ -169,22 +169,22 @@ Module( }, MatchCase { range: 125..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 130..142, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..142, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..136, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, value: Int( 1, @@ -194,7 +194,7 @@ Module( op: BitOr, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, value: Int( 2, @@ -206,7 +206,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..142, value: Complex { real: 0.0, @@ -222,7 +222,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..156, }, ), @@ -230,23 +230,23 @@ Module( }, MatchCase { range: 161..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 166..177, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..177, left: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..172, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, value: Int( 1, @@ -255,7 +255,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, value: Int( 2, @@ -269,7 +269,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..177, value: Complex { real: 0.0, @@ -285,7 +285,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..191, }, ), @@ -293,25 +293,25 @@ Module( }, MatchCase { range: 196..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 201..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..215, left: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..210, items: [ DictItem { key: Some( BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..206, value: true, }, @@ -319,7 +319,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..209, value: Int( 1, @@ -333,7 +333,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..215, value: Complex { real: 0.0, @@ -349,7 +349,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..229, }, ), @@ -357,18 +357,18 @@ Module( }, MatchCase { range: 234..260, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 239..246, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..246, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..241, value: Complex { real: 0.0, @@ -379,7 +379,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..246, value: Complex { real: 0.0, @@ -395,7 +395,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 256..260, }, ), @@ -403,23 +403,23 @@ Module( }, MatchCase { range: 265..292, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 270..278, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..278, left: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..273, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..273, value: Complex { real: 0.0, @@ -432,7 +432,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..278, value: Complex { real: 0.0, @@ -448,7 +448,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 288..292, }, ), @@ -456,22 +456,22 @@ Module( }, MatchCase { range: 297..332, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 302..318, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..318, left: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..313, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..305, id: Name("Foo"), ctx: Load, @@ -479,11 +479,11 @@ Module( ), arguments: Arguments { range: 305..313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..312, id: Name(""), ctx: Invalid, @@ -497,7 +497,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..318, value: Complex { real: 0.0, @@ -513,7 +513,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..332, }, ), @@ -524,11 +524,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 334..625, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..359, id: Name("invalid_rhs_pattern"), ctx: Load, @@ -537,18 +537,18 @@ Module( cases: [ MatchCase { range: 365..393, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 370..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 370..379, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 370..371, value: Int( 1, @@ -558,11 +558,11 @@ Module( op: Add, right: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..379, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..377, id: Name("Foo"), ctx: Load, @@ -570,7 +570,7 @@ Module( ), arguments: Arguments { range: 377..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -584,7 +584,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 389..393, }, ), @@ -592,18 +592,18 @@ Module( }, MatchCase { range: 398..422, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 403..408, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..408, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..404, value: Int( 2, @@ -613,7 +613,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 407..408, id: Name("x"), ctx: Store, @@ -627,7 +627,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 418..422, }, ), @@ -635,18 +635,18 @@ Module( }, MatchCase { range: 427..451, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 432..437, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 432..437, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 432..433, value: Int( 3, @@ -656,7 +656,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 436..437, id: Name("_"), ctx: Store, @@ -670,7 +670,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 447..451, }, ), @@ -678,18 +678,18 @@ Module( }, MatchCase { range: 456..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 461..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 461..472, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 461..462, value: Int( 4, @@ -699,11 +699,11 @@ Module( op: Add, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 466..471, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 466..467, value: Int( 1, @@ -713,7 +713,7 @@ Module( op: BitOr, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 470..471, value: Int( 2, @@ -730,7 +730,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 482..486, }, ), @@ -738,18 +738,18 @@ Module( }, MatchCase { range: 491..520, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 496..506, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 496..506, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 496..497, value: Int( 5, @@ -759,12 +759,12 @@ Module( op: Add, right: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 500..506, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 501..502, value: Int( 1, @@ -773,7 +773,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 504..505, value: Int( 2, @@ -792,7 +792,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 516..520, }, ), @@ -800,18 +800,18 @@ Module( }, MatchCase { range: 525..557, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 530..543, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 530..543, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 530..531, value: Int( 6, @@ -821,14 +821,14 @@ Module( op: Add, right: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 534..543, items: [ DictItem { key: Some( BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 535..539, value: true, }, @@ -836,7 +836,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 541..542, value: Int( 1, @@ -855,7 +855,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 553..557, }, ), @@ -863,18 +863,18 @@ Module( }, MatchCase { range: 562..586, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 567..572, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..572, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..568, value: Int( 1, @@ -884,7 +884,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 571..572, value: Int( 2, @@ -899,7 +899,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 582..586, }, ), @@ -907,18 +907,18 @@ Module( }, MatchCase { range: 591..625, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 596..611, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..611, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..597, value: Int( 1, @@ -928,11 +928,11 @@ Module( op: Add, right: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 600..611, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 600..603, id: Name("Foo"), ctx: Load, @@ -940,11 +940,11 @@ Module( ), arguments: Arguments { range: 603..611, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 604..610, id: Name(""), ctx: Invalid, @@ -963,7 +963,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 621..625, }, ), @@ -974,11 +974,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 627..694, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 633..656, id: Name("invalid_lhs_rhs_pattern"), ctx: Load, @@ -987,22 +987,22 @@ Module( cases: [ MatchCase { range: 662..694, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 667..680, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 667..680, left: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 667..672, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 667..670, id: Name("Foo"), ctx: Load, @@ -1010,7 +1010,7 @@ Module( ), arguments: Arguments { range: 670..672, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1019,11 +1019,11 @@ Module( op: Add, right: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 675..680, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 675..678, id: Name("Bar"), ctx: Load, @@ -1031,7 +1031,7 @@ Module( ), arguments: Arguments { range: 678..680, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1045,7 +1045,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 690..694, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap index 69e3b740ee67d..67b66ad2eacd5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__invalid_mapping_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/invalid ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..509, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..209, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..74, id: Name("subject"), ctx: Load, @@ -25,19 +25,19 @@ Module( cases: [ MatchCase { range: 80..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 85..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..90, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..90, id: Name("key"), ctx: Store, @@ -51,10 +51,10 @@ Module( MatchValue( PatternMatchValue { range: 90..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..90, id: Name(""), ctx: Invalid, @@ -70,7 +70,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..105, }, ), @@ -78,19 +78,19 @@ Module( }, MatchCase { range: 110..138, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 115..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..120, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, id: Name("key"), ctx: Store, @@ -104,10 +104,10 @@ Module( MatchValue( PatternMatchValue { range: 122..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 1, @@ -124,7 +124,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..138, }, ), @@ -132,19 +132,19 @@ Module( }, MatchCase { range: 143..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 148..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..153, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..153, id: Name("key"), ctx: Store, @@ -158,10 +158,10 @@ Module( MatchValue( PatternMatchValue { range: 154..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..155, value: Int( 1, @@ -178,7 +178,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..170, }, ), @@ -186,19 +186,19 @@ Module( }, MatchCase { range: 175..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 180..195, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..185, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..185, id: Name("key"), ctx: Store, @@ -209,7 +209,7 @@ Module( ), NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..191, }, ), @@ -218,10 +218,10 @@ Module( MatchValue( PatternMatchValue { range: 185..185, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..185, id: Name(""), ctx: Invalid, @@ -232,10 +232,10 @@ Module( MatchValue( PatternMatchValue { range: 193..194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, value: Int( 1, @@ -252,7 +252,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..209, }, ), @@ -263,11 +263,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 305..462, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 311..318, id: Name("subject"), ctx: Load, @@ -276,15 +276,15 @@ Module( cases: [ MatchCase { range: 324..360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 329..346, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 338..342, }, ), @@ -293,10 +293,10 @@ Module( MatchValue( PatternMatchValue { range: 344..345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..345, value: Int( 1, @@ -310,7 +310,7 @@ Module( Identifier { id: Name("rest"), range: 332..336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -319,7 +319,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 356..360, }, ), @@ -327,15 +327,15 @@ Module( }, MatchCase { range: 365..411, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 370..397, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 389..393, }, ), @@ -344,10 +344,10 @@ Module( MatchValue( PatternMatchValue { range: 395..396, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..396, value: Int( 1, @@ -361,7 +361,7 @@ Module( Identifier { id: Name("rest2"), range: 382..387, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -370,7 +370,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 407..411, }, ), @@ -378,15 +378,15 @@ Module( }, MatchCase { range: 416..462, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 421..448, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 431..435, }, ), @@ -395,10 +395,10 @@ Module( MatchValue( PatternMatchValue { range: 437..438, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 437..438, value: Int( 1, @@ -412,7 +412,7 @@ Module( Identifier { id: Name("rest2"), range: 442..447, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -421,7 +421,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..462, }, ), @@ -432,11 +432,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..509, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 470..477, id: Name("subject"), ctx: Load, @@ -445,19 +445,19 @@ Module( cases: [ MatchCase { range: 483..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 488..504, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 489..500, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 489..492, id: Name("Foo"), ctx: Load, @@ -465,11 +465,11 @@ Module( ), arguments: Arguments { range: 492..500, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 493..499, id: Name(""), ctx: Invalid, @@ -485,10 +485,10 @@ Module( MatchValue( PatternMatchValue { range: 502..503, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 502..503, value: Int( 1, @@ -505,11 +505,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 506..509, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 506..509, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap index ca41862659884..121bc2d2a5bb4 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__star_pattern_usage.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/star_pa ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..408, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..407, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..70, id: Name("subject"), ctx: Load, @@ -25,11 +25,11 @@ Module( cases: [ MatchCase { range: 76..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchStar( PatternMatchStar { range: 81..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -37,7 +37,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..97, }, ), @@ -45,16 +45,16 @@ Module( }, MatchCase { range: 102..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 107..114, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchStar( PatternMatchStar { range: 107..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -63,7 +63,7 @@ Module( Identifier { id: Name("x"), range: 113..114, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -72,7 +72,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..128, }, ), @@ -80,16 +80,16 @@ Module( }, MatchCase { range: 133..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchStar( PatternMatchStar { range: 138..142, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("foo"), range: 139..142, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -98,7 +98,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..156, }, ), @@ -106,21 +106,21 @@ Module( }, MatchCase { range: 161..188, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 166..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 166..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("foo"), range: 167..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -128,10 +128,10 @@ Module( MatchValue( PatternMatchValue { range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..174, value: Int( 1, @@ -147,7 +147,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..188, }, ), @@ -155,19 +155,19 @@ Module( }, MatchCase { range: 193..220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 198..206, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 198..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..199, value: Int( 1, @@ -179,12 +179,12 @@ Module( MatchStar( PatternMatchStar { range: 202..206, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("foo"), range: 203..206, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -196,7 +196,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..220, }, ), @@ -204,14 +204,14 @@ Module( }, MatchCase { range: 225..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 230..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..233, id: Name("Foo"), ctx: Load, @@ -219,12 +219,12 @@ Module( ), arguments: PatternArguments { range: 233..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 234..236, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -237,7 +237,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 247..251, }, ), @@ -245,14 +245,14 @@ Module( }, MatchCase { range: 256..284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 261..270, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..264, id: Name("Foo"), ctx: Load, @@ -260,21 +260,21 @@ Module( ), arguments: PatternArguments { range: 264..270, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 265..269, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 265..266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchStar( PatternMatchStar { range: 267..269, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -287,7 +287,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..284, }, ), @@ -295,19 +295,19 @@ Module( }, MatchCase { range: 289..312, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 294..298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..297, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..297, id: Name("_"), ctx: Store, @@ -321,10 +321,10 @@ Module( MatchValue( PatternMatchValue { range: 297..297, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 297..297, id: Name(""), ctx: Invalid, @@ -340,7 +340,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..312, }, ), @@ -348,19 +348,19 @@ Module( }, MatchCase { range: 317..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 322..329, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 323..325, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..325, id: Name("_"), ctx: Store, @@ -374,10 +374,10 @@ Module( MatchValue( PatternMatchValue { range: 327..328, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..328, value: Int( 1, @@ -394,7 +394,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..343, }, ), @@ -402,15 +402,15 @@ Module( }, MatchCase { range: 348..377, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 353..363, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..358, }, ), @@ -419,7 +419,7 @@ Module( MatchStar( PatternMatchStar { range: 360..362, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -431,7 +431,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 373..377, }, ), @@ -439,18 +439,18 @@ Module( }, MatchCase { range: 382..407, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 387..393, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 387..393, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 387..388, value: Int( 1, @@ -460,11 +460,11 @@ Module( op: Add, right: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 391..393, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..393, id: Name("_"), ctx: Store, @@ -481,7 +481,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..407, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap index b0a9f945ab898..fe42f9c2894eb 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__match__unary_add_usage.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/match/unary_a ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..269, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..268, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..87, id: Name("subject"), ctx: Load, @@ -25,19 +25,19 @@ Module( cases: [ MatchCase { range: 93..114, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 98..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..100, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, value: Int( 1, @@ -52,7 +52,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..114, }, ), @@ -60,19 +60,19 @@ Module( }, MatchCase { range: 119..149, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 124..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..125, value: Int( 1, @@ -84,15 +84,15 @@ Module( MatchValue( PatternMatchValue { range: 128..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..130, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, value: Int( 2, @@ -106,15 +106,15 @@ Module( MatchValue( PatternMatchValue { range: 133..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..135, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, value: Int( 3, @@ -132,7 +132,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..149, }, ), @@ -140,19 +140,19 @@ Module( }, MatchCase { range: 154..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 159..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 160..161, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, value: Int( 1, @@ -164,15 +164,15 @@ Module( MatchValue( PatternMatchValue { range: 163..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..165, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, value: Int( 2, @@ -186,15 +186,15 @@ Module( MatchValue( PatternMatchValue { range: 167..169, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..169, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..169, value: Int( 3, @@ -212,7 +212,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..184, }, ), @@ -220,14 +220,14 @@ Module( }, MatchCase { range: 189..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 194..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..197, id: Name("Foo"), ctx: Load, @@ -235,29 +235,29 @@ Module( ), arguments: PatternArguments { range: 197..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 198..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 198..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 200..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..202, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: Int( 1, @@ -271,24 +271,24 @@ Module( }, PatternKeyword { range: 204..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 204..205, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 206..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..208, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..208, value: Int( 2, @@ -308,7 +308,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..223, }, ), @@ -316,22 +316,22 @@ Module( }, MatchCase { range: 228..268, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 233..254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..238, value: true, }, ), BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..249, value: false, }, @@ -341,15 +341,15 @@ Module( MatchValue( PatternMatchValue { range: 240..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..242, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, value: Int( 1, @@ -363,15 +363,15 @@ Module( MatchValue( PatternMatchValue { range: 251..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..253, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..253, value: Int( 2, @@ -390,7 +390,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..268, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap index 3c07014614489..9d872e920ef22 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__ambiguous_lpar_with_items.py.snap @@ -7,26 +7,26 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/with/ambiguou ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..950, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..188, is_async: false, items: [ WithItem { range: 168..182, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..182, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..174, id: Name("item1"), ctx: Load, @@ -34,7 +34,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..181, id: Name("item2"), ctx: Load, @@ -51,11 +51,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..188, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..188, }, ), @@ -66,21 +66,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..219, is_async: false, items: [ WithItem { range: 194..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..208, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 195..200, id: Name("item1"), ctx: Load, @@ -88,7 +88,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..207, id: Name("item2"), ctx: Load, @@ -103,10 +103,10 @@ Module( }, WithItem { range: 213..214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..214, id: Name("f"), ctx: Load, @@ -118,11 +118,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..219, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..219, }, ), @@ -133,21 +133,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..252, is_async: false, items: [ WithItem { range: 225..239, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..239, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..231, id: Name("item1"), ctx: Load, @@ -155,7 +155,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..238, id: Name("item2"), ctx: Load, @@ -170,10 +170,10 @@ Module( }, WithItem { range: 241..246, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..246, id: Name("item3"), ctx: Load, @@ -185,11 +185,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..252, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..252, }, ), @@ -200,20 +200,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..270, is_async: false, items: [ WithItem { range: 258..265, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..264, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..264, id: Name("item"), ctx: Load, @@ -228,11 +228,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 267..270, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 267..270, }, ), @@ -243,20 +243,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..293, is_async: false, items: [ WithItem { range: 276..288, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..282, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..282, id: Name("item"), ctx: Load, @@ -268,7 +268,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..288, id: Name("f"), ctx: Store, @@ -280,11 +280,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..293, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..293, }, ), @@ -295,20 +295,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 294..321, is_async: false, items: [ WithItem { range: 300..315, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..310, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..304, id: Name("item"), ctx: Store, @@ -316,7 +316,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..310, value: Int( 10, @@ -328,7 +328,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..315, id: Name("f"), ctx: Store, @@ -340,11 +340,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..321, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..321, }, ), @@ -355,16 +355,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 322..357, is_async: false, items: [ WithItem { range: 328..333, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..333, id: Name("item1"), ctx: Load, @@ -374,14 +374,14 @@ Module( }, WithItem { range: 335..351, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..346, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..340, id: Name("item2"), ctx: Store, @@ -389,7 +389,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..346, value: Int( 10, @@ -401,7 +401,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 350..351, id: Name("f"), ctx: Store, @@ -413,11 +413,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..357, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..357, }, ), @@ -428,20 +428,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 358..396, is_async: false, items: [ WithItem { range: 363..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 363..384, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..365, id: Name("x"), ctx: Load, @@ -450,10 +450,10 @@ Module( generators: [ Comprehension { range: 366..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 370..371, id: Name("x"), ctx: Store, @@ -461,11 +461,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 375..384, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 375..380, id: Name("range"), ctx: Load, @@ -473,11 +473,11 @@ Module( ), arguments: Arguments { range: 380..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 381..383, value: Int( 10, @@ -500,10 +500,10 @@ Module( }, WithItem { range: 386..390, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..390, id: Name("item"), ctx: Load, @@ -515,11 +515,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 393..396, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 393..396, }, ), @@ -530,21 +530,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 397..410, is_async: false, items: [ WithItem { range: 402..410, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 402..410, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..407, id: Name("item"), ctx: Load, @@ -552,7 +552,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..410, id: Name("x"), ctx: Load, @@ -571,12 +571,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 411..429, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 415..416, id: Name("x"), ctx: Store, @@ -584,11 +584,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..429, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..425, id: Name("range"), ctx: Load, @@ -596,11 +596,11 @@ Module( ), arguments: Arguments { range: 425..429, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 426..428, value: Int( 10, @@ -618,11 +618,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 432..435, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 432..435, }, ), @@ -630,20 +630,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 496..515, is_async: false, items: [ WithItem { range: 502..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 503..508, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 504..508, id: Name("item"), ctx: Load, @@ -658,11 +658,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 512..515, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 512..515, }, ), @@ -673,24 +673,24 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 517..551, is_async: false, items: [ WithItem { range: 522..539, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 522..539, elt: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 523..525, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 524..525, id: Name("x"), ctx: Load, @@ -702,10 +702,10 @@ Module( generators: [ Comprehension { range: 526..539, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 530..531, id: Name("x"), ctx: Store, @@ -713,7 +713,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 535..539, id: Name("iter"), ctx: Load, @@ -730,10 +730,10 @@ Module( }, WithItem { range: 541..545, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 541..545, id: Name("item"), ctx: Load, @@ -745,11 +745,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 548..551, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 548..551, }, ), @@ -760,21 +760,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 552..567, is_async: false, items: [ WithItem { range: 557..567, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 557..567, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 558..563, id: Name("item1"), ctx: Load, @@ -782,11 +782,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 565..567, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 566..567, id: Name("x"), ctx: Load, @@ -808,12 +808,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 568..588, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..573, id: Name("x"), ctx: Store, @@ -821,12 +821,12 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 577..588, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 577..581, id: Name("iter"), ctx: Load, @@ -834,7 +834,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 583..588, id: Name("item2"), ctx: Load, @@ -851,11 +851,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 591..594, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 591..594, }, ), @@ -863,16 +863,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 595..617, is_async: false, items: [ WithItem { range: 601..607, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 601..602, id: Name("x"), ctx: Load, @@ -881,7 +881,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 606..607, id: Name("f"), ctx: Store, @@ -891,14 +891,14 @@ Module( }, WithItem { range: 609..611, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 609..611, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 610..611, id: Name("y"), ctx: Load, @@ -913,11 +913,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 614..617, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 614..617, }, ), @@ -928,20 +928,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 618..640, is_async: false, items: [ WithItem { range: 624..626, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 624..626, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 625..626, id: Name("x"), ctx: Load, @@ -954,10 +954,10 @@ Module( }, WithItem { range: 628..634, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 628..629, id: Name("y"), ctx: Load, @@ -966,7 +966,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 633..634, id: Name("f"), ctx: Store, @@ -978,11 +978,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 637..640, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 637..640, }, ), @@ -993,21 +993,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 641..663, is_async: false, items: [ WithItem { range: 646..658, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 646..658, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 647..648, id: Name("x"), ctx: Load, @@ -1015,12 +1015,12 @@ Module( ), Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 650..657, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 656..657, id: Name("y"), ctx: Load, @@ -1040,11 +1040,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 660..663, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 660..663, }, ), @@ -1055,21 +1055,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 664..689, is_async: false, items: [ WithItem { range: 669..684, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 669..684, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 670..671, id: Name("x"), ctx: Load, @@ -1077,17 +1077,17 @@ Module( ), Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 673..683, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 679..683, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 679..680, id: Name("y"), ctx: Load, @@ -1095,7 +1095,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 682..683, id: Name("z"), ctx: Load, @@ -1120,11 +1120,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..689, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..689, }, ), @@ -1135,21 +1135,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 690..717, is_async: false, items: [ WithItem { range: 695..712, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 695..712, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 696..697, id: Name("x"), ctx: Load, @@ -1157,11 +1157,11 @@ Module( ), YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 699..711, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..711, id: Name("y"), ctx: Load, @@ -1180,11 +1180,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 714..717, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 714..717, }, ), @@ -1195,16 +1195,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 718..734, is_async: false, items: [ WithItem { range: 724..730, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 724..725, id: Name("x"), ctx: Load, @@ -1213,7 +1213,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 729..730, id: Name("f"), ctx: Store, @@ -1223,10 +1223,10 @@ Module( }, WithItem { range: 732..733, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 732..733, id: Name("y"), ctx: Load, @@ -1240,11 +1240,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 738..744, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 738..739, id: Name("f"), ctx: Store, @@ -1252,7 +1252,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 741..744, }, ), @@ -1262,20 +1262,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 745..777, is_async: false, items: [ WithItem { range: 750..771, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 750..766, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 751..752, id: Name("x"), ctx: Load, @@ -1284,10 +1284,10 @@ Module( generators: [ Comprehension { range: 753..766, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 757..758, id: Name("x"), ctx: Store, @@ -1295,7 +1295,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 762..766, id: Name("iter"), ctx: Load, @@ -1311,7 +1311,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 770..771, id: Name("y"), ctx: Store, @@ -1323,11 +1323,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 774..777, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 774..777, }, ), @@ -1338,16 +1338,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 837..854, is_async: false, items: [ WithItem { range: 843..853, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 844..848, id: Name("item"), ctx: Load, @@ -1356,7 +1356,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 852..853, id: Name("f"), ctx: Store, @@ -1370,11 +1370,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 857..860, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 857..860, }, ), @@ -1382,16 +1382,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 862..878, is_async: false, items: [ WithItem { range: 868..877, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 868..872, id: Name("item"), ctx: Load, @@ -1400,7 +1400,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 876..877, id: Name("f"), ctx: Store, @@ -1414,11 +1414,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 880..886, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 880..881, id: Name("x"), ctx: Store, @@ -1426,7 +1426,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 883..886, }, ), @@ -1436,16 +1436,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 887..904, is_async: false, items: [ WithItem { range: 893..903, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 893..897, id: Name("item"), ctx: Load, @@ -1454,7 +1454,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 901..903, id: Name("f1"), ctx: Store, @@ -1468,11 +1468,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 908..915, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 908..910, id: Name("f2"), ctx: Store, @@ -1480,7 +1480,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 912..915, }, ), @@ -1490,16 +1490,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 916..950, is_async: false, items: [ WithItem { range: 922..932, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 922..927, id: Name("item1"), ctx: Load, @@ -1508,7 +1508,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 931..932, id: Name("f"), ctx: Store, @@ -1518,14 +1518,14 @@ Module( }, WithItem { range: 934..944, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 934..944, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 934..939, id: Name("item2"), ctx: Store, @@ -1533,7 +1533,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 943..944, value: Int( 0, @@ -1548,11 +1548,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 947..950, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 947..950, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap index 1798ad6c23613..6b0b38c2e329c 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__empty_with_items.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/with/empty_wi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..105, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..98, is_async: false, items: [], body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..98, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..98, }, ), @@ -34,15 +34,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..105, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..105, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("x"), ctx: Load, @@ -51,7 +51,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap index 15bb2f058b3bc..9c651474b89b5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/with/unclosed ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, is_async: false, items: [ WithItem { range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..6, id: Name(""), ctx: Invalid, @@ -33,15 +33,15 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("x"), ctx: Load, @@ -50,7 +50,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap index ce5678ded9b49..317469f9005a5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unclosed_ambiguous_lpar_eof.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/with/unclosed ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, is_async: false, items: [ WithItem { range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..6, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap index c93979143a337..7e2d808bc68ff 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@statements__with__unparenthesized_with_items.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/invalid/statements/with/unparent ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..249, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..102, is_async: false, items: [ WithItem { range: 91..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..95, id: Name("item"), ctx: Load, @@ -33,7 +33,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..102, }, ), @@ -42,16 +42,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..124, is_async: false, items: [ WithItem { range: 108..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..112, id: Name("item"), ctx: Load, @@ -60,7 +60,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, id: Name("x"), ctx: Store, @@ -72,7 +72,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..124, }, ), @@ -81,20 +81,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..141, is_async: false, items: [ WithItem { range: 130..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..135, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..135, id: Name("item"), ctx: Load, @@ -109,7 +109,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..141, }, ), @@ -118,20 +118,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..163, is_async: false, items: [ WithItem { range: 147..157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..152, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..152, id: Name("item"), ctx: Load, @@ -143,7 +143,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("x"), ctx: Store, @@ -155,7 +155,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..163, }, ), @@ -164,20 +164,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..193, is_async: false, items: [ WithItem { range: 169..175, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..175, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..175, id: Name("item1"), ctx: Load, @@ -190,10 +190,10 @@ Module( }, WithItem { range: 177..187, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..182, id: Name("item2"), ctx: Load, @@ -202,7 +202,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..187, id: Name("f"), ctx: Store, @@ -214,7 +214,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..193, }, ), @@ -223,16 +223,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..223, is_async: false, items: [ WithItem { range: 199..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..204, id: Name("item1"), ctx: Load, @@ -241,7 +241,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..209, id: Name("f"), ctx: Store, @@ -251,14 +251,14 @@ Module( }, WithItem { range: 211..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..217, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..217, id: Name("item2"), ctx: Load, @@ -273,7 +273,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..223, }, ), @@ -282,16 +282,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..249, is_async: false, items: [ WithItem { range: 229..233, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..233, id: Name("item"), ctx: Load, @@ -301,10 +301,10 @@ Module( }, WithItem { range: 237..243, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..238, value: Int( 0, @@ -314,7 +314,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..243, id: Name("f"), ctx: Store, @@ -326,7 +326,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..249, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_empty_expression.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_empty_expression.py.snap index 6fade07f51d7b..e1c3d47bda395 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_empty_expression.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_empty_expression.py.snap @@ -7,30 +7,30 @@ input_file: crates/ruff_python_parser/resources/inline/err/t_string_empty_expres ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..58, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..49, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..49, value: TStringValue { inner: Single( TString { range: 44..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 46..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..47, id: Name(""), ctx: Invalid, @@ -56,25 +56,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..57, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..57, value: TStringValue { inner: Single( TString { range: 50..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 52..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..53, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_name_tok.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_name_tok.py.snap index 4666c540d1673..6b648bae65530 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_name_tok.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_name_tok.py.snap @@ -7,30 +7,30 @@ input_file: crates/ruff_python_parser/resources/inline/err/t_string_invalid_conv ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: TStringValue { inner: Single( TString { range: 44..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 46..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_other_tok.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_other_tok.py.snap index def26a3f18b97..9c937acac3319 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_other_tok.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_conversion_flag_other_tok.py.snap @@ -7,30 +7,30 @@ input_file: crates/ruff_python_parser/resources/inline/err/t_string_invalid_conv ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..66, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..54, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..54, value: TStringValue { inner: Single( TString { range: 44..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 46..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Load, @@ -56,25 +56,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..65, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..65, value: TStringValue { inner: Single( TString { range: 55..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 57..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_starred_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_starred_expr.py.snap index ea5934128b7cd..592c6eedced27 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_starred_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_invalid_starred_expr.py.snap @@ -7,34 +7,34 @@ input_file: crates/ruff_python_parser/resources/inline/err/t_string_invalid_star ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..156, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..127, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..127, value: TStringValue { inner: Single( TString { range: 121..127, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 123..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..125, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..125, id: Name(""), ctx: Invalid, @@ -63,35 +63,35 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..141, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..141, value: TStringValue { inner: Single( TString { range: 128..141, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 130..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..139, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..139, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("x"), ctx: Load, @@ -99,7 +99,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..139, id: Name("y"), ctx: Load, @@ -131,34 +131,34 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..155, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..155, value: TStringValue { inner: Single( TString { range: 142..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 144..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..153, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..153, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..153, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_lambda_without_parentheses.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_lambda_without_parentheses.py.snap index ceeb8540da3d1..d0d8abdfd3d83 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_lambda_without_parentheses.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_lambda_without_parentheses.py.snap @@ -7,49 +7,47 @@ input_file: crates/ruff_python_parser/resources/inline/err/t_string_lambda_witho ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..61, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..60, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..60, value: TStringValue { inner: Single( TString { range: 44..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 46..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, parameters: Some( Parameters { range: 54..55, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -63,7 +61,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..56, id: Name(""), ctx: Invalid, @@ -79,7 +77,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 56..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " x", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace.py.snap index 3078488a9830d..4218d6845d8ab 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace.py.snap @@ -7,30 +7,30 @@ input_file: crates/ruff_python_parser/resources/inline/err/t_string_unclosed_lbr ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..82, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..48, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..48, value: TStringValue { inner: Single( TString { range: 44..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..47, id: Name(""), ctx: Invalid, @@ -56,25 +56,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..58, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..58, value: TStringValue { inner: Single( TString { range: 49..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 51..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..55, id: Name("foo"), ctx: Load, @@ -100,25 +100,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..67, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..67, value: TStringValue { inner: Single( TString { range: 59..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 61..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, id: Name("foo"), ctx: Load, @@ -149,26 +149,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..81, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..81, value: TStringValue { inner: Concatenated( [ TString { range: 68..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..71, id: Name(""), ctx: Invalid, @@ -188,15 +188,15 @@ Module( }, TString { range: 73..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 77..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..78, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace_in_format_spec.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace_in_format_spec.py.snap index 0a7f827af2fd6..3a002658cc6c8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace_in_format_spec.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@t_string_unclosed_lbrace_in_format_spec.py.snap @@ -7,37 +7,37 @@ input_file: crates/ruff_python_parser/resources/inline/err/t_string_unclosed_lbr ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..73, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, value: TStringValue { inner: Single( TString { range: 44..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 46..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 52..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("x"), ctx: Load, @@ -48,7 +48,7 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 55..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], }, ), @@ -69,32 +69,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..72, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..72, value: TStringValue { inner: Single( TString { range: 57..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 59..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 65..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("x"), ctx: Load, @@ -105,12 +105,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 68..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 68..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@template_strings_py313.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@template_strings_py313.py.snap index 8767d279bfa4b..b63187911997d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@template_strings_py313.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@template_strings_py313.py.snap @@ -7,30 +7,30 @@ input_file: crates/ruff_python_parser/resources/inline/err/template_strings_py31 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..89, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: TStringValue { inner: Single( TString { range: 44..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 46..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..50, id: Name("hey"), ctx: Load, @@ -56,25 +56,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..63, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..63, value: TStringValue { inner: Single( TString { range: 53..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 55..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..61, id: Name("there"), ctx: Load, @@ -100,22 +100,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..88, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..88, value: TStringValue { inner: Single( TString { range: 64..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 68..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "what's\nhappening?", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_invalid_order.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_invalid_order.py.snap index 81e4bacde6996..0bcf4355aa95e 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_invalid_order.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_invalid_order.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/try_stmt_invalid_orde ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..47, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -27,7 +27,7 @@ Module( finalbody: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..31, }, ), @@ -37,7 +37,7 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..46, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_missing_except_finally.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_missing_except_finally.py.snap index b86a2ad5bf5bf..cdba080314348 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_missing_except_finally.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_missing_except_finally.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/try_stmt_missing_exce ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..43, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -30,12 +30,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..42, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..27, }, ), @@ -44,7 +44,7 @@ Module( orelse: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..42, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap index 2bb1a1e8282ea..1803efb100daa 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_misspelled_except.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/try_stmt_misspelled_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..165, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -30,11 +30,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..20, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..19, id: Name("exept"), ctx: Store, @@ -42,7 +42,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..20, id: Name(""), ctx: Invalid, @@ -54,24 +54,24 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..58, }, ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..76, }, ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..82, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("a"), ctx: Store, @@ -80,7 +80,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: Int( 1, @@ -91,12 +91,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..113, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..96, }, ), @@ -105,13 +105,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 97..113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..113, }, ), @@ -126,11 +126,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..120, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..119, id: Name("exept"), ctx: Store, @@ -138,7 +138,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..120, id: Name(""), ctx: Invalid, @@ -150,18 +150,18 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..158, }, ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..164, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..160, id: Name("b"), ctx: Store, @@ -170,7 +170,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_mixed_except_kind.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_mixed_except_kind.py.snap index 689c42622ecbe..98f032e8c9c15 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_mixed_except_kind.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@try_stmt_mixed_except_kind.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/try_stmt_mixed_except ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..242, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..63, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -26,13 +26,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 14..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..30, }, ), @@ -42,11 +42,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 31..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..53, id: Name("ExceptionGroup"), ctx: Load, @@ -57,7 +57,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..63, }, ), @@ -72,12 +72,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..127, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..77, }, ), @@ -86,11 +86,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 78..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..100, id: Name("ExceptionGroup"), ctx: Load, @@ -101,7 +101,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..110, }, ), @@ -111,13 +111,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 111..127, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..127, }, ), @@ -132,12 +132,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..241, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..141, }, ), @@ -146,13 +146,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 142..158, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..158, }, ), @@ -162,13 +162,13 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 159..175, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..175, }, ), @@ -178,11 +178,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 176..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..198, id: Name("ExceptionGroup"), ctx: Load, @@ -193,7 +193,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..208, }, ), @@ -203,11 +203,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 209..241, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..231, id: Name("ExceptionGroup"), ctx: Load, @@ -218,7 +218,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..241, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@tuple_context_manager_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@tuple_context_manager_py38.py.snap index b0c18e8a43e7d..88c24c69722a1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@tuple_context_manager_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@tuple_context_manager_py38.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/tuple_context_manager ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..327, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..236, is_async: false, items: [ WithItem { range: 222..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..225, id: Name("foo"), ctx: Load, @@ -31,10 +31,10 @@ Module( }, WithItem { range: 227..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..230, id: Name("bar"), ctx: Load, @@ -46,11 +46,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..236, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..236, }, ), @@ -61,20 +61,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..274, is_async: false, items: [ WithItem { range: 242..269, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..261, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..250, id: Name("open"), ctx: Load, @@ -82,17 +82,17 @@ Module( ), arguments: Arguments { range: 250..261, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..260, value: StringLiteralValue { inner: Single( StringLiteral { range: 251..260, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo.txt", flags: StringLiteralFlags { quote_style: Single, @@ -112,7 +112,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..269, id: Name("foo"), ctx: Store, @@ -124,11 +124,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..274, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..274, }, ), @@ -139,16 +139,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 275..309, is_async: false, items: [ WithItem { range: 284..287, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..287, id: Name("foo"), ctx: Load, @@ -158,10 +158,10 @@ Module( }, WithItem { range: 291..294, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 291..294, id: Name("bar"), ctx: Load, @@ -171,10 +171,10 @@ Module( }, WithItem { range: 298..301, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 298..301, id: Name("baz"), ctx: Load, @@ -186,11 +186,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..309, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..309, }, ), @@ -201,16 +201,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..326, is_async: false, items: [ WithItem { range: 316..319, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..319, id: Name("foo"), ctx: Load, @@ -222,11 +222,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 323..326, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 323..326, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap index 96e430a647c3e..b035de8a7fa62 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_incomplete_stmt.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_alias_incomplete ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("type"), ctx: Load, @@ -26,11 +26,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..9, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..9, id: Name("type"), ctx: Load, @@ -40,11 +40,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("x"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..20, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("x"), ctx: Store, @@ -67,7 +67,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..20, id: Name(""), ctx: Invalid, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap index a7f11501f60d9..57d354e2fdef9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_alias_invalid_value_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_alias_invalid_va ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..67, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Store, @@ -25,11 +25,11 @@ Module( type_params: None, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("y"), ctx: Load, @@ -42,11 +42,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..28, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("x"), ctx: Store, @@ -55,12 +55,12 @@ Module( type_params: None, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..28, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("y"), ctx: Load, @@ -73,11 +73,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..50, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("x"), ctx: Store, @@ -86,11 +86,11 @@ Module( type_params: None, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..50, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("y"), ctx: Load, @@ -102,11 +102,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..61, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Store, @@ -115,7 +115,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("x"), ctx: Load, @@ -125,11 +125,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap index c9de513d8a75e..60ecaa07d24e9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_default_py312.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_default_py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..149, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..65, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("X"), ctx: Store, @@ -25,22 +25,22 @@ Module( type_params: Some( TypeParams { range: 50..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 51..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, id: Name("int"), ctx: Load, @@ -54,7 +54,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, id: Name("int"), ctx: Load, @@ -64,34 +64,34 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..87, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 71..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 72..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, id: Name("int"), ctx: Load, @@ -105,9 +105,7 @@ Module( ), parameters: Parameters { range: 80..82, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -118,11 +116,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..87, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..87, }, ), @@ -133,33 +131,33 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..111, decorator_list: [], name: Identifier { id: Name("C"), range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 95..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 96..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 96..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..103, id: Name("int"), ctx: Load, @@ -174,7 +172,7 @@ Module( arguments: Some( Arguments { range: 104..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -182,11 +180,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, }, ), @@ -197,27 +195,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..148, decorator_list: [], name: Identifier { id: Name("D"), range: 118..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 119..141, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("S"), range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -226,17 +224,17 @@ Module( TypeVar( TypeParamTypeVar { range: 123..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 123..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, id: Name("int"), ctx: Load, @@ -248,17 +246,17 @@ Module( TypeVar( TypeParamTypeVar { range: 132..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 132..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..140, id: Name("uint"), ctx: Load, @@ -273,7 +271,7 @@ Module( arguments: Some( Arguments { range: 141..143, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -281,11 +279,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..148, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..148, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap index ce4ecda18c831..46a51aa71bee5 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_invalid_bound_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_invalid_bo ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..103, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,25 +25,25 @@ Module( type_params: Some( TypeParams { range: 6..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 7..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..14, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, id: Name("int"), ctx: Load, @@ -61,7 +61,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, id: Name("int"), ctx: Load, @@ -71,11 +71,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..46, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("X"), ctx: Store, @@ -84,26 +84,26 @@ Module( type_params: Some( TypeParams { range: 28..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 29..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..39, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("x"), ctx: Load, @@ -121,7 +121,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..46, id: Name("int"), ctx: Load, @@ -131,11 +131,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..76, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, id: Name("X"), ctx: Store, @@ -144,25 +144,25 @@ Module( type_params: Some( TypeParams { range: 53..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 54..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..69, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -179,7 +179,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, id: Name("int"), ctx: Load, @@ -189,11 +189,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..102, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("X"), ctx: Store, @@ -202,21 +202,21 @@ Module( type_params: Some( TypeParams { range: 83..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 84..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 84..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, id: Name("x"), ctx: Load, @@ -229,11 +229,11 @@ Module( TypeVar( TypeParamTypeVar { range: 92..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("int"), range: 92..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -244,7 +244,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..102, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap index 84551e10b69c1..91001fe28b936 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_missing_bound.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_missing_bo ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 7..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -45,7 +45,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -55,11 +55,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..40, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("X"), ctx: Store, @@ -68,16 +68,16 @@ Module( type_params: Some( TypeParams { range: 24..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 25..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T1"), range: 25..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -86,11 +86,11 @@ Module( TypeVar( TypeParamTypeVar { range: 31..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T2"), range: 31..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -101,7 +101,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..40, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap index 7b4e3d833c6a2..cdda1b6d5c73f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_bound.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_param_spec ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -44,7 +44,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..10, id: Name(""), ctx: Invalid, @@ -54,11 +54,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, id: Name("int"), ctx: Load, @@ -68,11 +68,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap index 6cde8b6197543..01b78df9f63a9 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_invalid_default_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_param_spec ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..140, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,25 +25,25 @@ Module( type_params: Some( TypeParams { range: 6..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 7..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -60,7 +60,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, id: Name("int"), ctx: Load, @@ -70,11 +70,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..52, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, id: Name("X"), ctx: Store, @@ -83,26 +83,26 @@ Module( type_params: Some( TypeParams { range: 31..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 32..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 34..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..45, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("x"), ctx: Load, @@ -119,7 +119,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, id: Name("int"), ctx: Load, @@ -129,11 +129,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..85, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("X"), ctx: Store, @@ -142,25 +142,25 @@ Module( type_params: Some( TypeParams { range: 59..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 60..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..78, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("x"), ctx: Load, @@ -176,7 +176,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, id: Name("int"), ctx: Load, @@ -186,11 +186,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..114, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, id: Name("X"), ctx: Store, @@ -199,21 +199,21 @@ Module( type_params: Some( TypeParams { range: 92..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 93..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 95..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("x"), ctx: Load, @@ -225,11 +225,11 @@ Module( TypeVar( TypeParamTypeVar { range: 104..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("int"), range: 104..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -240,7 +240,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..114, id: Name("int"), ctx: Load, @@ -250,11 +250,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..139, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, id: Name("X"), ctx: Store, @@ -263,25 +263,25 @@ Module( type_params: Some( TypeParams { range: 121..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 122..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..132, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..132, id: Name("int"), ctx: Load, @@ -298,7 +298,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..139, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap index ce7099a5e3aec..1a9ac4c029157 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_param_spec_missing_default.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_param_spec ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..44, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 7..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -44,7 +44,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..19, id: Name("int"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..43, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("X"), ctx: Store, @@ -67,16 +67,16 @@ Module( type_params: Some( TypeParams { range: 26..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 27..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -84,11 +84,11 @@ Module( TypeVar( TypeParamTypeVar { range: 34..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T2"), range: 34..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -99,7 +99,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap index 17ce8c72fdb21..d8b0ce565c1c6 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_invalid_default_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_i ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..163, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,26 +25,26 @@ Module( type_params: Some( TypeParams { range: 6..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 7..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..15, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, id: Name("int"), ctx: Load, @@ -61,7 +61,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, id: Name("int"), ctx: Load, @@ -71,11 +71,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..48, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("X"), ctx: Store, @@ -84,27 +84,27 @@ Module( type_params: Some( TypeParams { range: 29..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 30..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 30..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..41, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("x"), ctx: Load, @@ -121,7 +121,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..48, id: Name("int"), ctx: Load, @@ -131,11 +131,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..76, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("X"), ctx: Store, @@ -144,27 +144,27 @@ Module( type_params: Some( TypeParams { range: 55..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 56..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..68, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("x"), ctx: Load, @@ -181,7 +181,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, id: Name("int"), ctx: Load, @@ -191,11 +191,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..107, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("X"), ctx: Store, @@ -204,26 +204,26 @@ Module( type_params: Some( TypeParams { range: 83..101, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 84..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 84..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..100, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("x"), ctx: Load, @@ -239,7 +239,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..107, id: Name("int"), ctx: Load, @@ -249,11 +249,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..134, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("X"), ctx: Store, @@ -262,22 +262,22 @@ Module( type_params: Some( TypeParams { range: 114..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 115..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 115..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, id: Name("x"), ctx: Load, @@ -289,11 +289,11 @@ Module( TypeVar( TypeParamTypeVar { range: 124..127, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("int"), range: 124..127, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -304,7 +304,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..134, id: Name("int"), ctx: Load, @@ -314,11 +314,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..162, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, id: Name("X"), ctx: Store, @@ -327,21 +327,21 @@ Module( type_params: Some( TypeParams { range: 141..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 142..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 142..143, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..148, id: Name("int"), ctx: Load, @@ -351,11 +351,11 @@ Module( default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..155, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..155, id: Name("int"), ctx: Load, @@ -372,7 +372,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..162, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap index 5ad35632e6892..1ecc4bfb345c8 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_missing_default.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_m ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..64, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -45,7 +45,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -55,11 +55,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..40, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("X"), ctx: Store, @@ -68,21 +68,21 @@ Module( type_params: Some( TypeParams { range: 24..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 25..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, id: Name("int"), ctx: Load, @@ -97,7 +97,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..40, id: Name("int"), ctx: Load, @@ -107,11 +107,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..63, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("X"), ctx: Store, @@ -120,16 +120,16 @@ Module( type_params: Some( TypeParams { range: 47..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 48..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T1"), range: 48..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -138,11 +138,11 @@ Module( TypeVar( TypeParamTypeVar { range: 54..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T2"), range: 54..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -153,7 +153,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap index 3ffc891d81d14..1f30abc277231 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_bound.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_t ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 7..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -44,7 +44,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..9, id: Name(""), ctx: Invalid, @@ -54,11 +54,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, id: Name("int"), ctx: Load, @@ -68,11 +68,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap index c6ab71d84ff4a..8e8de2e2740ac 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_invalid_default_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_t ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..147, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,25 +25,25 @@ Module( type_params: Some( TypeParams { range: 6..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 7..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -60,7 +60,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, id: Name("int"), ctx: Load, @@ -70,11 +70,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..56, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, id: Name("X"), ctx: Store, @@ -83,31 +83,31 @@ Module( type_params: Some( TypeParams { range: 31..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 32..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 33..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..49, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..49, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, id: Name("int"), ctx: Load, @@ -115,7 +115,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..49, id: Name("str"), ctx: Load, @@ -135,7 +135,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, id: Name("int"), ctx: Load, @@ -145,11 +145,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..84, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("X"), ctx: Store, @@ -158,26 +158,26 @@ Module( type_params: Some( TypeParams { range: 63..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 64..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 65..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..77, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, id: Name("x"), ctx: Load, @@ -194,7 +194,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, id: Name("int"), ctx: Load, @@ -204,11 +204,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..117, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("X"), ctx: Store, @@ -217,25 +217,25 @@ Module( type_params: Some( TypeParams { range: 91..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 92..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 93..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..110, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..110, id: Name("x"), ctx: Load, @@ -251,7 +251,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..117, id: Name("int"), ctx: Load, @@ -261,11 +261,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..146, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..124, id: Name("X"), ctx: Store, @@ -274,21 +274,21 @@ Module( type_params: Some( TypeParams { range: 124..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 125..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 126..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, id: Name("x"), ctx: Load, @@ -300,11 +300,11 @@ Module( TypeVar( TypeParamTypeVar { range: 136..139, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("int"), range: 136..139, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -315,7 +315,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..146, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap index b7e862a1056cc..fb3c198af0c5d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_param_type_var_tuple_missing_default.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_param_type_var_t ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..44, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 7..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -44,7 +44,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..19, id: Name("int"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..43, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("X"), ctx: Store, @@ -67,16 +67,16 @@ Module( type_params: Some( TypeParams { range: 26..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 27..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 28..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -84,11 +84,11 @@ Module( TypeVar( TypeParamTypeVar { range: 34..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T2"), range: 34..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -99,7 +99,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap index fd3e6b168fe01..967dce60f483f 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_params_empty.py.snap @@ -7,32 +7,30 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_params_empty.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..52, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 7..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [], }, ), parameters: Parameters { range: 9..11, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -43,7 +41,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..21, }, ), @@ -52,11 +50,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..51, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..36, id: Name("ListOrSet"), ctx: Store, @@ -65,17 +63,17 @@ Module( type_params: Some( TypeParams { range: 36..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [], }, ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..51, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..45, id: Name("list"), ctx: Load, @@ -84,7 +82,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..51, id: Name("set"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_stmt_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_stmt_py311.py.snap index df2f28b34dd9e..05bad9f457ac2 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_stmt_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@type_stmt_py311.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/type_stmt_py311.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..57, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("x"), ctx: Store, @@ -25,7 +25,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_index_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_index_py38.py.snap index cbeb13482ff1c..15c59e5cca480 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_index_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_index_py38.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/unparenthesized_named ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..52, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..52, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..46, id: Name("lst"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), slice: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..51, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -40,7 +40,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap index abbb6e06fa69e..f907721b0f939 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_comp_py38.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/err/unparenthesized_named ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..73, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..72, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..72, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..53, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..48, id: Name("last"), ctx: Store, @@ -32,7 +32,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, id: Name("x"), ctx: Load, @@ -43,10 +43,10 @@ Module( generators: [ Comprehension { range: 54..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("x"), ctx: Store, @@ -54,11 +54,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..71, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..68, id: Name("range"), ctx: Load, @@ -66,11 +66,11 @@ Module( ), arguments: Arguments { range: 68..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_literal_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_literal_py38.py.snap index 16c0b89b5378c..bf277fe095619 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_literal_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unparenthesized_named_expr_set_literal_py38.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/inline/err/unparenthesized_named ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..88, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..57, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..57, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..50, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("x"), ctx: Store, @@ -33,7 +33,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, value: Int( 1, @@ -44,7 +44,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, value: Int( 2, @@ -53,7 +53,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, value: Int( 3, @@ -67,16 +67,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..72, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..72, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, value: Int( 1, @@ -85,11 +85,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..68, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Store, @@ -97,7 +97,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, value: Int( 2, @@ -108,7 +108,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, value: Int( 3, @@ -122,16 +122,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..87, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..87, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, value: Int( 1, @@ -140,7 +140,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, value: Int( 2, @@ -149,11 +149,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..86, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, id: Name("x"), ctx: Store, @@ -161,7 +161,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..86, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap index f02e2c45bd3fe..096671b850202 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@unterminated_fstring_newline_recovery.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/inline/err/unterminated_fstring_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..67, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: FStringValue { inner: Single( FString( FString { range: 0..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Double, @@ -40,15 +40,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..13, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..13, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 1, @@ -58,7 +58,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, value: Int( 1, @@ -71,33 +71,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..24, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..24, value: FStringValue { inner: Single( FString( FString { range: 14..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 16..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 22..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("x"), ctx: Load, @@ -124,15 +124,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..30, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..30, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 2, @@ -142,7 +142,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, value: Int( 2, @@ -155,33 +155,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..42, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..42, value: FStringValue { inner: Single( FString( FString { range: 31..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 33..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 39..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("x"), ctx: Load, @@ -192,7 +192,7 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 42..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], }, ), @@ -214,15 +214,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..48, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..48, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, value: Int( 3, @@ -232,7 +232,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, value: Int( 3, @@ -245,33 +245,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..60, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..60, value: FStringValue { inner: Single( FString( FString { range: 49..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 51..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 57..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("x"), ctx: Load, @@ -298,15 +298,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..66, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..66, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, value: Int( 4, @@ -316,7 +316,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 4, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@walrus_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@walrus_py37.py.snap index 9949fa6cbc5f1..dc64a3105d37a 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@walrus_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@walrus_py37.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/walrus_py37.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..54, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..53, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..52, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("x"), ctx: Store, @@ -28,7 +28,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap index 4f87608d79b56..0af23c288c2a7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_invalid_test_expr.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/while_stmt_invalid_te ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..70, body: [ While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, test: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, @@ -32,11 +32,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, }, ), @@ -48,16 +48,16 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..32, test: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..27, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("x"), ctx: Load, @@ -69,11 +69,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), @@ -85,11 +85,11 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..40, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("a"), ctx: Load, @@ -101,11 +101,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..48, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, id: Name("b"), ctx: Store, @@ -113,7 +113,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..48, }, ), @@ -123,15 +123,15 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..61, test: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..61, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, id: Name("a"), ctx: Store, @@ -139,7 +139,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, value: Int( 1, @@ -154,11 +154,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..69, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, id: Name("b"), ctx: Store, @@ -166,7 +166,7 @@ Module( ), annotation: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..69, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap index 7006daf690aa9..67fb75a82492d 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_colon.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/err/while_stmt_missing_co ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..40, body: [ While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..39, test: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..18, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, id: Name("a"), ctx: Load, @@ -32,7 +32,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..18, value: Int( 30, @@ -45,7 +45,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..39, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap index e86db412de29b..be86004a045d1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@while_stmt_missing_test.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/err/while_stmt_missing_te ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..30, body: [ While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..5, id: Name(""), ctx: Invalid, @@ -25,11 +25,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..11, }, ), @@ -41,11 +41,11 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..29, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..17, id: Name(""), ctx: Invalid, @@ -54,12 +54,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..29, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("a"), ctx: Store, @@ -68,7 +68,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap index 8a24d7009d379..668c7c2c089c1 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_colon.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/with_items_parenthesi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..57, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..56, is_async: false, items: [ WithItem { range: 34..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..39, id: Name("item1"), ctx: Load, @@ -31,10 +31,10 @@ Module( }, WithItem { range: 41..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..46, id: Name("item2"), ctx: Load, @@ -46,7 +46,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..56, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap index 7a3cf04fb1747..ea060453a98c7 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@with_items_parenthesized_missing_comma.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/err/with_items_parenthesi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..160, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, is_async: false, items: [ WithItem { range: 6..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..11, id: Name("item1"), ctx: Load, @@ -31,10 +31,10 @@ Module( }, WithItem { range: 12..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..17, id: Name("item2"), ctx: Load, @@ -46,11 +46,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, }, ), @@ -61,16 +61,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..53, is_async: false, items: [ WithItem { range: 30..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..35, id: Name("item1"), ctx: Load, @@ -79,7 +79,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..41, id: Name("f1"), ctx: Store, @@ -89,10 +89,10 @@ Module( }, WithItem { range: 42..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..47, id: Name("item2"), ctx: Load, @@ -104,11 +104,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, }, ), @@ -119,16 +119,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..91, is_async: false, items: [ WithItem { range: 60..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..65, id: Name("item1"), ctx: Load, @@ -138,10 +138,10 @@ Module( }, WithItem { range: 67..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..72, id: Name("item2"), ctx: Load, @@ -151,10 +151,10 @@ Module( }, WithItem { range: 73..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..78, id: Name("item3"), ctx: Load, @@ -164,10 +164,10 @@ Module( }, WithItem { range: 80..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..85, id: Name("item4"), ctx: Load, @@ -179,11 +179,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..91, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..91, }, ), @@ -194,16 +194,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..135, is_async: false, items: [ WithItem { range: 98..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..103, id: Name("item1"), ctx: Load, @@ -213,10 +213,10 @@ Module( }, WithItem { range: 105..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..110, id: Name("item2"), ctx: Load, @@ -225,7 +225,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..116, id: Name("f1"), ctx: Store, @@ -235,10 +235,10 @@ Module( }, WithItem { range: 117..122, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..122, id: Name("item3"), ctx: Load, @@ -248,10 +248,10 @@ Module( }, WithItem { range: 124..129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..129, id: Name("item4"), ctx: Load, @@ -263,11 +263,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..135, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..135, }, ), @@ -278,21 +278,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..159, is_async: false, items: [ WithItem { range: 141..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..154, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..147, id: Name("item1"), ctx: Load, @@ -300,7 +300,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..154, id: Name("item2"), ctx: Load, @@ -317,11 +317,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..159, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..159, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@write_to_debug_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@write_to_debug_expr.py.snap index cf762a1792c96..cb9bd384b5885 100644 --- a/crates/ruff_python_parser/tests/snapshots/invalid_syntax@write_to_debug_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/invalid_syntax@write_to_debug_expr.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/err/write_to_debug_expr.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..83, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..13, id: Name("__debug__"), ctx: Del, @@ -28,12 +28,12 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..36, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("x"), ctx: Del, @@ -41,7 +41,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("y"), ctx: Del, @@ -49,7 +49,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..33, id: Name("__debug__"), ctx: Del, @@ -57,7 +57,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("z"), ctx: Del, @@ -68,12 +68,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..50, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..46, id: Name("__debug__"), ctx: Store, @@ -82,7 +82,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, value: Int( 1, @@ -93,17 +93,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..82, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..69, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("x"), ctx: Store, @@ -111,7 +111,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("y"), ctx: Store, @@ -119,7 +119,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..66, id: Name("__debug__"), ctx: Store, @@ -127,7 +127,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("z"), ctx: Store, @@ -141,12 +141,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..82, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, value: Int( 1, @@ -155,7 +155,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 2, @@ -164,7 +164,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 3, @@ -173,7 +173,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: Int( 4, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap index 411a58148d8f5..7982e188e27ee 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@all_async_comprehension_py310.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/all_async_comprehensio ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..126, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..125, is_async: true, decorator_list: [], name: Identifier { id: Name("test"), range: 54..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 58..60, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,20 +35,20 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..125, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..125, elt: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..100, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, id: Name("x"), ctx: Load, @@ -59,10 +57,10 @@ Module( generators: [ Comprehension { range: 73..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Store, @@ -70,11 +68,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..99, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..96, id: Name("elements"), ctx: Load, @@ -82,11 +80,11 @@ Module( ), arguments: Arguments { range: 96..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, id: Name("n"), ctx: Load, @@ -106,10 +104,10 @@ Module( generators: [ Comprehension { range: 101..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, id: Name("n"), ctx: Store, @@ -117,11 +115,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..124, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..121, id: Name("range"), ctx: Load, @@ -129,11 +127,11 @@ Module( ), arguments: Arguments { range: 121..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap index 40c7d68cfd2d9..0e73bb0c25c88 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_binary_expr.py.snap @@ -7,27 +7,27 @@ input_file: crates/ruff_python_parser/resources/inline/ok/ambiguous_lpar_with_it ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..337, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..143, is_async: false, items: [ WithItem { range: 129..138, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..138, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..131, id: Name("a"), ctx: Load, @@ -35,7 +35,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("b"), ctx: Load, @@ -50,11 +50,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..143, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..143, }, ), @@ -65,20 +65,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..166, is_async: false, items: [ WithItem { range: 149..161, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..161, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..151, id: Name("a"), ctx: Load, @@ -90,7 +90,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, id: Name("b"), ctx: Load, @@ -105,11 +105,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..166, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..166, }, ), @@ -120,22 +120,22 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..220, is_async: false, items: [ WithItem { range: 201..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..215, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..203, id: Name("a"), ctx: Load, @@ -143,13 +143,13 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..215, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..209, id: Name("b"), ctx: Load, @@ -157,7 +157,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("c"), ctx: Load, @@ -175,11 +175,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..220, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..220, }, ), @@ -190,28 +190,28 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..245, is_async: false, items: [ WithItem { range: 226..240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..240, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..235, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..228, id: Name("a"), ctx: Load, @@ -219,7 +219,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..235, id: Name("b"), ctx: Load, @@ -230,7 +230,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, id: Name("c"), ctx: Load, @@ -245,11 +245,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..245, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..245, }, ), @@ -260,28 +260,28 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..272, is_async: false, items: [ WithItem { range: 251..267, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..267, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..263, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..257, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..253, id: Name("a"), ctx: Load, @@ -290,7 +290,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 256..257, id: Name("b"), ctx: Load, @@ -301,7 +301,7 @@ Module( op: LShift, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..263, id: Name("c"), ctx: Load, @@ -312,7 +312,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..267, id: Name("d"), ctx: Load, @@ -326,11 +326,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..272, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..272, }, ), @@ -341,24 +341,24 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..336, is_async: false, items: [ WithItem { range: 317..331, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..331, left: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..323, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..319, id: Name("a"), ctx: Load, @@ -366,7 +366,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..322, value: Int( 0, @@ -379,11 +379,11 @@ Module( op: Add, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 326..331, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 326..327, id: Name("b"), ctx: Load, @@ -392,7 +392,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 330..331, id: Name("c"), ctx: Load, @@ -408,11 +408,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..336, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..336, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap index 00a32e1ab3bd5..d035e3bff61ca 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ambiguous_lpar_with_items_if_expr.py.snap @@ -7,32 +7,32 @@ input_file: crates/ruff_python_parser/resources/inline/ok/ambiguous_lpar_with_it ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..153, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, items: [ WithItem { range: 5..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..23, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..16, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -40,7 +40,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("y"), ctx: Load, @@ -54,11 +54,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -69,31 +69,31 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..71, is_async: false, items: [ WithItem { range: 34..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..66, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..59, value: true, }, ), body: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..51, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("x"), ctx: Load, @@ -102,10 +102,10 @@ Module( generators: [ Comprehension { range: 37..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Store, @@ -113,7 +113,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..50, id: Name("iter"), ctx: Load, @@ -128,7 +128,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("y"), ctx: Load, @@ -142,11 +142,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, }, ), @@ -157,31 +157,31 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..120, is_async: false, items: [ WithItem { range: 77..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..115, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..108, value: true, }, ), body: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..100, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, id: Name("x"), ctx: Load, @@ -190,10 +190,10 @@ Module( generators: [ Comprehension { range: 80..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("x"), ctx: Store, @@ -201,7 +201,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..99, id: Name("iter"), ctx: Load, @@ -216,7 +216,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, id: Name("y"), ctx: Load, @@ -230,11 +230,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, }, ), @@ -245,31 +245,31 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..152, is_async: false, items: [ WithItem { range: 126..147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..147, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..140, value: true, }, ), body: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..132, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("x"), ctx: Load, @@ -277,7 +277,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..131, value: Int( 0, @@ -289,7 +289,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("y"), ctx: Load, @@ -303,11 +303,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..152, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..152, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap index c0dc9bb14803d..36a6809370615 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@ann_assign_stmt_simple_target.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/ann_assign_stmt_simple ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..45, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Store, @@ -24,7 +24,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("int"), ctx: Load, @@ -36,11 +36,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..25, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("a"), ctx: Store, @@ -48,7 +48,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, id: Name("int"), ctx: Load, @@ -60,15 +60,15 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..34, target: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("a"), ctx: Load, @@ -77,14 +77,14 @@ Module( attr: Identifier { id: Name("b"), range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, id: Name("int"), ctx: Load, @@ -96,15 +96,15 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..44, target: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..39, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("a"), ctx: Load, @@ -112,7 +112,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, value: Int( 0, @@ -124,7 +124,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..44, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap index 650a3b6e53aeb..495601cfa5ed3 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@args_unparenthesized_generator.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/args_unparenthesized_g ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..107, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..51, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..51, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, id: Name("zip"), ctx: Load, @@ -28,15 +28,15 @@ Module( ), arguments: Arguments { range: 3..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..26, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("x"), ctx: Load, @@ -45,10 +45,10 @@ Module( generators: [ Comprehension { range: 7..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("x"), ctx: Store, @@ -56,11 +56,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..25, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..21, id: Name("range"), ctx: Load, @@ -68,11 +68,11 @@ Module( ), arguments: Arguments { range: 21..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..24, value: Int( 10, @@ -93,11 +93,11 @@ Module( ), Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..50, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("y"), ctx: Load, @@ -106,10 +106,10 @@ Module( generators: [ Comprehension { range: 31..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("y"), ctx: Store, @@ -117,11 +117,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..49, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..45, id: Name("range"), ctx: Load, @@ -129,11 +129,11 @@ Module( ), arguments: Arguments { range: 45..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..48, value: Int( 10, @@ -161,15 +161,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..77, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..77, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..55, id: Name("sum"), ctx: Load, @@ -177,15 +177,15 @@ Module( ), arguments: Arguments { range: 55..77, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..76, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Load, @@ -194,10 +194,10 @@ Module( generators: [ Comprehension { range: 58..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Store, @@ -205,11 +205,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..76, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..72, id: Name("range"), ctx: Load, @@ -217,11 +217,11 @@ Module( ), arguments: Arguments { range: 72..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..75, value: Int( 10, @@ -249,15 +249,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..106, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..106, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..81, id: Name("sum"), ctx: Load, @@ -265,15 +265,15 @@ Module( ), arguments: Arguments { range: 81..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..104, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Load, @@ -282,10 +282,10 @@ Module( generators: [ Comprehension { range: 85..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("x"), ctx: Store, @@ -293,11 +293,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..103, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..99, id: Name("range"), ctx: Load, @@ -305,11 +305,11 @@ Module( ), arguments: Arguments { range: 99..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..102, value: Int( 10, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_stmt_starred_expr_value.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_stmt_starred_expr_value.py.snap index a9a4f61078021..1fe9bc4e9c1e2 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_stmt_starred_expr_value.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_stmt_starred_expr_value.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/assign_stmt_starred_ex ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..36, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("_"), ctx: Store, @@ -26,7 +26,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, value: Int( 4, @@ -37,12 +37,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("_"), ctx: Store, @@ -51,12 +51,12 @@ Module( ], value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Int( 4, @@ -71,12 +71,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..25, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("_"), ctx: Store, @@ -85,21 +85,21 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..25, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..23, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, value: Int( 1, @@ -122,12 +122,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..35, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("_"), ctx: Store, @@ -136,21 +136,21 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..35, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..34, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap index 52e3ad233850c..5d1a27f814f9e 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@assign_targets_terminator.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/assign_targets_termina ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..39, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -25,7 +25,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("y"), ctx: Store, @@ -33,7 +33,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("z"), ctx: Store, @@ -42,7 +42,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, value: Int( 1, @@ -53,16 +53,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..19, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..19, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("a"), ctx: Load, @@ -70,7 +70,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("b"), ctx: Load, @@ -85,12 +85,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..33, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("x"), ctx: Store, @@ -98,7 +98,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("y"), ctx: Store, @@ -106,7 +106,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("z"), ctx: Store, @@ -115,7 +115,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 1, @@ -126,16 +126,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..38, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..38, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("a"), ctx: Load, @@ -143,7 +143,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap index f01730187c311..5443d07ff3e14 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_for_statement.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/async_for_statement.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..30, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, is_async: true, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..16, id: Name("target"), ctx: Store, @@ -25,7 +25,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..24, id: Name("iter"), ctx: Load, @@ -34,11 +34,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap index 52ec987c61341..d3fe2817d2874 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_function_definition.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/async_function_definit ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, is_async: true, decorator_list: [], name: Identifier { id: Name("foo"), range: 10..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 13..15, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,11 +35,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap index be892875b2369..d653933f323f2 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@async_with_statement.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/async_with_statement.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..21, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, is_async: true, items: [ WithItem { range: 11..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..15, id: Name("item"), ctx: Load, @@ -33,11 +33,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap index d1f1b93250fe3..19bfd3e342131 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_def_arguments.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/inline/ok/class_def_arguments.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..14, decorator_list: [], name: Identifier { id: Name("Foo"), range: 6..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..14, }, ), @@ -40,19 +40,19 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..31, decorator_list: [], name: Identifier { id: Name("Foo"), range: 21..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 24..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -60,11 +60,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_keyword_in_case_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_keyword_in_case_pattern.py.snap index ad057f45f606e..12e1125f1a37b 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_keyword_in_case_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_keyword_in_case_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/class_keyword_in_case_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..34, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..33, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: Int( 2, @@ -26,14 +26,14 @@ Module( cases: [ MatchCase { range: 13..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 18..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..23, id: Name("Class"), ctx: Load, @@ -41,27 +41,27 @@ Module( ), arguments: PatternArguments { range: 23..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 24..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchAs( PatternMatchAs { range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -75,11 +75,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..33, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..33, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_type_params_py312.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_type_params_py312.py.snap index e55236a706576..d56ec292ba229 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_type_params_py312.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@class_type_params_py312.py.snap @@ -7,42 +7,42 @@ input_file: crates/ruff_python_parser/resources/inline/ok/class_type_params_py31 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..96, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..95, decorator_list: [], name: Identifier { id: Name("Foo"), range: 50..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 53..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 54..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("S"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..69, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, id: Name("str"), ctx: Load, @@ -50,7 +50,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..68, id: Name("bytes"), ctx: Load, @@ -68,16 +68,16 @@ Module( TypeVar( TypeParamTypeVar { range: 71..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..79, id: Name("float"), ctx: Load, @@ -90,11 +90,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 81..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 82..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -102,11 +102,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 86..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 88..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -118,11 +118,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@comma_separated_regular_list_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@comma_separated_regular_list_terminator.py.snap index 9d9c72049a34c..c755a0542b10f 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@comma_separated_regular_list_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@comma_separated_regular_list_terminator.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/comma_separated_regula ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..181, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..144, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..144, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..143, value: Int( 0, @@ -36,16 +36,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..151, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..151, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, value: Int( 0, @@ -54,7 +54,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, value: Int( 1, @@ -69,16 +69,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..159, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..159, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..154, value: Int( 0, @@ -87,7 +87,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, value: Int( 1, @@ -102,16 +102,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..169, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..169, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, value: Int( 0, @@ -120,7 +120,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, value: Int( 1, @@ -129,7 +129,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, value: Int( 2, @@ -144,16 +144,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..180, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..180, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, value: Int( 0, @@ -162,7 +162,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..175, value: Int( 1, @@ -171,7 +171,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..178, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@debug_rename_import.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@debug_rename_import.py.snap index 3a7f83d488b45..f53b08abea87c 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@debug_rename_import.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@debug_rename_import.py.snap @@ -7,27 +7,27 @@ input_file: crates/ruff_python_parser/resources/inline/ok/debug_rename_import.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..86, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, names: [ Alias { range: 7..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 7..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("debug"), range: 20..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -36,23 +36,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..52, module: Some( Identifier { id: Name("__debug__"), range: 31..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 48..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Some"), range: 48..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -62,29 +62,29 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..85, module: Some( Identifier { id: Name("x"), range: 58..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 67..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("__debug__"), range: 67..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("debug"), range: 80..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap index 14d34fa18b017..7d009ac3d44c1 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_async_function.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/decorator_async_functi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, is_async: true, decorator_list: [ Decorator { range: 0..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..10, id: Name("decorator"), ctx: Load, @@ -32,14 +32,12 @@ Module( name: Identifier { id: Name("foo"), range: 21..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 24..26, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -50,11 +48,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_await_expression_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_await_expression_py39.py.snap index 4ad9fb1dc8fac..957a81dd4fb4a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_await_expression_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_await_expression_py39.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/decorator_await_expres ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..96, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..95, is_async: true, decorator_list: [], name: Identifier { id: Name("foo"), range: 55..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 58..60, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,20 +35,20 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..95, is_async: false, decorator_list: [ Decorator { range: 66..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..76, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, id: Name("bar"), ctx: Load, @@ -63,14 +61,12 @@ Module( name: Identifier { id: Name("baz"), range: 85..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 88..90, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -81,11 +77,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..95, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_dotted_ident_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_dotted_ident_py38.py.snap index 25bdacc7477a8..578a528c1d761 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_dotted_ident_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_dotted_ident_py38.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/inline/ok/decorator_expression_d ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..86, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..85, is_async: false, decorator_list: [ Decorator { range: 45..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..69, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..61, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..53, id: Name("buttons"), ctx: Load, @@ -38,7 +38,7 @@ Module( attr: Identifier { id: Name("clicked"), range: 54..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -46,7 +46,7 @@ Module( attr: Identifier { id: Name("connect"), range: 62..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -56,14 +56,12 @@ Module( name: Identifier { id: Name("spam"), range: 74..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 78..80, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -74,11 +72,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap index d3208630da234..d6d40d9536990 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_eval_hack_py38.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/inline/ok/decorator_expression_e ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..97, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..96, is_async: false, decorator_list: [ Decorator { range: 45..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..80, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..50, id: Name("eval"), ctx: Load, @@ -33,17 +33,17 @@ Module( ), arguments: Arguments { range: 50..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..79, value: StringLiteralValue { inner: Single( StringLiteral { range: 51..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "buttons[0].clicked.connect", flags: StringLiteralFlags { quote_style: Double, @@ -65,14 +65,12 @@ Module( name: Identifier { id: Name("spam"), range: 85..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 89..91, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -83,11 +81,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap index f83bba2ca6482..3250a9ad0fd2c 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_identity_hack_py38.py.snap @@ -7,38 +7,36 @@ input_file: crates/ruff_python_parser/resources/inline/ok/decorator_expression_i ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..111, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..63, is_async: false, decorator_list: [], name: Identifier { id: Name("_"), range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 50..53, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -53,12 +51,12 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..63, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Load, @@ -72,20 +70,20 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..110, is_async: false, decorator_list: [ Decorator { range: 64..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..94, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("_"), ctx: Load, @@ -93,23 +91,23 @@ Module( ), arguments: Arguments { range: 66..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..93, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..85, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..77, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..74, id: Name("buttons"), ctx: Load, @@ -117,7 +115,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 0, @@ -130,7 +128,7 @@ Module( attr: Identifier { id: Name("clicked"), range: 78..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -138,7 +136,7 @@ Module( attr: Identifier { id: Name("connect"), range: 86..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -153,14 +151,12 @@ Module( name: Identifier { id: Name("spam"), range: 99..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 103..105, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -171,11 +167,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..110, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..110, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap index 500d2a4b2389b..dca975e0e9802 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@decorator_expression_py39.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/ok/decorator_expression_p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..129, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..88, is_async: false, decorator_list: [ Decorator { range: 45..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..72, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..64, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..56, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..53, id: Name("buttons"), ctx: Load, @@ -41,7 +41,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 0, @@ -54,7 +54,7 @@ Module( attr: Identifier { id: Name("clicked"), range: 57..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -62,7 +62,7 @@ Module( attr: Identifier { id: Name("connect"), range: 65..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -72,14 +72,12 @@ Module( name: Identifier { id: Name("spam"), range: 77..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 81..83, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,11 +88,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, }, ), @@ -105,24 +103,24 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..128, is_async: false, decorator_list: [ Decorator { range: 89..113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..113, func: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..107, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, id: Name("x"), ctx: Store, @@ -130,26 +128,24 @@ Module( ), value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..107, parameters: Some( Parameters { range: 103..104, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 103..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 103..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 103..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -163,7 +159,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..107, id: Name("x"), ctx: Load, @@ -175,11 +171,11 @@ Module( ), arguments: Arguments { range: 108..113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, id: Name("foo"), ctx: Load, @@ -195,14 +191,12 @@ Module( name: Identifier { id: Name("bar"), range: 118..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 121..123, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -213,11 +207,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..128, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..128, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_debug_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_debug_py38.py.snap index ebaae1fd52466..e3595cb15786a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_debug_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_debug_py38.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/del_debug_py38.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..57, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..56, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, id: Name("__debug__"), ctx: Del, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap index cd953e90416dd..2c6467849cf96 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@del_targets_terminator.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/del_targets_terminator ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("a"), ctx: Del, @@ -25,7 +25,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("b"), ctx: Del, @@ -36,16 +36,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..14, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..14, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("c"), ctx: Load, @@ -53,7 +53,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("d"), ctx: Load, @@ -68,12 +68,12 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..23, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("a"), ctx: Del, @@ -81,7 +81,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("b"), ctx: Del, @@ -92,16 +92,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("c"), ctx: Load, @@ -109,7 +109,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("d"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap index 9c3c3f576f89c..68d5a3ac0e5b9 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@dotted_name_normalized_spaces.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/dotted_name_normalized ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, names: [ Alias { range: 7..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a.b.c"), range: 7..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -30,16 +30,16 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..31, names: [ Alias { range: 20..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a.b.c"), range: 20..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@duplicate_match_key_attr.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@duplicate_match_key_attr.py.snap index 277f35c1505e2..bb0ad14135c12 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@duplicate_match_key_attr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@duplicate_match_key_attr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/duplicate_match_key_at ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..40, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..39, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,19 +25,19 @@ Module( cases: [ MatchCase { range: 13..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 18..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("x"), ctx: Load, @@ -46,18 +46,18 @@ Module( attr: Identifier { id: Name("a"), range: 21..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("x"), ctx: Load, @@ -66,7 +66,7 @@ Module( attr: Identifier { id: Name("a"), range: 29..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -76,10 +76,10 @@ Module( MatchValue( PatternMatchValue { range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, value: Int( 1, @@ -91,10 +91,10 @@ Module( MatchValue( PatternMatchValue { range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 2, @@ -111,11 +111,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_star_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_star_py311.py.snap index c3efa0df92331..f4f83b064f903 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_star_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_star_py311.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/except_star_py311.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..77, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..76, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, }, ), @@ -32,11 +32,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 53..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..71, id: Name("ValueError"), ctx: Load, @@ -47,11 +47,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..76, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap index 07ef1ddbd3c03..d6f25ac1cc6ff 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_as_name_soft_keyword.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/except_stmt_as_name_so ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..100, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..99, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..8, }, ), @@ -32,11 +32,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 9..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..25, id: Name("Exception"), ctx: Load, @@ -47,17 +47,17 @@ Module( Identifier { id: Name("match"), range: 29..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, }, ), @@ -69,11 +69,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 40..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, id: Name("Exception"), ctx: Load, @@ -84,17 +84,17 @@ Module( Identifier { id: Name("case"), range: 60..64, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..69, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..69, }, ), @@ -106,11 +106,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 70..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..86, id: Name("Exception"), ctx: Load, @@ -121,17 +121,17 @@ Module( Identifier { id: Name("type"), range: 90..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_unparenthesized_tuple_no_as_py314.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_unparenthesized_tuple_no_as_py314.py.snap index bf94e92b01cfd..2d4a97a396148 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_unparenthesized_tuple_no_as_py314.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@except_stmt_unparenthesized_tuple_no_as_py314.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/except_stmt_unparenthe ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..117, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..79, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..57, }, ), @@ -26,16 +26,16 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 58..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..69, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("x"), ctx: Load, @@ -43,7 +43,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("y"), ctx: Load, @@ -59,7 +59,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..79, }, ), @@ -74,12 +74,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..116, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..93, }, ), @@ -88,16 +88,16 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 94..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..106, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("x"), ctx: Load, @@ -105,7 +105,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, id: Name("y"), ctx: Load, @@ -121,7 +121,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..116, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap index d5977dbfc4e14..05f893a42cd16 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__arguments.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/arguments.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..805, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..108, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..108, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..106, id: Name("call"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), arguments: Arguments { range: 106..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -38,15 +38,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..119, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..119, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..113, id: Name("call"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), arguments: Arguments { range: 113..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, id: Name("x"), ctx: Load, @@ -66,7 +66,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..118, id: Name("y"), ctx: Load, @@ -81,15 +81,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..131, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..131, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..124, id: Name("call"), ctx: Load, @@ -97,11 +97,11 @@ Module( ), arguments: Arguments { range: 124..131, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..126, id: Name("x"), ctx: Load, @@ -109,7 +109,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("y"), ctx: Load, @@ -124,15 +124,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..164, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..164, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..154, id: Name("call"), ctx: Load, @@ -140,22 +140,22 @@ Module( ), arguments: Arguments { range: 154..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 155..158, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 155..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, value: Int( 1, @@ -165,17 +165,17 @@ Module( }, Keyword { range: 160..163, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("y"), range: 160..161, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..163, value: Int( 2, @@ -191,15 +191,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..173, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..173, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..169, id: Name("call"), ctx: Load, @@ -207,15 +207,15 @@ Module( ), arguments: Arguments { range: 169..173, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..172, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("x"), ctx: Load, @@ -233,15 +233,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..183, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..183, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..178, id: Name("call"), ctx: Load, @@ -249,16 +249,16 @@ Module( ), arguments: Arguments { range: 178..183, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 179..182, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..182, id: Name("x"), ctx: Load, @@ -273,15 +273,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..205, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..205, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..197, id: Name("call"), ctx: Load, @@ -289,11 +289,11 @@ Module( ), arguments: Arguments { range: 197..205, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..199, id: Name("x"), ctx: Load, @@ -303,17 +303,17 @@ Module( keywords: [ Keyword { range: 201..204, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("y"), range: 201..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..204, value: Int( 1, @@ -329,15 +329,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..217, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..217, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..210, id: Name("call"), ctx: Load, @@ -345,11 +345,11 @@ Module( ), arguments: Arguments { range: 210..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, id: Name("x"), ctx: Load, @@ -357,11 +357,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..216, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..216, id: Name("y"), ctx: Load, @@ -379,15 +379,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..230, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..230, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..222, id: Name("call"), ctx: Load, @@ -395,11 +395,11 @@ Module( ), arguments: Arguments { range: 222..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..224, id: Name("x"), ctx: Load, @@ -409,11 +409,11 @@ Module( keywords: [ Keyword { range: 226..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..229, id: Name("y"), ctx: Load, @@ -428,15 +428,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..244, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..244, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..235, id: Name("call"), ctx: Load, @@ -444,15 +444,15 @@ Module( ), arguments: Arguments { range: 235..244, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..243, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..243, id: Name("y"), ctx: Load, @@ -465,17 +465,17 @@ Module( keywords: [ Keyword { range: 236..239, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 236..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..239, value: Int( 1, @@ -491,15 +491,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..259, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..259, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..249, id: Name("call"), ctx: Load, @@ -507,22 +507,22 @@ Module( ), arguments: Arguments { range: 249..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 250..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 250..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..253, value: Int( 1, @@ -532,11 +532,11 @@ Module( }, Keyword { range: 255..258, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..258, id: Name("y"), ctx: Load, @@ -551,15 +551,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..273, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..273, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..264, id: Name("call"), ctx: Load, @@ -567,15 +567,15 @@ Module( ), arguments: Arguments { range: 264..273, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..267, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..267, id: Name("x"), ctx: Load, @@ -588,11 +588,11 @@ Module( keywords: [ Keyword { range: 269..272, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..272, id: Name("y"), ctx: Load, @@ -607,15 +607,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..288, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..288, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..278, id: Name("call"), ctx: Load, @@ -623,15 +623,15 @@ Module( ), arguments: Arguments { range: 278..288, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..281, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..281, id: Name("x"), ctx: Load, @@ -642,7 +642,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 283..284, id: Name("y"), ctx: Load, @@ -650,7 +650,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..287, id: Name("z"), ctx: Load, @@ -665,15 +665,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..308, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..308, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..293, id: Name("call"), ctx: Load, @@ -681,16 +681,16 @@ Module( ), arguments: Arguments { range: 293..308, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 294..297, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..297, id: Name("x"), ctx: Load, @@ -699,17 +699,17 @@ Module( }, Keyword { range: 299..302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("y"), range: 299..300, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..302, value: Int( 1, @@ -719,17 +719,17 @@ Module( }, Keyword { range: 304..307, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("z"), range: 304..305, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..307, value: Int( 2, @@ -745,15 +745,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 309..335, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 309..335, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 309..313, id: Name("call"), ctx: Load, @@ -761,15 +761,15 @@ Module( ), arguments: Arguments { range: 313..335, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..317, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..317, id: Name("x1"), ctx: Load, @@ -780,11 +780,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..322, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 320..322, id: Name("x2"), ctx: Load, @@ -797,11 +797,11 @@ Module( keywords: [ Keyword { range: 324..328, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 326..328, id: Name("y1"), ctx: Load, @@ -810,11 +810,11 @@ Module( }, Keyword { range: 330..334, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 332..334, id: Name("y2"), ctx: Load, @@ -829,15 +829,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..355, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..355, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..340, id: Name("call"), ctx: Load, @@ -845,22 +845,22 @@ Module( ), arguments: Arguments { range: 340..355, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 341..344, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 341..342, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..344, value: Int( 1, @@ -870,11 +870,11 @@ Module( }, Keyword { range: 346..349, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..349, id: Name("y"), ctx: Load, @@ -883,17 +883,17 @@ Module( }, Keyword { range: 351..354, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("z"), range: 351..352, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 353..354, value: Int( 1, @@ -909,15 +909,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 378..402, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 378..402, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 378..382, id: Name("call"), ctx: Load, @@ -925,33 +925,33 @@ Module( ), arguments: Arguments { range: 382..402, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 383..401, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 383..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 385..401, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..394, value: true, }, ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 385..386, value: Int( 1, @@ -960,7 +960,7 @@ Module( ), orelse: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..401, value: Int( 2, @@ -978,15 +978,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..418, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..418, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 403..407, id: Name("call"), ctx: Load, @@ -994,26 +994,26 @@ Module( ), arguments: Arguments { range: 407..418, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 408..417, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 408..409, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 410..417, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 416..417, id: Name("y"), ctx: Load, @@ -1030,15 +1030,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 419..438, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 419..438, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 419..423, id: Name("call"), ctx: Load, @@ -1046,41 +1046,39 @@ Module( ), arguments: Arguments { range: 423..438, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 424..437, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 424..425, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 426..437, parameters: Some( Parameters { range: 433..434, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1094,7 +1092,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 436..437, id: Name("y"), ctx: Load, @@ -1111,15 +1109,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 439..455, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 439..455, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 439..443, id: Name("call"), ctx: Load, @@ -1127,26 +1125,26 @@ Module( ), arguments: Arguments { range: 443..455, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 444..454, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("x"), range: 444..445, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 447..453, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 447..448, id: Name("y"), ctx: Store, @@ -1154,7 +1152,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 452..453, value: Int( 1, @@ -1172,15 +1170,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 476..491, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 476..491, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 476..480, id: Name("call"), ctx: Load, @@ -1188,16 +1186,16 @@ Module( ), arguments: Arguments { range: 480..491, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 482..489, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 488..489, id: Name("x"), ctx: Load, @@ -1215,15 +1213,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 492..512, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 492..512, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 492..496, id: Name("call"), ctx: Load, @@ -1231,15 +1229,15 @@ Module( ), arguments: Arguments { range: 496..512, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..510, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 509..510, id: Name("x"), ctx: Load, @@ -1256,15 +1254,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 533..545, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 533..545, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 533..537, id: Name("call"), ctx: Load, @@ -1272,15 +1270,15 @@ Module( ), arguments: Arguments { range: 537..545, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 538..544, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 538..539, id: Name("x"), ctx: Store, @@ -1288,7 +1286,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 543..544, value: Int( 1, @@ -1306,15 +1304,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 546..572, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 546..572, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 546..550, id: Name("call"), ctx: Load, @@ -1322,19 +1320,19 @@ Module( ), arguments: Arguments { range: 550..572, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..571, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..557, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..552, id: Name("x"), ctx: Store, @@ -1342,7 +1340,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 556..557, value: Int( 1, @@ -1354,10 +1352,10 @@ Module( generators: [ Comprehension { range: 558..571, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 562..563, id: Name("i"), ctx: Store, @@ -1365,7 +1363,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..571, id: Name("iter"), ctx: Load, @@ -1387,15 +1385,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..610, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..610, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..600, id: Name("call"), ctx: Load, @@ -1403,21 +1401,21 @@ Module( ), arguments: Arguments { range: 600..610, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 601..609, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 602..609, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 602..603, id: Name("x"), ctx: Load, @@ -1425,7 +1423,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 608..609, id: Name("y"), ctx: Load, @@ -1446,15 +1444,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 611..623, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 611..623, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 611..615, id: Name("call"), ctx: Load, @@ -1462,19 +1460,19 @@ Module( ), arguments: Arguments { range: 615..623, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 616..622, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 617..622, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 617..618, id: Name("x"), ctx: Load, @@ -1483,7 +1481,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 621..622, id: Name("y"), ctx: Load, @@ -1503,15 +1501,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 624..638, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 624..638, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 624..628, id: Name("call"), ctx: Load, @@ -1519,19 +1517,19 @@ Module( ), arguments: Arguments { range: 628..638, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 629..637, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 630..637, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 636..637, id: Name("x"), ctx: Load, @@ -1551,15 +1549,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 639..657, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 639..657, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 639..643, id: Name("call"), ctx: Load, @@ -1567,34 +1565,32 @@ Module( ), arguments: Arguments { range: 643..657, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 644..656, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 645..656, parameters: Some( Parameters { range: 652..653, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 652..653, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 652..653, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 652..653, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1608,7 +1604,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 655..656, id: Name("x"), ctx: Load, @@ -1628,15 +1624,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..681, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..681, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..662, id: Name("call"), ctx: Load, @@ -1644,26 +1640,26 @@ Module( ), arguments: Arguments { range: 662..681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 663..680, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 664..680, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 669..673, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 664..665, id: Name("x"), ctx: Load, @@ -1671,7 +1667,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 679..680, id: Name("y"), ctx: Load, @@ -1691,15 +1687,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..709, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..709, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..704, id: Name("call"), ctx: Load, @@ -1707,16 +1703,16 @@ Module( ), arguments: Arguments { range: 704..709, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 705..708, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 707..708, id: Name("x"), ctx: Load, @@ -1731,15 +1727,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..725, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..725, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..714, id: Name("call"), ctx: Load, @@ -1747,22 +1743,22 @@ Module( ), arguments: Arguments { range: 714..725, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 715..724, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 717..724, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 717..718, id: Name("x"), ctx: Load, @@ -1770,7 +1766,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 723..724, id: Name("y"), ctx: Load, @@ -1788,15 +1784,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 726..741, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 726..741, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 726..730, id: Name("call"), ctx: Load, @@ -1804,20 +1800,20 @@ Module( ), arguments: Arguments { range: 730..741, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 731..740, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 733..740, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 739..740, id: Name("x"), ctx: Load, @@ -1834,15 +1830,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 742..766, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 742..766, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 742..746, id: Name("call"), ctx: Load, @@ -1850,27 +1846,27 @@ Module( ), arguments: Arguments { range: 746..766, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 747..765, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 749..765, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 754..758, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 749..750, id: Name("x"), ctx: Load, @@ -1878,7 +1874,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 764..765, id: Name("y"), ctx: Load, @@ -1895,15 +1891,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 767..784, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 767..784, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 767..771, id: Name("call"), ctx: Load, @@ -1911,21 +1907,21 @@ Module( ), arguments: Arguments { range: 771..784, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 772..783, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 775..782, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 781..782, id: Name("x"), ctx: Load, @@ -1943,15 +1939,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 785..804, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 785..804, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 785..789, id: Name("call"), ctx: Load, @@ -1959,35 +1955,33 @@ Module( ), arguments: Arguments { range: 789..804, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 790..803, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 792..803, parameters: Some( Parameters { range: 799..800, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 799..800, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 799..800, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 799..800, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2001,7 +1995,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 802..803, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap index e6b46d32b7b58..baa336d282c40 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__attribute.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/attribute.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..90, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, id: Name("value"), ctx: Load, @@ -29,7 +29,7 @@ Module( attr: Identifier { id: Name("attr"), range: 6..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -38,19 +38,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..23, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..23, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..21, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..16, id: Name("value"), ctx: Load, @@ -59,14 +59,14 @@ Module( attr: Identifier { id: Name("attr"), range: 17..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 21..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -76,19 +76,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..36, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..36, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..31, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..29, id: Name("value"), ctx: Load, @@ -96,7 +96,7 @@ Module( ), arguments: Arguments { range: 29..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -105,7 +105,7 @@ Module( attr: Identifier { id: Name("attr"), range: 32..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -114,27 +114,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..55, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..55, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..51, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..49, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..44, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..42, id: Name("value"), ctx: Load, @@ -142,7 +142,7 @@ Module( ), arguments: Arguments { range: 42..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -151,14 +151,14 @@ Module( attr: Identifier { id: Name("attr"), range: 45..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 49..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -167,7 +167,7 @@ Module( attr: Identifier { id: Name("foo"), range: 52..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -176,19 +176,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..70, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..70, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..66, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..61, id: Name("value"), ctx: Load, @@ -197,7 +197,7 @@ Module( attr: Identifier { id: Name("attr"), range: 62..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -205,7 +205,7 @@ Module( attr: Identifier { id: Name("foo"), range: 67..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -214,23 +214,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..89, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..89, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..85, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..83, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..77, id: Name("value"), ctx: Load, @@ -239,14 +239,14 @@ Module( attr: Identifier { id: Name("attr"), range: 79..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 83..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -255,7 +255,7 @@ Module( attr: Identifier { id: Name("foo"), range: 86..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap index d2791d35df9a4..4b39468468300 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__await.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/await.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..211, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -32,19 +32,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..19, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..19, left: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..15, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("x"), ctx: Load, @@ -55,7 +55,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 1, @@ -68,21 +68,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..33, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..33, op: And, values: [ Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..27, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("a"), ctx: Load, @@ -92,7 +92,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("b"), ctx: Load, @@ -105,19 +105,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..43, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..43, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("f"), ctx: Load, @@ -125,7 +125,7 @@ Module( ), arguments: Arguments { range: 41..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -137,20 +137,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..56, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 1, @@ -159,7 +159,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 2, @@ -176,20 +176,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..69, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..69, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..69, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, value: Int( 3, @@ -198,7 +198,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, value: Int( 4, @@ -214,22 +214,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..82, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..82, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..82, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("i"), ctx: Load, @@ -238,7 +238,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, value: Int( 5, @@ -255,20 +255,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..93, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..93, elts: [ Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..90, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 7, @@ -279,7 +279,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, value: Int( 8, @@ -295,20 +295,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..107, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..107, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..107, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, value: Int( 9, @@ -317,7 +317,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..106, value: Int( 10, @@ -335,19 +335,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..120, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..120, left: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..115, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, value: Int( 1, @@ -362,7 +362,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Int( 1, @@ -376,26 +376,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..146, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..146, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..136, value: true, }, ), body: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..128, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("x"), ctx: Load, @@ -405,7 +405,7 @@ Module( ), orelse: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..146, }, ), @@ -415,24 +415,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..158, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..158, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..158, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..156, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..156, id: Name("x"), ctx: Load, @@ -452,34 +452,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..178, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..178, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..177, parameters: Some( Parameters { range: 173..174, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 173..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -493,7 +491,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..177, id: Name("x"), ctx: Load, @@ -507,19 +505,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..192, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..192, left: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..186, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..186, id: Name("x"), ctx: Load, @@ -530,12 +528,12 @@ Module( op: Pow, right: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..192, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..192, id: Name("x"), ctx: Load, @@ -549,19 +547,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..211, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..211, left: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..200, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..200, id: Name("x"), ctx: Load, @@ -572,11 +570,11 @@ Module( op: Pow, right: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..211, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..211, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap index ac83b26a4d1a8..3b4a7feb7b101 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bin_op.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/bin_op.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..397, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 1, @@ -30,7 +30,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 2, @@ -43,15 +43,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..20, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..20, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, value: Int( 1, @@ -61,7 +61,7 @@ Module( op: Sub, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, value: Int( 2, @@ -74,15 +74,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..26, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..26, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, value: Int( 1, @@ -92,7 +92,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 2, @@ -105,15 +105,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..32, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..32, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, value: Int( 1, @@ -123,7 +123,7 @@ Module( op: Div, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..32, value: Int( 2, @@ -136,15 +136,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..39, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..39, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, value: Int( 1, @@ -154,7 +154,7 @@ Module( op: FloorDiv, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, value: Int( 2, @@ -167,15 +167,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..45, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..45, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, value: Int( 1, @@ -185,7 +185,7 @@ Module( op: Mod, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, value: Int( 2, @@ -198,15 +198,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..52, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..52, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, value: Int( 1, @@ -216,7 +216,7 @@ Module( op: Pow, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 2, @@ -229,15 +229,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..58, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..58, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, value: Int( 1, @@ -247,7 +247,7 @@ Module( op: BitOr, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 2, @@ -260,15 +260,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..64, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..64, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, value: Int( 1, @@ -278,7 +278,7 @@ Module( op: BitXor, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, value: Int( 2, @@ -291,15 +291,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..70, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..70, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 1, @@ -309,7 +309,7 @@ Module( op: BitAnd, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, value: Int( 2, @@ -322,15 +322,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..77, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..77, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, value: Int( 1, @@ -340,7 +340,7 @@ Module( op: RShift, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, value: Int( 2, @@ -353,15 +353,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..84, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..84, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 1, @@ -371,7 +371,7 @@ Module( op: LShift, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 2, @@ -384,15 +384,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..90, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..90, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..86, value: Int( 1, @@ -402,7 +402,7 @@ Module( op: MatMult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 2, @@ -415,23 +415,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..123, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..123, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..119, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..115, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..111, value: Int( 1, @@ -441,7 +441,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, value: Int( 2, @@ -453,7 +453,7 @@ Module( op: Sub, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, value: Int( 3, @@ -465,7 +465,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 4, @@ -478,31 +478,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..146, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..146, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..142, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..138, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..133, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..129, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..125, value: Int( 1, @@ -512,7 +512,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, value: Int( 2, @@ -524,7 +524,7 @@ Module( op: Div, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, value: Int( 3, @@ -536,7 +536,7 @@ Module( op: FloorDiv, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, value: Int( 4, @@ -548,7 +548,7 @@ Module( op: MatMult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, value: Int( 5, @@ -560,7 +560,7 @@ Module( op: Mod, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..146, value: Int( 6, @@ -573,27 +573,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..168, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..168, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..163, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..158, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..153, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..148, value: Int( 1, @@ -603,7 +603,7 @@ Module( op: LShift, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..153, value: Int( 2, @@ -615,7 +615,7 @@ Module( op: RShift, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, value: Int( 3, @@ -627,7 +627,7 @@ Module( op: RShift, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..163, value: Int( 4, @@ -639,7 +639,7 @@ Module( op: LShift, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, value: Int( 5, @@ -652,15 +652,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..202, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..202, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, value: Int( 1, @@ -670,11 +670,11 @@ Module( op: Add, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..202, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, value: Int( 2, @@ -684,7 +684,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: Int( 3, @@ -699,19 +699,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..212, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..212, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..208, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..204, value: Int( 1, @@ -721,7 +721,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..208, value: Int( 2, @@ -733,7 +733,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, value: Int( 3, @@ -746,31 +746,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..244, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..244, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..235, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..231, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..223, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..219, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..214, value: Int( 1, @@ -780,7 +780,7 @@ Module( op: Pow, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..219, value: Int( 2, @@ -792,7 +792,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..223, value: Int( 3, @@ -804,11 +804,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..231, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..227, value: Int( 4, @@ -818,7 +818,7 @@ Module( op: MatMult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..231, value: Int( 5, @@ -832,7 +832,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..235, value: Int( 6, @@ -844,11 +844,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..244, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..239, value: Int( 7, @@ -858,7 +858,7 @@ Module( op: FloorDiv, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..244, value: Int( 8, @@ -873,15 +873,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..306, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..306, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..271, value: Int( 1, @@ -891,15 +891,15 @@ Module( op: BitOr, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..306, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..279, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..275, value: Int( 2, @@ -909,7 +909,7 @@ Module( op: BitAnd, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..279, value: Int( 3, @@ -921,19 +921,19 @@ Module( op: BitXor, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..306, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..301, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..291, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..283, value: Int( 4, @@ -943,11 +943,11 @@ Module( op: Add, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..291, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..287, value: Int( 5, @@ -957,7 +957,7 @@ Module( op: MatMult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..291, value: Int( 6, @@ -971,11 +971,11 @@ Module( op: LShift, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..301, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..296, value: Int( 7, @@ -985,7 +985,7 @@ Module( op: FloorDiv, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..301, value: Int( 8, @@ -999,7 +999,7 @@ Module( op: RShift, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 305..306, value: Int( 9, @@ -1016,19 +1016,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..339, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..339, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..335, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..325, value: Int( 1, @@ -1038,11 +1038,11 @@ Module( op: Add, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..334, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..330, value: Int( 2, @@ -1052,7 +1052,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..334, value: Int( 3, @@ -1066,7 +1066,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 338..339, value: Int( 4, @@ -1079,19 +1079,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..359, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..359, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..345, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..341, value: Int( 1, @@ -1101,7 +1101,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..345, value: Int( 2, @@ -1113,15 +1113,15 @@ Module( op: Add, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..358, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..354, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..350, value: Int( 3, @@ -1131,7 +1131,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 353..354, value: Int( 4, @@ -1143,7 +1143,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..358, value: Int( 5, @@ -1158,15 +1158,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..396, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..396, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..391, id: Name("x"), ctx: Load, @@ -1175,12 +1175,12 @@ Module( op: Add, right: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 393..396, op: UAdd, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..396, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap index 7805f521fb4f3..90362fa9dd0f1 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__bool_op.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/bool_op.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..142, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Load, @@ -30,7 +30,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("b"), ctx: Load, @@ -43,17 +43,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..21, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..21, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("a"), ctx: Load, @@ -61,7 +61,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("b"), ctx: Load, @@ -69,7 +69,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("c"), ctx: Load, @@ -82,17 +82,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..28, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..28, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("a"), ctx: Load, @@ -100,7 +100,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, id: Name("b"), ctx: Load, @@ -113,17 +113,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..40, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..40, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("a"), ctx: Load, @@ -131,7 +131,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("b"), ctx: Load, @@ -139,7 +139,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("c"), ctx: Load, @@ -152,23 +152,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..53, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..53, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..48, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("a"), ctx: Load, @@ -176,7 +176,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("b"), ctx: Load, @@ -187,7 +187,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, id: Name("c"), ctx: Load, @@ -200,23 +200,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..88, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..88, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..67, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("a"), ctx: Load, @@ -224,7 +224,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("b"), ctx: Load, @@ -232,7 +232,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("c"), ctx: Load, @@ -243,7 +243,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, id: Name("d"), ctx: Load, @@ -251,13 +251,13 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..83, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, id: Name("e"), ctx: Load, @@ -265,7 +265,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("f"), ctx: Load, @@ -276,7 +276,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, id: Name("g"), ctx: Load, @@ -289,23 +289,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..105, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..105, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..100, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("a"), ctx: Load, @@ -313,12 +313,12 @@ Module( ), UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..100, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("b"), ctx: Load, @@ -331,7 +331,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("c"), ctx: Load, @@ -344,28 +344,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..124, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..124, value: Some( BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..124, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..119, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, id: Name("a"), ctx: Load, @@ -373,7 +373,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, id: Name("b"), ctx: Load, @@ -384,7 +384,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..124, id: Name("c"), ctx: Load, @@ -400,28 +400,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..141, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..141, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..136, op: And, values: [ UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..130, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("a"), ctx: Load, @@ -431,7 +431,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, id: Name("b"), ctx: Load, @@ -442,7 +442,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, id: Name("c"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap index 7a33b5db76879..452c617b2e7fd 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__call.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/call.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..349, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..120, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..120, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..118, id: Name("call"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), arguments: Arguments { range: 118..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -38,19 +38,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..132, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..132, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..130, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..125, id: Name("attr"), ctx: Load, @@ -59,14 +59,14 @@ Module( attr: Identifier { id: Name("expr"), range: 126..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 130..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -76,19 +76,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..150, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..150, func: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..148, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..142, id: Name("subscript"), ctx: Load, @@ -96,12 +96,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..147, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..144, value: Int( 1, @@ -110,7 +110,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, value: Int( 2, @@ -127,7 +127,7 @@ Module( ), arguments: Arguments { range: 148..150, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -137,19 +137,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..162, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..162, func: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..160, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..156, id: Name("slice"), ctx: Load, @@ -157,13 +157,13 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..159, lower: None, upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, value: Int( 1, @@ -179,7 +179,7 @@ Module( ), arguments: Arguments { range: 160..162, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -189,20 +189,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..174, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..174, func: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..172, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, value: Int( 1, @@ -211,7 +211,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, value: Int( 2, @@ -220,7 +220,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, value: Int( 3, @@ -233,7 +233,7 @@ Module( ), arguments: Arguments { range: 172..174, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -243,20 +243,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..186, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..186, func: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..184, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..177, value: Int( 1, @@ -265,7 +265,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, value: Int( 2, @@ -274,7 +274,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..183, value: Int( 3, @@ -288,7 +288,7 @@ Module( ), arguments: Arguments { range: 184..186, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -298,19 +298,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..206, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..206, func: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..204, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..189, id: Name("x"), ctx: Load, @@ -319,10 +319,10 @@ Module( generators: [ Comprehension { range: 190..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..195, id: Name("x"), ctx: Store, @@ -330,7 +330,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..203, id: Name("iter"), ctx: Load, @@ -345,7 +345,7 @@ Module( ), arguments: Arguments { range: 204..206, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -355,20 +355,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..218, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..218, func: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..216, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..209, value: Int( 1, @@ -377,7 +377,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, value: Int( 2, @@ -386,7 +386,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, value: Int( 3, @@ -398,7 +398,7 @@ Module( ), arguments: Arguments { range: 216..218, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -408,22 +408,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..233, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..233, func: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..231, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..221, value: Int( 1, @@ -433,7 +433,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..224, value: Int( 2, @@ -445,7 +445,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..227, value: Int( 3, @@ -455,7 +455,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..230, value: Int( 4, @@ -468,7 +468,7 @@ Module( ), arguments: Arguments { range: 231..233, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -478,20 +478,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..245, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..245, func: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..242, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, id: Name("x"), ctx: Load, @@ -502,7 +502,7 @@ Module( ), arguments: Arguments { range: 243..245, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -512,22 +512,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..312, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..312, func: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..310, value: true, }, ), arguments: Arguments { range: 310..312, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -537,22 +537,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..320, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..320, func: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..318, value: false, }, ), arguments: Arguments { range: 318..320, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -562,21 +562,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..327, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..327, func: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..325, }, ), arguments: Arguments { range: 325..327, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -586,21 +586,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..338, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..338, func: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..336, value: StringLiteralValue { inner: Single( StringLiteral { range: 328..336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "string", flags: StringLiteralFlags { quote_style: Double, @@ -614,7 +614,7 @@ Module( ), arguments: Arguments { range: 336..338, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -624,15 +624,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..342, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..342, func: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..340, value: Int( 1, @@ -641,7 +641,7 @@ Module( ), arguments: Arguments { range: 340..342, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -651,15 +651,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..348, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..348, func: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..346, value: Float( 1.0, @@ -668,7 +668,7 @@ Module( ), arguments: Arguments { range: 346..348, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap index e2bd2b568cd30..ef4b3720a0461 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__compare.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/compare.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..542, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..15, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..15, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("a"), ctx: Load, @@ -32,7 +32,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("b"), ctx: Load, @@ -45,15 +45,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..21, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..21, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("b"), ctx: Load, @@ -65,7 +65,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("a"), ctx: Load, @@ -78,15 +78,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..27, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..27, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("b"), ctx: Load, @@ -98,7 +98,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("a"), ctx: Load, @@ -111,15 +111,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..34, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..34, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("a"), ctx: Load, @@ -131,7 +131,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, id: Name("b"), ctx: Load, @@ -144,15 +144,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..41, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..41, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("a"), ctx: Load, @@ -164,7 +164,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("b"), ctx: Load, @@ -177,15 +177,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..48, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..48, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, id: Name("a"), ctx: Load, @@ -197,7 +197,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("b"), ctx: Load, @@ -210,15 +210,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..55, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..55, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("a"), ctx: Load, @@ -230,7 +230,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("c"), ctx: Load, @@ -243,15 +243,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..62, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..62, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("a"), ctx: Load, @@ -263,7 +263,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, id: Name("b"), ctx: Load, @@ -276,15 +276,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..73, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..73, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, id: Name("a"), ctx: Load, @@ -296,7 +296,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("c"), ctx: Load, @@ -309,15 +309,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..84, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..84, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("a"), ctx: Load, @@ -329,7 +329,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("b"), ctx: Load, @@ -342,15 +342,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..156, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..156, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..111, id: Name("a"), ctx: Load, @@ -366,7 +366,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, id: Name("b"), ctx: Load, @@ -374,7 +374,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("c"), ctx: Load, @@ -382,7 +382,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("d"), ctx: Load, @@ -390,7 +390,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("e"), ctx: Load, @@ -398,7 +398,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..156, id: Name("f"), ctx: Load, @@ -411,19 +411,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..203, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..203, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..182, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..178, id: Name("a"), ctx: Load, @@ -432,7 +432,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..182, id: Name("b"), ctx: Load, @@ -447,11 +447,11 @@ Module( comparators: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..190, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..186, id: Name("c"), ctx: Load, @@ -460,7 +460,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("d"), ctx: Load, @@ -470,11 +470,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..203, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..199, id: Name("e"), ctx: Load, @@ -483,7 +483,7 @@ Module( op: BitAnd, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..203, id: Name("f"), ctx: Load, @@ -498,20 +498,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 379..393, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 379..393, op: Not, operand: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..393, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..384, id: Name("x"), ctx: Load, @@ -523,7 +523,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..393, id: Name("y"), ctx: Load, @@ -538,17 +538,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..416, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..416, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..396, id: Name("x"), ctx: Load, @@ -556,17 +556,17 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..416, op: And, values: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..410, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..401, id: Name("y"), ctx: Load, @@ -578,7 +578,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..410, id: Name("z"), ctx: Load, @@ -589,7 +589,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 415..416, id: Name("a"), ctx: Load, @@ -605,15 +605,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 417..429, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 417..429, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 417..418, id: Name("x"), ctx: Load, @@ -625,11 +625,11 @@ Module( comparators: [ Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 422..429, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 428..429, id: Name("y"), ctx: Load, @@ -644,15 +644,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..446, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..446, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..431, id: Name("x"), ctx: Load, @@ -664,11 +664,11 @@ Module( comparators: [ Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 439..446, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 445..446, id: Name("y"), ctx: Load, @@ -683,15 +683,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 489..541, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 489..541, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 489..490, id: Name("a"), ctx: Load, @@ -711,7 +711,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 493..494, id: Name("b"), ctx: Load, @@ -719,7 +719,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..499, id: Name("c"), ctx: Load, @@ -727,7 +727,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 502..503, id: Name("d"), ctx: Load, @@ -735,7 +735,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 507..508, id: Name("e"), ctx: Load, @@ -743,7 +743,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 516..517, id: Name("f"), ctx: Load, @@ -751,7 +751,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 525..526, id: Name("g"), ctx: Load, @@ -759,7 +759,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 530..531, id: Name("h"), ctx: Load, @@ -767,7 +767,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 535..536, id: Name("i"), ctx: Load, @@ -775,7 +775,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 540..541, id: Name("j"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap index d368b8654bceb..8ff7bb7782ebe 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/dictionary.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..622, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, items: [], }, @@ -25,18 +25,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..18, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..18, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 1, @@ -46,7 +46,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, value: Int( 2, @@ -61,18 +61,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..43, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..43, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, value: Int( 1, @@ -82,7 +82,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Int( 2, @@ -94,7 +94,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("a"), ctx: Load, @@ -103,7 +103,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, value: Int( 1, @@ -115,7 +115,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("b"), ctx: Load, @@ -124,13 +124,13 @@ Module( ), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..42, value: StringLiteralValue { inner: Single( StringLiteral { range: 35..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello", flags: StringLiteralFlags { quote_style: Single, @@ -150,11 +150,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..69, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..69, items: [], }, @@ -163,18 +163,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..100, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..100, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, value: Int( 1, @@ -184,7 +184,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 2, @@ -196,7 +196,7 @@ Module( key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, value: Int( 3, @@ -206,7 +206,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, value: Int( 4, @@ -221,25 +221,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..132, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..132, items: [ DictItem { key: Some( Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..118, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, value: Int( 1, @@ -249,7 +249,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, value: Int( 2, @@ -263,14 +263,14 @@ Module( ), value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..131, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..122, value: Int( 3, @@ -280,14 +280,14 @@ Module( ), value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..130, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..126, value: Int( 4, @@ -297,7 +297,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, value: Int( 5, @@ -320,37 +320,35 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..171, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..171, items: [ DictItem { key: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..167, parameters: Some( Parameters { range: 163..164, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 163..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 163..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 163..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -364,7 +362,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("x"), ctx: Load, @@ -375,7 +373,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..170, value: Int( 1, @@ -390,24 +388,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..202, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..202, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..176, value: StringLiteralValue { inner: Single( StringLiteral { range: 173..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "A", flags: StringLiteralFlags { quote_style: Single, @@ -422,26 +420,24 @@ Module( ), value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..192, parameters: Some( Parameters { range: 185..186, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 185..186, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 185..186, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("p"), range: 185..186, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -455,7 +451,7 @@ Module( ), body: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..192, }, ), @@ -466,13 +462,13 @@ Module( key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..197, value: StringLiteralValue { inner: Single( StringLiteral { range: 194..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "B", flags: StringLiteralFlags { quote_style: Single, @@ -487,7 +483,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..200, id: Name("C"), ctx: Load, @@ -501,22 +497,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..237, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..237, items: [ DictItem { key: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..232, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..227, id: Name("x"), ctx: Store, @@ -524,7 +520,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..232, value: Int( 1, @@ -536,7 +532,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..236, id: Name("y"), ctx: Load, @@ -550,22 +546,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..258, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..258, items: [ DictItem { key: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..246, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..241, id: Name("x"), ctx: Store, @@ -573,7 +569,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, value: Int( 1, @@ -585,11 +581,11 @@ Module( ), value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..256, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..251, id: Name("y"), ctx: Store, @@ -597,7 +593,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..256, value: Int( 2, @@ -614,18 +610,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..289, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..289, items: [ DictItem { key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..288, id: Name("d"), ctx: Load, @@ -639,18 +635,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..301, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..301, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 291..292, id: Name("a"), ctx: Load, @@ -659,7 +655,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 294..295, id: Name("b"), ctx: Load, @@ -670,7 +666,7 @@ Module( key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..300, id: Name("d"), ctx: Load, @@ -684,18 +680,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..312, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..312, items: [ DictItem { key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 305..306, id: Name("a"), ctx: Load, @@ -706,7 +702,7 @@ Module( key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..311, id: Name("b"), ctx: Load, @@ -720,24 +716,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..338, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..338, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..317, value: StringLiteralValue { inner: Single( StringLiteral { range: 314..317, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", flags: StringLiteralFlags { quote_style: Double, @@ -752,13 +748,13 @@ Module( ), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..322, value: StringLiteralValue { inner: Single( StringLiteral { range: 319..322, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b", flags: StringLiteralFlags { quote_style: Double, @@ -775,7 +771,7 @@ Module( key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 326..327, id: Name("c"), ctx: Load, @@ -786,13 +782,13 @@ Module( key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..332, value: StringLiteralValue { inner: Single( StringLiteral { range: 329..332, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "d", flags: StringLiteralFlags { quote_style: Double, @@ -807,13 +803,13 @@ Module( ), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 334..337, value: StringLiteralValue { inner: Single( StringLiteral { range: 334..337, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "e", flags: StringLiteralFlags { quote_style: Double, @@ -833,18 +829,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..367, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..367, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..341, value: Int( 1, @@ -854,7 +850,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..344, value: Int( 2, @@ -866,20 +862,20 @@ Module( key: None, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..366, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..357, value: StringLiteralValue { inner: Single( StringLiteral { range: 349..357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "nested", flags: StringLiteralFlags { quote_style: Single, @@ -894,13 +890,13 @@ Module( ), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 359..365, value: StringLiteralValue { inner: Single( StringLiteral { range: 359..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "dict", flags: StringLiteralFlags { quote_style: Single, @@ -924,22 +920,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 368..393, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 368..393, items: [ DictItem { key: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 369..374, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 369..370, id: Name("x"), ctx: Load, @@ -948,7 +944,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 373..374, value: Int( 1, @@ -960,11 +956,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..382, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..377, id: Name("y"), ctx: Load, @@ -973,7 +969,7 @@ Module( op: Pow, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 381..382, value: Int( 2, @@ -987,11 +983,11 @@ Module( key: None, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..392, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..390, id: Name("call"), ctx: Load, @@ -999,7 +995,7 @@ Module( ), arguments: Arguments { range: 390..392, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1013,23 +1009,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 460..471, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 460..471, items: [ DictItem { key: None, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..469, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 468..469, id: Name("x"), ctx: Load, @@ -1045,18 +1041,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 494..515, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 494..515, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 495..496, value: Int( 1, @@ -1066,18 +1062,18 @@ Module( ), value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..514, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 503..507, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..499, id: Name("x"), ctx: Load, @@ -1085,7 +1081,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..514, id: Name("y"), ctx: Load, @@ -1101,26 +1097,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 516..575, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 516..575, key: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 517..533, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 522..526, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 517..518, id: Name("x"), ctx: Load, @@ -1128,7 +1124,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 532..533, id: Name("y"), ctx: Load, @@ -1138,7 +1134,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 535..536, id: Name("y"), ctx: Load, @@ -1147,10 +1143,10 @@ Module( generators: [ Comprehension { range: 537..555, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 541..542, id: Name("x"), ctx: Store, @@ -1158,11 +1154,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 546..555, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 546..551, id: Name("range"), ctx: Load, @@ -1170,11 +1166,11 @@ Module( ), arguments: Arguments { range: 551..555, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 552..554, value: Int( 10, @@ -1191,10 +1187,10 @@ Module( }, Comprehension { range: 556..574, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 560..561, id: Name("y"), ctx: Store, @@ -1202,11 +1198,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 565..574, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 565..570, id: Name("range"), ctx: Load, @@ -1214,11 +1210,11 @@ Module( ), arguments: Arguments { range: 570..574, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 571..573, value: Int( 10, @@ -1240,23 +1236,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 576..600, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 576..600, items: [ DictItem { key: Some( Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 577..583, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 578..579, value: Int( 1, @@ -1265,7 +1261,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 581..582, value: Int( 2, @@ -1278,7 +1274,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 585..586, value: Int( 3, @@ -1290,7 +1286,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 588..589, id: Name("x"), ctx: Load, @@ -1299,14 +1295,14 @@ Module( ), value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 591..598, items: [ DictItem { key: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 592..593, value: Int( 1, @@ -1316,7 +1312,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 595..596, value: Int( 2, @@ -1335,18 +1331,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 601..621, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 601..621, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 603..604, id: Name("x"), ctx: Load, @@ -1355,7 +1351,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 608..609, id: Name("y"), ctx: Load, @@ -1366,7 +1362,7 @@ Module( key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 613..614, id: Name("z"), ctx: Load, @@ -1375,7 +1371,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 618..619, id: Name("a"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap index d54aceae23f22..cf7709bd98507 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__dictionary_comprehension.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/dictionary_com ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..589, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("y"), ctx: Load, @@ -29,10 +29,10 @@ Module( generators: [ Comprehension { range: 3..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("y"), ctx: Store, @@ -40,12 +40,12 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..21, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 1, @@ -54,7 +54,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, value: Int( 2, @@ -63,7 +63,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, value: Int( 3, @@ -85,15 +85,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..42, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..42, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..26, id: Name("x1"), ctx: Load, @@ -101,7 +101,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..30, id: Name("x2"), ctx: Load, @@ -110,10 +110,10 @@ Module( generators: [ Comprehension { range: 31..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("y"), ctx: Store, @@ -121,7 +121,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("z"), ctx: Load, @@ -137,19 +137,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..73, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..73, key: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..49, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("x"), ctx: Load, @@ -158,7 +158,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, value: Int( 1, @@ -169,13 +169,13 @@ Module( ), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..54, value: StringLiteralValue { inner: Single( StringLiteral { range: 51..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x", flags: StringLiteralFlags { quote_style: Single, @@ -190,10 +190,10 @@ Module( generators: [ Comprehension { range: 55..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("i"), ctx: Store, @@ -201,11 +201,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..72, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..69, id: Name("range"), ctx: Load, @@ -213,11 +213,11 @@ Module( ), arguments: Arguments { range: 69..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, value: Int( 5, @@ -239,15 +239,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..122, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..122, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("b"), ctx: Load, @@ -255,11 +255,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..83, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, id: Name("c"), ctx: Load, @@ -268,7 +268,7 @@ Module( op: Mult, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 2, @@ -280,10 +280,10 @@ Module( generators: [ Comprehension { range: 84..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, id: Name("c"), ctx: Store, @@ -291,7 +291,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("d"), ctx: Load, @@ -300,11 +300,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..104, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("x"), ctx: Load, @@ -316,7 +316,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..104, id: Name("w"), ctx: Load, @@ -327,13 +327,13 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..116, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("y"), ctx: Load, @@ -341,7 +341,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..116, id: Name("yy"), ctx: Load, @@ -352,7 +352,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, id: Name("z"), ctx: Load, @@ -368,15 +368,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..176, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..176, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..125, id: Name("a"), ctx: Load, @@ -384,11 +384,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..133, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("a"), ctx: Load, @@ -397,7 +397,7 @@ Module( op: Pow, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, value: Int( 2, @@ -409,10 +409,10 @@ Module( generators: [ Comprehension { range: 134..155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..139, id: Name("b"), ctx: Store, @@ -420,7 +420,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..144, id: Name("c"), ctx: Load, @@ -429,13 +429,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..155, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..149, id: Name("d"), ctx: Load, @@ -443,7 +443,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..155, id: Name("e"), ctx: Load, @@ -457,10 +457,10 @@ Module( }, Comprehension { range: 156..175, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, id: Name("f"), ctx: Store, @@ -468,7 +468,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, id: Name("j"), ctx: Load, @@ -477,11 +477,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..175, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, id: Name("k"), ctx: Load, @@ -493,7 +493,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..175, id: Name("h"), ctx: Load, @@ -512,15 +512,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..231, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..231, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("a"), ctx: Load, @@ -528,7 +528,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..182, id: Name("b"), ctx: Load, @@ -537,10 +537,10 @@ Module( generators: [ Comprehension { range: 183..204, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..188, id: Name("b"), ctx: Store, @@ -548,7 +548,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, id: Name("c"), ctx: Load, @@ -557,13 +557,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..204, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, id: Name("d"), ctx: Load, @@ -571,7 +571,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..204, id: Name("e"), ctx: Load, @@ -585,10 +585,10 @@ Module( }, Comprehension { range: 205..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..216, id: Name("f"), ctx: Store, @@ -596,7 +596,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..221, id: Name("j"), ctx: Load, @@ -605,11 +605,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..230, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..226, id: Name("k"), ctx: Load, @@ -621,7 +621,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..230, id: Name("h"), ctx: Load, @@ -640,15 +640,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..252, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..252, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..234, id: Name("a"), ctx: Load, @@ -656,7 +656,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("a"), ctx: Load, @@ -665,15 +665,15 @@ Module( generators: [ Comprehension { range: 238..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..246, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..243, id: Name("b"), ctx: Store, @@ -681,7 +681,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, id: Name("c"), ctx: Store, @@ -694,7 +694,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..251, id: Name("d"), ctx: Load, @@ -710,15 +710,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 391..416, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 391..416, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..393, id: Name("x"), ctx: Load, @@ -726,7 +726,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 395..396, id: Name("y"), ctx: Load, @@ -735,10 +735,10 @@ Module( generators: [ Comprehension { range: 397..415, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..402, id: Name("x"), ctx: Store, @@ -746,12 +746,12 @@ Module( ), iter: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 407..414, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 413..414, id: Name("y"), ctx: Load, @@ -770,15 +770,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 417..447, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 417..447, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 418..419, id: Name("x"), ctx: Load, @@ -786,7 +786,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..422, id: Name("y"), ctx: Load, @@ -795,10 +795,10 @@ Module( generators: [ Comprehension { range: 423..446, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 427..428, id: Name("x"), ctx: Store, @@ -806,11 +806,11 @@ Module( ), iter: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 433..445, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 444..445, id: Name("y"), ctx: Load, @@ -828,15 +828,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 448..477, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 448..477, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 449..450, id: Name("x"), ctx: Load, @@ -844,7 +844,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 452..453, id: Name("y"), ctx: Load, @@ -853,10 +853,10 @@ Module( generators: [ Comprehension { range: 454..476, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..459, id: Name("x"), ctx: Store, @@ -864,26 +864,24 @@ Module( ), iter: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..475, parameters: Some( Parameters { range: 471..472, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 471..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 471..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 471..472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -897,7 +895,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 474..475, id: Name("y"), ctx: Load, @@ -915,15 +913,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 478..511, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 478..511, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 479..480, id: Name("x"), ctx: Load, @@ -931,7 +929,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 482..483, id: Name("y"), ctx: Load, @@ -940,10 +938,10 @@ Module( generators: [ Comprehension { range: 484..510, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 488..489, id: Name("x"), ctx: Store, @@ -951,7 +949,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 493..497, id: Name("data"), ctx: Load, @@ -960,12 +958,12 @@ Module( ifs: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 502..509, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 508..509, id: Name("y"), ctx: Load, @@ -984,15 +982,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 512..550, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 512..550, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..514, id: Name("x"), ctx: Load, @@ -1000,7 +998,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 516..517, id: Name("y"), ctx: Load, @@ -1009,10 +1007,10 @@ Module( generators: [ Comprehension { range: 518..549, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 522..523, id: Name("x"), ctx: Store, @@ -1020,7 +1018,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 527..531, id: Name("data"), ctx: Load, @@ -1029,11 +1027,11 @@ Module( ifs: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 536..548, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 547..548, id: Name("y"), ctx: Load, @@ -1051,15 +1049,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..588, value: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..588, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 552..553, id: Name("x"), ctx: Load, @@ -1067,7 +1065,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 555..556, id: Name("y"), ctx: Load, @@ -1076,10 +1074,10 @@ Module( generators: [ Comprehension { range: 557..587, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 561..562, id: Name("x"), ctx: Store, @@ -1087,7 +1085,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 566..570, id: Name("data"), ctx: Load, @@ -1096,26 +1094,24 @@ Module( ifs: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 575..586, parameters: Some( Parameters { range: 582..583, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 582..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 582..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 582..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1129,7 +1125,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 585..586, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap index 1fe9ef6fa7b96..adc00206098ef 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__f_string.py.snap @@ -7,23 +7,23 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/f_string.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..979, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, value: FStringValue { inner: Single( FString( FString { range: 18..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Double, @@ -40,18 +40,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, value: FStringValue { inner: Single( FString( FString { range: 22..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Double, @@ -68,18 +68,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: FStringValue { inner: Single( FString( FString { range: 26..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Single, @@ -96,18 +96,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..37, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..37, value: FStringValue { inner: Single( FString( FString { range: 30..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Double, @@ -124,18 +124,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..45, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..45, value: FStringValue { inner: Single( FString( FString { range: 38..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: FStringFlags { quote_style: Single, @@ -152,32 +152,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, value: FStringValue { inner: Single( FString( FString { range: 47..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 49..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..54, value: StringLiteralValue { inner: Single( StringLiteral { range: 50..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " f", flags: StringLiteralFlags { quote_style: Double, @@ -210,26 +210,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..67, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..67, value: FStringValue { inner: Single( FString( FString { range: 57..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 59..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, id: Name("foo"), ctx: Load, @@ -256,31 +256,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..75, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..75, value: FStringValue { inner: Single( FString( FString { range: 68..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 70..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..73, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, value: Int( 3, @@ -313,30 +313,30 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..86, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..86, value: FStringValue { inner: Single( FString( FString { range: 76..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 78..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..83, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 3, @@ -349,7 +349,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 4, @@ -364,7 +364,7 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 84..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], }, ), @@ -386,26 +386,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..102, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..102, value: FStringValue { inner: Single( FString( FString { range: 87..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 89..101, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, value: Int( 3, @@ -417,21 +417,21 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 92..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 92..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, value: StringLiteralValue { inner: Single( StringLiteral { range: 93..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "}", flags: StringLiteralFlags { quote_style: Double, @@ -451,7 +451,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 97..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ">10", }, ), @@ -476,26 +476,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..118, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..118, value: FStringValue { inner: Single( FString( FString { range: 103..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 105..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..107, value: Int( 3, @@ -507,21 +507,21 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 108..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 108..113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, value: StringLiteralValue { inner: Single( StringLiteral { range: 109..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "{", flags: StringLiteralFlags { quote_style: Double, @@ -541,7 +541,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 113..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ">10", }, ), @@ -566,26 +566,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..133, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..133, value: FStringValue { inner: Single( FString( FString { range: 119..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 121..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..127, id: Name("foo"), ctx: Load, @@ -617,26 +617,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..154, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..154, value: FStringValue { inner: Single( FString( FString { range: 134..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 136..153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..142, id: Name("foo"), ctx: Load, @@ -652,12 +652,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 147..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 147..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f ", }, ), @@ -682,26 +682,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..173, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..173, value: FStringValue { inner: Single( FString( FString { range: 155..173, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 157..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..163, id: Name("foo"), ctx: Load, @@ -733,31 +733,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..190, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..190, value: FStringValue { inner: Single( FString( FString { range: 174..190, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 176..189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..183, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, value: Int( 1, @@ -766,7 +766,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..183, value: Int( 2, @@ -804,41 +804,41 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..217, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..217, value: FStringValue { inner: Single( FString( FString { range: 191..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 193..216, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..210, value: FStringValue { inner: Single( FString( FString { range: 194..210, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 196..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..203, value: Float( 3.1415, @@ -855,12 +855,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 205..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 205..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".1f", }, ), @@ -886,12 +886,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 211..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 211..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "*^20", }, ), @@ -916,18 +916,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..253, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..253, items: [ DictItem { key: Some( FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..248, value: FStringValue { inner: Concatenated( @@ -935,7 +935,7 @@ Module( Literal( StringLiteral { range: 220..226, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo ", flags: StringLiteralFlags { quote_style: Double, @@ -947,26 +947,26 @@ Module( FString( FString { range: 227..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 229..233, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bar ", }, ), Interpolation( InterpolatedElement { range: 233..240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..239, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..235, id: Name("x"), ctx: Load, @@ -975,7 +975,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..239, id: Name("y"), ctx: Load, @@ -991,7 +991,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 240..241, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), @@ -1006,7 +1006,7 @@ Module( Literal( StringLiteral { range: 243..248, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "baz", flags: StringLiteralFlags { quote_style: Double, @@ -1023,7 +1023,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..252, value: Int( 10, @@ -1038,11 +1038,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..345, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..263, id: Name("foo"), ctx: Load, @@ -1051,20 +1051,20 @@ Module( cases: [ MatchCase { range: 269..293, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 274..279, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..279, value: StringLiteralValue { inner: Single( StringLiteral { range: 274..279, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "one", flags: StringLiteralFlags { quote_style: Double, @@ -1082,7 +1082,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..293, }, ), @@ -1090,14 +1090,14 @@ Module( }, MatchCase { range: 298..345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 303..331, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..331, value: StringLiteralValue { inner: Concatenated( @@ -1105,7 +1105,7 @@ Module( strings: [ StringLiteral { range: 303..316, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "implicitly ", flags: StringLiteralFlags { quote_style: Double, @@ -1115,7 +1115,7 @@ Module( }, StringLiteral { range: 317..331, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "concatenated", flags: StringLiteralFlags { quote_style: Double, @@ -1136,7 +1136,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 341..345, }, ), @@ -1147,33 +1147,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 347..364, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 347..364, value: FStringValue { inner: Single( FString( FString { range: 347..364, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 349..350, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), Interpolation( InterpolatedElement { range: 350..355, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..354, id: Name("foo"), ctx: Load, @@ -1187,17 +1187,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 355..356, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), Interpolation( InterpolatedElement { range: 356..363, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..360, id: Name("bar"), ctx: Load, @@ -1208,12 +1208,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 361..362, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 361..362, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), @@ -1238,23 +1238,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 365..379, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 365..379, value: FStringValue { inner: Single( FString( FString { range: 365..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 367..378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\{foo\\}", }, ), @@ -1274,26 +1274,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 380..420, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 380..420, value: FStringValue { inner: Single( FString( FString { range: 380..420, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 384..417, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..393, id: Name("foo"), ctx: Load, @@ -1304,12 +1304,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 394..416, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 394..416, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x\n y\n z\n", }, ), @@ -1334,26 +1334,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..439, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..439, value: FStringValue { inner: Single( FString( FString { range: 421..439, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 423..438, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 428..431, id: Name("foo"), ctx: Load, @@ -1385,33 +1385,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..486, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..486, value: FStringValue { inner: Single( FString( FString { range: 441..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 443..450, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "normal ", }, ), Interpolation( InterpolatedElement { range: 450..455, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 451..454, id: Name("foo"), ctx: Load, @@ -1425,17 +1425,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 455..468, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " {another} ", }, ), Interpolation( InterpolatedElement { range: 468..473, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 469..472, id: Name("bar"), ctx: Load, @@ -1449,17 +1449,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 473..476, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " {", }, ), Interpolation( InterpolatedElement { range: 476..483, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 477..482, id: Name("three"), ctx: Load, @@ -1473,7 +1473,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 483..485, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "}", }, ), @@ -1493,33 +1493,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 487..529, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 487..529, value: FStringValue { inner: Single( FString( FString { range: 487..529, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 489..496, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "normal ", }, ), Interpolation( InterpolatedElement { range: 496..503, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 497..500, id: Name("foo"), ctx: Load, @@ -1533,17 +1533,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 503..504, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), Interpolation( InterpolatedElement { range: 504..511, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 505..508, id: Name("bar"), ctx: Load, @@ -1557,17 +1557,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 511..512, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), Interpolation( InterpolatedElement { range: 512..519, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..516, id: Name("baz"), ctx: Load, @@ -1581,17 +1581,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 519..520, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), Interpolation( InterpolatedElement { range: 520..528, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 521..527, id: Name("foobar"), ctx: Load, @@ -1618,33 +1618,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 530..549, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 530..549, value: FStringValue { inner: Single( FString( FString { range: 530..549, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 532..539, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "normal ", }, ), Interpolation( InterpolatedElement { range: 539..548, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 540..541, id: Name("x"), ctx: Load, @@ -1655,12 +1655,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 542..547, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 542..547, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "y + 2", }, ), @@ -1685,26 +1685,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 550..568, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 550..568, value: FStringValue { inner: Single( FString( FString { range: 550..568, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 552..567, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 553..554, id: Name("x"), ctx: Load, @@ -1715,28 +1715,28 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 555..566, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 555..566, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 556..565, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 556..563, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 556..559, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 557..558, value: Int( 1, @@ -1749,14 +1749,14 @@ Module( attr: Identifier { id: Name("pop"), range: 560..563, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 563..565, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1788,45 +1788,43 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 569..588, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 569..588, value: FStringValue { inner: Single( FString( FString { range: 569..588, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 571..587, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 573..585, parameters: Some( Parameters { range: 580..581, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 580..581, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 580..581, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 580..581, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1840,12 +1838,12 @@ Module( ), body: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 582..585, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 583..584, id: Name("x"), ctx: Load, @@ -1877,26 +1875,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 589..597, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 589..597, value: FStringValue { inner: Single( FString( FString { range: 589..597, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 591..596, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 592..593, id: Name("x"), ctx: Load, @@ -1928,26 +1926,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 598..611, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 598..611, value: FStringValue { inner: Single( FString( FString { range: 598..611, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 600..610, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 605..606, id: Name("x"), ctx: Load, @@ -1979,26 +1977,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 612..621, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 612..621, value: FStringValue { inner: Single( FString( FString { range: 612..621, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 614..620, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 615..616, id: Name("x"), ctx: Load, @@ -2030,26 +2028,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 622..636, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 622..636, value: FStringValue { inner: Single( FString( FString { range: 622..636, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 624..635, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 625..626, id: Name("x"), ctx: Load, @@ -2060,12 +2058,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 627..634, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 627..634, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f!r =", }, ), @@ -2090,26 +2088,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 637..653, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 637..653, value: FStringValue { inner: Single( FString( FString { range: 637..653, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 639..652, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 640..641, id: Name("x"), ctx: Load, @@ -2125,12 +2123,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 648..651, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 648..651, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f", }, ), @@ -2155,26 +2153,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 654..667, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 654..667, value: FStringValue { inner: Single( FString( FString { range: 654..667, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 656..666, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 657..658, id: Name("x"), ctx: Load, @@ -2185,12 +2183,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 659..665, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 659..665, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f=!r", }, ), @@ -2215,11 +2213,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 668..682, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 668..682, value: FStringValue { inner: Concatenated( @@ -2227,7 +2225,7 @@ Module( Literal( StringLiteral { range: 668..675, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello", flags: StringLiteralFlags { quote_style: Double, @@ -2239,15 +2237,15 @@ Module( FString( FString { range: 676..682, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 678..681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 679..680, id: Name("x"), ctx: Load, @@ -2275,11 +2273,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 683..696, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 683..696, value: FStringValue { inner: Concatenated( @@ -2287,15 +2285,15 @@ Module( FString( FString { range: 683..689, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 685..688, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..687, id: Name("x"), ctx: Load, @@ -2317,15 +2315,15 @@ Module( FString( FString { range: 690..696, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 692..695, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 693..694, id: Name("y"), ctx: Load, @@ -2353,11 +2351,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 697..711, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 697..711, value: FStringValue { inner: Concatenated( @@ -2365,15 +2363,15 @@ Module( FString( FString { range: 697..703, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 699..702, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..701, id: Name("x"), ctx: Load, @@ -2395,7 +2393,7 @@ Module( Literal( StringLiteral { range: 704..711, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", flags: StringLiteralFlags { quote_style: Double, @@ -2413,38 +2411,38 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 712..756, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 712..756, value: FStringValue { inner: Single( FString( FString { range: 712..756, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 714..739, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Invalid args in command: ", }, ), Interpolation( InterpolatedElement { range: 739..755, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 740..754, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 740..747, id: Name("command"), ctx: Load, @@ -2452,11 +2450,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 749..754, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 750..754, id: Name("args"), ctx: Load, @@ -2491,11 +2489,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 757..775, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 757..775, value: FStringValue { inner: Concatenated( @@ -2503,7 +2501,7 @@ Module( Literal( StringLiteral { range: 757..762, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -2515,15 +2513,15 @@ Module( FString( FString { range: 763..769, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 765..768, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 766..767, id: Name("x"), ctx: Load, @@ -2545,7 +2543,7 @@ Module( Literal( StringLiteral { range: 770..775, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bar", flags: StringLiteralFlags { quote_style: Double, @@ -2563,11 +2561,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 776..825, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 782..823, value: FStringValue { inner: Concatenated( @@ -2575,12 +2573,12 @@ Module( FString( FString { range: 782..786, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 784..785, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", }, ), @@ -2595,12 +2593,12 @@ Module( FString( FString { range: 791..795, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 793..794, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b", }, ), @@ -2615,7 +2613,7 @@ Module( Literal( StringLiteral { range: 800..803, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "c", flags: StringLiteralFlags { quote_style: Double, @@ -2627,12 +2625,12 @@ Module( FString( FString { range: 808..813, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 811..812, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "d", }, ), @@ -2649,12 +2647,12 @@ Module( FString( FString { range: 818..823, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 821..822, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "e", }, ), @@ -2677,11 +2675,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 850..879, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 850..879, value: FStringValue { inner: Concatenated( @@ -2689,7 +2687,7 @@ Module( Literal( StringLiteral { range: 850..856, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -2701,15 +2699,15 @@ Module( FString( FString { range: 857..865, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 859..864, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 860..863, id: Name("bar"), ctx: Load, @@ -2731,7 +2729,7 @@ Module( Literal( StringLiteral { range: 866..871, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "baz", flags: StringLiteralFlags { quote_style: Double, @@ -2743,7 +2741,7 @@ Module( Literal( StringLiteral { range: 872..879, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " some", flags: StringLiteralFlags { quote_style: Double, @@ -2761,11 +2759,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 880..909, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 880..909, value: FStringValue { inner: Concatenated( @@ -2773,7 +2771,7 @@ Module( Literal( StringLiteral { range: 880..885, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -2785,15 +2783,15 @@ Module( FString( FString { range: 886..894, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 888..893, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 889..892, id: Name("bar"), ctx: Load, @@ -2815,7 +2813,7 @@ Module( Literal( StringLiteral { range: 895..901, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "baz", flags: StringLiteralFlags { quote_style: Double, @@ -2827,7 +2825,7 @@ Module( Literal( StringLiteral { range: 902..909, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " some", flags: StringLiteralFlags { quote_style: Double, @@ -2845,11 +2843,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 910..939, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 910..939, value: FStringValue { inner: Concatenated( @@ -2857,7 +2855,7 @@ Module( Literal( StringLiteral { range: 910..915, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -2869,15 +2867,15 @@ Module( FString( FString { range: 916..924, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 918..923, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 919..922, id: Name("bar"), ctx: Load, @@ -2899,7 +2897,7 @@ Module( Literal( StringLiteral { range: 925..930, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "baz", flags: StringLiteralFlags { quote_style: Double, @@ -2911,7 +2909,7 @@ Module( Literal( StringLiteral { range: 931..939, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " some", flags: StringLiteralFlags { quote_style: Double, @@ -2929,11 +2927,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 940..978, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 940..978, value: FStringValue { inner: Concatenated( @@ -2941,7 +2939,7 @@ Module( Literal( StringLiteral { range: 940..946, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -2953,22 +2951,22 @@ Module( FString( FString { range: 947..966, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 949..953, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bar ", }, ), Interpolation( InterpolatedElement { range: 953..958, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 954..957, id: Name("baz"), ctx: Load, @@ -2982,7 +2980,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 958..965, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " really", }, ), @@ -2997,7 +2995,7 @@ Module( Literal( StringLiteral { range: 967..973, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bar", flags: StringLiteralFlags { quote_style: Double, @@ -3009,7 +3007,7 @@ Module( Literal( StringLiteral { range: 974..978, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "no", flags: StringLiteralFlags { quote_style: Double, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap index 80e25b5146c21..6dcaa77c6b740 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__generator.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/generator.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..482, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("x"), ctx: Load, @@ -29,10 +29,10 @@ Module( generators: [ Comprehension { range: 3..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..13, id: Name("target"), ctx: Store, @@ -40,7 +40,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..21, id: Name("iter"), ctx: Load, @@ -57,15 +57,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..51, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..51, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Load, @@ -74,10 +74,10 @@ Module( generators: [ Comprehension { range: 26..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..42, id: Name("target"), ctx: Store, @@ -85,7 +85,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..50, id: Name("iter"), ctx: Load, @@ -102,15 +102,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..100, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..100, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("x"), ctx: Load, @@ -119,10 +119,10 @@ Module( generators: [ Comprehension { range: 55..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..65, id: Name("target"), ctx: Store, @@ -130,7 +130,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..73, id: Name("iter"), ctx: Load, @@ -139,11 +139,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..83, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("x"), ctx: Load, @@ -155,7 +155,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("y"), ctx: Load, @@ -166,13 +166,13 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..94, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, id: Name("a"), ctx: Load, @@ -180,7 +180,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("b"), ctx: Load, @@ -191,7 +191,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("c"), ctx: Load, @@ -208,15 +208,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..166, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..166, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("x"), ctx: Load, @@ -225,10 +225,10 @@ Module( generators: [ Comprehension { range: 104..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..115, id: Name("target1"), ctx: Store, @@ -236,7 +236,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..124, id: Name("iter1"), ctx: Load, @@ -245,13 +245,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..135, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("x"), ctx: Load, @@ -259,7 +259,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, id: Name("y"), ctx: Load, @@ -273,10 +273,10 @@ Module( }, Comprehension { range: 136..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..147, id: Name("target2"), ctx: Store, @@ -284,7 +284,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..156, id: Name("iter2"), ctx: Load, @@ -293,11 +293,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..165, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, id: Name("a"), ctx: Load, @@ -309,7 +309,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, id: Name("b"), ctx: Load, @@ -329,15 +329,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..238, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..238, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..169, id: Name("x"), ctx: Load, @@ -346,10 +346,10 @@ Module( generators: [ Comprehension { range: 170..201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..181, id: Name("target1"), ctx: Store, @@ -357,7 +357,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..190, id: Name("iter1"), ctx: Load, @@ -366,13 +366,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..201, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..195, id: Name("x"), ctx: Load, @@ -380,7 +380,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..201, id: Name("y"), ctx: Load, @@ -394,10 +394,10 @@ Module( }, Comprehension { range: 202..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..219, id: Name("target2"), ctx: Store, @@ -405,7 +405,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..228, id: Name("iter2"), ctx: Load, @@ -414,11 +414,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..237, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..233, id: Name("a"), ctx: Load, @@ -430,7 +430,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("b"), ctx: Load, @@ -450,19 +450,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..282, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..282, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..270, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..261, id: Name("x"), ctx: Store, @@ -470,11 +470,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..270, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..266, id: Name("y"), ctx: Load, @@ -483,7 +483,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..270, value: Int( 1, @@ -497,10 +497,10 @@ Module( generators: [ Comprehension { range: 271..281, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 275..276, id: Name("y"), ctx: Store, @@ -508,7 +508,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..281, id: Name("z"), ctx: Load, @@ -525,19 +525,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..326, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..326, elt: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..314, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..307, id: Name("y"), ctx: Load, @@ -545,7 +545,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..302, id: Name("x"), ctx: Load, @@ -553,7 +553,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..314, id: Name("y"), ctx: Load, @@ -564,10 +564,10 @@ Module( generators: [ Comprehension { range: 315..325, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..320, id: Name("y"), ctx: Store, @@ -575,7 +575,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..325, id: Name("z"), ctx: Load, @@ -592,25 +592,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..481, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..481, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..348, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..343, value: StringLiteralValue { inner: Single( StringLiteral { range: 340..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", flags: StringLiteralFlags { quote_style: Double, @@ -625,22 +625,22 @@ Module( attr: Identifier { id: Name("join"), range: 344..348, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 348..481, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..479, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..357, id: Name("sql"), ctx: Load, @@ -649,10 +649,10 @@ Module( generators: [ Comprehension { range: 362..479, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 366..369, id: Name("sql"), ctx: Store, @@ -660,16 +660,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 373..479, elts: [ If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..420, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 405..410, id: Name("limit"), ctx: Load, @@ -677,17 +677,17 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..401, left: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..393, value: StringLiteralValue { inner: Single( StringLiteral { range: 383..393, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "LIMIT %d", flags: StringLiteralFlags { quote_style: Double, @@ -702,7 +702,7 @@ Module( op: Mod, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 396..401, id: Name("limit"), ctx: Load, @@ -712,7 +712,7 @@ Module( ), orelse: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 416..420, }, ), @@ -720,11 +720,11 @@ Module( ), If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..472, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 456..462, id: Name("offset"), ctx: Load, @@ -732,17 +732,17 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 431..451, left: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 431..442, value: StringLiteralValue { inner: Single( StringLiteral { range: 431..442, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "OFFSET %d", flags: StringLiteralFlags { quote_style: Double, @@ -757,7 +757,7 @@ Module( op: Mod, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 445..451, id: Name("offset"), ctx: Load, @@ -767,7 +767,7 @@ Module( ), orelse: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 468..472, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap index f21914594fbae..98ed6f9e96cc8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__if.py.snap @@ -7,27 +7,27 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/if.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..423, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..9, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("a"), ctx: Load, @@ -35,7 +35,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, id: Name("b"), ctx: Load, @@ -47,15 +47,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..35, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..35, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Load, @@ -63,11 +63,11 @@ Module( ), body: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("f"), ctx: Load, @@ -75,7 +75,7 @@ Module( ), arguments: Arguments { range: 18..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -83,7 +83,7 @@ Module( ), orelse: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..35, }, ), @@ -93,15 +93,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..61, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..61, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("b"), ctx: Load, @@ -109,7 +109,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("a"), ctx: Load, @@ -117,11 +117,11 @@ Module( ), orelse: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..61, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("d"), ctx: Load, @@ -129,7 +129,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, id: Name("c"), ctx: Load, @@ -137,7 +137,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("e"), ctx: Load, @@ -151,19 +151,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..84, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..84, test: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..76, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, value: Int( 1, @@ -176,7 +176,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 0, @@ -188,11 +188,11 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..67, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, value: Int( 1, @@ -202,7 +202,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("x"), ctx: Load, @@ -212,12 +212,12 @@ Module( ), orelse: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..84, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 1, @@ -232,15 +232,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..108, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..108, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("x"), ctx: Load, @@ -248,13 +248,13 @@ Module( ), body: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..92, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..86, id: Name("a"), ctx: Load, @@ -262,7 +262,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, id: Name("b"), ctx: Load, @@ -273,7 +273,7 @@ Module( ), orelse: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..108, value: false, }, @@ -284,15 +284,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..127, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..127, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, id: Name("y"), ctx: Load, @@ -300,11 +300,11 @@ Module( ), body: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..115, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..110, id: Name("x"), ctx: Load, @@ -316,7 +316,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, id: Name("y"), ctx: Load, @@ -327,7 +327,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, id: Name("x"), ctx: Load, @@ -339,21 +339,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..154, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..154, test: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..143, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..137, id: Name("a"), ctx: Load, @@ -361,7 +361,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..143, id: Name("b"), ctx: Load, @@ -372,14 +372,14 @@ Module( ), body: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..132, value: true, }, ), orelse: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..154, value: false, }, @@ -390,16 +390,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..171, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..171, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..156, value: Int( 1, @@ -408,11 +408,11 @@ Module( ), If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..171, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, id: Name("a"), ctx: Load, @@ -420,7 +420,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, value: Int( 1, @@ -429,7 +429,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, id: Name("c"), ctx: Load, @@ -446,22 +446,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..240, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..240, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..223, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("x"), ctx: Load, @@ -469,26 +469,24 @@ Module( ), orelse: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..240, parameters: Some( Parameters { range: 236..237, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 236..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 236..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 236..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -502,7 +500,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, id: Name("y"), ctx: Load, @@ -516,20 +514,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..323, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..323, test: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..315, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..315, id: Name("x"), ctx: Load, @@ -540,7 +538,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..303, id: Name("x"), ctx: Load, @@ -548,7 +546,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 322..323, id: Name("y"), ctx: Load, @@ -560,19 +558,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..350, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..350, test: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 330..342, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 341..342, id: Name("x"), ctx: Load, @@ -582,7 +580,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..325, id: Name("x"), ctx: Load, @@ -590,7 +588,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..350, id: Name("y"), ctx: Load, @@ -602,34 +600,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..376, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..376, test: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..368, parameters: Some( Parameters { range: 364..365, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 364..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 364..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 364..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -643,7 +639,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..368, id: Name("x"), ctx: Load, @@ -653,7 +649,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..352, id: Name("x"), ctx: Load, @@ -661,7 +657,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 375..376, id: Name("y"), ctx: Load, @@ -673,15 +669,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 408..423, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..422, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 414..415, id: Name("y"), ctx: Load, @@ -689,7 +685,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 409..410, id: Name("x"), ctx: Load, @@ -697,7 +693,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..422, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap index 9e614f6c7e3a6..29db11b942119 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__lambda.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/lambda.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..530, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, parameters: None, body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("a"), ctx: Load, @@ -33,16 +33,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..19, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..19, parameters: None, body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 1, @@ -55,30 +55,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..31, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..31, parameters: Some( Parameters { range: 27..28, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -92,7 +90,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, value: Int( 1, @@ -105,30 +103,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..48, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..48, parameters: Some( Parameters { range: 39..43, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -136,14 +132,14 @@ Module( }, ParameterWithDefault { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -157,7 +153,7 @@ Module( ), body: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..48, }, ), @@ -167,30 +163,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..66, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..66, parameters: Some( Parameters { range: 56..63, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -198,14 +192,14 @@ Module( }, ParameterWithDefault { range: 59..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 59..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 59..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -213,14 +207,14 @@ Module( }, ParameterWithDefault { range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -234,7 +228,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 1, @@ -247,30 +241,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..90, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..90, parameters: Some( Parameters { range: 74..87, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -278,21 +270,21 @@ Module( }, ParameterWithDefault { range: 77..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 77..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 77..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..81, value: Int( 20, @@ -303,21 +295,21 @@ Module( }, ParameterWithDefault { range: 83..87, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 83..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 83..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..87, value: Int( 30, @@ -334,7 +326,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 1, @@ -347,30 +339,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..109, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..109, parameters: Some( Parameters { range: 98..102, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -378,14 +368,14 @@ Module( }, ParameterWithDefault { range: 101..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 101..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 101..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -399,11 +389,11 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..109, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("x"), ctx: Load, @@ -412,7 +402,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("y"), ctx: Load, @@ -426,30 +416,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..130, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..130, parameters: Some( Parameters { range: 117..123, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 117..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 117..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 117..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -457,21 +445,21 @@ Module( }, ParameterWithDefault { range: 120..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("z"), range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, value: Int( 1, @@ -488,11 +476,11 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..130, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..126, id: Name("z"), ctx: Load, @@ -501,7 +489,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("y"), ctx: Load, @@ -515,28 +503,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..143, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..143, parameters: Some( Parameters { range: 138..140, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 138..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 139..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -547,7 +533,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..143, id: Name("a"), ctx: Load, @@ -559,28 +545,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..166, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..166, parameters: Some( Parameters { range: 151..161, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 151..153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 152..153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -588,14 +572,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 155..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 155..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("z"), range: 155..156, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -603,21 +587,21 @@ Module( }, ParameterWithDefault { range: 158..161, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 158..159, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 158..159, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, value: Int( 0, @@ -632,7 +616,7 @@ Module( ), body: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..166, }, ), @@ -642,32 +626,30 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..187, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..187, parameters: Some( Parameters { range: 174..184, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, kwonlyargs: [ ParameterWithDefault { range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -675,14 +657,14 @@ Module( }, ParameterWithDefault { range: 180..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 180..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 180..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -690,14 +672,14 @@ Module( }, ParameterWithDefault { range: 183..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 183..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 183..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -709,7 +691,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..187, value: Int( 1, @@ -722,32 +704,30 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..214, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..214, parameters: Some( Parameters { range: 195..211, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, kwonlyargs: [ ParameterWithDefault { range: 198..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 198..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 198..199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -755,21 +735,21 @@ Module( }, ParameterWithDefault { range: 201..205, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 201..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 201..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 203..205, value: Int( 20, @@ -780,21 +760,21 @@ Module( }, ParameterWithDefault { range: 207..211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 207..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 207..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 209..211, value: Int( 30, @@ -809,7 +789,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..214, value: Int( 1, @@ -822,30 +802,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..241, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..241, parameters: Some( Parameters { range: 222..238, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -853,14 +831,14 @@ Module( }, ParameterWithDefault { range: 225..226, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 225..226, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 225..226, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -868,14 +846,14 @@ Module( }, ParameterWithDefault { range: 228..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 228..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 228..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -886,14 +864,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 234..235, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 234..235, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 234..235, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -901,14 +879,14 @@ Module( }, ParameterWithDefault { range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 237..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -920,7 +898,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..241, value: Int( 0, @@ -933,18 +911,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..262, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..262, parameters: Some( Parameters { range: 249..257, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -952,11 +928,11 @@ Module( kwarg: Some( Parameter { range: 249..257, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 251..257, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -965,11 +941,11 @@ Module( ), body: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..262, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..260, id: Name("f"), ctx: Load, @@ -977,7 +953,7 @@ Module( ), arguments: Arguments { range: 260..262, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -989,28 +965,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..294, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..294, parameters: Some( Parameters { range: 270..285, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 270..275, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 271..275, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1019,11 +993,11 @@ Module( kwarg: Some( Parameter { range: 277..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 279..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1032,15 +1006,15 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..294, left: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..290, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..288, id: Name("f"), ctx: Load, @@ -1048,7 +1022,7 @@ Module( ), arguments: Arguments { range: 288..290, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1057,7 +1031,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 293..294, value: Int( 1, @@ -1072,28 +1046,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..334, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..334, parameters: Some( Parameters { range: 302..325, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 302..307, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 303..307, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1101,14 +1073,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 309..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 309..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 309..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1116,21 +1088,21 @@ Module( }, ParameterWithDefault { range: 312..315, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 312..313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 312..313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..315, value: Int( 1, @@ -1143,11 +1115,11 @@ Module( kwarg: Some( Parameter { range: 317..325, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 319..325, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1156,15 +1128,15 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..334, left: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..330, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..328, id: Name("f"), ctx: Load, @@ -1172,7 +1144,7 @@ Module( ), arguments: Arguments { range: 328..330, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1181,7 +1153,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..334, value: Int( 1, @@ -1196,29 +1168,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..351, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..351, parameters: Some( Parameters { range: 342..346, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 342..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 342..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 342..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1233,7 +1203,7 @@ Module( ), body: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..351, }, ), @@ -1243,29 +1213,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 352..371, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 352..371, parameters: Some( Parameters { range: 359..366, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 359..360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 359..360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 359..360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1275,14 +1243,14 @@ Module( args: [ ParameterWithDefault { range: 365..366, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 365..366, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 365..366, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1296,7 +1264,7 @@ Module( ), body: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 368..371, }, ), @@ -1306,36 +1274,34 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 372..391, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 372..391, parameters: Some( Parameters { range: 379..386, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 379..382, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 379..380, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 379..380, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 381..382, value: Int( 1, @@ -1353,7 +1319,7 @@ Module( ), body: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 388..391, }, ), @@ -1363,29 +1329,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..417, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..417, parameters: Some( Parameters { range: 399..412, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 399..400, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 399..400, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 399..400, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1393,14 +1357,14 @@ Module( }, ParameterWithDefault { range: 402..403, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 402..403, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 402..403, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1412,14 +1376,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 411..412, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 411..412, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 411..412, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1431,7 +1395,7 @@ Module( ), body: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 414..417, }, ), @@ -1441,37 +1405,35 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 418..440, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 418..440, parameters: Some( Parameters { range: 425..435, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 425..429, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 425..427, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kw"), range: 425..427, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 428..429, value: Int( 1, @@ -1485,14 +1447,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 434..435, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 434..435, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 434..435, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1504,7 +1466,7 @@ Module( ), body: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 437..440, }, ), @@ -1514,29 +1476,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..467, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..467, parameters: Some( Parameters { range: 448..464, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 448..449, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 448..449, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 448..449, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1544,21 +1504,21 @@ Module( }, ParameterWithDefault { range: 451..455, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 451..452, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 451..452, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 453..455, value: Int( 20, @@ -1571,21 +1531,21 @@ Module( args: [ ParameterWithDefault { range: 460..464, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 460..461, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 460..461, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 462..464, value: Int( 30, @@ -1602,7 +1562,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 466..467, value: Int( 1, @@ -1615,29 +1575,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 468..497, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 468..497, parameters: Some( Parameters { range: 475..494, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 475..476, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 475..476, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 475..476, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1645,14 +1603,14 @@ Module( }, ParameterWithDefault { range: 478..479, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 478..479, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 478..479, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1662,14 +1620,14 @@ Module( args: [ ParameterWithDefault { range: 484..485, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 484..485, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 484..485, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1680,14 +1638,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 490..491, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 490..491, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 490..491, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1695,14 +1653,14 @@ Module( }, ParameterWithDefault { range: 493..494, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 493..494, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 493..494, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1714,7 +1672,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 496..497, value: Int( 0, @@ -1727,29 +1685,27 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..530, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..530, parameters: Some( Parameters { range: 505..527, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 505..506, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 505..506, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 505..506, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1757,14 +1713,14 @@ Module( }, ParameterWithDefault { range: 508..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 508..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 508..509, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1774,14 +1730,14 @@ Module( args: [ ParameterWithDefault { range: 514..515, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 514..515, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 514..515, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1791,11 +1747,11 @@ Module( vararg: Some( Parameter { range: 517..519, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 518..519, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1803,14 +1759,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 521..522, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 521..522, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 521..522, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1820,11 +1776,11 @@ Module( kwarg: Some( Parameter { range: 524..527, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 526..527, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1833,7 +1789,7 @@ Module( ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 529..530, value: Int( 0, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap index dec8d0d279234..a12de668bf90c 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/list.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..384, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..17, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..17, elts: [], ctx: Load, @@ -26,16 +26,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, value: Int( 1, @@ -50,16 +50,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..26, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..26, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Int( 1, @@ -74,16 +74,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..36, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..36, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, value: Int( 1, @@ -92,7 +92,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..32, value: Int( 2, @@ -101,7 +101,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, value: Int( 3, @@ -116,16 +116,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..47, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..47, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, value: Int( 1, @@ -134,7 +134,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, value: Int( 2, @@ -143,7 +143,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, value: Int( 3, @@ -158,11 +158,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, elts: [], ctx: Load, @@ -172,16 +172,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..92, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..92, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 1, @@ -196,16 +196,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..114, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..114, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, value: Int( 1, @@ -214,7 +214,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..111, value: Int( 2, @@ -229,26 +229,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..132, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..132, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..131, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, value: Int( 1, @@ -271,21 +271,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..149, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..149, elts: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..140, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, value: Int( 1, @@ -294,7 +294,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..139, value: Int( 2, @@ -307,12 +307,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..148, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..144, value: Int( 3, @@ -321,7 +321,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, value: Int( 4, @@ -340,20 +340,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..178, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..178, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..177, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("x"), ctx: Store, @@ -361,7 +361,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..177, value: Int( 2, @@ -378,20 +378,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..188, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..188, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..186, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..181, id: Name("x"), ctx: Store, @@ -399,7 +399,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..186, value: Int( 2, @@ -416,16 +416,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..203, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..203, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..191, value: Int( 1, @@ -434,11 +434,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..199, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, id: Name("x"), ctx: Store, @@ -446,7 +446,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..199, value: Int( 2, @@ -457,7 +457,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: Int( 3, @@ -472,16 +472,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..233, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..233, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..225, value: Int( 1, @@ -490,11 +490,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..229, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..229, id: Name("x"), ctx: Load, @@ -505,7 +505,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..232, value: Int( 3, @@ -520,16 +520,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..248, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..248, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..236, value: Int( 1, @@ -538,15 +538,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..244, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..244, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, id: Name("x"), ctx: Load, @@ -555,7 +555,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..244, id: Name("y"), ctx: Load, @@ -568,7 +568,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..247, value: Int( 3, @@ -583,20 +583,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..334, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..334, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..277, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..273, value: Int( 1, @@ -606,7 +606,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..277, value: Int( 2, @@ -617,12 +617,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..291, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..281, value: Int( 1, @@ -631,7 +631,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 283..284, value: Int( 2, @@ -640,7 +640,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..287, value: Int( 3, @@ -649,7 +649,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..290, value: Int( 4, @@ -662,12 +662,12 @@ Module( ), Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 293..306, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 294..295, id: Name("a"), ctx: Load, @@ -675,11 +675,11 @@ Module( ), BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 297..302, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 297..298, id: Name("b"), ctx: Load, @@ -688,7 +688,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..302, id: Name("c"), ctx: Load, @@ -698,7 +698,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..305, id: Name("d"), ctx: Load, @@ -711,12 +711,12 @@ Module( ), Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..317, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 309..310, id: Name("a"), ctx: Load, @@ -724,7 +724,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..313, id: Name("b"), ctx: Load, @@ -732,7 +732,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..316, id: Name("c"), ctx: Load, @@ -743,14 +743,14 @@ Module( ), Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..325, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 320..321, id: Name("a"), ctx: Load, @@ -759,7 +759,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 323..324, value: Int( 1, @@ -772,11 +772,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..333, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..328, id: Name("x"), ctx: Store, @@ -784,7 +784,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 332..333, value: Int( 2, @@ -801,20 +801,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..383, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..383, elts: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..382, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..341, id: Name("call1"), ctx: Load, @@ -822,19 +822,19 @@ Module( ), arguments: Arguments { range: 341..382, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..381, elt: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..361, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..347, id: Name("call2"), ctx: Load, @@ -842,19 +842,19 @@ Module( ), arguments: Arguments { range: 347..361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..360, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..358, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..353, id: Name("value"), ctx: Load, @@ -863,14 +863,14 @@ Module( attr: Identifier { id: Name("attr"), range: 354..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 358..360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -884,10 +884,10 @@ Module( generators: [ Comprehension { range: 362..381, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 366..373, id: Name("element"), ctx: Store, @@ -895,7 +895,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 377..381, id: Name("iter"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap index de7a7eb783a04..6f1310b33da71 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__list_comprehension.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/list_comprehen ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..776, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -26,11 +26,11 @@ Module( ], value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..26, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("y"), ctx: Load, @@ -39,10 +39,10 @@ Module( generators: [ Comprehension { range: 7..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("y"), ctx: Store, @@ -50,12 +50,12 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..25, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, value: Int( 1, @@ -64,7 +64,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, value: Int( 2, @@ -73,7 +73,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Int( 3, @@ -95,15 +95,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..49, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..49, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Load, @@ -112,10 +112,10 @@ Module( generators: [ Comprehension { range: 31..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("i"), ctx: Store, @@ -123,11 +123,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..48, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..45, id: Name("range"), ctx: Load, @@ -135,11 +135,11 @@ Module( ), arguments: Arguments { range: 45..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, value: Int( 5, @@ -161,15 +161,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..91, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..91, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("b"), ctx: Load, @@ -178,10 +178,10 @@ Module( generators: [ Comprehension { range: 53..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, id: Name("c"), ctx: Store, @@ -189,7 +189,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("d"), ctx: Load, @@ -198,11 +198,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..73, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("x"), ctx: Load, @@ -214,7 +214,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("w"), ctx: Load, @@ -225,13 +225,13 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..85, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("y"), ctx: Load, @@ -239,7 +239,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..85, id: Name("yy"), ctx: Load, @@ -250,7 +250,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("z"), ctx: Load, @@ -266,15 +266,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..137, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..137, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("a"), ctx: Load, @@ -283,10 +283,10 @@ Module( generators: [ Comprehension { range: 95..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("b"), ctx: Store, @@ -294,7 +294,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("c"), ctx: Load, @@ -303,13 +303,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..116, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..110, id: Name("d"), ctx: Load, @@ -317,7 +317,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, id: Name("e"), ctx: Load, @@ -331,10 +331,10 @@ Module( }, Comprehension { range: 117..136, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..122, id: Name("f"), ctx: Store, @@ -342,7 +342,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, id: Name("j"), ctx: Load, @@ -351,11 +351,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..136, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, id: Name("k"), ctx: Load, @@ -367,7 +367,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, id: Name("h"), ctx: Load, @@ -386,15 +386,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..189, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..189, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, id: Name("a"), ctx: Load, @@ -403,10 +403,10 @@ Module( generators: [ Comprehension { range: 141..162, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..146, id: Name("b"), ctx: Store, @@ -414,7 +414,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..151, id: Name("c"), ctx: Load, @@ -423,13 +423,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..162, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..156, id: Name("d"), ctx: Load, @@ -437,7 +437,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, id: Name("e"), ctx: Load, @@ -451,10 +451,10 @@ Module( }, Comprehension { range: 163..188, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..174, id: Name("f"), ctx: Store, @@ -462,7 +462,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("j"), ctx: Load, @@ -471,11 +471,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..188, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..184, id: Name("k"), ctx: Load, @@ -487,7 +487,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 187..188, id: Name("h"), ctx: Load, @@ -506,15 +506,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..209, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..209, elt: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..192, value: Int( 1, @@ -524,10 +524,10 @@ Module( generators: [ Comprehension { range: 193..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, id: Name("i"), ctx: Store, @@ -535,11 +535,11 @@ Module( ), iter: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..208, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..203, id: Name("x"), ctx: Load, @@ -551,7 +551,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..208, id: Name("a"), ctx: Load, @@ -570,15 +570,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..227, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..227, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, id: Name("a"), ctx: Load, @@ -587,15 +587,15 @@ Module( generators: [ Comprehension { range: 213..226, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..221, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..218, id: Name("a"), ctx: Store, @@ -603,7 +603,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..221, id: Name("b"), ctx: Store, @@ -616,7 +616,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..226, id: Name("G"), ctx: Load, @@ -632,19 +632,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..257, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..257, elt: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..241, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..241, id: Name("x"), ctx: Load, @@ -655,15 +655,15 @@ Module( generators: [ Comprehension { range: 242..255, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..250, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..247, id: Name("a"), ctx: Store, @@ -671,7 +671,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..250, id: Name("b"), ctx: Store, @@ -684,7 +684,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..255, id: Name("C"), ctx: Load, @@ -700,15 +700,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..300, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..300, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..260, id: Name("i"), ctx: Load, @@ -717,10 +717,10 @@ Module( generators: [ Comprehension { range: 261..299, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..266, id: Name("i"), ctx: Store, @@ -728,11 +728,11 @@ Module( ), iter: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..277, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..277, id: Name("x"), ctx: Load, @@ -743,11 +743,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..299, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..287, id: Name("entity"), ctx: Load, @@ -759,7 +759,7 @@ Module( comparators: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..299, }, ), @@ -776,15 +776,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..337, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..337, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 302..303, id: Name("x"), ctx: Load, @@ -793,10 +793,10 @@ Module( generators: [ Comprehension { range: 304..336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..309, id: Name("x"), ctx: Store, @@ -804,18 +804,18 @@ Module( ), iter: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..330, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..323, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 314..315, id: Name("l"), ctx: Load, @@ -823,7 +823,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 329..330, id: Name("L"), ctx: Load, @@ -834,7 +834,7 @@ Module( ifs: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..336, id: Name("T"), ctx: Load, @@ -850,15 +850,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 338..380, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 338..380, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 339..340, id: Name("i"), ctx: Load, @@ -867,10 +867,10 @@ Module( generators: [ Comprehension { range: 341..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..346, id: Name("i"), ctx: Store, @@ -878,22 +878,22 @@ Module( ), iter: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..373, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 362..366, value: true, }, ), body: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..358, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..358, id: Name("x"), ctx: Load, @@ -903,7 +903,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 372..373, id: Name("X"), ctx: Load, @@ -914,7 +914,7 @@ Module( ifs: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 378..379, id: Name("F"), ctx: Load, @@ -930,15 +930,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 381..423, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 381..423, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 382..383, id: Name("i"), ctx: Load, @@ -947,10 +947,10 @@ Module( generators: [ Comprehension { range: 384..422, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 388..389, id: Name("i"), ctx: Store, @@ -958,22 +958,22 @@ Module( ), iter: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 393..417, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..416, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 405..409, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 400..401, id: Name("x"), ctx: Load, @@ -981,7 +981,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 415..416, id: Name("X"), ctx: Load, @@ -994,7 +994,7 @@ Module( ifs: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..422, id: Name("F"), ctx: Load, @@ -1010,15 +1010,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 424..457, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 424..457, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 425..426, id: Name("f"), ctx: Load, @@ -1027,10 +1027,10 @@ Module( generators: [ Comprehension { range: 427..456, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 431..432, id: Name("f"), ctx: Store, @@ -1038,11 +1038,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 436..456, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 436..437, id: Name("c"), ctx: Load, @@ -1050,22 +1050,22 @@ Module( ), arguments: Arguments { range: 437..456, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 438..455, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..447, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 438..439, id: Name("x"), ctx: Load, @@ -1073,7 +1073,7 @@ Module( ), orelse: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 453..455, elts: [], ctx: Load, @@ -1096,15 +1096,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..618, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..618, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 597..598, id: Name("x"), ctx: Load, @@ -1113,10 +1113,10 @@ Module( generators: [ Comprehension { range: 599..617, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 603..604, id: Name("x"), ctx: Store, @@ -1124,12 +1124,12 @@ Module( ), iter: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 609..616, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 615..616, id: Name("y"), ctx: Load, @@ -1148,15 +1148,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 619..646, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 619..646, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 620..621, id: Name("x"), ctx: Load, @@ -1165,10 +1165,10 @@ Module( generators: [ Comprehension { range: 622..645, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 626..627, id: Name("x"), ctx: Store, @@ -1176,11 +1176,11 @@ Module( ), iter: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 632..644, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 643..644, id: Name("y"), ctx: Load, @@ -1198,15 +1198,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 647..673, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 647..673, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 648..649, id: Name("x"), ctx: Load, @@ -1215,10 +1215,10 @@ Module( generators: [ Comprehension { range: 650..672, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 654..655, id: Name("x"), ctx: Store, @@ -1226,26 +1226,24 @@ Module( ), iter: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 660..671, parameters: Some( Parameters { range: 667..668, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 667..668, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 667..668, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 667..668, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1259,7 +1257,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 670..671, id: Name("y"), ctx: Load, @@ -1277,15 +1275,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 674..704, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 674..704, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 675..676, id: Name("x"), ctx: Load, @@ -1294,10 +1292,10 @@ Module( generators: [ Comprehension { range: 677..703, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 681..682, id: Name("x"), ctx: Store, @@ -1305,7 +1303,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..690, id: Name("data"), ctx: Load, @@ -1314,12 +1312,12 @@ Module( ifs: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 695..702, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 701..702, id: Name("y"), ctx: Load, @@ -1338,15 +1336,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 705..740, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 705..740, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 706..707, id: Name("x"), ctx: Load, @@ -1355,10 +1353,10 @@ Module( generators: [ Comprehension { range: 708..739, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 712..713, id: Name("x"), ctx: Store, @@ -1366,7 +1364,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 717..721, id: Name("data"), ctx: Load, @@ -1375,11 +1373,11 @@ Module( ifs: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 726..738, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 737..738, id: Name("y"), ctx: Load, @@ -1397,15 +1395,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 741..775, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 741..775, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 742..743, id: Name("x"), ctx: Load, @@ -1414,10 +1412,10 @@ Module( generators: [ Comprehension { range: 744..774, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 748..749, id: Name("x"), ctx: Store, @@ -1425,7 +1423,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 753..757, id: Name("data"), ctx: Load, @@ -1434,26 +1432,24 @@ Module( ifs: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 762..773, parameters: Some( Parameters { range: 769..770, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 769..770, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 769..770, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 769..770, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1467,7 +1463,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 772..773, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap index 506ee527223dc..b32e08dff6b06 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__name.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/name.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..76, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("_"), ctx: Load, @@ -26,11 +26,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..5, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, id: Name("_"), ctx: Load, @@ -40,11 +40,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, id: Name("__"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..17, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..17, id: Name("__init__"), ctx: Load, @@ -68,11 +68,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..22, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..22, id: Name("name"), ctx: Load, @@ -82,11 +82,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..29, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, id: Name("name"), ctx: Load, @@ -96,11 +96,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..65, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..65, id: Name("match"), ctx: Load, @@ -110,11 +110,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..70, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..70, id: Name("case"), ctx: Load, @@ -124,11 +124,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..75, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..75, id: Name("type"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap index 1ac703b53b2e6..199a11eab69b7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__named.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/named.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..157, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..10, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..5, id: Name("name"), ctx: Store, @@ -28,7 +28,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 0, @@ -41,15 +41,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..29, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..28, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, id: Name("name"), ctx: Store, @@ -57,11 +57,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..27, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -70,7 +70,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("y"), ctx: Load, @@ -84,15 +84,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..45, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..44, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..35, id: Name("name"), ctx: Store, @@ -100,11 +100,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..44, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, value: Int( 1, @@ -114,7 +114,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, value: Int( 1, @@ -129,15 +129,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..63, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..62, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..51, id: Name("name"), ctx: Store, @@ -145,16 +145,16 @@ Module( ), value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..62, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..58, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, id: Name("x"), ctx: Load, @@ -165,7 +165,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("y"), ctx: Load, @@ -182,15 +182,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..90, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..89, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..69, id: Name("name"), ctx: Store, @@ -198,18 +198,18 @@ Module( ), value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..89, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..82, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("x"), ctx: Load, @@ -217,7 +217,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, id: Name("y"), ctx: Load, @@ -231,15 +231,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..112, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..111, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..96, id: Name("name"), ctx: Store, @@ -247,26 +247,24 @@ Module( ), value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..111, parameters: Some( Parameters { range: 107..108, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 107..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 107..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 107..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -280,7 +278,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..111, id: Name("x"), ctx: Load, @@ -294,15 +292,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..132, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..131, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..118, id: Name("name"), ctx: Store, @@ -310,12 +308,12 @@ Module( ), value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..130, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("x"), ctx: Load, @@ -330,15 +328,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..157, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..156, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..138, id: Name("name"), ctx: Store, @@ -346,11 +344,11 @@ Module( ), value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..155, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..155, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap index 46dac564f0a85..ad313fbab1b75 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__number_literal.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/number_literal ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..700, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -26,7 +26,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..13, value: Int( 123456789, @@ -37,12 +37,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..24, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("x"), ctx: Store, @@ -51,7 +51,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..24, value: Int( 123456, @@ -62,12 +62,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..31, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("x"), ctx: Store, @@ -76,7 +76,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..31, value: Float( 0.1, @@ -87,12 +87,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..38, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("x"), ctx: Store, @@ -101,7 +101,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..38, value: Float( 1.0, @@ -112,12 +112,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..47, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("x"), ctx: Store, @@ -126,7 +126,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, value: Float( 10.0, @@ -137,12 +137,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..56, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, id: Name("x"), ctx: Store, @@ -151,7 +151,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..56, value: Float( 0.1, @@ -162,12 +162,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..73, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, id: Name("x"), ctx: Store, @@ -176,7 +176,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..73, value: Float( 1.00000001, @@ -187,12 +187,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..97, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("x"), ctx: Store, @@ -201,7 +201,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..97, value: Float( 123456789.12345679, @@ -212,12 +212,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..131, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("x"), ctx: Store, @@ -226,7 +226,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..131, value: Float( inf, @@ -237,12 +237,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..155, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("x"), ctx: Store, @@ -251,7 +251,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..155, value: Float( inf, @@ -262,12 +262,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..170, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("x"), ctx: Store, @@ -276,7 +276,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..170, value: Complex { real: 0.0, @@ -288,12 +288,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..195, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("x"), ctx: Store, @@ -302,7 +302,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..195, value: Complex { real: 0.0, @@ -314,12 +314,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..207, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..197, id: Name("x"), ctx: Store, @@ -328,7 +328,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..207, value: Int( 727756, @@ -339,12 +339,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..218, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..209, id: Name("x"), ctx: Store, @@ -353,7 +353,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..218, value: Int( 11, @@ -364,12 +364,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..228, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..220, id: Name("x"), ctx: Store, @@ -378,7 +378,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..228, value: Int( 511, @@ -389,12 +389,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..244, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..230, id: Name("x"), ctx: Store, @@ -403,7 +403,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..244, value: Float( 6e-9, @@ -414,12 +414,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..254, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, id: Name("x"), ctx: Store, @@ -428,7 +428,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..254, value: Int( 10000, @@ -439,12 +439,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..265, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..256, id: Name("x"), ctx: Store, @@ -453,7 +453,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..265, value: Int( 133333, @@ -464,12 +464,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..298, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..287, id: Name("x"), ctx: Store, @@ -478,11 +478,11 @@ Module( ], value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..298, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..292, value: Float( 1.0, @@ -492,7 +492,7 @@ Module( attr: Identifier { id: Name("imag"), range: 294..298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -501,12 +501,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..312, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..300, id: Name("x"), ctx: Store, @@ -515,11 +515,11 @@ Module( ], value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..312, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..307, value: Float( 10.0, @@ -529,7 +529,7 @@ Module( attr: Identifier { id: Name("imag"), range: 308..312, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -538,12 +538,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..326, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..314, id: Name("x"), ctx: Store, @@ -552,11 +552,11 @@ Module( ], value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..326, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..321, value: Float( 0.1, @@ -566,7 +566,7 @@ Module( attr: Identifier { id: Name("real"), range: 322..326, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -575,12 +575,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..356, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..328, id: Name("x"), ctx: Store, @@ -589,15 +589,15 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..356, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..354, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..350, value: Float( 123456789.12345679, @@ -607,14 +607,14 @@ Module( attr: Identifier { id: Name("hex"), range: 351..354, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 354..356, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -624,12 +624,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..396, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 357..358, id: Name("x"), ctx: Store, @@ -638,11 +638,11 @@ Module( ], value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 361..396, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 361..390, value: Float( inf, @@ -652,7 +652,7 @@ Module( attr: Identifier { id: Name("real"), range: 392..396, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -661,12 +661,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 397..433, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 397..398, id: Name("x"), ctx: Store, @@ -675,15 +675,15 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..433, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..431, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..420, value: Float( inf, @@ -693,14 +693,14 @@ Module( attr: Identifier { id: Name("conjugate"), range: 422..431, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 431..433, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -710,12 +710,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 434..453, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 434..435, id: Name("x"), ctx: Store, @@ -724,11 +724,11 @@ Module( ], value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 438..453, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 438..448, value: Complex { real: 0.0, @@ -739,7 +739,7 @@ Module( attr: Identifier { id: Name("real"), range: 449..453, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -748,12 +748,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 454..507, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 454..455, id: Name("x"), ctx: Store, @@ -762,15 +762,15 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..507, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..486, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..478, value: Complex { real: 0.0, @@ -781,26 +781,26 @@ Module( attr: Identifier { id: Name("__add__"), range: 479..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 486..507, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 487..506, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 487..504, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 487..493, value: Int( 11, @@ -810,14 +810,14 @@ Module( attr: Identifier { id: Name("bit_length"), range: 494..504, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 504..506, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -832,12 +832,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 508..531, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 508..509, id: Name("x"), ctx: Store, @@ -846,15 +846,15 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 512..531, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 512..529, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 512..519, value: Int( 727756, @@ -864,14 +864,14 @@ Module( attr: Identifier { id: Name("conjugate"), range: 520..529, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 529..531, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -881,12 +881,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 532..555, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 532..533, id: Name("x"), ctx: Store, @@ -895,15 +895,15 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 536..555, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 536..553, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 536..542, value: Int( 11, @@ -913,14 +913,14 @@ Module( attr: Identifier { id: Name("conjugate"), range: 544..553, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 553..555, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -930,12 +930,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 556..571, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 556..557, id: Name("x"), ctx: Store, @@ -944,11 +944,11 @@ Module( ], value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 560..571, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 560..565, value: Int( 511, @@ -958,7 +958,7 @@ Module( attr: Identifier { id: Name("real"), range: 567..571, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -967,12 +967,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..595, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..573, id: Name("x"), ctx: Store, @@ -981,15 +981,15 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 576..595, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 576..593, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 576..587, value: Float( 6e-9, @@ -999,14 +999,14 @@ Module( attr: Identifier { id: Name("hex"), range: 590..593, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 593..595, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1016,12 +1016,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..610, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 596..597, id: Name("x"), ctx: Store, @@ -1030,12 +1030,12 @@ Module( ], value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 600..610, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 601..610, value: Complex { real: 0.0, @@ -1049,15 +1049,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 612..632, test: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 615..623, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 615..617, value: Int( 10, @@ -1067,7 +1067,7 @@ Module( attr: Identifier { id: Name("real"), range: 619..623, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -1075,11 +1075,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 629..632, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 629..632, }, ), @@ -1091,12 +1091,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 677..688, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 677..678, id: Name("y"), ctx: Store, @@ -1105,11 +1105,11 @@ Module( ], value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 681..688, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 681..684, value: Int( 100, @@ -1118,7 +1118,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 685..687, id: Name("no"), ctx: Load, @@ -1131,12 +1131,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 689..700, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 689..690, id: Name("y"), ctx: Store, @@ -1145,11 +1145,11 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 693..700, func: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 693..696, value: Int( 100, @@ -1158,11 +1158,11 @@ Module( ), arguments: Arguments { range: 696..700, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 697..699, id: Name("no"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap index 747ed8ee3dece..9854d74ac153b 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__parenthesized.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/parenthesized. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..92, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..5, id: Name("expr"), ctx: Load, @@ -26,15 +26,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..15, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..15, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..12, id: Name("expr"), ctx: Load, @@ -42,7 +42,7 @@ Module( ), arguments: Arguments { range: 13..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -52,23 +52,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..28, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..28, func: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..26, func: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..24, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..21, id: Name("expr"), ctx: Load, @@ -76,7 +76,7 @@ Module( ), arguments: Arguments { range: 22..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -84,7 +84,7 @@ Module( ), arguments: Arguments { range: 24..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -92,7 +92,7 @@ Module( ), arguments: Arguments { range: 26..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -102,23 +102,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..44, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..43, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..38, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..32, id: Name("a"), ctx: Load, @@ -126,7 +126,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, id: Name("b"), ctx: Load, @@ -137,7 +137,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, id: Name("c"), ctx: Load, @@ -150,30 +150,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..58, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..57, parameters: Some( Parameters { range: 53..54, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -187,7 +185,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Load, @@ -199,15 +197,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..67, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..66, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("x"), ctx: Store, @@ -215,7 +213,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 2, @@ -228,16 +226,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..77, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..76, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("x"), ctx: Load, @@ -250,15 +248,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..92, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..91, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap index eb99b5e4d078c..e65e97a2b8fb2 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/set.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..313, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..16, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..16, items: [], }, @@ -25,16 +25,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..20, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 1, @@ -48,16 +48,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..25, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..25, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, value: Int( 1, @@ -71,16 +71,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..35, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..35, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, value: Int( 1, @@ -89,7 +89,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, value: Int( 2, @@ -98,7 +98,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, value: Int( 3, @@ -112,16 +112,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..46, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..46, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, value: Int( 1, @@ -130,7 +130,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, value: Int( 2, @@ -139,7 +139,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, value: Int( 3, @@ -153,11 +153,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..77, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..77, items: [], }, @@ -166,16 +166,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..91, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..91, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, value: Int( 1, @@ -189,16 +189,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..113, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..113, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, value: Int( 1, @@ -207,7 +207,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..110, value: Int( 2, @@ -221,21 +221,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..129, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..129, elts: [ Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..128, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, value: Int( 1, @@ -252,21 +252,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..146, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..146, elts: [ Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..137, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, value: Int( 1, @@ -275,7 +275,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, value: Int( 2, @@ -287,12 +287,12 @@ Module( ), Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..145, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, value: Int( 3, @@ -301,7 +301,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..144, value: Int( 4, @@ -318,20 +318,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..175, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..175, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..174, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..169, id: Name("x"), ctx: Store, @@ -339,7 +339,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..174, value: Int( 2, @@ -355,16 +355,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..190, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..190, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..178, value: Int( 1, @@ -373,11 +373,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..186, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 180..181, id: Name("x"), ctx: Store, @@ -385,7 +385,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..186, value: Int( 2, @@ -396,7 +396,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..189, value: Int( 3, @@ -410,16 +410,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..205, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..205, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, value: Int( 1, @@ -428,11 +428,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..202, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..197, id: Name("x"), ctx: Store, @@ -440,7 +440,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, value: Int( 2, @@ -456,16 +456,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..235, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..235, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..227, value: Int( 1, @@ -474,11 +474,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..231, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..231, id: Name("x"), ctx: Load, @@ -489,7 +489,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..234, value: Int( 3, @@ -503,16 +503,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..250, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..250, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..238, value: Int( 1, @@ -521,15 +521,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..246, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..246, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, id: Name("x"), ctx: Load, @@ -538,7 +538,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, id: Name("y"), ctx: Load, @@ -551,7 +551,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 248..249, value: Int( 3, @@ -565,20 +565,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 273..312, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 273..312, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..279, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..275, value: Int( 1, @@ -588,7 +588,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..279, value: Int( 2, @@ -599,12 +599,12 @@ Module( ), Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..287, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..283, id: Name("a"), ctx: Load, @@ -612,7 +612,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 285..286, id: Name("b"), ctx: Load, @@ -625,12 +625,12 @@ Module( ), Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..298, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..291, value: Int( 1, @@ -639,7 +639,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 293..294, value: Int( 2, @@ -648,7 +648,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..297, value: Int( 3, @@ -660,14 +660,14 @@ Module( ), Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..311, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..302, id: Name("a"), ctx: Load, @@ -676,7 +676,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..305, id: Name("b"), ctx: Load, @@ -687,7 +687,7 @@ Module( key: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 309..310, id: Name("d"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap index 8ead74d20d457..5482a567fce87 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__set_comprehension.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/set_comprehens ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..492, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("x"), ctx: Load, @@ -29,10 +29,10 @@ Module( generators: [ Comprehension { range: 3..14, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("i"), ctx: Store, @@ -40,7 +40,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..14, id: Name("ll"), ctx: Load, @@ -56,15 +56,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..57, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..57, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("b"), ctx: Load, @@ -73,10 +73,10 @@ Module( generators: [ Comprehension { range: 19..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("c"), ctx: Store, @@ -84,7 +84,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("d"), ctx: Load, @@ -93,11 +93,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..39, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, id: Name("x"), ctx: Load, @@ -109,7 +109,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("w"), ctx: Load, @@ -120,13 +120,13 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..51, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("y"), ctx: Load, @@ -134,7 +134,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..51, id: Name("yy"), ctx: Load, @@ -145,7 +145,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, id: Name("z"), ctx: Load, @@ -161,15 +161,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..103, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..103, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("a"), ctx: Load, @@ -178,10 +178,10 @@ Module( generators: [ Comprehension { range: 61..82, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("b"), ctx: Store, @@ -189,7 +189,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("c"), ctx: Load, @@ -198,13 +198,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..82, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("d"), ctx: Load, @@ -212,7 +212,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, id: Name("e"), ctx: Load, @@ -226,10 +226,10 @@ Module( }, Comprehension { range: 83..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, id: Name("f"), ctx: Store, @@ -237,7 +237,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, id: Name("j"), ctx: Load, @@ -246,11 +246,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..102, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, id: Name("k"), ctx: Load, @@ -262,7 +262,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, id: Name("h"), ctx: Load, @@ -281,15 +281,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..155, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..155, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, id: Name("a"), ctx: Load, @@ -298,10 +298,10 @@ Module( generators: [ Comprehension { range: 107..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..112, id: Name("b"), ctx: Store, @@ -309,7 +309,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, id: Name("c"), ctx: Load, @@ -318,13 +318,13 @@ Module( ifs: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..128, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..122, id: Name("d"), ctx: Load, @@ -332,7 +332,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("e"), ctx: Load, @@ -346,10 +346,10 @@ Module( }, Comprehension { range: 129..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, id: Name("f"), ctx: Store, @@ -357,7 +357,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..145, id: Name("j"), ctx: Load, @@ -366,11 +366,11 @@ Module( ifs: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..154, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, id: Name("k"), ctx: Load, @@ -382,7 +382,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..154, id: Name("h"), ctx: Load, @@ -401,15 +401,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..173, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..173, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, id: Name("a"), ctx: Load, @@ -418,15 +418,15 @@ Module( generators: [ Comprehension { range: 159..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..167, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, id: Name("a"), ctx: Store, @@ -434,7 +434,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("b"), ctx: Store, @@ -447,7 +447,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..172, id: Name("G"), ctx: Load, @@ -463,15 +463,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..334, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..334, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..314, id: Name("x"), ctx: Load, @@ -480,10 +480,10 @@ Module( generators: [ Comprehension { range: 315..333, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..320, id: Name("x"), ctx: Store, @@ -491,12 +491,12 @@ Module( ), iter: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 325..332, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..332, id: Name("y"), ctx: Load, @@ -515,15 +515,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..362, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..362, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..337, id: Name("x"), ctx: Load, @@ -532,10 +532,10 @@ Module( generators: [ Comprehension { range: 338..361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 342..343, id: Name("x"), ctx: Store, @@ -543,11 +543,11 @@ Module( ), iter: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..360, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 359..360, id: Name("y"), ctx: Load, @@ -565,15 +565,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 363..389, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 363..389, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..365, id: Name("x"), ctx: Load, @@ -582,10 +582,10 @@ Module( generators: [ Comprehension { range: 366..388, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 370..371, id: Name("x"), ctx: Store, @@ -593,26 +593,24 @@ Module( ), iter: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..387, parameters: Some( Parameters { range: 383..384, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 383..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 383..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 383..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -626,7 +624,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..387, id: Name("y"), ctx: Load, @@ -644,15 +642,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..420, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..420, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 391..392, id: Name("x"), ctx: Load, @@ -661,10 +659,10 @@ Module( generators: [ Comprehension { range: 393..419, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 397..398, id: Name("x"), ctx: Store, @@ -672,7 +670,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 402..406, id: Name("data"), ctx: Load, @@ -681,12 +679,12 @@ Module( ifs: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 411..418, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 417..418, id: Name("y"), ctx: Load, @@ -705,15 +703,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..456, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..456, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 422..423, id: Name("x"), ctx: Load, @@ -722,10 +720,10 @@ Module( generators: [ Comprehension { range: 424..455, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 428..429, id: Name("x"), ctx: Store, @@ -733,7 +731,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 433..437, id: Name("data"), ctx: Load, @@ -742,11 +740,11 @@ Module( ifs: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 442..454, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 453..454, id: Name("y"), ctx: Load, @@ -764,15 +762,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 457..491, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 457..491, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..459, id: Name("x"), ctx: Load, @@ -781,10 +779,10 @@ Module( generators: [ Comprehension { range: 460..490, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..465, id: Name("x"), ctx: Store, @@ -792,7 +790,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 469..473, id: Name("data"), ctx: Load, @@ -801,26 +799,24 @@ Module( ifs: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 478..489, parameters: Some( Parameters { range: 485..486, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 485..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 485..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 485..486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -834,7 +830,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 488..489, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap index c04177fae75bd..d19e76dab3bec 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__slice.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/slice.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..211, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..27, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..27, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("x"), ctx: Load, @@ -28,7 +28,7 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, lower: None, upper: None, @@ -42,15 +42,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..33, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..33, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("x"), ctx: Load, @@ -58,12 +58,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..32, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..31, value: Int( 1, @@ -82,15 +82,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..39, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..39, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("x"), ctx: Load, @@ -98,13 +98,13 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..38, lower: None, upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, value: Int( 2, @@ -122,15 +122,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..46, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..46, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("x"), ctx: Load, @@ -138,12 +138,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, value: Int( 1, @@ -154,7 +154,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, value: Int( 2, @@ -172,15 +172,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..52, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Load, @@ -188,7 +188,7 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..51, lower: None, upper: None, @@ -202,15 +202,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..59, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..59, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("x"), ctx: Load, @@ -218,12 +218,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, value: Int( 1, @@ -242,15 +242,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..66, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..66, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("x"), ctx: Load, @@ -258,13 +258,13 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, lower: None, upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, value: Int( 2, @@ -282,15 +282,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..74, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..74, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("x"), ctx: Load, @@ -298,12 +298,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..73, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, value: Int( 1, @@ -314,7 +314,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, value: Int( 2, @@ -332,15 +332,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..81, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..81, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("x"), ctx: Load, @@ -348,14 +348,14 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..80, lower: None, upper: None, step: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 3, @@ -372,15 +372,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..89, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..89, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("x"), ctx: Load, @@ -388,12 +388,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..88, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, value: Int( 1, @@ -405,7 +405,7 @@ Module( step: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..88, value: Int( 3, @@ -422,15 +422,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..97, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..97, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("x"), ctx: Load, @@ -438,13 +438,13 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..96, lower: None, upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, value: Int( 2, @@ -455,7 +455,7 @@ Module( step: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..96, value: Int( 3, @@ -472,15 +472,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..106, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..106, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("x"), ctx: Load, @@ -488,12 +488,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..105, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, value: Int( 1, @@ -504,7 +504,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, value: Int( 2, @@ -515,7 +515,7 @@ Module( step: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, value: Int( 3, @@ -532,15 +532,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..136, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..136, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("x"), ctx: Load, @@ -548,11 +548,11 @@ Module( ), slice: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..135, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("y"), ctx: Store, @@ -560,7 +560,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, value: Int( 2, @@ -576,15 +576,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..149, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..149, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("x"), ctx: Load, @@ -592,16 +592,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..148, lower: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..146, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..141, id: Name("y"), ctx: Store, @@ -609,7 +609,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..146, value: Int( 2, @@ -630,15 +630,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..160, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..160, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..151, id: Name("x"), ctx: Load, @@ -646,16 +646,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..159, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..158, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..153, id: Name("y"), ctx: Store, @@ -663,7 +663,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, value: Int( 2, @@ -684,15 +684,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..210, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..210, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..203, id: Name("x"), ctx: Load, @@ -700,12 +700,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..209, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..205, value: Int( 1, @@ -714,13 +714,13 @@ Module( ), Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..208, lower: None, upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..208, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap index a4fe4f78b4714..be5cfdc577d60 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__starred.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/starred.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..172, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..2, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..2, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("a"), ctx: Load, @@ -33,19 +33,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..11, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..11, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("a"), ctx: Load, @@ -54,7 +54,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 1, @@ -70,19 +70,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..19, value: Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..19, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..19, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, id: Name("x"), ctx: Load, @@ -91,7 +91,7 @@ Module( attr: Identifier { id: Name("attr"), range: 15..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -103,12 +103,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..57, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..32, id: Name("array_slice"), ctx: Store, @@ -117,11 +117,11 @@ Module( ], value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..57, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..40, id: Name("array"), ctx: Load, @@ -129,12 +129,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..56, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, value: Int( 0, @@ -143,11 +143,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..52, id: Name("indexes"), ctx: Load, @@ -158,12 +158,12 @@ Module( ), UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..56, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, value: Int( 1, @@ -184,16 +184,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..94, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..80, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..63, id: Name("array"), ctx: Load, @@ -201,12 +201,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..79, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, value: Int( 0, @@ -215,11 +215,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..75, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..75, id: Name("indexes"), ctx: Load, @@ -230,12 +230,12 @@ Module( ), UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..79, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 1, @@ -255,7 +255,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..94, id: Name("array_slice"), ctx: Load, @@ -265,15 +265,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..140, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..140, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..100, id: Name("array"), ctx: Load, @@ -281,16 +281,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..139, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..119, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..119, id: Name("indexes_to_select"), ctx: Load, @@ -301,11 +301,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..139, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..139, id: Name("indexes_to_select"), ctx: Load, @@ -326,15 +326,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..171, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..171, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..146, id: Name("array"), ctx: Load, @@ -342,17 +342,17 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..170, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..150, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..148, value: Int( 3, @@ -363,7 +363,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, value: Int( 5, @@ -376,11 +376,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..170, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..170, id: Name("indexes_to_select"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__string.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__string.py.snap index f9480bed422c7..e03b149d1a65d 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__string.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__string.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/string.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..163, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, value: StringLiteralValue { inner: Single( StringLiteral { range: 0..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello World", flags: StringLiteralFlags { quote_style: Single, @@ -38,17 +38,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..20, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..20, value: StringLiteralValue { inner: Single( StringLiteral { range: 14..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "😎", flags: StringLiteralFlags { quote_style: Double, @@ -64,11 +64,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..32, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..32, value: StringLiteralValue { inner: Concatenated( @@ -76,7 +76,7 @@ Module( strings: [ StringLiteral { range: 21..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Foo", flags: StringLiteralFlags { quote_style: Single, @@ -86,7 +86,7 @@ Module( }, StringLiteral { range: 27..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Bar", flags: StringLiteralFlags { quote_style: Single, @@ -105,11 +105,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..60, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..58, value: StringLiteralValue { inner: Concatenated( @@ -117,7 +117,7 @@ Module( strings: [ StringLiteral { range: 39..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "A", flags: StringLiteralFlags { quote_style: Single, @@ -127,7 +127,7 @@ Module( }, StringLiteral { range: 47..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "B", flags: StringLiteralFlags { quote_style: Single, @@ -137,7 +137,7 @@ Module( }, StringLiteral { range: 55..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "C", flags: StringLiteralFlags { quote_style: Single, @@ -156,17 +156,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..79, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..79, value: StringLiteralValue { inner: Single( StringLiteral { range: 61..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Olá, Mundo!", flags: StringLiteralFlags { quote_style: Single, @@ -182,17 +182,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..91, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..91, value: StringLiteralValue { inner: Single( StringLiteral { range: 80..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "ABCDE", flags: StringLiteralFlags { quote_style: Double, @@ -208,11 +208,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..121, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..119, value: StringLiteralValue { inner: Concatenated( @@ -220,7 +220,7 @@ Module( strings: [ StringLiteral { range: 98..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "aB", flags: StringLiteralFlags { quote_style: Single, @@ -230,7 +230,7 @@ Module( }, StringLiteral { range: 111..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "cD", flags: StringLiteralFlags { quote_style: Single, @@ -249,17 +249,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..136, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..136, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 122..136, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 104, 101, @@ -287,18 +287,18 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..161, value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..161, value: BytesLiteralValue { inner: Concatenated( [ BytesLiteral { range: 137..145, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 98, 121, @@ -314,7 +314,7 @@ Module( }, BytesLiteral { range: 146..161, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [ 99, 111, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap index f90b4a3033bf7..8407b7a8d8c56 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__subscript.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/subscript.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..266, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..7, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..4, id: Name("data"), ctx: Load, @@ -32,7 +32,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 0, @@ -44,7 +44,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 0, @@ -58,15 +58,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..21, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..21, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..15, id: Name("data"), ctx: Load, @@ -74,12 +74,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..20, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, value: Int( 0, @@ -88,7 +88,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, value: Int( 1, @@ -107,15 +107,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..31, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..31, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..26, id: Name("data"), ctx: Load, @@ -123,17 +123,17 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..29, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, value: Int( 0, @@ -157,15 +157,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..43, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..43, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..36, id: Name("data"), ctx: Load, @@ -173,17 +173,17 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..42, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..39, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, value: Int( 0, @@ -197,7 +197,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, value: Int( 1, @@ -216,15 +216,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..48, id: Name("data"), ctx: Load, @@ -232,17 +232,17 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..55, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, value: Int( 0, @@ -253,7 +253,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 1, @@ -266,7 +266,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 2, @@ -285,15 +285,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..80, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..80, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..61, id: Name("data"), ctx: Load, @@ -301,17 +301,17 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..79, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..67, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, value: Int( 0, @@ -322,7 +322,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, value: Int( 1, @@ -333,7 +333,7 @@ Module( step: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, value: Int( 2, @@ -345,7 +345,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, value: Int( 3, @@ -354,12 +354,12 @@ Module( ), Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..79, lower: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("a"), ctx: Load, @@ -369,11 +369,11 @@ Module( upper: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..79, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("b"), ctx: Load, @@ -382,7 +382,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 1, @@ -407,15 +407,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..93, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..93, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..85, id: Name("data"), ctx: Load, @@ -423,11 +423,11 @@ Module( ), slice: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..92, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, id: Name("a"), ctx: Store, @@ -435,7 +435,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, id: Name("b"), ctx: Load, @@ -450,15 +450,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..106, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..106, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..98, id: Name("data"), ctx: Load, @@ -466,12 +466,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..105, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, lower: None, upper: None, @@ -480,13 +480,13 @@ Module( ), Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..105, lower: None, upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..105, value: Int( 11, @@ -509,15 +509,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..120, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..120, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..111, id: Name("data"), ctx: Load, @@ -525,12 +525,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..119, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, value: Int( 1, @@ -539,7 +539,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, value: Int( 2, @@ -548,7 +548,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, value: Int( 3, @@ -567,15 +567,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..132, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..132, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..125, id: Name("data"), ctx: Load, @@ -583,12 +583,12 @@ Module( ), slice: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..131, op: Invert, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..131, id: Name("flag"), ctx: Load, @@ -603,15 +603,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..148, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..148, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..137, id: Name("data"), ctx: Load, @@ -619,16 +619,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..147, lower: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..145, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, id: Name("a"), ctx: Store, @@ -636,7 +636,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..145, value: Int( 0, @@ -657,15 +657,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..165, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..165, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..153, id: Name("data"), ctx: Load, @@ -673,16 +673,16 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..164, lower: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..161, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..156, id: Name("a"), ctx: Store, @@ -690,7 +690,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, value: Int( 0, @@ -703,7 +703,7 @@ Module( upper: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, id: Name("y"), ctx: Load, @@ -720,15 +720,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..234, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..234, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..230, id: Name("data"), ctx: Load, @@ -736,16 +736,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..233, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..233, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..233, id: Name("x"), ctx: Load, @@ -766,15 +766,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..249, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..249, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..239, id: Name("data"), ctx: Load, @@ -782,22 +782,22 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..248, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..248, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..248, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, id: Name("x"), ctx: Load, @@ -805,7 +805,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 247..248, id: Name("y"), ctx: Load, @@ -829,15 +829,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..265, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..265, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..254, id: Name("data"), ctx: Load, @@ -845,20 +845,20 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..264, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..264, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..263, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..258, id: Name("x"), ctx: Store, @@ -866,7 +866,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..263, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap index c2ee44b3be7a5..2233e19dc5e9f 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__t_string.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/t_string.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..864, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..21, value: TStringValue { inner: Single( TString { range: 18..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: TStringFlags { quote_style: Double, @@ -38,17 +38,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, value: TStringValue { inner: Single( TString { range: 22..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: TStringFlags { quote_style: Double, @@ -64,17 +64,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: TStringValue { inner: Single( TString { range: 26..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: TStringFlags { quote_style: Single, @@ -90,17 +90,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..37, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..37, value: TStringValue { inner: Single( TString { range: 30..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: TStringFlags { quote_style: Double, @@ -116,17 +116,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..45, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..45, value: TStringValue { inner: Single( TString { range: 38..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], flags: TStringFlags { quote_style: Single, @@ -142,31 +142,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..56, value: TStringValue { inner: Single( TString { range: 47..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 49..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..54, value: StringLiteralValue { inner: Single( StringLiteral { range: 50..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " t", flags: StringLiteralFlags { quote_style: Double, @@ -198,25 +198,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..67, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..67, value: TStringValue { inner: Single( TString { range: 57..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 59..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, id: Name("foo"), ctx: Load, @@ -242,30 +242,30 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..75, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..75, value: TStringValue { inner: Single( TString { range: 68..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 70..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..73, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, value: Int( 3, @@ -297,29 +297,29 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..86, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..86, value: TStringValue { inner: Single( TString { range: 76..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 78..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..83, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 3, @@ -332,7 +332,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 4, @@ -347,7 +347,7 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 84..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], }, ), @@ -368,25 +368,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..102, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..102, value: TStringValue { inner: Single( TString { range: 87..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 89..101, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, value: Int( 3, @@ -398,21 +398,21 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 92..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 92..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, value: StringLiteralValue { inner: Single( StringLiteral { range: 93..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "}", flags: StringLiteralFlags { quote_style: Double, @@ -432,7 +432,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 97..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ">10", }, ), @@ -456,25 +456,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..118, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..118, value: TStringValue { inner: Single( TString { range: 103..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 105..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..107, value: Int( 3, @@ -486,21 +486,21 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 108..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 108..113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, value: StringLiteralValue { inner: Single( StringLiteral { range: 109..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "{", flags: StringLiteralFlags { quote_style: Double, @@ -520,7 +520,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 113..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ">10", }, ), @@ -544,25 +544,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..133, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..133, value: TStringValue { inner: Single( TString { range: 119..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 121..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..127, id: Name("foo"), ctx: Load, @@ -593,25 +593,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..154, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..154, value: TStringValue { inner: Single( TString { range: 134..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 136..153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..142, id: Name("foo"), ctx: Load, @@ -627,12 +627,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 147..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 147..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f ", }, ), @@ -656,25 +656,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..173, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..173, value: TStringValue { inner: Single( TString { range: 155..173, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 157..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..163, id: Name("foo"), ctx: Load, @@ -705,30 +705,30 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..190, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..190, value: TStringValue { inner: Single( TString { range: 174..190, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 176..189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..183, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, value: Int( 1, @@ -737,7 +737,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..183, value: Int( 2, @@ -774,39 +774,39 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..217, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..217, value: TStringValue { inner: Single( TString { range: 191..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 193..216, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..210, value: TStringValue { inner: Single( TString { range: 194..210, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 196..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..203, value: Float( 3.1415, @@ -823,12 +823,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 205..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 205..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".1f", }, ), @@ -853,12 +853,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 211..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 211..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "*^20", }, ), @@ -882,30 +882,30 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..255, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..255, items: [ DictItem { key: Some( TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 220..250, value: TStringValue { inner: Concatenated( [ TString { range: 220..227, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 222..226, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo ", }, ), @@ -918,26 +918,26 @@ Module( }, TString { range: 228..243, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 230..234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bar ", }, ), Interpolation( InterpolatedElement { range: 234..241, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..240, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..236, id: Name("x"), ctx: Load, @@ -946,7 +946,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, id: Name("y"), ctx: Load, @@ -962,7 +962,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 241..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), @@ -975,12 +975,12 @@ Module( }, TString { range: 244..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 246..249, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "baz", }, ), @@ -999,7 +999,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..254, value: Int( 10, @@ -1014,11 +1014,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 256..347, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..265, id: Name("foo"), ctx: Load, @@ -1027,20 +1027,20 @@ Module( cases: [ MatchCase { range: 271..295, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 276..281, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..281, value: StringLiteralValue { inner: Single( StringLiteral { range: 276..281, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "one", flags: StringLiteralFlags { quote_style: Double, @@ -1058,7 +1058,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 291..295, }, ), @@ -1066,14 +1066,14 @@ Module( }, MatchCase { range: 300..347, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 305..333, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 305..333, value: StringLiteralValue { inner: Concatenated( @@ -1081,7 +1081,7 @@ Module( strings: [ StringLiteral { range: 305..318, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "implicitly ", flags: StringLiteralFlags { quote_style: Double, @@ -1091,7 +1091,7 @@ Module( }, StringLiteral { range: 319..333, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "concatenated", flags: StringLiteralFlags { quote_style: Double, @@ -1112,7 +1112,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 343..347, }, ), @@ -1123,32 +1123,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..366, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 349..366, value: TStringValue { inner: Single( TString { range: 349..366, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 351..352, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), Interpolation( InterpolatedElement { range: 352..357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 353..356, id: Name("foo"), ctx: Load, @@ -1162,17 +1162,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 357..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), Interpolation( InterpolatedElement { range: 358..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 359..362, id: Name("bar"), ctx: Load, @@ -1183,12 +1183,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 363..364, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 363..364, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\", }, ), @@ -1212,22 +1212,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..381, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..381, value: TStringValue { inner: Single( TString { range: 367..381, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 369..380, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\\{foo\\}", }, ), @@ -1246,25 +1246,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 382..422, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 382..422, value: TStringValue { inner: Single( TString { range: 382..422, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 386..419, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 392..395, id: Name("foo"), ctx: Load, @@ -1275,12 +1275,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 396..418, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 396..418, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "x\n y\n z\n", }, ), @@ -1304,25 +1304,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 423..441, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 423..441, value: TStringValue { inner: Single( TString { range: 423..441, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 425..440, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..433, id: Name("foo"), ctx: Load, @@ -1353,32 +1353,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..488, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..488, value: TStringValue { inner: Single( TString { range: 443..488, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 445..452, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "normal ", }, ), Interpolation( InterpolatedElement { range: 452..457, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 453..456, id: Name("foo"), ctx: Load, @@ -1392,17 +1392,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 457..470, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " {another} ", }, ), Interpolation( InterpolatedElement { range: 470..475, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 471..474, id: Name("bar"), ctx: Load, @@ -1416,17 +1416,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 475..478, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " {", }, ), Interpolation( InterpolatedElement { range: 478..485, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 479..484, id: Name("three"), ctx: Load, @@ -1440,7 +1440,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 485..487, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "}", }, ), @@ -1459,32 +1459,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 489..531, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 489..531, value: TStringValue { inner: Single( TString { range: 489..531, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 491..498, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "normal ", }, ), Interpolation( InterpolatedElement { range: 498..505, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 499..502, id: Name("foo"), ctx: Load, @@ -1498,17 +1498,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 505..506, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), Interpolation( InterpolatedElement { range: 506..513, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 507..510, id: Name("bar"), ctx: Load, @@ -1522,17 +1522,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 513..514, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), Interpolation( InterpolatedElement { range: 514..521, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 515..518, id: Name("baz"), ctx: Load, @@ -1546,17 +1546,17 @@ Module( Literal( InterpolatedStringLiteralElement { range: 521..522, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), Interpolation( InterpolatedElement { range: 522..530, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 523..529, id: Name("foobar"), ctx: Load, @@ -1582,32 +1582,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 532..551, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 532..551, value: TStringValue { inner: Single( TString { range: 532..551, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 534..541, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "normal ", }, ), Interpolation( InterpolatedElement { range: 541..550, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 542..543, id: Name("x"), ctx: Load, @@ -1618,12 +1618,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 544..549, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 544..549, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "y + 2", }, ), @@ -1647,25 +1647,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 552..570, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 552..570, value: TStringValue { inner: Single( TString { range: 552..570, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 554..569, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 555..556, id: Name("x"), ctx: Load, @@ -1676,28 +1676,28 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 557..568, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 557..568, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 558..567, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 558..565, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 558..561, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 559..560, value: Int( 1, @@ -1710,14 +1710,14 @@ Module( attr: Identifier { id: Name("pop"), range: 562..565, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 565..567, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1748,44 +1748,42 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 571..590, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 571..590, value: TStringValue { inner: Single( TString { range: 571..590, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 573..589, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 575..587, parameters: Some( Parameters { range: 582..583, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 582..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 582..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 582..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1799,12 +1797,12 @@ Module( ), body: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 584..587, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 585..586, id: Name("x"), ctx: Load, @@ -1835,25 +1833,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 591..599, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 591..599, value: TStringValue { inner: Single( TString { range: 591..599, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 593..598, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 594..595, id: Name("x"), ctx: Load, @@ -1884,25 +1882,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 600..613, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 600..613, value: TStringValue { inner: Single( TString { range: 600..613, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 602..612, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 607..608, id: Name("x"), ctx: Load, @@ -1933,25 +1931,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 614..623, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 614..623, value: TStringValue { inner: Single( TString { range: 614..623, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 616..622, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 617..618, id: Name("x"), ctx: Load, @@ -1982,25 +1980,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 624..638, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 624..638, value: TStringValue { inner: Single( TString { range: 624..638, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 626..637, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 627..628, id: Name("x"), ctx: Load, @@ -2011,12 +2009,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 629..636, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 629..636, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f!r =", }, ), @@ -2040,25 +2038,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 639..655, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 639..655, value: TStringValue { inner: Single( TString { range: 639..655, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 641..654, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 642..643, id: Name("x"), ctx: Load, @@ -2074,12 +2072,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 650..653, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 650..653, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f", }, ), @@ -2103,25 +2101,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 656..669, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 656..669, value: TStringValue { inner: Single( TString { range: 656..669, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 658..668, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 659..660, id: Name("x"), ctx: Load, @@ -2132,12 +2130,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 661..667, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 661..667, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f=!r", }, ), @@ -2161,23 +2159,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 670..685, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 670..685, value: TStringValue { inner: Concatenated( [ TString { range: 670..678, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 672..677, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello", }, ), @@ -2190,15 +2188,15 @@ Module( }, TString { range: 679..685, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 681..684, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 682..683, id: Name("x"), ctx: Load, @@ -2225,26 +2223,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..699, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..699, value: TStringValue { inner: Concatenated( [ TString { range: 686..692, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 688..691, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 689..690, id: Name("x"), ctx: Load, @@ -2264,15 +2262,15 @@ Module( }, TString { range: 693..699, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 695..698, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 696..697, id: Name("y"), ctx: Load, @@ -2299,26 +2297,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..715, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..715, value: TStringValue { inner: Concatenated( [ TString { range: 700..706, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 702..705, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 703..704, id: Name("x"), ctx: Load, @@ -2338,12 +2336,12 @@ Module( }, TString { range: 707..715, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 709..714, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "world", }, ), @@ -2363,37 +2361,37 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 716..760, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 716..760, value: TStringValue { inner: Single( TString { range: 716..760, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 718..743, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Invalid args in command: ", }, ), Interpolation( InterpolatedElement { range: 743..759, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 744..758, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 744..751, id: Name("command"), ctx: Load, @@ -2401,11 +2399,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 753..758, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 754..758, id: Name("args"), ctx: Load, @@ -2439,23 +2437,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 761..781, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 761..781, value: TStringValue { inner: Concatenated( [ TString { range: 761..767, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 763..766, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", }, ), @@ -2468,15 +2466,15 @@ Module( }, TString { range: 768..774, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 770..773, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 771..772, id: Name("x"), ctx: Load, @@ -2496,12 +2494,12 @@ Module( }, TString { range: 775..781, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 777..780, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bar", }, ), @@ -2521,23 +2519,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 782..832, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 788..830, value: TStringValue { inner: Concatenated( [ TString { range: 788..792, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 790..791, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a", }, ), @@ -2550,12 +2548,12 @@ Module( }, TString { range: 797..801, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 799..800, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b", }, ), @@ -2568,12 +2566,12 @@ Module( }, TString { range: 806..810, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 808..809, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "c", }, ), @@ -2586,12 +2584,12 @@ Module( }, TString { range: 815..820, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 818..819, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "d", }, ), @@ -2606,12 +2604,12 @@ Module( }, TString { range: 825..830, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 828..829, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "e", }, ), @@ -2633,54 +2631,54 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 844..863, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 844..863, value: TStringValue { inner: Single( TString { range: 844..863, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 846..862, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 847..861, value: FStringValue { inner: Single( FString( FString { range: 847..861, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 849..860, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 850..859, value: TStringValue { inner: Single( TString { range: 850..859, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 852..858, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 853..857, id: Name("this"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap index 4b019c87550a9..85d7b0c3f69aa 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__tuple.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/tuple.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..276, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..21, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..21, elts: [], ctx: Load, @@ -27,11 +27,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..26, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..25, elts: [], ctx: Load, @@ -42,16 +42,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..37, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..37, elts: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..31, elts: [], ctx: Load, @@ -60,7 +60,7 @@ Module( ), Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..36, elts: [], ctx: Load, @@ -76,16 +76,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..42, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..42, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("a"), ctx: Load, @@ -100,16 +100,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..49, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..49, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("a"), ctx: Load, @@ -117,7 +117,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("b"), ctx: Load, @@ -132,16 +132,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..57, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..57, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("a"), ctx: Load, @@ -149,7 +149,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("b"), ctx: Load, @@ -164,16 +164,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..66, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..65, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, id: Name("a"), ctx: Load, @@ -181,7 +181,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, id: Name("b"), ctx: Load, @@ -196,16 +196,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..92, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..92, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("a"), ctx: Load, @@ -220,16 +220,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..97, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..97, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("a"), ctx: Load, @@ -237,7 +237,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, id: Name("b"), ctx: Load, @@ -252,16 +252,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..103, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..103, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("a"), ctx: Load, @@ -269,7 +269,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, id: Name("b"), ctx: Load, @@ -284,20 +284,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..129, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..129, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..128, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("a"), ctx: Load, @@ -315,16 +315,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..135, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..135, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..131, id: Name("a"), ctx: Load, @@ -332,11 +332,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..135, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, id: Name("b"), ctx: Load, @@ -354,24 +354,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..161, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..161, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..142, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..142, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("a"), ctx: Load, @@ -380,7 +380,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, id: Name("b"), ctx: Load, @@ -393,15 +393,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..152, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..152, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, id: Name("x"), ctx: Load, @@ -414,7 +414,7 @@ Module( ), Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..156, elts: [], ctx: Load, @@ -423,11 +423,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..161, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..161, elts: [], ctx: Load, @@ -446,20 +446,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..167, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..167, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..165, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, id: Name("a"), ctx: Load, @@ -477,16 +477,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..175, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..175, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..170, id: Name("a"), ctx: Load, @@ -494,11 +494,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..174, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..174, id: Name("b"), ctx: Load, @@ -516,24 +516,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..203, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..203, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..183, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..183, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("a"), ctx: Load, @@ -542,7 +542,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..183, id: Name("b"), ctx: Load, @@ -555,15 +555,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..193, value: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..193, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, id: Name("x"), ctx: Load, @@ -576,7 +576,7 @@ Module( ), Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 195..197, elts: [], ctx: Load, @@ -585,11 +585,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 199..202, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..202, elts: [], ctx: Load, @@ -608,20 +608,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..233, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..233, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..231, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..226, id: Name("x"), ctx: Store, @@ -629,7 +629,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..231, value: Int( 1, @@ -647,16 +647,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..245, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..245, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..236, id: Name("x"), ctx: Load, @@ -664,11 +664,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..244, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..239, id: Name("y"), ctx: Store, @@ -676,7 +676,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..244, value: Int( 2, @@ -694,16 +694,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..260, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 246..260, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 247..248, id: Name("x"), ctx: Load, @@ -711,11 +711,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..256, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..251, id: Name("y"), ctx: Store, @@ -723,7 +723,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..256, value: Int( 2, @@ -734,7 +734,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..259, id: Name("z"), ctx: Load, @@ -749,16 +749,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..275, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..275, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..262, id: Name("x"), ctx: Load, @@ -766,11 +766,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..271, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..266, id: Name("y"), ctx: Store, @@ -778,7 +778,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 270..271, value: Int( 2, @@ -789,7 +789,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..275, id: Name("z"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap index cf09c3dcf5ee1..5098bc60446b0 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__unary_op.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/unary_op.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..276, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..11, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Int( 1, @@ -34,16 +34,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..14, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..14, op: UAdd, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..14, value: Int( 1, @@ -56,16 +56,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..17, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..17, op: Invert, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, value: Int( 1, @@ -78,16 +78,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..23, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..23, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -99,26 +99,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..40, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..40, op: USub, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..40, op: USub, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..40, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, value: Int( 1, @@ -135,26 +135,26 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..45, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..45, op: USub, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..45, op: UAdd, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..45, op: Invert, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, value: Int( 1, @@ -171,31 +171,31 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..53, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..53, op: Not, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..53, op: USub, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, op: UAdd, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..53, op: Invert, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, value: Int( 1, @@ -214,21 +214,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..63, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..63, op: Not, operand: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..63, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, id: Name("x"), ctx: Load, @@ -242,20 +242,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..93, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..93, op: USub, operand: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..93, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, value: Int( 1, @@ -270,24 +270,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..109, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..109, op: UAdd, operand: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..109, left: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..103, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, value: Int( 1, @@ -299,12 +299,12 @@ Module( op: Pow, right: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..109, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, value: Int( 2, @@ -321,21 +321,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..117, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..117, op: Invert, operand: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..117, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, value: Int( 1, @@ -344,7 +344,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, value: Int( 2, @@ -362,20 +362,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..124, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..124, left: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..120, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, value: Int( 1, @@ -387,7 +387,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..124, value: Int( 2, @@ -400,28 +400,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..246, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..246, op: Or, values: [ BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..223, op: And, values: [ UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..217, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 216..217, id: Name("a"), ctx: Load, @@ -431,7 +431,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..223, id: Name("b"), ctx: Load, @@ -442,22 +442,22 @@ Module( ), BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..246, op: And, values: [ UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..236, op: Not, operand: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..236, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..232, id: Name("c"), ctx: Load, @@ -466,7 +466,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 235..236, id: Name("d"), ctx: Load, @@ -478,12 +478,12 @@ Module( ), UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..246, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, id: Name("e"), ctx: Load, @@ -501,20 +501,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 247..259, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 247..259, op: Not, operand: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..258, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..253, id: Name("x"), ctx: Store, @@ -522,7 +522,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..258, value: Int( 1, @@ -537,20 +537,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..275, value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..275, op: Not, operand: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..275, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..265, id: Name("a"), ctx: Load, @@ -559,12 +559,12 @@ Module( op: BitOr, right: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..274, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 273..274, id: Name("b"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap index cafb60b46058d..e137cd09fc3de 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/yield.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..166, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: None, }, @@ -25,16 +25,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, id: Name("x"), ctx: Load, @@ -47,20 +47,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..25, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..25, value: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..25, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("x"), ctx: Load, @@ -69,7 +69,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, value: Int( 1, @@ -85,22 +85,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..39, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..39, value: Some( BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..39, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("x"), ctx: Load, @@ -108,7 +108,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("y"), ctx: Load, @@ -124,20 +124,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..52, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..52, value: Some( Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..52, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..50, id: Name("call"), ctx: Load, @@ -145,7 +145,7 @@ Module( ), arguments: Arguments { range: 50..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -158,21 +158,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..65, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..65, value: Some( List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..65, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, value: Int( 1, @@ -181,7 +181,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, value: Int( 2, @@ -199,21 +199,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..78, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..78, value: Some( Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..78, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, value: Int( 3, @@ -222,7 +222,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, value: Int( 4, @@ -239,23 +239,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..91, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..91, value: Some( Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..91, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, id: Name("x"), ctx: Load, @@ -264,7 +264,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, value: Int( 5, @@ -282,21 +282,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..102, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..102, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..102, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("x"), ctx: Load, @@ -304,7 +304,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, id: Name("y"), ctx: Load, @@ -322,21 +322,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..115, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..115, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..115, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..111, id: Name("x"), ctx: Load, @@ -344,7 +344,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("y"), ctx: Load, @@ -362,20 +362,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..128, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..128, value: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..128, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, id: Name("x"), ctx: Load, @@ -387,7 +387,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, id: Name("y"), ctx: Load, @@ -403,20 +403,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..143, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..143, value: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..142, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..137, id: Name("x"), ctx: Store, @@ -424,7 +424,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, value: Int( 1, @@ -440,21 +440,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..155, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..155, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..155, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..151, id: Name("x"), ctx: Load, @@ -462,11 +462,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..155, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..155, id: Name("y"), ctx: Load, @@ -487,25 +487,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..165, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..165, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..165, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..164, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap index 0d7bfe36e3b23..86e8a9ac06f33 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@expressions__yield_from.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/expressions/yield_from.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..199, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("x"), ctx: Load, @@ -32,19 +32,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..29, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..29, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..29, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Load, @@ -53,7 +53,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, value: Int( 1, @@ -68,21 +68,21 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..48, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..48, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..48, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Load, @@ -90,7 +90,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("y"), ctx: Load, @@ -105,19 +105,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..66, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..66, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..66, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..64, id: Name("call"), ctx: Load, @@ -125,7 +125,7 @@ Module( ), arguments: Arguments { range: 64..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -137,20 +137,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..84, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..84, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..84, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 1, @@ -159,7 +159,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 2, @@ -176,20 +176,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..102, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..102, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..102, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, value: Int( 3, @@ -198,7 +198,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, value: Int( 4, @@ -214,22 +214,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..120, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..120, value: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..120, items: [ DictItem { key: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, id: Name("x"), ctx: Load, @@ -238,7 +238,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..119, value: Int( 5, @@ -255,20 +255,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..138, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..138, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..138, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..134, id: Name("x"), ctx: Load, @@ -276,7 +276,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..137, id: Name("y"), ctx: Load, @@ -293,19 +293,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..156, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..156, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..156, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..151, id: Name("x"), ctx: Load, @@ -317,7 +317,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..156, id: Name("y"), ctx: Load, @@ -332,19 +332,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..176, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..176, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..175, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..170, id: Name("x"), ctx: Store, @@ -352,7 +352,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..175, value: Int( 1, @@ -367,20 +367,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..199, value: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..199, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..199, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("x"), ctx: Load, @@ -388,15 +388,15 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..198, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..198, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..194, id: Name("x"), ctx: Load, @@ -405,7 +405,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap index 8d3f2a874385a..05a956dcf6ffe 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_in_target_valid_expr.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/for_in_target_valid_ex ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..89, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, target: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..13, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("d"), ctx: Load, @@ -29,11 +29,11 @@ Module( ), slice: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..12, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -45,7 +45,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("y"), ctx: Load, @@ -59,7 +59,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..23, id: Name("target"), ctx: Load, @@ -68,11 +68,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -84,20 +84,20 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..57, is_async: false, target: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..44, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..40, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("x"), ctx: Load, @@ -109,7 +109,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("y"), ctx: Load, @@ -120,7 +120,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, value: Int( 0, @@ -132,7 +132,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..52, id: Name("iter"), ctx: Load, @@ -141,11 +141,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, }, ), @@ -157,20 +157,20 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..88, is_async: false, target: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..75, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..69, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..64, id: Name("x"), ctx: Load, @@ -182,7 +182,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("y"), ctx: Load, @@ -194,14 +194,14 @@ Module( attr: Identifier { id: Name("attr"), range: 71..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..83, id: Name("iter"), ctx: Load, @@ -210,11 +210,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py38.py.snap index e981ecdd5d676..bebfeca6cb8d6 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py38.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/for_iter_unpack_py38.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..112, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..65, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -25,16 +25,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..60, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..55, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("a"), ctx: Load, @@ -45,7 +45,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("b"), ctx: Load, @@ -59,11 +59,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, }, ), @@ -75,12 +75,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..88, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("x"), ctx: Store, @@ -88,12 +88,12 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..83, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("a"), ctx: Load, @@ -101,11 +101,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..82, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, id: Name("b"), ctx: Load, @@ -122,11 +122,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, }, ), @@ -138,12 +138,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..111, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("x"), ctx: Store, @@ -151,16 +151,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..106, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..101, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("a"), ctx: Load, @@ -171,11 +171,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..105, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("b"), ctx: Load, @@ -192,11 +192,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py39.py.snap index 2579c5e35f3a1..57ae9806a24a1 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@for_iter_unpack_py39.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/for_iter_unpack_py39.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..106, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..63, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -25,16 +25,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..58, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..54, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("a"), ctx: Load, @@ -45,7 +45,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, id: Name("b"), ctx: Load, @@ -59,11 +59,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, }, ), @@ -75,12 +75,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..84, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Store, @@ -88,12 +88,12 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..79, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("a"), ctx: Load, @@ -101,11 +101,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..79, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, id: Name("b"), ctx: Load, @@ -122,11 +122,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, }, ), @@ -138,12 +138,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..105, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("x"), ctx: Store, @@ -151,16 +151,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..100, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..96, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..96, id: Name("a"), ctx: Load, @@ -171,11 +171,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..100, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("b"), ctx: Load, @@ -192,11 +192,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..105, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..105, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap index 4e27abaf5828b..dc39444395cc0 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_no_space.py.snap @@ -7,22 +7,22 @@ input_file: crates/ruff_python_parser/resources/inline/ok/from_import_no_space.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..30, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, module: None, names: [ Alias { range: 12..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 12..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -32,17 +32,17 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..29, module: None, names: [ Alias { range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap index ffbf2fa38ddc2..6afb4d35ee291 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_soft_keyword_module_name.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/inline/ok/from_import_soft_keywo ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..104, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..25, module: Some( Identifier { id: Name("match"), range: 5..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 18..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("pattern"), range: 18..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -38,23 +38,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..46, module: Some( Identifier { id: Name("type"), range: 31..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 43..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("bar"), range: 43..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -64,23 +64,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..71, module: Some( Identifier { id: Name("case"), range: 52..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 64..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("pattern"), range: 64..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -90,23 +90,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..103, module: Some( Identifier { id: Name("match.type.case"), range: 77..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 100..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("foo"), range: 100..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap index afc649c201f3a..5d66543330428 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@from_import_stmt_terminator.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/ok/from_import_stmt_termi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..97, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, module: Some( Identifier { id: Name("a"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 15..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 15..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -48,33 +48,33 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..41, module: Some( Identifier { id: Name("a"), range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 39..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -84,16 +84,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("x"), ctx: Load, @@ -101,7 +101,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("y"), ctx: Load, @@ -116,33 +116,33 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..66, module: Some( Identifier { id: Name("a"), range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 62..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 65..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -152,16 +152,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..72, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..72, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -169,7 +169,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, id: Name("y"), ctx: Load, @@ -184,33 +184,33 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..91, module: Some( Identifier { id: Name("a"), range: 78..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 87..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 87..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -220,16 +220,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..96, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..96, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, id: Name("x"), ctx: Load, @@ -237,7 +237,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..96, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap index 386e5a0f15d95..331e7ba86f9b6 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@fstring_format_spec_terminator.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/ok/fstring_format_spec_te ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..43, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, value: FStringValue { inner: Single( FString( FString { range: 0..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 2..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 8..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, id: Name("x"), ctx: Load, @@ -49,7 +49,7 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 11..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [], }, ), @@ -58,7 +58,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 12..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " world", }, ), @@ -78,33 +78,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..42, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..42, value: FStringValue { inner: Single( FString( FString { range: 20..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 22..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "hello ", }, ), Interpolation( InterpolatedElement { range: 28..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Load, @@ -115,12 +115,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 31..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 31..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: ".3f", }, ), @@ -132,7 +132,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 35..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " world", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap index 68a01e322fcbd..900be0a882988 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parameter_range.py.snap @@ -7,43 +7,41 @@ input_file: crates/ruff_python_parser/resources/inline/ok/function_def_parameter ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..56, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..55, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..43, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 13..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 13..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("first"), range: 13..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, id: Name("int"), ctx: Load, @@ -55,19 +53,19 @@ Module( }, ParameterWithDefault { range: 29..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 29..40, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("second"), range: 29..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..40, id: Name("int"), ctx: Load, @@ -85,7 +83,7 @@ Module( returns: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..50, id: Name("int"), ctx: Load, @@ -95,11 +93,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..55, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..55, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap index 2008c48ad0c35..207800f85ee6f 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_parenthesized_return_types.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/function_def_parenthes ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..54, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..9, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -36,12 +34,12 @@ Module( returns: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..19, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -56,11 +54,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, }, ), @@ -71,21 +69,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..53, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 32..34, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -95,12 +91,12 @@ Module( returns: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..48, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, id: Name("int"), ctx: Load, @@ -108,7 +104,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, id: Name("str"), ctx: Load, @@ -123,11 +119,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap index f3762e02fdce5..5415e94eee9fd 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_def_valid_return_expr.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/function_def_valid_ret ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..97, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..9, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -36,11 +34,11 @@ Module( returns: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..22, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, id: Name("int"), ctx: Load, @@ -49,7 +47,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, id: Name("str"), ctx: Load, @@ -61,11 +59,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, }, ), @@ -76,21 +74,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..57, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 32..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 35..37, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -100,26 +96,24 @@ Module( returns: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..52, parameters: Some( Parameters { range: 48..49, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -133,7 +127,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, id: Name("x"), ctx: Load, @@ -145,11 +139,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, }, ), @@ -160,21 +154,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..96, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 62..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -184,18 +176,18 @@ Module( returns: Some( If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..91, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..82, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..74, id: Name("int"), ctx: Load, @@ -203,7 +195,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..91, id: Name("str"), ctx: Load, @@ -215,11 +207,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..96, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_type_params_py312.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_type_params_py312.py.snap index c4bcad78137cc..4dee727ea19c1 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_type_params_py312.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@function_type_params_py312.py.snap @@ -7,33 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/ok/function_type_params_p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..62, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..61, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 48..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 51..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -44,9 +44,7 @@ Module( ), parameters: Parameters { range: 54..56, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -57,11 +55,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap index e5a51faf375a4..2282955763fe7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@global_stmt.py.snap @@ -7,41 +7,41 @@ input_file: crates/ruff_python_parser/resources/inline/ok/global_stmt.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ Global( StmtGlobal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, names: [ Identifier { id: Name("x"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, ), Global( StmtGlobal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..23, names: [ Identifier { id: Name("x"), range: 16..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, Identifier { id: Name("y"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, Identifier { id: Name("z"), range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap index 15b856b9bc98c..12b0c4ea590fa 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_as_name_soft_keyword.py.snap @@ -7,27 +7,27 @@ input_file: crates/ruff_python_parser/resources/inline/ok/import_as_name_soft_ke ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..58, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, names: [ Alias { range: 7..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("foo"), range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("match"), range: 14..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -36,22 +36,22 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..38, names: [ Alias { range: 27..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("bar"), range: 27..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("case"), range: 34..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -60,22 +60,22 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..57, names: [ Alias { range: 46..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("baz"), range: 46..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("type"), range: 53..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap index 507563d546b40..0412ecc38f7cf 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@import_stmt_terminator.py.snap @@ -7,31 +7,31 @@ input_file: crates/ruff_python_parser/resources/inline/ok/import_stmt_terminator ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..42, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, names: [ Alias { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 10..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -40,26 +40,26 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..24, names: [ Alias { range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -68,26 +68,26 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..36, names: [ Alias { range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -96,16 +96,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..41, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..41, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, id: Name("c"), ctx: Load, @@ -113,7 +113,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("d"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@irrefutable_case_pattern_at_end.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@irrefutable_case_pattern_at_end.py.snap index 4dc3301709967..355e84ac03394 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@irrefutable_case_pattern_at_end.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@irrefutable_case_pattern_at_end.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/irrefutable_case_patte ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..176, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..42, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,14 +25,14 @@ Module( cases: [ MatchCase { range: 13..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 2, @@ -45,11 +45,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..24, }, ), @@ -59,17 +59,17 @@ Module( }, MatchCase { range: 29..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 34..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("var"), range: 34..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -78,11 +78,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, }, ), @@ -95,11 +95,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..83, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("x"), ctx: Load, @@ -108,14 +108,14 @@ Module( cases: [ MatchCase { range: 56..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, value: Int( 2, @@ -128,11 +128,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, }, ), @@ -142,11 +142,11 @@ Module( }, MatchCase { range: 72..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 77..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -155,11 +155,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, }, ), @@ -172,11 +172,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..175, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("x"), ctx: Load, @@ -185,17 +185,17 @@ Module( cases: [ MatchCase { range: 97..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 102..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("var"), range: 102..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -203,7 +203,7 @@ Module( guard: Some( BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..113, value: true, }, @@ -212,11 +212,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..118, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..118, }, ), @@ -226,14 +226,14 @@ Module( }, MatchCase { range: 164..175, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 169..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..170, value: Int( 2, @@ -246,11 +246,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..175, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..175, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py37.py.snap index 470474aa7fb6f..f98e1ddaa3818 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py37.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/iter_unpack_return_py3 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..93, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, id: Name("rest"), ctx: Store, @@ -26,12 +26,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..59, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 4, @@ -40,7 +40,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 5, @@ -49,7 +49,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 6, @@ -65,21 +65,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..92, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,17 +88,17 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..92, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..92, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, value: Int( 1, @@ -109,7 +107,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, value: Int( 2, @@ -118,7 +116,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 3, @@ -127,11 +125,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..91, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..91, id: Name("rest"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py38.py.snap index e0f7c8ec2297b..4b66019a93412 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_return_py38.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/iter_unpack_return_py3 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..91, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, id: Name("rest"), ctx: Store, @@ -26,12 +26,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..59, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 4, @@ -40,7 +40,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 5, @@ -49,7 +49,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 6, @@ -65,21 +65,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..90, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,17 +88,17 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..90, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..90, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, value: Int( 1, @@ -109,7 +107,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 2, @@ -118,7 +116,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 3, @@ -127,11 +125,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..90, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..90, id: Name("rest"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py37.py.snap index 092f50c312700..6738798560aac 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py37.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/iter_unpack_yield_py37 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..92, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, id: Name("rest"), ctx: Store, @@ -26,12 +26,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..59, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 4, @@ -40,7 +40,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 5, @@ -49,7 +49,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 6, @@ -65,21 +65,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..91, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,21 +88,21 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..91, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..91, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..91, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..77, value: Int( 1, @@ -113,7 +111,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..80, value: Int( 2, @@ -122,7 +120,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 3, @@ -131,11 +129,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..90, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..90, id: Name("rest"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py38.py.snap index 78df6541052c5..9f1c150b3d61f 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@iter_unpack_yield_py38.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/inline/ok/iter_unpack_yield_py38 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..128, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, id: Name("rest"), ctx: Store, @@ -26,12 +26,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..59, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 4, @@ -40,7 +40,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 5, @@ -49,7 +49,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 6, @@ -65,21 +65,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..89, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -90,21 +88,21 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..89, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..89, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..89, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 1, @@ -113,7 +111,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 2, @@ -122,7 +120,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: Int( 3, @@ -131,11 +129,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..89, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..89, id: Name("rest"), ctx: Load, @@ -159,21 +157,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..127, is_async: false, decorator_list: [], name: Identifier { id: Name("h"), range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 95..97, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -184,21 +180,21 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..127, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..127, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..127, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, value: Int( 1, @@ -207,17 +203,17 @@ Module( ), Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..123, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..123, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..116, value: Int( 2, @@ -226,11 +222,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..123, id: Name("rest"), ctx: Load, @@ -249,7 +245,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_no_parameters.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_no_parameters.py.snap index 7a76f5f14cc87..597604369514c 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_no_parameters.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_no_parameters.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/lambda_with_no_paramet ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..10, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..9, parameters: None, body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap index c407279f9daea..30d038eb10c91 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@lambda_with_valid_body.py.snap @@ -7,35 +7,33 @@ input_file: crates/ruff_python_parser/resources/inline/ok/lambda_with_valid_body ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..152, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..11, parameters: Some( Parameters { range: 7..8, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -49,7 +47,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, id: Name("x"), ctx: Load, @@ -61,30 +59,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..38, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..38, parameters: Some( Parameters { range: 19..20, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 19..20, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -98,18 +94,18 @@ Module( ), body: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..38, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..31, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..23, id: Name("x"), ctx: Load, @@ -117,7 +113,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, id: Name("y"), ctx: Load, @@ -131,30 +127,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..56, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..56, parameters: Some( Parameters { range: 46..47, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -168,11 +162,11 @@ Module( ), body: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..56, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, id: Name("x"), ctx: Load, @@ -186,30 +180,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..82, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..82, parameters: Some( Parameters { range: 64..65, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -223,26 +215,24 @@ Module( ), body: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..82, parameters: Some( Parameters { range: 74..75, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -256,11 +246,11 @@ Module( ), body: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..82, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("x"), ctx: Load, @@ -269,7 +259,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, id: Name("y"), ctx: Load, @@ -285,30 +275,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..102, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..102, parameters: Some( Parameters { range: 90..91, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 90..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -322,12 +310,12 @@ Module( ), body: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..101, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("x"), ctx: Load, @@ -342,35 +330,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..151, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..151, elts: [ Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..147, parameters: Some( Parameters { range: 143..144, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 143..144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 143..144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 143..144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -384,7 +370,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("x"), ctx: Load, @@ -394,11 +380,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..151, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..151, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_after_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_after_py310.py.snap index a4b120445780c..155afee96fae7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_after_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_after_py310.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_after_py310.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..80, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..79, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, value: Int( 2, @@ -26,14 +26,14 @@ Module( cases: [ MatchCase { range: 59..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, value: Int( 1, @@ -46,7 +46,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..79, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap index c300ac48439f6..f69f8a5947166 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_as_pattern.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..60, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("foo"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 15..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 20..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("foo_bar"), range: 20..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -44,11 +44,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..32, }, ), @@ -61,11 +61,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..59, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, id: Name("foo"), ctx: Load, @@ -74,11 +74,11 @@ Module( cases: [ MatchCase { range: 48..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -87,11 +87,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap index 6ca3b670574fd..7795d1b45ca04 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_as_pattern_soft_keyword.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_as_pattern_soft_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..91, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("foo"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 15..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 20..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("case"), range: 20..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -44,11 +44,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, }, ), @@ -61,11 +61,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..60, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..39, id: Name("foo"), ctx: Load, @@ -74,17 +74,17 @@ Module( cases: [ MatchCase { range: 45..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 50..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("match"), range: 50..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -93,11 +93,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, }, ), @@ -110,11 +110,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..90, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..70, id: Name("foo"), ctx: Load, @@ -123,17 +123,17 @@ Module( cases: [ MatchCase { range: 76..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 81..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("type"), range: 81..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -142,11 +142,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..90, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..90, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap index 17a7f854b3a2f..0f911c5ce4d44 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_attr_pattern_soft_keyword.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_attr_pattern_sof ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..131, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..130, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("foo"), ctx: Load, @@ -25,18 +25,18 @@ Module( cases: [ MatchCase { range: 15..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 20..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..29, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..25, id: Name("match"), ctx: Load, @@ -45,7 +45,7 @@ Module( attr: Identifier { id: Name("bar"), range: 26..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -56,11 +56,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, }, ), @@ -70,18 +70,18 @@ Module( }, MatchCase { range: 39..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 44..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..48, id: Name("case"), ctx: Load, @@ -90,7 +90,7 @@ Module( attr: Identifier { id: Name("bar"), range: 49..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -101,11 +101,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, }, ), @@ -115,18 +115,18 @@ Module( }, MatchCase { range: 62..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 67..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..75, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..71, id: Name("type"), ctx: Load, @@ -135,7 +135,7 @@ Module( attr: Identifier { id: Name("bar"), range: 72..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -146,11 +146,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..80, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..80, }, ), @@ -160,38 +160,38 @@ Module( }, MatchCase { range: 85..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 90..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..125, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..119, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..114, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..109, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..105, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..100, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..95, id: Name("match"), ctx: Load, @@ -200,7 +200,7 @@ Module( attr: Identifier { id: Name("case"), range: 96..100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -208,7 +208,7 @@ Module( attr: Identifier { id: Name("type"), range: 101..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -216,7 +216,7 @@ Module( attr: Identifier { id: Name("bar"), range: 106..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -224,7 +224,7 @@ Module( attr: Identifier { id: Name("type"), range: 110..114, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -232,7 +232,7 @@ Module( attr: Identifier { id: Name("case"), range: 115..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -240,7 +240,7 @@ Module( attr: Identifier { id: Name("match"), range: 120..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -251,11 +251,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..130, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap index 7c7131c6e54c2..7eb5caad2970a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_1.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_iden ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..18, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, id: Name("match"), ctx: Load, @@ -32,7 +32,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, id: Name("case"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap index e0c274a03d11e..5377ee65eac70 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_identifier_2.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_iden ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..149, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, id: Name("match"), ctx: Load, @@ -26,15 +26,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..18, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..18, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..11, id: Name("match"), ctx: Load, @@ -46,7 +46,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..18, id: Name("foo"), ctx: Load, @@ -59,16 +59,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..31, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..31, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, id: Name("foo"), ctx: Load, @@ -76,7 +76,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..30, id: Name("match"), ctx: Load, @@ -91,16 +91,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..44, value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..44, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..36, id: Name("foo"), ctx: Load, @@ -108,7 +108,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..43, id: Name("match"), ctx: Load, @@ -122,16 +122,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..57, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..57, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..49, id: Name("foo"), ctx: Load, @@ -139,7 +139,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..56, id: Name("match"), ctx: Load, @@ -152,11 +152,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..63, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..63, id: Name("match"), ctx: Load, @@ -166,11 +166,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..75, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..70, id: Name("match"), ctx: Store, @@ -178,7 +178,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..75, id: Name("int"), ctx: Load, @@ -190,16 +190,16 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..82, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..82, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..81, id: Name("match"), ctx: Load, @@ -214,15 +214,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..92, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..92, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..88, id: Name("match"), ctx: Load, @@ -231,7 +231,7 @@ Module( attr: Identifier { id: Name("foo"), range: 89..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -240,15 +240,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..104, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..104, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..98, id: Name("match"), ctx: Load, @@ -257,7 +257,7 @@ Module( op: Div, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..104, id: Name("foo"), ctx: Load, @@ -269,15 +269,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..117, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..117, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..110, id: Name("match"), ctx: Load, @@ -286,7 +286,7 @@ Module( op: LShift, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..117, id: Name("foo"), ctx: Load, @@ -298,17 +298,17 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..131, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..131, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 118..123, id: Name("match"), ctx: Load, @@ -316,7 +316,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..131, id: Name("foo"), ctx: Load, @@ -329,15 +329,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..148, value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..148, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..137, id: Name("match"), ctx: Load, @@ -349,7 +349,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..148, id: Name("foo"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap index 2345dca24948a..7c83386b60798 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_1.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_keyw ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..358, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..9, id: Name("foo"), ctx: Load, @@ -25,11 +25,11 @@ Module( cases: [ MatchCase { range: 15..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -38,11 +38,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..26, }, ), @@ -55,11 +55,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..51, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, value: Int( 1, @@ -69,11 +69,11 @@ Module( cases: [ MatchCase { range: 40..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 45..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -82,11 +82,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..51, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..51, }, ), @@ -99,11 +99,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..78, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: Float( 1.0, @@ -113,11 +113,11 @@ Module( cases: [ MatchCase { range: 67..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -126,11 +126,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, }, ), @@ -143,11 +143,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..104, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..87, value: Complex { real: 0.0, @@ -158,11 +158,11 @@ Module( cases: [ MatchCase { range: 93..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -171,11 +171,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..104, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..104, }, ), @@ -188,17 +188,17 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..133, subject: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..116, value: StringLiteralValue { inner: Single( StringLiteral { range: 111..116, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -213,11 +213,11 @@ Module( cases: [ MatchCase { range: 122..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 127..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -226,11 +226,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..133, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..133, }, ), @@ -243,33 +243,33 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..167, subject: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..150, value: FStringValue { inner: Single( FString( FString { range: 140..150, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 142..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo ", }, ), Interpolation( InterpolatedElement { range: 146..149, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..148, id: Name("x"), ctx: Load, @@ -295,11 +295,11 @@ Module( cases: [ MatchCase { range: 156..167, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 161..162, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -308,11 +308,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..167, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..167, }, ), @@ -325,16 +325,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..197, subject: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..180, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..176, value: Int( 1, @@ -343,7 +343,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, value: Int( 2, @@ -356,11 +356,11 @@ Module( cases: [ MatchCase { range: 186..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 191..192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -369,11 +369,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..197, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..197, }, ), @@ -386,16 +386,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..225, subject: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..208, op: Invert, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..208, id: Name("foo"), ctx: Load, @@ -406,11 +406,11 @@ Module( cases: [ MatchCase { range: 214..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 219..220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -419,11 +419,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..225, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..225, }, ), @@ -436,22 +436,22 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..252, subject: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..235, }, ), cases: [ MatchCase { range: 241..252, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 246..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -460,11 +460,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..252, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..252, }, ), @@ -477,16 +477,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..283, subject: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..266, op: Not, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..266, id: Name("foo"), ctx: Load, @@ -497,11 +497,11 @@ Module( cases: [ MatchCase { range: 272..283, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 277..278, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -510,11 +510,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..283, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..283, }, ), @@ -527,19 +527,19 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..318, subject: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..301, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..301, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..299, id: Name("foo"), ctx: Load, @@ -547,7 +547,7 @@ Module( ), arguments: Arguments { range: 299..301, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -558,11 +558,11 @@ Module( cases: [ MatchCase { range: 307..318, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 312..313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -571,11 +571,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..318, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..318, }, ), @@ -588,30 +588,28 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..357, subject: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 325..340, parameters: Some( Parameters { range: 332..335, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 332..335, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 332..335, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("foo"), range: 332..335, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -625,7 +623,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 337..340, id: Name("foo"), ctx: Load, @@ -636,11 +634,11 @@ Module( cases: [ MatchCase { range: 346..357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 351..352, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -649,11 +647,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..357, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..357, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap index d4d62a6c6f386..16ff76beb6d74 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_2.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_keyw ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..170, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..11, id: Name("match"), ctx: Load, @@ -25,11 +25,11 @@ Module( cases: [ MatchCase { range: 17..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -38,11 +38,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -55,11 +55,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..56, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..39, id: Name("case"), ctx: Load, @@ -68,11 +68,11 @@ Module( cases: [ MatchCase { range: 45..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -81,11 +81,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, }, ), @@ -98,11 +98,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..84, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..67, id: Name("type"), ctx: Load, @@ -111,11 +111,11 @@ Module( cases: [ MatchCase { range: 73..84, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 78..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -124,11 +124,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, }, ), @@ -141,22 +141,22 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..112, subject: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..95, }, ), cases: [ MatchCase { range: 101..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 106..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -165,11 +165,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, }, ), @@ -182,11 +182,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..140, subject: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..123, value: true, }, @@ -194,11 +194,11 @@ Module( cases: [ MatchCase { range: 129..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 134..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -207,11 +207,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..140, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..140, }, ), @@ -224,11 +224,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..169, subject: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 147..152, value: false, }, @@ -236,11 +236,11 @@ Module( cases: [ MatchCase { range: 158..169, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 163..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -249,11 +249,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..169, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..169, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap index 849251e03e811..71fa711fb744d 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_classify_as_keyword_or_identifier.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_classify_as_keyw ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..225, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, id: Name("match"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), arguments: Arguments { range: 6..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Int( 1, @@ -41,7 +41,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..11, value: Int( 2, @@ -57,16 +57,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..67, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..39, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, value: Int( 1, @@ -75,7 +75,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, value: Int( 2, @@ -90,11 +90,11 @@ Module( cases: [ MatchCase { range: 56..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -103,11 +103,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..67, }, ), @@ -120,15 +120,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..78, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..78, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..73, id: Name("match"), ctx: Load, @@ -136,12 +136,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..77, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, value: Int( 1, @@ -160,16 +160,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..133, subject: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..105, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, value: Int( 1, @@ -178,7 +178,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..104, value: Int( 2, @@ -192,11 +192,11 @@ Module( cases: [ MatchCase { range: 122..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 127..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -205,11 +205,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..133, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..133, }, ), @@ -222,15 +222,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..145, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..145, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..139, id: Name("match"), ctx: Load, @@ -239,7 +239,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..145, id: Name("foo"), ctx: Load, @@ -251,15 +251,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..171, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..171, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..165, id: Name("match"), ctx: Load, @@ -268,7 +268,7 @@ Module( op: Sub, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, id: Name("foo"), ctx: Load, @@ -280,16 +280,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..224, subject: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..196, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..196, id: Name("foo"), ctx: Load, @@ -300,11 +300,11 @@ Module( cases: [ MatchCase { range: 213..224, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 218..219, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -313,11 +313,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..224, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..224, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap index 7416b29f05f23..4abf3285a63c1 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_parentheses_terminator.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_sequence_pattern ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..57, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..56, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,22 +25,22 @@ Module( cases: [ MatchCase { range: 19..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 24..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -48,13 +48,13 @@ Module( MatchAs( PatternMatchAs { range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("b"), range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -66,11 +66,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..35, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..35, }, ), @@ -80,22 +80,22 @@ Module( }, MatchCase { range: 40..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 45..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -103,13 +103,13 @@ Module( MatchAs( PatternMatchAs { range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("b"), range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -121,11 +121,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap index 91f128eafcd65..d980cea8b2fac 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_sequence_pattern_terminator.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_sequence_pattern ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..95, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..94, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, id: Name("subject"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 19..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -43,7 +43,7 @@ Module( guard: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Load, @@ -53,11 +53,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..35, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..35, }, ), @@ -67,22 +67,22 @@ Module( }, MatchCase { range: 40..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 45..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 45..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 45..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -90,13 +90,13 @@ Module( MatchAs( PatternMatchAs { range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("b"), range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -108,11 +108,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..54, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..54, }, ), @@ -122,22 +122,22 @@ Module( }, MatchCase { range: 59..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 64..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -145,13 +145,13 @@ Module( MatchAs( PatternMatchAs { range: 67..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("b"), range: 67..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -162,7 +162,7 @@ Module( guard: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("x"), ctx: Load, @@ -172,11 +172,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, }, ), @@ -186,17 +186,17 @@ Module( }, MatchCase { range: 83..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 88..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 88..89, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -205,11 +205,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap index e0042a2cc5a75..43db08647ca2b 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_subject_expr.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_stmt_subject_exp ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..185, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, subject: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..12, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Store, @@ -28,7 +28,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Int( 1, @@ -40,11 +40,11 @@ Module( cases: [ MatchCase { range: 18..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -53,11 +53,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..29, }, ), @@ -70,15 +70,15 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..61, subject: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..43, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, id: Name("x"), ctx: Store, @@ -86,7 +86,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..43, value: Int( 1, @@ -98,11 +98,11 @@ Module( cases: [ MatchCase { range: 50..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -111,11 +111,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), @@ -128,24 +128,24 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..153, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..136, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..133, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..133, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("x"), ctx: Load, @@ -154,7 +154,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("y"), ctx: Load, @@ -167,7 +167,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, id: Name("z"), ctx: Load, @@ -181,11 +181,11 @@ Module( cases: [ MatchCase { range: 142..153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 147..148, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -194,11 +194,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..153, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..153, }, ), @@ -211,15 +211,15 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..184, subject: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..167, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("x"), ctx: Load, @@ -230,11 +230,11 @@ Module( cases: [ MatchCase { range: 173..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 178..179, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -243,11 +243,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..184, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..184, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap index 32f6791cd44fc..ed559fabac8da 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@match_stmt_valid_guard_expr.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/match_stmt_valid_guard ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..158, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..34, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,17 +25,17 @@ Module( cases: [ MatchCase { range: 13..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 18..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -43,11 +43,11 @@ Module( guard: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..29, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("a"), ctx: Store, @@ -55,7 +55,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, value: Int( 1, @@ -68,11 +68,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, }, ), @@ -85,11 +85,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..79, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, id: Name("x"), ctx: Load, @@ -98,17 +98,17 @@ Module( cases: [ MatchCase { range: 48..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -116,18 +116,18 @@ Module( guard: Some( If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..74, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..67, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..59, id: Name("a"), ctx: Load, @@ -135,7 +135,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("b"), ctx: Load, @@ -147,11 +147,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, }, ), @@ -164,11 +164,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..119, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, id: Name("x"), ctx: Load, @@ -177,17 +177,17 @@ Module( cases: [ MatchCase { range: 93..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -195,26 +195,24 @@ Module( guard: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..114, parameters: Some( Parameters { range: 110..111, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 110..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 110..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 110..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -228,7 +226,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("b"), ctx: Load, @@ -240,11 +238,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..119, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..119, }, ), @@ -257,11 +255,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..157, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, id: Name("x"), ctx: Load, @@ -270,17 +268,17 @@ Module( cases: [ MatchCase { range: 133..157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 138..139, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 138..139, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -288,12 +286,12 @@ Module( guard: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..151, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..151, id: Name("x"), ctx: Load, @@ -306,11 +304,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..157, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..157, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@multiple_assignment_in_case_pattern.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@multiple_assignment_in_case_pattern.py.snap index b61390df0d8bb..1f7090f2c9479 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@multiple_assignment_in_case_pattern.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@multiple_assignment_in_case_pattern.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/multiple_assignment_in ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..42, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..41, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: Int( 2, @@ -26,19 +26,19 @@ Module( cases: [ MatchCase { range: 13..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 18..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchClass( PatternMatchClass { range: 18..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..23, id: Name("Class"), ctx: Load, @@ -46,18 +46,18 @@ Module( ), arguments: PatternArguments { range: 23..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 24..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -70,18 +70,18 @@ Module( MatchSequence( PatternMatchSequence { range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 30..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 30..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -92,13 +92,13 @@ Module( MatchAs( PatternMatchAs { range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 35..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -110,11 +110,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap index b36ef0858ecad..9c269d6c6997a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py310.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/nested_async_comprehen ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..181, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..116, is_async: true, decorator_list: [], name: Identifier { id: Name("f"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 55..57, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,15 +35,15 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..84, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..84, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, id: Name("_"), ctx: Load, @@ -54,10 +52,10 @@ Module( generators: [ Comprehension { range: 66..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("n"), ctx: Store, @@ -65,11 +63,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..83, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..80, id: Name("range"), ctx: Load, @@ -77,11 +75,11 @@ Module( ), arguments: Arguments { range: 80..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, value: Int( 3, @@ -103,15 +101,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..116, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..116, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("_"), ctx: Load, @@ -120,10 +118,10 @@ Module( generators: [ Comprehension { range: 92..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("n"), ctx: Store, @@ -131,11 +129,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..115, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..112, id: Name("range"), ctx: Load, @@ -143,11 +141,11 @@ Module( ), arguments: Arguments { range: 112..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, value: Int( 3, @@ -172,21 +170,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..180, is_async: true, decorator_list: [], name: Identifier { id: Name("f"), range: 127..128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 128..130, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -197,21 +193,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..148, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 140..141, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 141..143, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -222,11 +216,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..148, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..148, }, ), @@ -237,15 +231,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..180, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..180, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..155, id: Name("_"), ctx: Load, @@ -254,10 +248,10 @@ Module( generators: [ Comprehension { range: 156..179, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("n"), ctx: Store, @@ -265,11 +259,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..179, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..176, id: Name("range"), ctx: Load, @@ -277,11 +271,11 @@ Module( ), arguments: Arguments { range: 176..179, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..178, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap index 2a0a766dabd89..3754f5f1bad5d 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nested_async_comprehension_py311.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/nested_async_comprehen ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..277, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..111, is_async: true, decorator_list: [], name: Identifier { id: Name("f"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 55..57, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,20 +35,20 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..111, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..111, elt: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..92, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("x"), ctx: Load, @@ -59,10 +57,10 @@ Module( generators: [ Comprehension { range: 70..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, id: Name("x"), ctx: Store, @@ -70,11 +68,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..91, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, id: Name("foo"), ctx: Load, @@ -82,11 +80,11 @@ Module( ), arguments: Arguments { range: 88..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 89..90, id: Name("n"), ctx: Load, @@ -106,10 +104,10 @@ Module( generators: [ Comprehension { range: 93..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, id: Name("n"), ctx: Store, @@ -117,11 +115,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..110, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..107, id: Name("range"), ctx: Load, @@ -129,11 +127,11 @@ Module( ), arguments: Arguments { range: 107..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, value: Int( 3, @@ -159,21 +157,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..192, is_async: true, decorator_list: [], name: Identifier { id: Name("g"), range: 132..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 133..135, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -184,20 +180,20 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..192, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..192, elt: DictComp( ExprDictComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..173, key: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("x"), ctx: Load, @@ -205,7 +201,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, value: Int( 1, @@ -215,10 +211,10 @@ Module( generators: [ Comprehension { range: 151..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, id: Name("x"), ctx: Store, @@ -226,11 +222,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..172, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..169, id: Name("foo"), ctx: Load, @@ -238,11 +234,11 @@ Module( ), arguments: Arguments { range: 169..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, id: Name("n"), ctx: Load, @@ -262,10 +258,10 @@ Module( generators: [ Comprehension { range: 174..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..179, id: Name("n"), ctx: Store, @@ -273,11 +269,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..191, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..188, id: Name("range"), ctx: Load, @@ -285,11 +281,11 @@ Module( ), arguments: Arguments { range: 188..191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, value: Int( 3, @@ -315,21 +311,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..267, is_async: true, decorator_list: [], name: Identifier { id: Name("h"), range: 210..211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 211..213, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -340,20 +334,20 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..267, value: Some( ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..267, elt: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 223..248, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..225, id: Name("x"), ctx: Load, @@ -362,10 +356,10 @@ Module( generators: [ Comprehension { range: 226..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("x"), ctx: Store, @@ -373,11 +367,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..247, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..244, id: Name("foo"), ctx: Load, @@ -385,11 +379,11 @@ Module( ), arguments: Arguments { range: 244..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 245..246, id: Name("n"), ctx: Load, @@ -409,10 +403,10 @@ Module( generators: [ Comprehension { range: 249..266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..254, id: Name("n"), ctx: Store, @@ -420,11 +414,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..266, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..263, id: Name("range"), ctx: Load, @@ -432,11 +426,11 @@ Module( ), arguments: Arguments { range: 263..266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..265, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_type_parameter_names.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_type_parameter_names.py.snap index 76ed4f593790a..c1a5fcb44538c 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_type_parameter_names.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_duplicate_type_parameter_names.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/non_duplicate_type_par ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..150, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..10, id: Name("Alias"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 10..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -45,11 +45,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..23, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..20, id: Name("list"), ctx: Load, @@ -57,7 +57,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("T"), ctx: Load, @@ -70,28 +70,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..43, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 29..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 30..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 30..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -102,26 +102,24 @@ Module( ), parameters: Parameters { range: 32..38, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 33..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 33..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("t"), range: 33..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("T"), ctx: Load, @@ -140,11 +138,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..43, }, ), @@ -155,27 +153,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..59, decorator_list: [], name: Identifier { id: Name("C"), range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 51..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 52..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -188,11 +186,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, }, ), @@ -203,27 +201,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..81, decorator_list: [], name: Identifier { id: Name("C"), range: 66..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 67..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 68..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 68..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -232,11 +230,11 @@ Module( TypeVar( TypeParamTypeVar { range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -245,11 +243,11 @@ Module( TypeVar( TypeParamTypeVar { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("V"), range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -262,11 +260,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..81, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..81, }, ), @@ -277,11 +275,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..149, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..92, id: Name("Alias"), ctx: Store, @@ -290,16 +288,16 @@ Module( type_params: Some( TypeParams { range: 92..143, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 93..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 93..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -308,16 +306,16 @@ Module( TypeVar( TypeParamTypeVar { range: 96..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 96..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..102, id: Name("str"), ctx: Load, @@ -330,21 +328,21 @@ Module( TypeVar( TypeParamTypeVar { range: 104..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("V"), range: 104..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..119, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, id: Name("str"), ctx: Load, @@ -352,7 +350,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..118, id: Name("bytes"), ctx: Load, @@ -370,11 +368,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 121..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 122..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -382,11 +380,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 126..129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 128..129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -394,17 +392,17 @@ Module( TypeVar( TypeParamTypeVar { range: 131..142, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("D"), range: 131..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..142, id: Name("default"), ctx: Load, @@ -418,7 +416,7 @@ Module( ), value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..149, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap index 3e80ba428d953..32f31b1690e9d 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@non_rebound_comprehension_variable.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/non_rebound_comprehens ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, value: ListComp( ExprListComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..26, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..7, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..2, id: Name("a"), ctx: Store, @@ -32,7 +32,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, value: Int( 0, @@ -44,10 +44,10 @@ Module( generators: [ Comprehension { range: 8..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..13, id: Name("x"), ctx: Store, @@ -55,11 +55,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..25, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..22, id: Name("range"), ctx: Load, @@ -67,11 +67,11 @@ Module( ), arguments: Arguments { range: 22..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Int( 0, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_declaration_at_module_level.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_declaration_at_module_level.py.snap index c3a1f13b039e3..f8015717e31d8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_declaration_at_module_level.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_declaration_at_module_level.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/nonlocal_declaration_a ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..24, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, is_async: false, decorator_list: [], name: Identifier { id: Name("_"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,13 +35,13 @@ Module( body: [ Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..23, names: [ Identifier { id: Name("x"), range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap index 6ff8f3a6850ba..da1fa3289eccc 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@nonlocal_stmt.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/nonlocal_stmt.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..45, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..44, is_async: false, decorator_list: [], name: Identifier { id: Name("_"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,36 +35,36 @@ Module( body: [ Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..23, names: [ Identifier { id: Name("x"), range: 22..23, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, ), Nonlocal( StmtNonlocal { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..44, names: [ Identifier { id: Name("x"), range: 37..38, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, Identifier { id: Name("y"), range: 40..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, Identifier { id: Name("z"), range: 43..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ], }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__atom.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__atom.py.snap index c990da6f6ec14..07f19ba72a957 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__atom.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__atom.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/other/atom.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..73, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3, }, ), @@ -24,11 +24,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..8, value: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..8, value: true, }, @@ -37,11 +37,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, value: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..14, value: false, }, @@ -50,11 +50,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..19, value: NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..19, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap index 4278651bd2531..f90d87e8c7e01 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@other__decorator.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/valid/other/decorator.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..407, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..40, is_async: false, decorator_list: [ Decorator { range: 0..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..19, id: Name("function_decorator"), ctx: Load, @@ -32,14 +32,12 @@ Module( name: Identifier { id: Name("test"), range: 24..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 28..30, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -50,7 +48,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..40, }, ), @@ -59,15 +57,15 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..80, decorator_list: [ Decorator { range: 43..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..59, id: Name("class_decorator"), ctx: Load, @@ -78,14 +76,14 @@ Module( name: Identifier { id: Name("Test"), range: 66..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..80, }, ), @@ -94,16 +92,16 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..106, is_async: false, decorator_list: [ Decorator { range: 83..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..93, id: Name("decorator"), ctx: Load, @@ -114,14 +112,12 @@ Module( name: Identifier { id: Name("f"), range: 98..99, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 99..101, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -132,11 +128,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..106, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..106, }, ), @@ -147,24 +143,24 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..128, is_async: false, decorator_list: [ Decorator { range: 109..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..115, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..113, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 110..111, id: Name("a"), ctx: Load, @@ -173,7 +169,7 @@ Module( attr: Identifier { id: Name("b"), range: 112..113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -181,7 +177,7 @@ Module( attr: Identifier { id: Name("c"), range: 114..115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -191,14 +187,12 @@ Module( name: Identifier { id: Name("f"), range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 121..123, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -209,11 +203,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..128, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..128, }, ), @@ -224,16 +218,16 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..153, is_async: false, decorator_list: [ Decorator { range: 131..133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("a"), ctx: Load, @@ -242,18 +236,18 @@ Module( }, Decorator { range: 134..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..140, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..138, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, id: Name("a"), ctx: Load, @@ -262,7 +256,7 @@ Module( attr: Identifier { id: Name("b"), range: 137..138, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -270,7 +264,7 @@ Module( attr: Identifier { id: Name("c"), range: 139..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -280,14 +274,12 @@ Module( name: Identifier { id: Name("f"), range: 145..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 146..148, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -298,11 +290,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..153, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 150..153, }, ), @@ -313,15 +305,15 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..185, decorator_list: [ Decorator { range: 156..158, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, id: Name("a"), ctx: Load, @@ -330,14 +322,14 @@ Module( }, Decorator { range: 159..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..165, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, value: Int( 1, @@ -347,7 +339,7 @@ Module( op: BitOr, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, value: Int( 2, @@ -359,18 +351,18 @@ Module( }, Decorator { range: 166..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..172, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..170, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, id: Name("a"), ctx: Load, @@ -379,7 +371,7 @@ Module( attr: Identifier { id: Name("b"), range: 169..170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -387,7 +379,7 @@ Module( attr: Identifier { id: Name("c"), range: 171..172, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -397,18 +389,18 @@ Module( name: Identifier { id: Name("T"), range: 179..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..185, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..185, }, ), @@ -419,20 +411,20 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 188..269, is_async: false, decorator_list: [ Decorator { range: 188..195, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..195, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("x"), ctx: Store, @@ -440,7 +432,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..195, value: Int( 1, @@ -452,21 +444,21 @@ Module( }, Decorator { range: 196..213, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..213, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..206, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, id: Name("x"), ctx: Load, @@ -474,7 +466,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..213, id: Name("y"), ctx: Load, @@ -485,29 +477,27 @@ Module( }, Decorator { range: 214..226, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 215..226, parameters: Some( Parameters { range: 222..223, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 222..223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -521,7 +511,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..226, id: Name("x"), ctx: Load, @@ -532,16 +522,16 @@ Module( }, Decorator { range: 227..235, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..235, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..229, id: Name("x"), ctx: Load, @@ -549,7 +539,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..235, id: Name("y"), ctx: Load, @@ -561,15 +551,15 @@ Module( }, Decorator { range: 236..246, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..245, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..245, id: Name("x"), ctx: Load, @@ -581,19 +571,19 @@ Module( }, Decorator { range: 247..256, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 248..256, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..251, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 250..251, id: Name("x"), ctx: Load, @@ -604,11 +594,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 253..255, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..255, id: Name("y"), ctx: Load, @@ -627,14 +617,12 @@ Module( name: Identifier { id: Name("f"), range: 261..262, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 262..264, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -645,11 +633,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..269, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..269, }, ), @@ -660,20 +648,20 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 360..380, is_async: false, decorator_list: [ Decorator { range: 360..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 361..365, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 361..362, id: Name("x"), ctx: Load, @@ -682,7 +670,7 @@ Module( op: MatMult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..365, id: Name("y"), ctx: Load, @@ -695,14 +683,12 @@ Module( name: Identifier { id: Name("foo"), range: 370..373, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 373..375, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -713,11 +699,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 377..380, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 377..380, }, ), @@ -728,16 +714,16 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..407, is_async: false, decorator_list: [ Decorator { range: 383..385, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 384..385, id: Name("x"), ctx: Load, @@ -746,10 +732,10 @@ Module( }, Decorator { range: 388..390, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 389..390, id: Name("y"), ctx: Load, @@ -760,14 +746,12 @@ Module( name: Identifier { id: Name("foo"), range: 397..400, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 400..402, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -778,11 +762,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 404..407, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 404..407, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap index af944be2fba0c..03b7fab965ca2 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_annotation.py.snap @@ -7,43 +7,41 @@ input_file: crates/ruff_python_parser/resources/inline/ok/param_with_annotation. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..54, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..22, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..17, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 8..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, id: Name("int"), ctx: Load, @@ -62,11 +60,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..22, }, ), @@ -77,57 +75,53 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..53, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 27..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 30..48, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 31..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 31..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 31..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..47, parameters: Some( Parameters { range: 43..44, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 43..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 43..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 43..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -141,7 +135,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("x"), ctx: Load, @@ -162,11 +156,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..53, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap index 7951972b14ba8..97ade21863414 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_default.py.snap @@ -7,64 +7,60 @@ input_file: crates/ruff_python_parser/resources/inline/ok/param_with_default.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..111, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..27, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..22, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..21, parameters: Some( Parameters { range: 17..18, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -78,7 +74,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("y"), ctx: Load, @@ -97,11 +93,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..27, }, ), @@ -112,51 +108,49 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..60, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 32..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 35..55, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 36..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 36..37, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..54, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, value: true, }, ), body: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, value: Int( 1, @@ -165,7 +159,7 @@ Module( ), orelse: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, value: Int( 2, @@ -185,11 +179,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, }, ), @@ -200,44 +194,42 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..84, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 65..68, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 68..79, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 69..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 69..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 69..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..78, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("y"), ctx: Load, @@ -256,11 +248,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, }, ), @@ -271,45 +263,43 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..110, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 89..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 92..105, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 93..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 93..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 93..94, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..103, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, id: Name("y"), ctx: Load, @@ -329,11 +319,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..110, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..110, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap index a9987458b010f..6a3c7ccc9c98e 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation.py.snap @@ -7,49 +7,47 @@ input_file: crates/ruff_python_parser/resources/inline/ok/param_with_star_annota ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..67, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..31, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..26, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 8..25, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 9..13, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..25, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..25, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..19, id: Name("int"), ctx: Load, @@ -58,7 +56,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, id: Name("str"), ctx: Load, @@ -79,11 +77,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, }, ), @@ -94,46 +92,44 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..66, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 36..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 39..61, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 40..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 41..45, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..60, value: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..59, op: Or, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, id: Name("int"), ctx: Load, @@ -141,7 +137,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, id: Name("str"), ctx: Load, @@ -163,11 +159,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..66, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..66, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py310.py.snap index 8e1d5b24be1ba..d411155da7a28 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py310.py.snap @@ -7,38 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/ok/param_with_star_annota ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..432, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..206, module: Some( Identifier { id: Name("typing"), range: 174..180, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 188..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Annotated"), range: 188..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 199..206, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Literal"), range: 199..206, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -48,36 +48,34 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..230, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 211..214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 214..225, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 215..224, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 216..220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..224, id: Name("Ts"), ctx: Load, @@ -93,11 +91,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..230, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..230, }, ), @@ -108,40 +106,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..295, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 235..238, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 238..290, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 239..289, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 240..241, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..289, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..250, id: Name("Literal"), ctx: Load, @@ -149,13 +145,13 @@ Module( ), slice: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..288, value: StringLiteralValue { inner: Single( StringLiteral { range: 251..288, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "this should allow arbitrary strings", flags: StringLiteralFlags { quote_style: Double, @@ -180,11 +176,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 292..295, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 292..295, }, ), @@ -195,40 +191,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..367, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 300..303, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 303..362, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 304..361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 305..306, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..361, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 308..317, id: Name("Annotated"), ctx: Load, @@ -236,12 +230,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..360, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..321, id: Name("str"), ctx: Load, @@ -249,13 +243,13 @@ Module( ), StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 323..360, value: StringLiteralValue { inner: Single( StringLiteral { range: 323..360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "this should allow arbitrary strings", flags: StringLiteralFlags { quote_style: Double, @@ -285,11 +279,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..367, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..367, }, ), @@ -300,36 +294,34 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 368..405, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 372..375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 375..400, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 376..386, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 377..381, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..386, id: Name("str"), ctx: Load, @@ -342,16 +334,16 @@ Module( kwarg: Some( Parameter { range: 388..399, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwds"), range: 390..394, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 396..399, id: Name("int"), ctx: Load, @@ -365,11 +357,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 402..405, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 402..405, }, ), @@ -380,40 +372,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 406..431, is_async: false, decorator_list: [], name: Identifier { id: Name("union"), range: 410..415, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 415..426, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 416..425, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 417..418, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..425, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..421, id: Name("A"), ctx: Load, @@ -422,7 +412,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 424..425, id: Name("B"), ctx: Load, @@ -440,11 +430,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 428..431, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 428..431, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py311.py.snap index 0f1eed04f9f26..0853afb16c6b0 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@param_with_star_annotation_py311.py.snap @@ -7,45 +7,43 @@ input_file: crates/ruff_python_parser/resources/inline/ok/param_with_star_annota ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..69, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..68, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 48..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 51..63, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 52..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 53..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..62, id: Name("Ts"), ctx: Load, @@ -64,11 +62,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap index 2a4bdc6a75a1b..fba5d8d3ecdbe 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_non_default_after_star.py.snap @@ -7,45 +7,43 @@ input_file: crates/ruff_python_parser/resources/inline/ok/params_non_default_aft ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..72, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..33, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..28, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 8..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 8..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..12, value: Int( 10, @@ -59,14 +57,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 17..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -74,21 +72,21 @@ Module( }, ParameterWithDefault { range: 20..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 20..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..24, value: Int( 11, @@ -99,14 +97,14 @@ Module( }, ParameterWithDefault { range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 26..27, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -119,11 +117,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..33, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..33, }, ), @@ -134,40 +132,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..71, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 38..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 41..66, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 42..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 42..43, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..46, value: Int( 10, @@ -180,11 +176,11 @@ Module( vararg: Some( Parameter { range: 48..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 49..53, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -192,14 +188,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 55..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -207,21 +203,21 @@ Module( }, ParameterWithDefault { range: 58..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 58..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 58..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..62, value: Int( 11, @@ -232,14 +228,14 @@ Module( }, ParameterWithDefault { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -252,11 +248,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..71, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap index 458f38d3292e0..755948038868a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@params_seen_keyword_only_param_after_star.py.snap @@ -7,40 +7,38 @@ input_file: crates/ruff_python_parser/resources/inline/ok/params_seen_keyword_on ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..61, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 4..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 7..23, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, kwonlyargs: [ ParameterWithDefault { range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 11..12, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -50,11 +48,11 @@ Module( kwarg: Some( Parameter { range: 14..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 16..22, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -64,11 +62,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -79,42 +77,40 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..60, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 33..36, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 36..55, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, kwonlyargs: [ ParameterWithDefault { range: 40..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 40..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 40..41, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..44, value: Int( 10, @@ -127,11 +123,11 @@ Module( kwarg: Some( Parameter { range: 46..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 48..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -141,11 +137,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_context_manager_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_context_manager_py39.py.snap index b8b9b08747d5b..9d627ba68f530 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_context_manager_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_context_manager_py39.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/parenthesized_context_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..126, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..73, is_async: false, items: [ WithItem { range: 49..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, id: Name("foo"), ctx: Load, @@ -30,7 +30,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Store, @@ -40,10 +40,10 @@ Module( }, WithItem { range: 59..67, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, id: Name("bar"), ctx: Load, @@ -52,7 +52,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("y"), ctx: Store, @@ -64,11 +64,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..73, }, ), @@ -79,16 +79,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..99, is_async: false, items: [ WithItem { range: 80..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, id: Name("foo"), ctx: Load, @@ -98,10 +98,10 @@ Module( }, WithItem { range: 85..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, id: Name("bar"), ctx: Load, @@ -110,7 +110,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, id: Name("y"), ctx: Store, @@ -122,11 +122,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..99, }, ), @@ -137,16 +137,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..125, is_async: false, items: [ WithItem { range: 106..114, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..109, id: Name("foo"), ctx: Load, @@ -155,7 +155,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, id: Name("x"), ctx: Store, @@ -165,10 +165,10 @@ Module( }, WithItem { range: 116..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..119, id: Name("bar"), ctx: Load, @@ -180,11 +180,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..125, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..125, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap index 15feb12d3839c..91e6d3ec220e8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_kwarg_py37.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/parenthesized_kwarg_py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..52, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..51, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..51, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("f"), ctx: Load, @@ -28,22 +28,22 @@ Module( ), arguments: Arguments { range: 44..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 45..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("a"), range: 46..47, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_index_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_index_py38.py.snap index b5b5b300e52a1..a422908b73639 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_index_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_index_py38.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/parenthesized_named_ex ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..55, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..54, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..54, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..46, id: Name("lst"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), slice: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..52, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, id: Name("x"), ctx: Store, @@ -40,7 +40,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap index c1f65ffc1dd2a..1f14d31def9b3 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_named_expr_py38.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/inline/ok/parenthesized_named_ex ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..92, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..59, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..51, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, id: Name("x"), ctx: Store, @@ -33,7 +33,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, value: Int( 1, @@ -44,7 +44,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, value: Int( 2, @@ -53,7 +53,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, value: Int( 3, @@ -67,19 +67,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..91, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..91, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..71, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..66, id: Name("last"), ctx: Store, @@ -87,7 +87,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("x"), ctx: Load, @@ -98,10 +98,10 @@ Module( generators: [ Comprehension { range: 73..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("x"), ctx: Store, @@ -109,11 +109,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..90, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..87, id: Name("range"), ctx: Load, @@ -121,11 +121,11 @@ Module( ), arguments: Arguments { range: 87..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..89, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap index a1f2cd011db2c..cfae3dd052d1f 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@parenthesized_star_index_py310.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/inline/ok/parenthesized_star_ind ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..94, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..93, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..89, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, id: Name("out"), ctx: Load, @@ -29,24 +29,24 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..88, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..81, value: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..81, elt: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..62, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..56, id: Name("slice"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), arguments: Arguments { range: 56..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..61, }, ), @@ -70,10 +70,10 @@ Module( generators: [ Comprehension { range: 63..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("_"), ctx: Store, @@ -81,11 +81,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..80, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..77, id: Name("range"), ctx: Load, @@ -93,11 +93,11 @@ Module( ), arguments: Arguments { range: 77..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, value: Int( 2, @@ -121,11 +121,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..87, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..87, id: Name("ind"), ctx: Load, @@ -145,7 +145,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..93, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py311.py.snap index 6f728ba6daf91..581693aa41722 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py311.py.snap @@ -7,44 +7,44 @@ input_file: crates/ruff_python_parser/resources/inline/ok/pep701_f_string_py311. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..278, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..72, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..72, value: FStringValue { inner: Single( FString( FString { range: 44..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 46..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "outer ", }, ), Interpolation( InterpolatedElement { range: 52..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..70, value: StringLiteralValue { inner: Single( StringLiteral { range: 53..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "# not a comment", flags: StringLiteralFlags { quote_style: Single, @@ -77,33 +77,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..106, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..106, value: FStringValue { inner: Single( FString( FString { range: 73..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 75..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "outer ", }, ), Interpolation( InterpolatedElement { range: 81..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("x"), ctx: Load, @@ -114,21 +114,21 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 84..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 84..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..102, value: StringLiteralValue { inner: Single( StringLiteral { range: 85..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "# not a comment", flags: StringLiteralFlags { quote_style: Double, @@ -148,7 +148,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 103..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " ", }, ), @@ -173,62 +173,62 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..147, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..147, value: FStringValue { inner: Single( FString( FString { range: 107..147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 111..144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..143, value: FStringValue { inner: Single( FString( FString { range: 112..143, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 116..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..139, value: FStringValue { inner: Single( FString( FString { range: 117..139, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 119..138, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..137, value: StringLiteralValue { inner: Single( StringLiteral { range: 120..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "# not a comment", flags: StringLiteralFlags { quote_style: Double, @@ -295,96 +295,96 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..230, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..230, value: FStringValue { inner: Single( FString( FString { range: 148..230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 152..208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..207, value: FStringValue { inner: Single( FString( FString { range: 153..207, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 157..177, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "# before expression ", }, ), Interpolation( InterpolatedElement { range: 177..204, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..203, value: FStringValue { inner: Single( FString( FString { range: 178..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 180..185, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "# aro", }, ), Interpolation( InterpolatedElement { range: 185..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..196, value: FStringValue { inner: Single( FString( FString { range: 186..196, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 188..189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "#", }, ), Interpolation( InterpolatedElement { range: 189..194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..193, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..191, value: Int( 1, @@ -394,7 +394,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, value: Int( 1, @@ -411,7 +411,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 194..195, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "#", }, ), @@ -435,7 +435,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 197..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "und #", }, ), @@ -476,7 +476,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 208..227, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " # after expression", }, ), @@ -496,33 +496,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..263, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..263, value: FStringValue { inner: Single( FString( FString { range: 231..263, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 233..254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "escape outside of \t ", }, ), Interpolation( InterpolatedElement { range: 254..260, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..259, id: Name("expr"), ctx: Load, @@ -536,7 +536,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 260..262, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", }, ), @@ -556,23 +556,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..277, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..277, value: FStringValue { inner: Single( FString( FString { range: 264..277, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 266..276, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "test\"abcd", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap index aad89368d1754..6fb97c216eb27 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep701_f_string_py312.py.snap @@ -7,42 +7,42 @@ input_file: crates/ruff_python_parser/resources/inline/ok/pep701_f_string_py312. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..403, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..74, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..74, value: FStringValue { inner: Single( FString( FString { range: 44..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 46..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Magic wand: ", }, ), Interpolation( InterpolatedElement { range: 58..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..71, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, id: Name("bag"), ctx: Load, @@ -50,13 +50,13 @@ Module( ), slice: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..70, value: StringLiteralValue { inner: Single( StringLiteral { range: 64..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "wand", flags: StringLiteralFlags { quote_style: Single, @@ -92,40 +92,40 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..112, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..112, value: FStringValue { inner: Single( FString( FString { range: 95..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 97..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..110, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..107, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..102, value: StringLiteralValue { inner: Single( StringLiteral { range: 98..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", flags: StringLiteralFlags { quote_style: Single, @@ -140,18 +140,18 @@ Module( attr: Identifier { id: Name("join"), range: 103..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 107..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("a"), ctx: Load, @@ -183,37 +183,37 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..220, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..220, value: FStringValue { inner: Single( FString( FString { range: 148..220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 152..169, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "A complex trick: ", }, ), Interpolation( InterpolatedElement { range: 169..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..185, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..178, id: Name("bag"), ctx: Load, @@ -221,13 +221,13 @@ Module( ), slice: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..184, value: StringLiteralValue { inner: Single( StringLiteral { range: 179..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bag", flags: StringLiteralFlags { quote_style: Single, @@ -263,105 +263,105 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..254, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..254, value: FStringValue { inner: Single( FString( FString { range: 221..254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 223..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..252, value: FStringValue { inner: Single( FString( FString { range: 224..252, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 226..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..250, value: FStringValue { inner: Single( FString( FString { range: 227..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 229..249, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..248, value: FStringValue { inner: Single( FString( FString { range: 230..248, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 232..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..246, value: FStringValue { inner: Single( FString( FString { range: 233..246, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 235..245, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..244, value: FStringValue { inner: Single( FString( FString { range: 236..244, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 238..243, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..242, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, value: Int( 1, @@ -371,7 +371,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, value: Int( 1, @@ -486,47 +486,47 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..310, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..310, value: FStringValue { inner: Single( FString( FString { range: 276..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 278..303, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..302, value: FStringValue { inner: Single( FString( FString { range: 279..302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 283..293, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..292, value: StringLiteralValue { inner: Single( StringLiteral { range: 284..292, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "nested", flags: StringLiteralFlags { quote_style: Double, @@ -546,7 +546,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 293..299, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " inner", }, ), @@ -570,7 +570,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 303..309, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " outer", }, ), @@ -590,33 +590,33 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..359, value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..359, value: FStringValue { inner: Single( FString( FString { range: 336..359, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 338..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "test ", }, ), Interpolation( InterpolatedElement { range: 343..353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..345, id: Name("a"), ctx: Load, @@ -630,7 +630,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 353..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " more", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap index 217b66b09c347..6c656364a8eb7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pep750_t_string_py314.py.snap @@ -7,41 +7,41 @@ input_file: crates/ruff_python_parser/resources/inline/ok/pep750_t_string_py314. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..403, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..74, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..74, value: TStringValue { inner: Single( TString { range: 44..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 46..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Magic wand: ", }, ), Interpolation( InterpolatedElement { range: 58..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..71, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..63, id: Name("bag"), ctx: Load, @@ -49,13 +49,13 @@ Module( ), slice: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..70, value: StringLiteralValue { inner: Single( StringLiteral { range: 64..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "wand", flags: StringLiteralFlags { quote_style: Single, @@ -90,39 +90,39 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..112, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..112, value: TStringValue { inner: Single( TString { range: 95..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 97..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..110, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..107, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..102, value: StringLiteralValue { inner: Single( StringLiteral { range: 98..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "\n", flags: StringLiteralFlags { quote_style: Single, @@ -137,18 +137,18 @@ Module( attr: Identifier { id: Name("join"), range: 103..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 107..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("a"), ctx: Load, @@ -179,36 +179,36 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..220, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..220, value: TStringValue { inner: Single( TString { range: 148..220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 152..169, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "A complex trick: ", }, ), Interpolation( InterpolatedElement { range: 169..217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..185, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 175..178, id: Name("bag"), ctx: Load, @@ -216,13 +216,13 @@ Module( ), slice: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..184, value: StringLiteralValue { inner: Single( StringLiteral { range: 179..184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "bag", flags: StringLiteralFlags { quote_style: Single, @@ -257,99 +257,99 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..254, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..254, value: TStringValue { inner: Single( TString { range: 221..254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 223..253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..252, value: TStringValue { inner: Single( TString { range: 224..252, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 226..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..250, value: TStringValue { inner: Single( TString { range: 227..250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 229..249, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..248, value: TStringValue { inner: Single( TString { range: 230..248, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 232..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..246, value: TStringValue { inner: Single( TString { range: 233..246, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 235..245, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..244, value: TStringValue { inner: Single( TString { range: 236..244, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 238..243, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..242, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, value: Int( 1, @@ -359,7 +359,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..242, value: Int( 1, @@ -468,45 +468,45 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..310, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 276..310, value: TStringValue { inner: Single( TString { range: 276..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 278..303, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..302, value: TStringValue { inner: Single( TString { range: 279..302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 283..293, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..292, value: StringLiteralValue { inner: Single( StringLiteral { range: 284..292, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "nested", flags: StringLiteralFlags { quote_style: Double, @@ -526,7 +526,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 293..299, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " inner", }, ), @@ -549,7 +549,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 303..309, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " outer", }, ), @@ -568,32 +568,32 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..359, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..359, value: TStringValue { inner: Single( TString { range: 336..359, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 338..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "test ", }, ), Interpolation( InterpolatedElement { range: 343..353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..345, id: Name("a"), ctx: Load, @@ -607,7 +607,7 @@ Module( Literal( InterpolatedStringLiteralElement { range: 353..358, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " more", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pos_only_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pos_only_py38.py.snap index 69b218e41941d..fbf17fc8613eb 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@pos_only_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@pos_only_py38.py.snap @@ -7,37 +7,35 @@ input_file: crates/ruff_python_parser/resources/inline/ok/pos_only_py38.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..62, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..61, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 47..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 50..56, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -53,11 +51,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@read_from_debug.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@read_from_debug.py.snap index 7d3b052d80b2c..993a3512aacca 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@read_from_debug.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@read_from_debug.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/read_from_debug.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..32, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..12, id: Name("__debug__"), ctx: Load, @@ -25,11 +25,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, }, ), @@ -41,12 +41,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..31, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("x"), ctx: Store, @@ -55,7 +55,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..31, id: Name("__debug__"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap index 46c8be7e44698..6dbd6b9fbffe8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_in_block.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/simple_stmts_in_block. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..84, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..7, value: true, }, @@ -24,7 +24,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..13, }, ), @@ -34,11 +34,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..27, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..21, value: true, }, @@ -46,7 +46,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..27, }, ), @@ -56,11 +56,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..52, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..36, value: true, }, @@ -68,13 +68,13 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..42, }, ), Continue( StmtContinue { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, }, ), @@ -84,11 +84,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..76, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..60, value: true, }, @@ -96,13 +96,13 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..66, }, ), Continue( StmtContinue { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..76, }, ), @@ -112,12 +112,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..83, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..79, id: Name("x"), ctx: Store, @@ -126,7 +126,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap index 41be29071fedc..0f302ff4d14d7 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@simple_stmts_with_semicolons.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/inline/ok/simple_stmts_with_semi ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..51, body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: None, }, ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..16, names: [ Alias { range: 15..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 15..16, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -37,23 +37,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..33, module: Some( Identifier { id: Name("x"), range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 32..33, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -63,11 +63,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("z"), ctx: Load, @@ -77,11 +77,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..50, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("T"), ctx: Store, @@ -90,7 +90,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..50, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_star_in_tuple.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_star_in_tuple.py.snap index 4c44c9cbb38ef..ca0b875086d1b 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_star_in_tuple.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_star_in_tuple.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/single_star_in_tuple.p ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..84, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..20, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 4..5, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 5..7, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,25 +35,25 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..20, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..20, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..20, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..18, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..18, id: Name("x"), ctx: Load, @@ -79,21 +77,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..42, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 25..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 26..28, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -104,21 +100,21 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..42, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..42, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..40, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("x"), ctx: Load, @@ -140,12 +136,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..62, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("_"), ctx: Store, @@ -153,16 +149,16 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..57, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..55, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..55, id: Name("x"), ctx: Load, @@ -179,11 +175,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, }, ), @@ -195,21 +191,21 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..83, is_async: false, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..72, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..70, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, id: Name("x"), ctx: Store, @@ -225,7 +221,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..78, id: Name("xs"), ctx: Load, @@ -234,11 +230,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..83, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_starred_assignment_target.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_starred_assignment_target.py.snap index b2022525334a4..05dfde51fa531 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_starred_assignment_target.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@single_starred_assignment_target.py.snap @@ -7,26 +7,26 @@ input_file: crates/ruff_python_parser/resources/inline/ok/single_starred_assignm ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..36, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1..3, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2..3, id: Name("a"), ctx: Store, @@ -43,12 +43,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..12, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..10, value: Int( 1, @@ -64,21 +64,21 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..23, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..15, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("a"), ctx: Store, @@ -95,12 +95,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..23, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, value: Int( 1, @@ -116,21 +116,21 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..35, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..27, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("a"), ctx: Store, @@ -146,12 +146,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..35, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap index daf54439c214a..562a74ae6de00 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@star_index_py311.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/star_index_py311.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..293, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..55, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..55, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..47, id: Name("lst"), ctx: Load, @@ -28,16 +28,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..54, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..54, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..54, id: Name("index"), ctx: Load, @@ -58,27 +58,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..112, decorator_list: [], name: Identifier { id: Name("Array"), range: 78..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 83..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..106, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..91, id: Name("Generic"), ctx: Load, @@ -86,12 +86,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..105, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..97, id: Name("DType"), ctx: Load, @@ -99,11 +99,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..105, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..105, id: Name("Shape"), ctx: Load, @@ -127,11 +127,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, }, ), @@ -142,15 +142,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..161, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..161, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..151, id: Name("lst"), ctx: Load, @@ -158,12 +158,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..160, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..153, id: Name("a"), ctx: Load, @@ -171,11 +171,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..157, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("b"), ctx: Load, @@ -186,7 +186,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..160, id: Name("c"), ctx: Load, @@ -204,15 +204,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..198, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..198, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..188, id: Name("lst"), ctx: Load, @@ -220,12 +220,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..197, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("a"), ctx: Load, @@ -233,7 +233,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, id: Name("b"), ctx: Load, @@ -241,11 +241,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 195..197, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..197, id: Name("c"), ctx: Load, @@ -266,15 +266,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..233, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..233, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..225, id: Name("lst"), ctx: Load, @@ -282,16 +282,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..232, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..228, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..228, id: Name("a"), ctx: Load, @@ -302,11 +302,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..232, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..232, id: Name("b"), ctx: Load, @@ -327,15 +327,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..271, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..271, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..259, id: Name("array"), ctx: Load, @@ -343,17 +343,17 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..270, elts: [ Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..263, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..261, value: Int( 3, @@ -364,7 +364,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..263, value: Int( 5, @@ -377,11 +377,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..270, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..270, id: Name("idxs"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap index df0e3f80ed7b3..8e048cdfb7537 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__ambiguous_lpar_with_items.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/valid/statement/ambiguous_lpar_w ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..3620, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 588..604, is_async: false, items: [ WithItem { range: 594..598, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 594..598, id: Name("item"), ctx: Load, @@ -33,11 +33,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 601..604, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 601..604, }, ), @@ -48,16 +48,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 605..622, is_async: false, items: [ WithItem { range: 611..615, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 611..615, id: Name("item"), ctx: Load, @@ -69,11 +69,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 619..622, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 619..622, }, ), @@ -84,16 +84,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 648..668, is_async: false, items: [ WithItem { range: 654..662, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 656..660, id: Name("item"), ctx: Load, @@ -105,11 +105,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 665..668, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 665..668, }, ), @@ -120,16 +120,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 669..693, is_async: false, items: [ WithItem { range: 675..680, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 675..680, id: Name("item1"), ctx: Load, @@ -139,10 +139,10 @@ Module( }, WithItem { range: 682..687, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 682..687, id: Name("item2"), ctx: Load, @@ -154,11 +154,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 690..693, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 690..693, }, ), @@ -169,16 +169,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 694..719, is_async: false, items: [ WithItem { range: 700..705, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 700..705, id: Name("item1"), ctx: Load, @@ -188,10 +188,10 @@ Module( }, WithItem { range: 707..712, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 707..712, id: Name("item2"), ctx: Load, @@ -203,11 +203,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 716..719, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 716..719, }, ), @@ -218,16 +218,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 745..794, is_async: false, items: [ WithItem { range: 751..758, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 752..757, id: Name("item1"), ctx: Load, @@ -237,10 +237,10 @@ Module( }, WithItem { range: 760..767, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 761..766, id: Name("item2"), ctx: Load, @@ -250,10 +250,10 @@ Module( }, WithItem { range: 769..779, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 769..774, id: Name("item3"), ctx: Load, @@ -262,7 +262,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 778..779, id: Name("f"), ctx: Store, @@ -272,10 +272,10 @@ Module( }, WithItem { range: 781..788, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 782..787, id: Name("item4"), ctx: Load, @@ -287,11 +287,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 791..794, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 791..794, }, ), @@ -302,21 +302,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 795..828, is_async: false, items: [ WithItem { range: 801..815, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 801..815, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 802..807, id: Name("item1"), ctx: Load, @@ -324,7 +324,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 809..814, id: Name("item2"), ctx: Load, @@ -339,10 +339,10 @@ Module( }, WithItem { range: 817..822, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 817..822, id: Name("item3"), ctx: Load, @@ -354,11 +354,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 825..828, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 825..828, }, ), @@ -369,21 +369,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 829..852, is_async: false, items: [ WithItem { range: 835..846, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 835..841, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 836..837, id: Name("x"), ctx: Load, @@ -391,7 +391,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 839..840, id: Name("y"), ctx: Load, @@ -405,7 +405,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 845..846, id: Name("f"), ctx: Store, @@ -417,11 +417,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 849..852, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 849..852, }, ), @@ -432,16 +432,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 853..889, is_async: false, items: [ WithItem { range: 859..870, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 859..864, id: Name("item1"), ctx: Load, @@ -450,7 +450,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 868..870, id: Name("f1"), ctx: Store, @@ -460,10 +460,10 @@ Module( }, WithItem { range: 872..883, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 872..877, id: Name("item2"), ctx: Load, @@ -472,7 +472,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 881..883, id: Name("f2"), ctx: Store, @@ -484,11 +484,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 886..889, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 886..889, }, ), @@ -499,16 +499,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 890..927, is_async: false, items: [ WithItem { range: 896..907, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 896..901, id: Name("item1"), ctx: Load, @@ -517,7 +517,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 905..907, id: Name("f1"), ctx: Store, @@ -527,10 +527,10 @@ Module( }, WithItem { range: 909..920, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 909..914, id: Name("item2"), ctx: Load, @@ -539,7 +539,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 918..920, id: Name("f2"), ctx: Store, @@ -551,11 +551,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 924..927, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 924..927, }, ), @@ -566,20 +566,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 953..976, is_async: false, items: [ WithItem { range: 959..969, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 959..969, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 959..963, id: Name("item"), ctx: Load, @@ -591,7 +591,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 967..969, value: Int( 10, @@ -607,11 +607,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 973..976, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 973..976, }, ), @@ -622,20 +622,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 977..1001, is_async: false, items: [ WithItem { range: 983..995, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 984..994, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 984..988, id: Name("item"), ctx: Store, @@ -643,7 +643,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 992..994, value: Int( 10, @@ -658,11 +658,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 998..1001, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 998..1001, }, ), @@ -673,25 +673,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1002..1027, is_async: false, items: [ WithItem { range: 1008..1021, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1008..1021, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1009..1019, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1009..1013, id: Name("item"), ctx: Store, @@ -699,7 +699,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1017..1019, value: Int( 10, @@ -719,11 +719,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1024..1027, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1024..1027, }, ), @@ -734,25 +734,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1028..1048, is_async: false, items: [ WithItem { range: 1034..1042, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1034..1042, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1035..1040, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1036..1040, id: Name("item"), ctx: Load, @@ -772,11 +772,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1045..1048, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1045..1048, }, ), @@ -787,20 +787,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1049..1081, is_async: false, items: [ WithItem { range: 1055..1068, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1056..1067, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1056..1061, id: Name("item1"), ctx: Store, @@ -808,7 +808,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1065..1067, value: Int( 10, @@ -821,10 +821,10 @@ Module( }, WithItem { range: 1070..1075, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1070..1075, id: Name("item2"), ctx: Load, @@ -836,11 +836,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1078..1081, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1078..1081, }, ), @@ -851,16 +851,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1082..1119, is_async: false, items: [ WithItem { range: 1088..1098, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1088..1093, id: Name("item1"), ctx: Load, @@ -869,7 +869,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1097..1098, id: Name("f"), ctx: Store, @@ -879,14 +879,14 @@ Module( }, WithItem { range: 1100..1113, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1101..1112, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1101..1106, id: Name("item2"), ctx: Store, @@ -894,7 +894,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1110..1112, value: Int( 10, @@ -909,11 +909,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1116..1119, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1116..1119, }, ), @@ -924,20 +924,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1120..1137, is_async: false, items: [ WithItem { range: 1126..1131, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1126..1131, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1126..1129, id: Name("foo"), ctx: Load, @@ -945,7 +945,7 @@ Module( ), arguments: Arguments { range: 1129..1131, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -957,11 +957,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1134..1137, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1134..1137, }, ), @@ -972,20 +972,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1138..1156, is_async: false, items: [ WithItem { range: 1144..1149, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1144..1149, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1144..1147, id: Name("foo"), ctx: Load, @@ -993,7 +993,7 @@ Module( ), arguments: Arguments { range: 1147..1149, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1005,11 +1005,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1153..1156, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1153..1156, }, ), @@ -1020,20 +1020,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1157..1179, is_async: false, items: [ WithItem { range: 1163..1173, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1163..1168, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1163..1166, id: Name("foo"), ctx: Load, @@ -1041,7 +1041,7 @@ Module( ), arguments: Arguments { range: 1166..1168, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1050,7 +1050,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1172..1173, id: Name("f"), ctx: Store, @@ -1062,11 +1062,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1176..1179, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1176..1179, }, ), @@ -1077,31 +1077,31 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1180..1207, is_async: false, items: [ WithItem { range: 1186..1201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1186..1201, value: FStringValue { inner: Single( FString( FString { range: 1186..1201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 1188..1200, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1189..1193, id: Name("item"), ctx: Load, @@ -1112,12 +1112,12 @@ Module( format_spec: Some( InterpolatedStringFormatSpec { range: 1195..1199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 1195..1199, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "= 42", }, ), @@ -1144,11 +1144,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1204..1207, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1204..1207, }, ), @@ -1159,35 +1159,35 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1208..1237, is_async: false, items: [ WithItem { range: 1214..1231, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1214..1231, value: FStringValue { inner: Single( FString( FString { range: 1214..1231, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 1216..1230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1218..1228, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1218..1222, id: Name("item"), ctx: Store, @@ -1195,7 +1195,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1226..1228, value: Int( 42, @@ -1227,11 +1227,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1234..1237, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1234..1237, }, ), @@ -1242,20 +1242,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1238..1278, is_async: false, items: [ WithItem { range: 1244..1266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1244..1266, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1245..1246, id: Name("x"), ctx: Load, @@ -1264,10 +1264,10 @@ Module( generators: [ Comprehension { range: 1247..1265, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1251..1252, id: Name("x"), ctx: Store, @@ -1275,11 +1275,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1256..1265, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1256..1261, id: Name("range"), ctx: Load, @@ -1287,11 +1287,11 @@ Module( ), arguments: Arguments { range: 1261..1265, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1262..1264, value: Int( 10, @@ -1314,10 +1314,10 @@ Module( }, WithItem { range: 1268..1272, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1268..1272, id: Name("item"), ctx: Load, @@ -1329,11 +1329,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1275..1278, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1275..1278, }, ), @@ -1344,16 +1344,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1279..1319, is_async: false, items: [ WithItem { range: 1285..1289, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1285..1289, id: Name("item"), ctx: Load, @@ -1363,14 +1363,14 @@ Module( }, WithItem { range: 1291..1313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1291..1313, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1292..1293, id: Name("x"), ctx: Load, @@ -1379,10 +1379,10 @@ Module( generators: [ Comprehension { range: 1294..1312, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1298..1299, id: Name("x"), ctx: Store, @@ -1390,11 +1390,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1303..1312, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1303..1308, id: Name("range"), ctx: Load, @@ -1402,11 +1402,11 @@ Module( ), arguments: Arguments { range: 1308..1312, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1309..1311, value: Int( 10, @@ -1431,11 +1431,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1316..1319, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1316..1319, }, ), @@ -1446,16 +1446,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1320..1366, is_async: false, items: [ WithItem { range: 1326..1330, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1326..1330, id: Name("item"), ctx: Load, @@ -1465,14 +1465,14 @@ Module( }, WithItem { range: 1332..1354, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1332..1354, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1333..1334, id: Name("x"), ctx: Load, @@ -1481,10 +1481,10 @@ Module( generators: [ Comprehension { range: 1335..1353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1339..1340, id: Name("x"), ctx: Store, @@ -1492,11 +1492,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1344..1353, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1344..1349, id: Name("range"), ctx: Load, @@ -1504,11 +1504,11 @@ Module( ), arguments: Arguments { range: 1349..1353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1350..1352, value: Int( 10, @@ -1531,10 +1531,10 @@ Module( }, WithItem { range: 1356..1360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1356..1360, id: Name("item"), ctx: Load, @@ -1546,11 +1546,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1363..1366, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1363..1366, }, ), @@ -1561,20 +1561,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1367..1388, is_async: false, items: [ WithItem { range: 1373..1382, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1373..1382, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1373..1377, id: Name("data"), ctx: Load, @@ -1582,12 +1582,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1378..1381, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1378..1379, value: Int( 1, @@ -1598,7 +1598,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1380..1381, value: Int( 2, @@ -1618,11 +1618,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1385..1388, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1385..1388, }, ), @@ -1633,20 +1633,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1389..1415, is_async: false, items: [ WithItem { range: 1395..1409, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1395..1404, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1395..1399, id: Name("data"), ctx: Load, @@ -1654,12 +1654,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1400..1403, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1400..1401, value: Int( 1, @@ -1670,7 +1670,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1402..1403, value: Int( 2, @@ -1687,7 +1687,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1408..1409, id: Name("f"), ctx: Store, @@ -1699,11 +1699,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1412..1415, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1412..1415, }, ), @@ -1714,20 +1714,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1416..1450, is_async: false, items: [ WithItem { range: 1422..1444, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1422..1439, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1423..1424, id: Name("x"), ctx: Load, @@ -1736,10 +1736,10 @@ Module( generators: [ Comprehension { range: 1425..1438, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1429..1430, id: Name("x"), ctx: Store, @@ -1747,7 +1747,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1434..1438, id: Name("iter"), ctx: Load, @@ -1763,7 +1763,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1443..1444, id: Name("y"), ctx: Store, @@ -1775,11 +1775,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1447..1450, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1447..1450, }, ), @@ -1790,16 +1790,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1663..1684, is_async: false, items: [ WithItem { range: 1668..1679, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1669..1673, id: Name("item"), ctx: Load, @@ -1808,7 +1808,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1678..1679, id: Name("f"), ctx: Store, @@ -1820,11 +1820,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1681..1684, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1681..1684, }, ), @@ -1835,20 +1835,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1685..1707, is_async: false, items: [ WithItem { range: 1690..1702, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1691..1701, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1691..1695, id: Name("item"), ctx: Store, @@ -1856,7 +1856,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1699..1701, value: Int( 10, @@ -1871,11 +1871,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1704..1707, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1704..1707, }, ), @@ -1886,20 +1886,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1708..1735, is_async: false, items: [ WithItem { range: 1713..1730, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1714..1724, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1714..1718, id: Name("item"), ctx: Store, @@ -1907,7 +1907,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1722..1724, value: Int( 10, @@ -1919,7 +1919,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1729..1730, id: Name("f"), ctx: Store, @@ -1931,11 +1931,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1732..1735, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1732..1735, }, ), @@ -1946,20 +1946,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1736..1762, is_async: false, items: [ WithItem { range: 1741..1757, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1744..1753, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1744..1748, id: Name("item"), ctx: Store, @@ -1967,7 +1967,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1752..1753, value: Int( 1, @@ -1982,11 +1982,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1759..1762, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1759..1762, }, ), @@ -1997,20 +1997,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1763..1793, is_async: false, items: [ WithItem { range: 1768..1781, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1769..1780, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1769..1774, id: Name("item1"), ctx: Store, @@ -2018,7 +2018,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1778..1780, value: Int( 42, @@ -2031,10 +2031,10 @@ Module( }, WithItem { range: 1783..1788, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1783..1788, id: Name("item2"), ctx: Load, @@ -2046,11 +2046,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1790..1793, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1790..1793, }, ), @@ -2061,28 +2061,28 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1794..1828, is_async: false, items: [ WithItem { range: 1799..1823, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1799..1823, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1799..1821, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1800..1815, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1800..1804, id: Name("root"), ctx: Load, @@ -2091,7 +2091,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1807..1815, id: Name("filename"), ctx: Load, @@ -2102,14 +2102,14 @@ Module( attr: Identifier { id: Name("read"), range: 1817..1821, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 1821..1823, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -2121,11 +2121,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1825..1828, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1825..1828, }, ), @@ -2136,28 +2136,28 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1851..1890, is_async: false, items: [ WithItem { range: 1856..1885, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1856..1880, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1856..1878, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1857..1872, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1857..1861, id: Name("root"), ctx: Load, @@ -2166,7 +2166,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1864..1872, id: Name("filename"), ctx: Load, @@ -2177,14 +2177,14 @@ Module( attr: Identifier { id: Name("read"), range: 1874..1878, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 1878..1880, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -2193,7 +2193,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1884..1885, id: Name("f"), ctx: Store, @@ -2205,11 +2205,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1887..1890, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1887..1890, }, ), @@ -2220,20 +2220,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1913..1930, is_async: false, items: [ WithItem { range: 1918..1925, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1918..1925, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1919..1922, id: Name("foo"), ctx: Load, @@ -2241,7 +2241,7 @@ Module( ), arguments: Arguments { range: 1923..1925, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -2253,11 +2253,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1927..1930, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1927..1930, }, ), @@ -2268,20 +2268,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1953..1975, is_async: false, items: [ WithItem { range: 1958..1970, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1958..1965, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1959..1962, id: Name("foo"), ctx: Load, @@ -2289,7 +2289,7 @@ Module( ), arguments: Arguments { range: 1963..1965, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -2298,7 +2298,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1969..1970, id: Name("f"), ctx: Store, @@ -2310,11 +2310,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1972..1975, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1972..1975, }, ), @@ -2325,20 +2325,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1998..2020, is_async: false, items: [ WithItem { range: 2003..2015, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2004..2009, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2004..2007, id: Name("foo"), ctx: Load, @@ -2346,7 +2346,7 @@ Module( ), arguments: Arguments { range: 2007..2009, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -2355,7 +2355,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2014..2015, id: Name("f"), ctx: Store, @@ -2367,11 +2367,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2017..2020, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2017..2020, }, ), @@ -2382,20 +2382,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2021..2047, is_async: false, items: [ WithItem { range: 2026..2042, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2027..2036, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2027..2031, id: Name("data"), ctx: Load, @@ -2403,12 +2403,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2032..2035, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2032..2033, value: Int( 1, @@ -2419,7 +2419,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2034..2035, value: Int( 2, @@ -2436,7 +2436,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2041..2042, id: Name("f"), ctx: Store, @@ -2448,11 +2448,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2044..2047, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2044..2047, }, ), @@ -2463,25 +2463,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2048..2070, is_async: false, items: [ WithItem { range: 2053..2065, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2053..2065, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2053..2062, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2054..2055, value: Int( 1, @@ -2490,7 +2490,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2057..2058, value: Int( 2, @@ -2499,7 +2499,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2060..2061, value: Int( 3, @@ -2513,7 +2513,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2063..2064, value: Int( 0, @@ -2529,11 +2529,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2067..2070, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2067..2070, }, ), @@ -2544,25 +2544,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2093..2120, is_async: false, items: [ WithItem { range: 2098..2115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2098..2110, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2098..2107, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2099..2100, value: Int( 1, @@ -2571,7 +2571,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2102..2103, value: Int( 2, @@ -2580,7 +2580,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2105..2106, value: Int( 3, @@ -2594,7 +2594,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2108..2109, value: Int( 0, @@ -2607,7 +2607,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2114..2115, id: Name("f"), ctx: Store, @@ -2619,11 +2619,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2117..2120, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2117..2120, }, ), @@ -2634,16 +2634,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2143..2169, is_async: false, items: [ WithItem { range: 2148..2155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2149..2154, id: Name("item1"), ctx: Load, @@ -2653,10 +2653,10 @@ Module( }, WithItem { range: 2157..2164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2158..2163, id: Name("item2"), ctx: Load, @@ -2668,11 +2668,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2166..2169, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2166..2169, }, ), @@ -2683,20 +2683,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2170..2210, is_async: false, items: [ WithItem { range: 2175..2189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2176..2188, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2176..2180, id: Name("open"), ctx: Load, @@ -2704,17 +2704,17 @@ Module( ), arguments: Arguments { range: 2180..2188, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2181..2187, value: StringLiteralValue { inner: Single( StringLiteral { range: 2181..2187, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "a.py", flags: StringLiteralFlags { quote_style: Single, @@ -2735,14 +2735,14 @@ Module( }, WithItem { range: 2191..2205, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2192..2204, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2192..2196, id: Name("open"), ctx: Load, @@ -2750,17 +2750,17 @@ Module( ), arguments: Arguments { range: 2196..2204, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2197..2203, value: StringLiteralValue { inner: Single( StringLiteral { range: 2197..2203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "b.py", flags: StringLiteralFlags { quote_style: Single, @@ -2783,11 +2783,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2207..2210, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2207..2210, }, ), @@ -2798,21 +2798,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2211..2230, is_async: false, items: [ WithItem { range: 2216..2225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2217..2224, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2223..2224, id: Name("x"), ctx: Load, @@ -2827,11 +2827,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2227..2230, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2227..2230, }, ), @@ -2842,21 +2842,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2231..2252, is_async: false, items: [ WithItem { range: 2237..2246, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2238..2245, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2244..2245, id: Name("x"), ctx: Load, @@ -2871,11 +2871,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2249..2252, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2249..2252, }, ), @@ -2886,20 +2886,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2253..2277, is_async: false, items: [ WithItem { range: 2258..2272, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2259..2271, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2270..2271, id: Name("x"), ctx: Load, @@ -2913,11 +2913,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2274..2277, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2274..2277, }, ), @@ -2928,20 +2928,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2278..2304, is_async: false, items: [ WithItem { range: 2284..2298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2285..2297, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2296..2297, id: Name("x"), ctx: Load, @@ -2955,11 +2955,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2301..2304, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2301..2304, }, ), @@ -2970,21 +2970,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2305..2329, is_async: false, items: [ WithItem { range: 2310..2324, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2311..2318, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2317..2318, id: Name("x"), ctx: Load, @@ -2996,7 +2996,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2323..2324, id: Name("f"), ctx: Store, @@ -3008,11 +3008,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2326..2329, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2326..2329, }, ), @@ -3023,26 +3023,26 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2330..2355, is_async: false, items: [ WithItem { range: 2335..2350, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2336..2344, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2342..2344, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2342..2343, id: Name("x"), ctx: Load, @@ -3059,7 +3059,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2349..2350, id: Name("f"), ctx: Store, @@ -3071,11 +3071,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2352..2355, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2352..2355, }, ), @@ -3086,16 +3086,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2741..2753, is_async: false, items: [ WithItem { range: 2746..2748, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2746..2748, elts: [], ctx: Load, @@ -3108,11 +3108,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2750..2753, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2750..2753, }, ), @@ -3123,16 +3123,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2754..2771, is_async: false, items: [ WithItem { range: 2759..2766, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2759..2761, elts: [], ctx: Load, @@ -3142,7 +3142,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2765..2766, id: Name("f"), ctx: Store, @@ -3154,11 +3154,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2768..2771, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2768..2771, }, ), @@ -3169,25 +3169,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2772..2795, is_async: false, items: [ WithItem { range: 2777..2790, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2777..2790, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2778..2788, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2778..2782, id: Name("item"), ctx: Store, @@ -3195,7 +3195,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2786..2788, value: Int( 42, @@ -3215,11 +3215,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2792..2795, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2792..2795, }, ), @@ -3230,21 +3230,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2796..2820, is_async: false, items: [ WithItem { range: 2801..2815, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2801..2815, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2802..2803, value: Int( 1, @@ -3253,11 +3253,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2805..2814, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2805..2809, id: Name("item"), ctx: Store, @@ -3265,7 +3265,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2813..2814, value: Int( 2, @@ -3285,11 +3285,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2817..2820, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2817..2820, }, ), @@ -3300,25 +3300,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2821..2851, is_async: false, items: [ WithItem { range: 2826..2846, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2826..2846, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2827..2838, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2827..2832, id: Name("item1"), ctx: Store, @@ -3326,7 +3326,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2836..2838, value: Int( 10, @@ -3337,7 +3337,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2840..2845, id: Name("item2"), ctx: Load, @@ -3354,11 +3354,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2848..2851, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2848..2851, }, ), @@ -3369,21 +3369,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2852..2893, is_async: false, items: [ WithItem { range: 2857..2888, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2857..2883, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2858..2863, id: Name("item1"), ctx: Load, @@ -3391,11 +3391,11 @@ Module( ), Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2865..2875, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2865..2870, id: Name("item2"), ctx: Store, @@ -3403,7 +3403,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2874..2875, value: Int( 2, @@ -3414,7 +3414,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2877..2882, id: Name("item3"), ctx: Load, @@ -3428,7 +3428,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2887..2888, id: Name("f"), ctx: Store, @@ -3440,11 +3440,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2890..2893, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2890..2893, }, ), @@ -3455,21 +3455,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2894..2916, is_async: false, items: [ WithItem { range: 2899..2911, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2899..2906, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2900..2904, id: Name("item"), ctx: Load, @@ -3483,7 +3483,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2910..2911, id: Name("f"), ctx: Store, @@ -3495,11 +3495,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2913..2916, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2913..2916, }, ), @@ -3510,25 +3510,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2917..2935, is_async: false, items: [ WithItem { range: 2922..2930, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2922..2930, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2923..2928, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2924..2928, id: Name("item"), ctx: Load, @@ -3548,11 +3548,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2932..2935, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2932..2935, }, ), @@ -3563,25 +3563,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2936..2959, is_async: false, items: [ WithItem { range: 2941..2954, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2941..2949, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2942..2947, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2943..2947, id: Name("item"), ctx: Load, @@ -3598,7 +3598,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2953..2954, id: Name("f"), ctx: Store, @@ -3610,11 +3610,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2956..2959, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2956..2959, }, ), @@ -3625,21 +3625,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2960..2989, is_async: false, items: [ WithItem { range: 2965..2984, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2965..2979, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2966..2971, id: Name("item1"), ctx: Load, @@ -3647,7 +3647,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2973..2978, id: Name("item2"), ctx: Load, @@ -3661,7 +3661,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2983..2984, id: Name("f"), ctx: Store, @@ -3673,11 +3673,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2986..2989, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2986..2989, }, ), @@ -3688,21 +3688,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2990..3020, is_async: false, items: [ WithItem { range: 2995..3015, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2995..3010, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2996..3001, id: Name("item1"), ctx: Load, @@ -3710,7 +3710,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3003..3008, id: Name("item2"), ctx: Load, @@ -3724,7 +3724,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3014..3015, id: Name("f"), ctx: Store, @@ -3736,11 +3736,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3017..3020, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3017..3020, }, ), @@ -3751,21 +3751,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3021..3052, is_async: false, items: [ WithItem { range: 3026..3040, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3026..3040, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3027..3032, id: Name("item1"), ctx: Load, @@ -3773,7 +3773,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3034..3039, id: Name("item2"), ctx: Load, @@ -3788,10 +3788,10 @@ Module( }, WithItem { range: 3042..3047, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3042..3047, id: Name("item3"), ctx: Load, @@ -3803,11 +3803,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3049..3052, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3049..3052, }, ), @@ -3818,26 +3818,26 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3053..3091, is_async: false, items: [ WithItem { range: 3058..3086, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3058..3081, elts: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3059..3073, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3060..3065, id: Name("item1"), ctx: Load, @@ -3845,7 +3845,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3067..3072, id: Name("item2"), ctx: Load, @@ -3858,7 +3858,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3075..3080, id: Name("item3"), ctx: Load, @@ -3872,7 +3872,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3085..3086, id: Name("f"), ctx: Store, @@ -3884,11 +3884,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3088..3091, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3088..3091, }, ), @@ -3899,21 +3899,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3092..3138, is_async: false, items: [ WithItem { range: 3097..3105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3097..3105, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3098..3103, id: Name("item1"), ctx: Load, @@ -3928,10 +3928,10 @@ Module( }, WithItem { range: 3107..3112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3107..3112, id: Name("item2"), ctx: Load, @@ -3941,15 +3941,15 @@ Module( }, WithItem { range: 3114..3133, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3114..3128, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3115..3120, id: Name("item3"), ctx: Load, @@ -3957,7 +3957,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3122..3127, id: Name("item4"), ctx: Load, @@ -3971,7 +3971,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3132..3133, id: Name("f"), ctx: Store, @@ -3983,11 +3983,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3135..3138, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3135..3138, }, ), @@ -3998,21 +3998,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3139..3182, is_async: false, items: [ WithItem { range: 3144..3164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3144..3158, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3145..3150, id: Name("item1"), ctx: Load, @@ -4020,7 +4020,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3152..3157, id: Name("item2"), ctx: Load, @@ -4034,7 +4034,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3162..3164, id: Name("f1"), ctx: Store, @@ -4044,10 +4044,10 @@ Module( }, WithItem { range: 3166..3177, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3166..3171, id: Name("item3"), ctx: Load, @@ -4056,7 +4056,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3175..3177, id: Name("f2"), ctx: Store, @@ -4068,11 +4068,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3179..3182, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3179..3182, }, ), @@ -4083,21 +4083,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3183..3208, is_async: false, items: [ WithItem { range: 3188..3203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3188..3203, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3189..3194, id: Name("item1"), ctx: Load, @@ -4105,11 +4105,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3196..3202, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3197..3202, id: Name("item2"), ctx: Load, @@ -4129,11 +4129,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3205..3208, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3205..3208, }, ), @@ -4144,21 +4144,21 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3209..3239, is_async: false, items: [ WithItem { range: 3214..3234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3214..3229, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3215..3220, id: Name("item1"), ctx: Load, @@ -4166,11 +4166,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3222..3228, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3223..3228, id: Name("item2"), ctx: Load, @@ -4187,7 +4187,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3233..3234, id: Name("f"), ctx: Store, @@ -4199,11 +4199,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3236..3239, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3236..3239, }, ), @@ -4214,25 +4214,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3240..3271, is_async: false, items: [ WithItem { range: 3245..3266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3245..3266, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3246..3257, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3246..3251, id: Name("item1"), ctx: Store, @@ -4240,7 +4240,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3255..3257, value: Int( 10, @@ -4251,11 +4251,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3259..3265, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3260..3265, id: Name("item2"), ctx: Load, @@ -4275,11 +4275,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3268..3271, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3268..3271, }, ), @@ -4290,25 +4290,25 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3272..3305, is_async: false, items: [ WithItem { range: 3277..3300, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3277..3300, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3279..3290, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3279..3284, id: Name("item1"), ctx: Store, @@ -4316,7 +4316,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3288..3290, value: Int( 10, @@ -4327,11 +4327,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3293..3299, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3294..3299, id: Name("item2"), ctx: Load, @@ -4351,11 +4351,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3302..3305, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3302..3305, }, ), @@ -4366,20 +4366,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3510..3542, is_async: false, items: [ WithItem { range: 3515..3537, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3515..3537, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3516..3517, id: Name("x"), ctx: Load, @@ -4388,10 +4388,10 @@ Module( generators: [ Comprehension { range: 3518..3536, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3522..3523, id: Name("x"), ctx: Store, @@ -4399,11 +4399,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3527..3536, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3527..3532, id: Name("range"), ctx: Load, @@ -4411,11 +4411,11 @@ Module( ), arguments: Arguments { range: 3532..3536, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3533..3535, value: Int( 10, @@ -4440,11 +4440,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3539..3542, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3539..3542, }, ), @@ -4455,20 +4455,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3543..3581, is_async: false, items: [ WithItem { range: 3548..3576, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3548..3576, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3549..3550, id: Name("x"), ctx: Load, @@ -4477,10 +4477,10 @@ Module( generators: [ Comprehension { range: 3551..3575, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3561..3562, id: Name("x"), ctx: Store, @@ -4488,11 +4488,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3566..3575, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3566..3571, id: Name("range"), ctx: Load, @@ -4500,11 +4500,11 @@ Module( ), arguments: Arguments { range: 3571..3575, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3572..3574, value: Int( 10, @@ -4529,11 +4529,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3578..3581, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3578..3581, }, ), @@ -4544,20 +4544,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3582..3620, is_async: false, items: [ WithItem { range: 3587..3609, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Generator( ExprGenerator { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3587..3609, elt: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3588..3589, id: Name("x"), ctx: Load, @@ -4566,10 +4566,10 @@ Module( generators: [ Comprehension { range: 3590..3608, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3594..3595, id: Name("x"), ctx: Store, @@ -4577,11 +4577,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3599..3608, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3599..3604, id: Name("range"), ctx: Load, @@ -4589,11 +4589,11 @@ Module( ), arguments: Arguments { range: 3604..3608, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3605..3607, value: Int( 10, @@ -4616,10 +4616,10 @@ Module( }, WithItem { range: 3611..3615, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3611..3615, id: Name("item"), ctx: Load, @@ -4631,11 +4631,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3617..3620, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3617..3620, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap index 4f2c579ca34c4..dfcabffa7688b 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__annotated_assignment.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/statement/annotated_assign ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..103, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -24,7 +24,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..6, id: Name("int"), ctx: Load, @@ -36,11 +36,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..17, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Store, @@ -48,7 +48,7 @@ Module( ), annotation: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 10..13, id: Name("int"), ctx: Load, @@ -57,7 +57,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, value: Int( 1, @@ -70,11 +70,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..28, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("x"), ctx: Store, @@ -82,11 +82,11 @@ Module( ), annotation: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..28, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, value: Int( 1, @@ -96,7 +96,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..28, value: Int( 2, @@ -111,11 +111,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..55, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("x"), ctx: Store, @@ -123,15 +123,15 @@ Module( ), annotation: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..48, left: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..42, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..37, id: Name("tuple"), ctx: Load, @@ -139,7 +139,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, id: Name("int"), ctx: Load, @@ -151,7 +151,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..48, id: Name("int"), ctx: Load, @@ -162,12 +162,12 @@ Module( value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..55, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, value: Int( 1, @@ -185,11 +185,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..83, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Store, @@ -197,18 +197,18 @@ Module( ), annotation: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..79, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..70, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, id: Name("int"), ctx: Load, @@ -216,7 +216,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, id: Name("str"), ctx: Load, @@ -227,7 +227,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, value: Int( 1, @@ -240,11 +240,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..102, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, id: Name("x"), ctx: Store, @@ -252,26 +252,24 @@ Module( ), annotation: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..98, parameters: Some( Parameters { range: 94..95, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -285,7 +283,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..98, id: Name("y"), ctx: Load, @@ -296,7 +294,7 @@ Module( value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap index e73517455e5c7..b3cb2bc013d1a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assert.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/valid/statement/assert.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..186, body: [ Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, test: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..12, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, value: Int( 1, @@ -33,7 +33,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Int( 2, @@ -48,15 +48,15 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..26, test: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..26, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..24, id: Name("call"), ctx: Load, @@ -64,7 +64,7 @@ Module( ), arguments: Arguments { range: 24..26, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -75,17 +75,17 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..41, test: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..41, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..35, id: Name("a"), ctx: Load, @@ -93,7 +93,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..41, id: Name("b"), ctx: Load, @@ -107,30 +107,28 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..60, test: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..60, parameters: Some( Parameters { range: 56..57, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 56..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -144,7 +142,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("y"), ctx: Load, @@ -157,15 +155,15 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..75, test: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..75, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("x"), ctx: Load, @@ -178,22 +176,22 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..99, test: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..99, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..92, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Load, @@ -201,7 +199,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("y"), ctx: Load, @@ -214,11 +212,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..118, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..109, id: Name("x"), ctx: Load, @@ -227,13 +225,13 @@ Module( msg: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..118, value: StringLiteralValue { inner: Single( StringLiteral { range: 111..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "error", flags: StringLiteralFlags { quote_style: Double, @@ -250,11 +248,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..140, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..127, id: Name("x"), ctx: Load, @@ -263,26 +261,24 @@ Module( msg: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..140, parameters: Some( Parameters { range: 136..137, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 136..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 136..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 136..137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -296,7 +292,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..140, id: Name("y"), ctx: Load, @@ -309,11 +305,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..158, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..149, id: Name("x"), ctx: Load, @@ -322,11 +318,11 @@ Module( msg: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..158, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, id: Name("x"), ctx: Load, @@ -339,11 +335,11 @@ Module( ), Assert( StmtAssert { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..185, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("x"), ctx: Load, @@ -352,18 +348,18 @@ Module( msg: Some( If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..185, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..178, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..170, id: Name("x"), ctx: Load, @@ -371,7 +367,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..185, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap index d649315b7d8b5..852bb10a83c19 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__assignment.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/valid/statement/assignment.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..729, body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..13, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -26,12 +26,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..13, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -40,7 +40,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, value: Int( 2, @@ -49,7 +49,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, value: Int( 3, @@ -65,17 +65,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..33, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..21, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..17, id: Name("x"), ctx: Store, @@ -83,7 +83,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 19..20, id: Name("y"), ctx: Store, @@ -97,12 +97,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..33, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, value: Int( 1, @@ -111,7 +111,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, value: Int( 2, @@ -120,7 +120,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..32, value: Int( 3, @@ -136,17 +136,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..53, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..41, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("x"), ctx: Store, @@ -154,7 +154,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("y"), ctx: Store, @@ -167,12 +167,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..53, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, value: Int( 1, @@ -181,7 +181,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, value: Int( 2, @@ -190,7 +190,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 3, @@ -206,16 +206,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..70, targets: [ Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, id: Name("x"), ctx: Load, @@ -224,7 +224,7 @@ Module( attr: Identifier { id: Name("y"), range: 57..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, @@ -232,12 +232,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..70, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..63, value: Int( 1, @@ -246,7 +246,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, value: Int( 2, @@ -255,7 +255,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, value: Int( 3, @@ -271,16 +271,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..88, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..76, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("x"), ctx: Load, @@ -288,7 +288,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..75, id: Name("y"), ctx: Load, @@ -300,12 +300,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..88, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, value: Int( 1, @@ -314,7 +314,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 2, @@ -323,7 +323,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, value: Int( 3, @@ -339,17 +339,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..109, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..97, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, id: Name("x"), ctx: Store, @@ -357,11 +357,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..96, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..96, id: Name("y"), ctx: Store, @@ -378,12 +378,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..109, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, value: Int( 1, @@ -392,7 +392,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, value: Int( 2, @@ -401,7 +401,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..108, value: Int( 3, @@ -417,17 +417,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..280, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..268, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..261, id: Name("x"), ctx: Store, @@ -435,7 +435,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..264, id: Name("y"), ctx: Store, @@ -443,7 +443,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 266..267, id: Name("z"), ctx: Store, @@ -456,12 +456,12 @@ Module( ], value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..280, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..273, value: Int( 1, @@ -470,7 +470,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 275..276, value: Int( 2, @@ -479,7 +479,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..279, value: Int( 3, @@ -494,17 +494,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..303, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..291, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 283..284, id: Name("x"), ctx: Store, @@ -512,7 +512,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..287, id: Name("y"), ctx: Store, @@ -520,7 +520,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..290, id: Name("z"), ctx: Store, @@ -534,12 +534,12 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 294..303, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 295..296, value: Int( 1, @@ -548,7 +548,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 298..299, value: Int( 2, @@ -557,7 +557,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..302, value: Int( 3, @@ -573,16 +573,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..313, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..308, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..305, id: Name("x"), ctx: Load, @@ -590,7 +590,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..307, value: Int( 0, @@ -603,7 +603,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 311..313, value: Int( 42, @@ -614,16 +614,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 410..419, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 410..414, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 410..411, value: Int( 5, @@ -632,7 +632,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 412..413, value: Int( 0, @@ -645,7 +645,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 417..419, value: Int( 42, @@ -656,16 +656,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..433, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..426, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 420..421, id: Name("x"), ctx: Load, @@ -673,12 +673,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 422..425, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 422..423, value: Int( 1, @@ -689,7 +689,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 424..425, value: Int( 2, @@ -706,12 +706,12 @@ Module( ], value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 429..433, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 430..432, value: Int( 42, @@ -726,16 +726,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 529..542, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 529..535, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 529..530, value: Int( 5, @@ -744,12 +744,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 531..534, lower: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 531..532, value: Int( 1, @@ -760,7 +760,7 @@ Module( upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 533..534, value: Int( 2, @@ -777,12 +777,12 @@ Module( ], value: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 538..542, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 539..541, value: Int( 42, @@ -797,16 +797,16 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 544..556, targets: [ Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 544..551, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 544..547, id: Name("foo"), ctx: Load, @@ -815,7 +815,7 @@ Module( attr: Identifier { id: Name("bar"), range: 548..551, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, @@ -823,7 +823,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 554..556, value: Int( 42, @@ -834,22 +834,22 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..670, targets: [ Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..665, value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..663, value: StringLiteralValue { inner: Single( StringLiteral { range: 658..663, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -864,7 +864,7 @@ Module( attr: Identifier { id: Name("y"), range: 664..665, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, @@ -872,7 +872,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 668..670, value: Int( 42, @@ -883,12 +883,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 672..680, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 672..675, id: Name("foo"), ctx: Store, @@ -897,7 +897,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 678..680, value: Int( 42, @@ -908,12 +908,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 682..695, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 682..684, elts: [], ctx: Store, @@ -922,16 +922,16 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 687..695, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 688..693, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 689..693, id: Name("data"), ctx: Load, @@ -949,12 +949,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 696..709, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 696..698, elts: [], ctx: Store, @@ -964,16 +964,16 @@ Module( ], value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 701..709, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 702..707, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 703..707, id: Name("data"), ctx: Load, @@ -991,17 +991,17 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..719, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..714, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 710..711, id: Name("a"), ctx: Store, @@ -1009,7 +1009,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 713..714, id: Name("b"), ctx: Store, @@ -1023,7 +1023,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 717..719, id: Name("ab"), ctx: Load, @@ -1033,12 +1033,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 720..729, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 720..721, id: Name("a"), ctx: Store, @@ -1046,7 +1046,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 724..725, id: Name("b"), ctx: Store, @@ -1055,7 +1055,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 728..729, id: Name("c"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap index aabb6b245bd57..3b4ad5727e073 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__augmented_assignment.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/statement/augmented_assign ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..212, body: [ AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1, id: Name("x"), ctx: Store, @@ -25,7 +25,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, value: Int( 1, @@ -36,15 +36,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..23, target: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..10, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..8, id: Name("x"), ctx: Load, @@ -53,7 +53,7 @@ Module( attr: Identifier { id: Name("y"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, @@ -61,12 +61,12 @@ Module( op: Add, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..23, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 15..16, value: Int( 1, @@ -75,7 +75,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, value: Int( 2, @@ -84,7 +84,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, value: Int( 3, @@ -100,15 +100,15 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..41, target: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Load, @@ -116,7 +116,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..27, id: Name("y"), ctx: Load, @@ -128,12 +128,12 @@ Module( op: Add, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..41, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..34, value: Int( 1, @@ -142,7 +142,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, value: Int( 2, @@ -151,7 +151,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, value: Int( 3, @@ -167,11 +167,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..92, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, id: Name("x"), ctx: Store, @@ -180,7 +180,7 @@ Module( op: Add, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, value: Int( 1, @@ -191,11 +191,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..99, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("x"), ctx: Store, @@ -204,7 +204,7 @@ Module( op: Sub, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, value: Int( 1, @@ -215,11 +215,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..106, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("x"), ctx: Store, @@ -228,7 +228,7 @@ Module( op: Mult, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, value: Int( 1, @@ -239,11 +239,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..113, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..108, id: Name("x"), ctx: Store, @@ -252,7 +252,7 @@ Module( op: Div, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, value: Int( 1, @@ -263,11 +263,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..121, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, id: Name("x"), ctx: Store, @@ -276,7 +276,7 @@ Module( op: FloorDiv, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, value: Int( 1, @@ -287,11 +287,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..128, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, id: Name("x"), ctx: Store, @@ -300,7 +300,7 @@ Module( op: Mod, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 127..128, value: Int( 1, @@ -311,11 +311,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..136, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..130, id: Name("x"), ctx: Store, @@ -324,7 +324,7 @@ Module( op: Pow, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..136, value: Int( 1, @@ -335,11 +335,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..143, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..138, id: Name("x"), ctx: Store, @@ -348,7 +348,7 @@ Module( op: BitAnd, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..143, value: Int( 1, @@ -359,11 +359,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..150, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..145, id: Name("x"), ctx: Store, @@ -372,7 +372,7 @@ Module( op: BitOr, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..150, value: Int( 1, @@ -383,11 +383,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..157, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, id: Name("x"), ctx: Store, @@ -396,7 +396,7 @@ Module( op: BitXor, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, value: Int( 1, @@ -407,11 +407,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..165, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..159, id: Name("x"), ctx: Store, @@ -420,7 +420,7 @@ Module( op: LShift, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..165, value: Int( 1, @@ -431,11 +431,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..173, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, id: Name("x"), ctx: Store, @@ -444,7 +444,7 @@ Module( op: RShift, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..173, value: Int( 1, @@ -455,11 +455,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..180, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 174..175, id: Name("x"), ctx: Store, @@ -468,7 +468,7 @@ Module( op: MatMult, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, value: Int( 1, @@ -479,11 +479,11 @@ Module( ), AugAssign( StmtAugAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..212, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..191, id: Name("a"), ctx: Store, @@ -492,15 +492,15 @@ Module( op: FloorDiv, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..212, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..202, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..198, id: Name("a"), ctx: Load, @@ -509,7 +509,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 201..202, id: Name("b"), ctx: Load, @@ -520,11 +520,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..212, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..207, id: Name("c"), ctx: Load, @@ -533,7 +533,7 @@ Module( op: Pow, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, value: Int( 2, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap index 9882e26371592..981e0fe0de796 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__class.py.snap @@ -7,29 +7,29 @@ input_file: crates/ruff_python_parser/resources/valid/statement/class.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1023, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..19, decorator_list: [], name: Identifier { id: Name("Test"), range: 6..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..19, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..19, }, ), @@ -40,19 +40,19 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..80, decorator_list: [], name: Identifier { id: Name("Test"), range: 28..32, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 32..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -60,33 +60,31 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..80, is_async: false, decorator_list: [], name: Identifier { id: Name("__init__"), range: 48..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 56..62, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 57..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 57..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("self"), range: 57..61, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -101,7 +99,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..80, }, ), @@ -113,27 +111,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..116, decorator_list: [], name: Identifier { id: Name("Test"), range: 89..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 93..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..101, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..101, id: Name("A"), ctx: Load, @@ -146,17 +144,17 @@ Module( keywords: [ Keyword { range: 94..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("a"), range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, value: Int( 1, @@ -166,11 +164,11 @@ Module( }, Keyword { range: 103..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, id: Name("k"), ctx: Load, @@ -183,11 +181,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..116, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..116, }, ), @@ -198,34 +196,32 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..168, decorator_list: [], name: Identifier { id: Name("Test"), range: 125..129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..168, is_async: false, decorator_list: [], name: Identifier { id: Name("method"), range: 139..145, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 145..147, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -236,17 +232,17 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..168, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..161, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..158, id: Name("a"), ctx: Store, @@ -254,7 +250,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, id: Name("b"), ctx: Store, @@ -268,7 +264,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..168, id: Name("data"), ctx: Load, @@ -284,23 +280,23 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..289, decorator_list: [], name: Identifier { id: Name("Test"), range: 177..181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 181..187, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 182..183, id: Name("A"), ctx: Load, @@ -308,7 +304,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 185..186, id: Name("B"), ctx: Load, @@ -321,33 +317,31 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 193..225, is_async: false, decorator_list: [], name: Identifier { id: Name("__init__"), range: 197..205, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 205..211, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 206..210, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 206..210, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("self"), range: 206..210, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -362,7 +356,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..225, }, ), @@ -371,33 +365,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..289, is_async: false, decorator_list: [], name: Identifier { id: Name("method_with_default"), range: 235..254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 254..275, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 255..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 255..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("self"), range: 255..259, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -405,27 +397,27 @@ Module( }, ParameterWithDefault { range: 261..274, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 261..264, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 261..264, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..274, value: StringLiteralValue { inner: Single( StringLiteral { range: 265..274, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "default", flags: StringLiteralFlags { quote_style: Single, @@ -448,7 +440,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 285..289, }, ), @@ -460,27 +452,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..351, decorator_list: [], name: Identifier { id: Name("Test"), range: 337..341, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 341..344, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 342..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 342..343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -492,7 +484,7 @@ Module( arguments: Some( Arguments { range: 344..346, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -500,11 +492,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..351, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 348..351, }, ), @@ -515,33 +507,33 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..402, decorator_list: [], name: Identifier { id: Name("Test"), range: 382..386, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 386..395, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 387..394, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 387..388, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 391..394, id: Name("str"), ctx: Load, @@ -556,7 +548,7 @@ Module( arguments: Some( Arguments { range: 395..397, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -564,11 +556,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 399..402, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 399..402, }, ), @@ -579,32 +571,32 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 425..450, decorator_list: [], name: Identifier { id: Name("Test"), range: 431..435, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 435..443, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 436..442, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 436..437, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 439..442, id: Name("str"), ctx: Load, @@ -620,7 +612,7 @@ Module( arguments: Some( Arguments { range: 443..445, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -628,11 +620,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 447..450, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 447..450, }, ), @@ -643,36 +635,36 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 485..522, decorator_list: [], name: Identifier { id: Name("Test"), range: 491..495, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 495..515, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 496..514, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 496..497, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 499..508, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 499..502, id: Name("int"), ctx: Load, @@ -681,7 +673,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 505..508, id: Name("str"), ctx: Load, @@ -693,7 +685,7 @@ Module( default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 511..514, id: Name("int"), ctx: Load, @@ -708,7 +700,7 @@ Module( arguments: Some( Arguments { range: 515..517, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -716,11 +708,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 519..522, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 519..522, }, ), @@ -731,37 +723,37 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..585, decorator_list: [], name: Identifier { id: Name("Test"), range: 557..561, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 561..578, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 562..577, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 562..563, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 565..577, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 566..569, id: Name("str"), ctx: Load, @@ -769,7 +761,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 571..576, id: Name("bytes"), ctx: Load, @@ -790,7 +782,7 @@ Module( arguments: Some( Arguments { range: 578..580, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -798,11 +790,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 582..585, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 582..585, }, ), @@ -813,27 +805,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 606..629, decorator_list: [], name: Identifier { id: Name("Test"), range: 612..616, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 616..622, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 617..618, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 617..618, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -842,11 +834,11 @@ Module( TypeVar( TypeParamTypeVar { range: 620..621, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 620..621, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -858,7 +850,7 @@ Module( arguments: Some( Arguments { range: 622..624, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -866,11 +858,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 626..629, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 626..629, }, ), @@ -881,27 +873,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 648..672, decorator_list: [], name: Identifier { id: Name("Test"), range: 654..658, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 658..665, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 659..660, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 659..660, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -910,11 +902,11 @@ Module( TypeVar( TypeParamTypeVar { range: 662..663, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 662..663, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -926,7 +918,7 @@ Module( arguments: Some( Arguments { range: 665..667, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -934,11 +926,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 669..672, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 669..672, }, ), @@ -949,27 +941,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 689..711, decorator_list: [], name: Identifier { id: Name("Test"), range: 695..699, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 699..704, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 700..703, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 701..703, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -980,7 +972,7 @@ Module( arguments: Some( Arguments { range: 704..706, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -988,11 +980,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 708..711, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 708..711, }, ), @@ -1003,36 +995,36 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 741..789, decorator_list: [], name: Identifier { id: Name("Test"), range: 747..751, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 751..782, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 752..781, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 753..755, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 758..781, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 758..764, id: Name("Unpack"), ctx: Load, @@ -1040,11 +1032,11 @@ Module( ), slice: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 765..780, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 765..770, id: Name("tuple"), ctx: Load, @@ -1052,12 +1044,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 771..779, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 771..774, id: Name("int"), ctx: Load, @@ -1065,7 +1057,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 776..779, id: Name("str"), ctx: Load, @@ -1091,7 +1083,7 @@ Module( arguments: Some( Arguments { range: 782..784, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1099,11 +1091,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 786..789, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 786..789, }, ), @@ -1114,40 +1106,40 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 827..868, decorator_list: [], name: Identifier { id: Name("Test"), range: 833..837, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 837..861, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 838..860, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 839..841, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 844..860, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 845..860, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 845..850, id: Name("tuple"), ctx: Load, @@ -1155,12 +1147,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 851..859, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 851..854, id: Name("int"), ctx: Load, @@ -1168,7 +1160,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 856..859, id: Name("str"), ctx: Load, @@ -1194,7 +1186,7 @@ Module( arguments: Some( Arguments { range: 861..863, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1202,11 +1194,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 865..868, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 865..868, }, ), @@ -1217,27 +1209,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 882..904, decorator_list: [], name: Identifier { id: Name("Test"), range: 888..892, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 892..897, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 893..896, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 895..896, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -1248,7 +1240,7 @@ Module( arguments: Some( Arguments { range: 897..899, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1256,11 +1248,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 901..904, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 901..904, }, ), @@ -1271,37 +1263,37 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 931..966, decorator_list: [], name: Identifier { id: Name("Test"), range: 937..941, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 941..959, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 942..958, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 944..945, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 948..958, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 949..952, id: Name("int"), ctx: Load, @@ -1309,7 +1301,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 954..957, id: Name("str"), ctx: Load, @@ -1328,7 +1320,7 @@ Module( arguments: Some( Arguments { range: 959..961, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1336,11 +1328,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 963..966, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 963..966, }, ), @@ -1351,27 +1343,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 982..1022, decorator_list: [], name: Identifier { id: Name("Test"), range: 988..992, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 992..1012, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 993..994, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("X"), range: 993..994, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -1380,16 +1372,16 @@ Module( TypeVar( TypeParamTypeVar { range: 996..1002, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Y"), range: 996..997, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 999..1002, id: Name("str"), ctx: Load, @@ -1402,11 +1394,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 1004..1006, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 1005..1006, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -1414,11 +1406,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 1008..1011, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 1010..1011, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -1429,7 +1421,7 @@ Module( arguments: Some( Arguments { range: 1012..1014, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1437,7 +1429,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1018..1022, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap index bc20d70fae3c5..50f3cb4b0bacc 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__delete.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/valid/statement/delete.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..122, body: [ Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..5, id: Name("x"), ctx: Del, @@ -28,12 +28,12 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..13, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 11..12, id: Name("x"), ctx: Del, @@ -44,12 +44,12 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..23, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("a"), ctx: Del, @@ -57,7 +57,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("b"), ctx: Del, @@ -68,12 +68,12 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..40, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("a"), ctx: Del, @@ -81,12 +81,12 @@ Module( ), Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..37, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("b"), ctx: Del, @@ -94,7 +94,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..36, id: Name("c"), ctx: Del, @@ -107,7 +107,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..40, id: Name("d"), ctx: Del, @@ -118,17 +118,17 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..51, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..51, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("a"), ctx: Del, @@ -136,7 +136,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("b"), ctx: Del, @@ -151,17 +151,17 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..70, targets: [ List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..70, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..58, id: Name("a"), ctx: Del, @@ -169,12 +169,12 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..66, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, id: Name("b"), ctx: Del, @@ -182,7 +182,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..65, id: Name("c"), ctx: Del, @@ -194,7 +194,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("d"), ctx: Del, @@ -209,16 +209,16 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..78, targets: [ Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..78, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("x"), ctx: Load, @@ -227,7 +227,7 @@ Module( attr: Identifier { id: Name("y"), range: 77..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Del, }, @@ -237,16 +237,16 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..87, targets: [ Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..87, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, id: Name("x"), ctx: Load, @@ -254,7 +254,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..86, id: Name("y"), ctx: Load, @@ -268,17 +268,17 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..121, targets: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 92..121, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("x"), ctx: Del, @@ -286,11 +286,11 @@ Module( ), Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..108, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, id: Name("x"), ctx: Load, @@ -299,18 +299,18 @@ Module( attr: Identifier { id: Name("y"), range: 107..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Del, }, ), Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..118, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, id: Name("x"), ctx: Load, @@ -318,7 +318,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 116..117, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap index a003c4896d716..2687f08bc2259 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__for.py.snap @@ -7,17 +7,17 @@ input_file: crates/ruff_python_parser/resources/valid/statement/for.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..523, body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4..10, id: Name("target"), ctx: Store, @@ -25,7 +25,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..18, id: Name("iter"), ctx: Load, @@ -34,7 +34,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..28, }, ), @@ -44,12 +44,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..63, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..40, id: Name("target"), ctx: Store, @@ -57,12 +57,12 @@ Module( ), iter: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..53, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, value: Int( 1, @@ -71,7 +71,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, value: Int( 2, @@ -80,7 +80,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 3, @@ -95,7 +95,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..63, }, ), @@ -105,16 +105,16 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..100, is_async: false, target: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..80, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..75, id: Name("target"), ctx: Load, @@ -123,18 +123,18 @@ Module( attr: Identifier { id: Name("attr"), range: 76..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..90, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..88, id: Name("call"), ctx: Load, @@ -142,7 +142,7 @@ Module( ), arguments: Arguments { range: 88..90, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -151,7 +151,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..100, }, ), @@ -161,16 +161,16 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..135, is_async: false, target: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..115, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..112, id: Name("target"), ctx: Load, @@ -178,7 +178,7 @@ Module( ), slice: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..114, value: Int( 0, @@ -190,11 +190,11 @@ Module( ), iter: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..125, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..120, id: Name("x"), ctx: Load, @@ -203,7 +203,7 @@ Module( attr: Identifier { id: Name("attr"), range: 121..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -211,7 +211,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..135, }, ), @@ -221,12 +221,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..167, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..147, id: Name("target"), ctx: Store, @@ -234,11 +234,11 @@ Module( ), iter: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..157, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, id: Name("x"), ctx: Load, @@ -250,7 +250,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("y"), ctx: Load, @@ -262,7 +262,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..167, }, ), @@ -272,12 +272,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..200, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..179, id: Name("target"), ctx: Store, @@ -285,13 +285,13 @@ Module( ), iter: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..190, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 183..184, id: Name("a"), ctx: Load, @@ -299,7 +299,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..190, id: Name("b"), ctx: Load, @@ -311,7 +311,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..200, }, ), @@ -321,17 +321,17 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 202..232, is_async: false, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..214, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..207, id: Name("a"), ctx: Store, @@ -339,7 +339,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 209..210, id: Name("b"), ctx: Store, @@ -347,7 +347,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 212..213, id: Name("c"), ctx: Store, @@ -360,7 +360,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 218..222, id: Name("iter"), ctx: Load, @@ -369,7 +369,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..232, }, ), @@ -379,17 +379,17 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 234..262, is_async: false, target: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..244, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, id: Name("a"), ctx: Store, @@ -397,7 +397,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 242..243, id: Name("b"), ctx: Store, @@ -410,7 +410,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 248..252, id: Name("iter"), ctx: Load, @@ -419,7 +419,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..262, }, ), @@ -429,12 +429,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..294, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 268..274, id: Name("target"), ctx: Store, @@ -442,12 +442,12 @@ Module( ), iter: List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..284, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 279..280, value: Int( 1, @@ -456,7 +456,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 282..283, value: Int( 2, @@ -470,7 +470,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 290..294, }, ), @@ -480,12 +480,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..322, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..306, id: Name("target"), ctx: Store, @@ -493,11 +493,11 @@ Module( ), iter: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..317, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 316..317, id: Name("x"), ctx: Load, @@ -508,11 +508,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..322, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 319..322, }, ), @@ -524,12 +524,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 323..353, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..333, id: Name("target"), ctx: Store, @@ -537,26 +537,24 @@ Module( ), iter: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 337..348, parameters: Some( Parameters { range: 344..345, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 344..345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 344..345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 344..345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -570,7 +568,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 347..348, id: Name("x"), ctx: Load, @@ -581,11 +579,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 350..353, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 350..353, }, ), @@ -597,12 +595,12 @@ Module( ), For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..389, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 358..364, id: Name("target"), ctx: Store, @@ -610,18 +608,18 @@ Module( ), iter: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 368..384, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 373..377, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 368..369, id: Name("x"), ctx: Load, @@ -629,7 +627,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..384, id: Name("y"), ctx: Load, @@ -640,11 +638,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..389, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..389, }, ), @@ -656,11 +654,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 391..522, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 394..395, id: Name("x"), ctx: Load, @@ -669,12 +667,12 @@ Module( body: [ For( StmtFor { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 401..433, is_async: false, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 405..411, id: Name("target"), ctx: Store, @@ -682,7 +680,7 @@ Module( ), iter: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 415..419, id: Name("iter"), ctx: Load, @@ -691,7 +689,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 429..433, }, ), @@ -703,12 +701,12 @@ Module( elif_else_clauses: [ ElifElseClause { range: 508..522, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 518..522, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap index d6f6e5015867e..c962949c16809 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__from_import.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/valid/statement/from_import.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..259, body: [ ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, module: Some( Identifier { id: Name("a"), range: 5..6, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 14..15, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -38,17 +38,17 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..42, module: None, names: [ Alias { range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 41..42, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -58,45 +58,45 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..85, module: Some( Identifier { id: Name("foo.bar"), range: 48..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 63..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("baz"), range: 63..66, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("b"), range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, Alias { range: 73..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("FooBar"), range: 73..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("fb"), range: 83..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -106,23 +106,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..102, module: Some( Identifier { id: Name("a"), range: 92..93, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 101..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 101..102, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -132,17 +132,17 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..120, module: None, names: [ Alias { range: 119..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 119..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -152,17 +152,17 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 121..161, module: None, names: [ Alias { range: 160..161, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 160..161, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -172,23 +172,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..207, module: Some( Identifier { id: Name("a.b.c"), range: 193..198, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 206..207, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 206..207, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -198,49 +198,49 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..242, module: Some( Identifier { id: Name("module"), range: 213..219, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 228..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 228..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 231..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 231..232, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("B"), range: 236..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, Alias { range: 239..240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 239..240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -250,23 +250,23 @@ Module( ), ImportFrom( StmtImportFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 243..258, module: Some( Identifier { id: Name("a"), range: 248..249, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), names: [ Alias { range: 257..258, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("*"), range: 257..258, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap index d2b7caef14121..e715f81366be5 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__function.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/valid/statement/function.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..2399, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..29, is_async: false, decorator_list: [], name: Identifier { id: Name("no_parameters"), range: 4..17, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 17..19, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -37,7 +35,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..29, }, ), @@ -46,33 +44,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..76, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_parameters"), range: 36..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 57..66, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 58..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 58..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 58..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -80,14 +76,14 @@ Module( }, ParameterWithDefault { range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 61..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -95,14 +91,14 @@ Module( }, ParameterWithDefault { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -117,7 +113,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..76, }, ), @@ -126,33 +122,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..149, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_parameters_with_default_values"), range: 83..124, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 124..139, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 125..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 125..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 125..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -160,21 +154,21 @@ Module( }, ParameterWithDefault { range: 128..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 128..129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 128..129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 130..132, value: Int( 20, @@ -185,21 +179,21 @@ Module( }, ParameterWithDefault { range: 134..138, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 134..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 134..135, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..138, value: Int( 30, @@ -217,7 +211,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 145..149, }, ), @@ -226,32 +220,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..226, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_parameters_with_default_values2"), range: 156..198, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 198..216, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 199..200, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 199..200, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 199..200, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -259,21 +251,21 @@ Module( }, ParameterWithDefault { range: 202..206, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 202..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 202..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..206, value: Int( 20, @@ -286,21 +278,21 @@ Module( args: [ ParameterWithDefault { range: 211..215, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..215, value: Int( 30, @@ -318,7 +310,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..226, }, ), @@ -327,32 +319,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..296, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_only_and_positional_parameters"), range: 233..274, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 274..286, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 275..276, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 275..276, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 275..276, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -362,14 +352,14 @@ Module( args: [ ParameterWithDefault { range: 281..282, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 281..282, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 281..282, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -377,14 +367,14 @@ Module( }, ParameterWithDefault { range: 284..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 284..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 284..285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -399,7 +389,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 292..296, }, ), @@ -408,32 +398,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..393, is_async: false, decorator_list: [], name: Identifier { id: Name("pos_args_with_defaults_and_varargs_and_kwargs"), range: 303..348, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 348..383, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 349..350, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 349..350, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 349..350, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -441,21 +429,21 @@ Module( }, ParameterWithDefault { range: 352..356, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 352..353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 352..353, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 354..356, value: Int( 20, @@ -468,21 +456,21 @@ Module( args: [ ParameterWithDefault { range: 361..365, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 361..362, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 361..362, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 363..365, value: Int( 30, @@ -495,11 +483,11 @@ Module( vararg: Some( Parameter { range: 367..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 368..372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -508,11 +496,11 @@ Module( kwarg: Some( Parameter { range: 374..382, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 376..382, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -522,7 +510,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 389..393, }, ), @@ -531,35 +519,33 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 396..445, is_async: false, decorator_list: [], name: Identifier { id: Name("keyword_only_parameters"), range: 400..423, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 423..435, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, kwonlyargs: [ ParameterWithDefault { range: 427..428, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 427..428, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 427..428, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -567,14 +553,14 @@ Module( }, ParameterWithDefault { range: 430..431, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 430..431, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 430..431, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -582,14 +568,14 @@ Module( }, ParameterWithDefault { range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 433..434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -602,7 +588,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 441..445, }, ), @@ -611,35 +597,33 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 448..517, is_async: false, decorator_list: [], name: Identifier { id: Name("keyword_only_parameters_with_defaults"), range: 452..489, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 489..507, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, kwonlyargs: [ ParameterWithDefault { range: 493..494, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 493..494, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 493..494, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -647,21 +631,21 @@ Module( }, ParameterWithDefault { range: 496..500, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 496..497, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 496..497, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 498..500, value: Int( 20, @@ -672,21 +656,21 @@ Module( }, ParameterWithDefault { range: 502..506, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 502..503, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 502..503, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 504..506, value: Int( 30, @@ -702,7 +686,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 513..517, }, ), @@ -711,31 +695,29 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 520..594, is_async: false, decorator_list: [], name: Identifier { id: Name("kw_only_args_with_defaults_and_varargs"), range: 524..562, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 562..584, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 563..568, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 564..568, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -743,14 +725,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 570..571, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 570..571, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 570..571, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -758,21 +740,21 @@ Module( }, ParameterWithDefault { range: 573..577, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 573..574, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 573..574, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 575..577, value: Int( 20, @@ -783,21 +765,21 @@ Module( }, ParameterWithDefault { range: 579..583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 579..580, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 579..580, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 581..583, value: Int( 30, @@ -813,7 +795,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 590..594, }, ), @@ -822,35 +804,33 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 597..676, is_async: false, decorator_list: [], name: Identifier { id: Name("kw_only_args_with_defaults_and_kwargs"), range: 601..638, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 638..666, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, kwonlyargs: [ ParameterWithDefault { range: 642..643, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 642..643, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 642..643, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -858,21 +838,21 @@ Module( }, ParameterWithDefault { range: 645..649, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 645..646, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 645..646, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 647..649, value: Int( 20, @@ -883,21 +863,21 @@ Module( }, ParameterWithDefault { range: 651..655, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 651..652, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 651..652, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 653..655, value: Int( 30, @@ -910,11 +890,11 @@ Module( kwarg: Some( Parameter { range: 657..665, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 659..665, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -924,7 +904,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 672..676, }, ), @@ -933,31 +913,29 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 679..774, is_async: false, decorator_list: [], name: Identifier { id: Name("kw_only_args_with_defaults_and_varargs_and_kwargs"), range: 683..732, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 732..764, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 733..738, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 734..738, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -965,14 +943,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 740..741, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 740..741, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 740..741, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -980,21 +958,21 @@ Module( }, ParameterWithDefault { range: 743..747, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 743..744, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 743..744, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 745..747, value: Int( 20, @@ -1005,21 +983,21 @@ Module( }, ParameterWithDefault { range: 749..753, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 749..750, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 749..750, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 751..753, value: Int( 30, @@ -1032,11 +1010,11 @@ Module( kwarg: Some( Parameter { range: 755..763, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 757..763, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1046,7 +1024,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 770..774, }, ), @@ -1055,32 +1033,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 777..835, is_async: false, decorator_list: [], name: Identifier { id: Name("pos_and_kw_only_args"), range: 781..801, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 801..825, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 802..803, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 802..803, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 802..803, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1088,14 +1064,14 @@ Module( }, ParameterWithDefault { range: 805..806, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 805..806, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 805..806, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1105,14 +1081,14 @@ Module( args: [ ParameterWithDefault { range: 811..812, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 811..812, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 811..812, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1123,14 +1099,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 817..818, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 817..818, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 817..818, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1138,14 +1114,14 @@ Module( }, ParameterWithDefault { range: 820..821, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 820..821, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 820..821, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1153,14 +1129,14 @@ Module( }, ParameterWithDefault { range: 823..824, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 823..824, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 823..824, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1173,7 +1149,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 831..835, }, ), @@ -1182,32 +1158,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 838..916, is_async: false, decorator_list: [], name: Identifier { id: Name("pos_and_kw_only_args_with_defaults"), range: 842..876, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 876..906, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 877..878, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 877..878, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 877..878, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1215,14 +1189,14 @@ Module( }, ParameterWithDefault { range: 880..881, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 880..881, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 880..881, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1232,14 +1206,14 @@ Module( args: [ ParameterWithDefault { range: 886..887, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 886..887, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 886..887, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1250,14 +1224,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 892..893, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 892..893, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 892..893, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1265,21 +1239,21 @@ Module( }, ParameterWithDefault { range: 895..899, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 895..896, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 895..896, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 897..899, value: Int( 20, @@ -1290,21 +1264,21 @@ Module( }, ParameterWithDefault { range: 901..905, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 901..902, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 901..902, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 903..905, value: Int( 30, @@ -1320,7 +1294,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 912..916, }, ), @@ -1329,32 +1303,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 919..1013, is_async: false, decorator_list: [], name: Identifier { id: Name("pos_and_kw_only_args_with_defaults_and_varargs"), range: 923..969, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 969..1003, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 970..971, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 970..971, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 970..971, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1362,14 +1334,14 @@ Module( }, ParameterWithDefault { range: 973..974, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 973..974, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 973..974, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1379,14 +1351,14 @@ Module( args: [ ParameterWithDefault { range: 979..980, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 979..980, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 979..980, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1396,11 +1368,11 @@ Module( vararg: Some( Parameter { range: 982..987, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 983..987, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1408,14 +1380,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 989..990, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 989..990, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 989..990, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1423,21 +1395,21 @@ Module( }, ParameterWithDefault { range: 992..996, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 992..993, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 992..993, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 994..996, value: Int( 20, @@ -1448,21 +1420,21 @@ Module( }, ParameterWithDefault { range: 998..1002, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 998..999, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 998..999, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1000..1002, value: Int( 30, @@ -1478,7 +1450,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1009..1013, }, ), @@ -1487,32 +1459,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1016..1121, is_async: false, decorator_list: [], name: Identifier { id: Name("pos_and_kw_only_args_with_defaults_and_kwargs"), range: 1020..1065, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 1065..1111, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 1071..1072, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1071..1072, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1071..1072, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1520,14 +1490,14 @@ Module( }, ParameterWithDefault { range: 1074..1075, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1074..1075, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 1074..1075, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1537,14 +1507,14 @@ Module( args: [ ParameterWithDefault { range: 1080..1081, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1080..1081, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 1080..1081, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1555,14 +1525,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 1086..1087, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1086..1087, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 1086..1087, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1570,21 +1540,21 @@ Module( }, ParameterWithDefault { range: 1089..1093, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1089..1090, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 1089..1090, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1091..1093, value: Int( 20, @@ -1595,21 +1565,21 @@ Module( }, ParameterWithDefault { range: 1095..1099, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1095..1096, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 1095..1096, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1097..1099, value: Int( 30, @@ -1622,11 +1592,11 @@ Module( kwarg: Some( Parameter { range: 1101..1109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 1103..1109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1636,7 +1606,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1117..1121, }, ), @@ -1645,32 +1615,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1124..1245, is_async: false, decorator_list: [], name: Identifier { id: Name("pos_and_kw_only_args_with_defaults_and_varargs_and_kwargs"), range: 1128..1185, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 1185..1235, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 1191..1192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1191..1192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1191..1192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1678,14 +1646,14 @@ Module( }, ParameterWithDefault { range: 1194..1195, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1194..1195, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 1194..1195, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1695,14 +1663,14 @@ Module( args: [ ParameterWithDefault { range: 1200..1201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1200..1201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 1200..1201, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1712,11 +1680,11 @@ Module( vararg: Some( Parameter { range: 1203..1208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 1204..1208, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1724,14 +1692,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 1210..1211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1210..1211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 1210..1211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1739,21 +1707,21 @@ Module( }, ParameterWithDefault { range: 1213..1217, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1213..1214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 1213..1214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1215..1217, value: Int( 20, @@ -1764,21 +1732,21 @@ Module( }, ParameterWithDefault { range: 1219..1223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1219..1220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 1219..1220, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1221..1223, value: Int( 30, @@ -1791,11 +1759,11 @@ Module( kwarg: Some( Parameter { range: 1225..1233, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 1227..1233, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1805,7 +1773,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1241..1245, }, ), @@ -1814,33 +1782,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1248..1316, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_and_keyword_parameters"), range: 1252..1285, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 1285..1306, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1286..1287, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1286..1287, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1286..1287, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1848,14 +1814,14 @@ Module( }, ParameterWithDefault { range: 1289..1290, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1289..1290, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 1289..1290, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1863,14 +1829,14 @@ Module( }, ParameterWithDefault { range: 1292..1293, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1292..1293, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 1292..1293, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1881,14 +1847,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 1298..1299, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1298..1299, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 1298..1299, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1896,14 +1862,14 @@ Module( }, ParameterWithDefault { range: 1301..1302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1301..1302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 1301..1302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1911,14 +1877,14 @@ Module( }, ParameterWithDefault { range: 1304..1305, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1304..1305, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 1304..1305, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1931,7 +1897,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1312..1316, }, ), @@ -1940,33 +1906,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1319..1407, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_and_keyword_parameters_with_defaults"), range: 1323..1370, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 1370..1397, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1371..1372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1371..1372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1371..1372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1974,14 +1938,14 @@ Module( }, ParameterWithDefault { range: 1374..1375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1374..1375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 1374..1375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1989,14 +1953,14 @@ Module( }, ParameterWithDefault { range: 1377..1378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1377..1378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 1377..1378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2007,14 +1971,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 1383..1384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1383..1384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 1383..1384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2022,21 +1986,21 @@ Module( }, ParameterWithDefault { range: 1386..1390, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1386..1387, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 1386..1387, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1388..1390, value: Int( 20, @@ -2047,21 +2011,21 @@ Module( }, ParameterWithDefault { range: 1392..1396, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1392..1393, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 1392..1393, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1394..1396, value: Int( 30, @@ -2077,7 +2041,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1403..1407, }, ), @@ -2086,33 +2050,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1410..1520, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_and_keyword_parameters_with_defaults_and_varargs"), range: 1414..1473, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 1473..1510, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1479..1480, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1479..1480, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1479..1480, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2120,14 +2082,14 @@ Module( }, ParameterWithDefault { range: 1482..1483, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1482..1483, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 1482..1483, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2135,14 +2097,14 @@ Module( }, ParameterWithDefault { range: 1485..1486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1485..1486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 1485..1486, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2152,11 +2114,11 @@ Module( vararg: Some( Parameter { range: 1488..1493, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 1489..1493, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2164,14 +2126,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 1495..1496, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1495..1496, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 1495..1496, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2179,21 +2141,21 @@ Module( }, ParameterWithDefault { range: 1498..1502, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1498..1499, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 1498..1499, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1500..1502, value: Int( 20, @@ -2204,21 +2166,21 @@ Module( }, ParameterWithDefault { range: 1504..1508, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1504..1505, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 1504..1505, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1506..1508, value: Int( 30, @@ -2234,7 +2196,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1516..1520, }, ), @@ -2243,33 +2205,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1523..1654, is_async: false, decorator_list: [], name: Identifier { id: Name("positional_and_keyword_parameters_with_defaults_and_varargs_and_kwargs"), range: 1527..1597, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 1597..1644, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1603..1604, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1603..1604, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1603..1604, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2277,14 +2237,14 @@ Module( }, ParameterWithDefault { range: 1606..1607, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1606..1607, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 1606..1607, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2292,14 +2252,14 @@ Module( }, ParameterWithDefault { range: 1609..1610, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1609..1610, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 1609..1610, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2309,11 +2269,11 @@ Module( vararg: Some( Parameter { range: 1612..1617, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 1613..1617, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2321,14 +2281,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 1619..1620, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1619..1620, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("d"), range: 1619..1620, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2336,21 +2296,21 @@ Module( }, ParameterWithDefault { range: 1622..1626, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1622..1623, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("e"), range: 1622..1623, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1624..1626, value: Int( 20, @@ -2361,21 +2321,21 @@ Module( }, ParameterWithDefault { range: 1628..1632, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1628..1629, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("f"), range: 1628..1629, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1630..1632, value: Int( 30, @@ -2388,11 +2348,11 @@ Module( kwarg: Some( Parameter { range: 1634..1642, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 1636..1642, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2402,7 +2362,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1650..1654, }, ), @@ -2411,28 +2371,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1703..1735, is_async: false, decorator_list: [], name: Identifier { id: Name("func"), range: 1707..1711, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 1711..1714, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 1712..1713, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 1712..1713, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -2443,26 +2403,24 @@ Module( ), parameters: Parameters { range: 1714..1720, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1715..1719, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1715..1719, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1715..1716, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1718..1719, id: Name("T"), ctx: Load, @@ -2480,7 +2438,7 @@ Module( returns: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1724..1725, id: Name("T"), ctx: Load, @@ -2490,7 +2448,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1731..1735, }, ), @@ -2499,33 +2457,33 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1738..1775, is_async: false, decorator_list: [], name: Identifier { id: Name("func"), range: 1742..1746, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 1746..1754, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 1747..1753, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 1747..1748, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1750..1753, id: Name("str"), ctx: Load, @@ -2540,26 +2498,24 @@ Module( ), parameters: Parameters { range: 1754..1760, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1755..1759, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1755..1759, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1755..1756, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1758..1759, id: Name("T"), ctx: Load, @@ -2577,7 +2533,7 @@ Module( returns: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1764..1765, id: Name("T"), ctx: Load, @@ -2587,7 +2543,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1771..1775, }, ), @@ -2596,38 +2552,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1778..1824, is_async: false, decorator_list: [], name: Identifier { id: Name("func"), range: 1782..1786, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 1786..1803, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 1787..1802, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 1787..1788, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1790..1802, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1791..1794, id: Name("str"), ctx: Load, @@ -2635,7 +2591,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1796..1801, id: Name("bytes"), ctx: Load, @@ -2655,26 +2611,24 @@ Module( ), parameters: Parameters { range: 1803..1809, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1804..1808, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1804..1808, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1804..1805, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1807..1808, id: Name("T"), ctx: Load, @@ -2692,7 +2646,7 @@ Module( returns: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1813..1814, id: Name("T"), ctx: Load, @@ -2702,7 +2656,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1820..1824, }, ), @@ -2711,28 +2665,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1827..1873, is_async: false, decorator_list: [], name: Identifier { id: Name("func"), range: 1831..1835, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 1835..1840, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 1836..1839, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 1837..1839, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -2742,28 +2696,26 @@ Module( ), parameters: Parameters { range: 1840..1849, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 1841..1848, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 1842..1843, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1845..1848, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1846..1848, id: Name("Ts"), ctx: Load, @@ -2781,11 +2733,11 @@ Module( returns: Some( Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1853..1863, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1853..1858, id: Name("Tuple"), ctx: Load, @@ -2793,16 +2745,16 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1859..1862, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1859..1862, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1860..1862, id: Name("Ts"), ctx: Load, @@ -2823,7 +2775,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1869..1873, }, ), @@ -2832,28 +2784,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1876..1934, is_async: false, decorator_list: [], name: Identifier { id: Name("func"), range: 1880..1884, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 1884..1889, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 1885..1888, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 1887..1888, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -2863,28 +2815,26 @@ Module( ), parameters: Parameters { range: 1889..1924, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 1890..1903, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 1891..1895, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1897..1903, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1897..1898, id: Name("P"), ctx: Load, @@ -2893,7 +2843,7 @@ Module( attr: Identifier { id: Name("args"), range: 1899..1903, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2905,20 +2855,20 @@ Module( kwarg: Some( Parameter { range: 1905..1923, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 1907..1913, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1915..1923, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1915..1916, id: Name("P"), ctx: Load, @@ -2927,7 +2877,7 @@ Module( attr: Identifier { id: Name("kwargs"), range: 1917..1923, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2940,7 +2890,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1930..1934, }, ), @@ -2949,28 +2899,28 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1937..1978, is_async: false, decorator_list: [], name: Identifier { id: Name("func"), range: 1941..1945, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 1945..1966, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 1946..1947, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 1946..1947, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -2979,16 +2929,16 @@ Module( TypeVar( TypeParamTypeVar { range: 1949..1955, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 1949..1950, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1952..1955, id: Name("str"), ctx: Load, @@ -3001,11 +2951,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 1957..1960, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 1958..1960, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -3013,11 +2963,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 1962..1965, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 1964..1965, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -3027,9 +2977,7 @@ Module( ), parameters: Parameters { range: 1966..1968, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -3040,7 +2988,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1974..1978, }, ), @@ -3049,21 +2997,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1981..2000, is_async: false, decorator_list: [], name: Identifier { id: Name("ellipsis"), range: 1985..1993, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 1993..1995, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -3074,11 +3020,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1997..2000, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1997..2000, }, ), @@ -3089,21 +3035,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2003..2064, is_async: false, decorator_list: [], name: Identifier { id: Name("multiple_statements"), range: 2007..2026, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2026..2028, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -3113,7 +3057,7 @@ Module( returns: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2032..2035, id: Name("int"), ctx: Load, @@ -3123,15 +3067,15 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2041..2047, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2041..2047, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2041..2045, id: Name("call"), ctx: Load, @@ -3139,7 +3083,7 @@ Module( ), arguments: Arguments { range: 2045..2047, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -3149,17 +3093,17 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2052..2056, }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2061..2064, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2061..2064, }, ), @@ -3170,31 +3114,29 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2067..2091, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2071..2074, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2074..2081, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 2075..2080, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 2076..2080, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3206,7 +3148,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2087..2091, }, ), @@ -3215,21 +3157,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2094..2121, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2098..2101, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2101..2111, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -3237,11 +3177,11 @@ Module( kwarg: Some( Parameter { range: 2102..2110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 2104..2110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3251,7 +3191,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2117..2121, }, ), @@ -3260,31 +3200,29 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2124..2158, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2128..2131, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2131..2148, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: Some( Parameter { range: 2132..2137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("args"), range: 2133..2137, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3293,11 +3231,11 @@ Module( kwarg: Some( Parameter { range: 2139..2147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kwargs"), range: 2141..2147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3307,7 +3245,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2154..2158, }, ), @@ -3316,32 +3254,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2161..2184, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2165..2168, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2168..2174, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 2169..2170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2169..2170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 2169..2170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3357,7 +3293,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2180..2184, }, ), @@ -3366,32 +3302,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2187..2213, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2191..2194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2194..2203, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 2195..2196, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2195..2196, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 2195..2196, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3401,14 +3335,14 @@ Module( args: [ ParameterWithDefault { range: 2201..2202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2201..2202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 2201..2202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3423,7 +3357,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2209..2213, }, ), @@ -3432,39 +3366,37 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2216..2242, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2220..2223, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2223..2232, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 2224..2227, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2224..2225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 2224..2225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2226..2227, value: Int( 1, @@ -3483,7 +3415,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2238..2242, }, ), @@ -3492,32 +3424,30 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2245..2277, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2249..2252, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2252..2267, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [ ParameterWithDefault { range: 2253..2254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2253..2254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 2253..2254, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3525,14 +3455,14 @@ Module( }, ParameterWithDefault { range: 2256..2257, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2256..2257, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 2256..2257, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3544,14 +3474,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 2265..2266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2265..2266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 2265..2266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3564,7 +3494,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2273..2277, }, ), @@ -3573,40 +3503,38 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2280..2309, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2284..2287, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2287..2299, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 2288..2292, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2288..2290, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("kw"), range: 2288..2290, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2291..2292, value: Int( 1, @@ -3620,14 +3548,14 @@ Module( kwonlyargs: [ ParameterWithDefault { range: 2297..2298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2297..2298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 2297..2298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3640,7 +3568,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2305..2309, }, ), @@ -3649,38 +3577,36 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2312..2357, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2316..2319, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2319..2347, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 2320..2326, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2320..2326, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 2320..2321, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2323..2326, id: Name("int"), ctx: Load, @@ -3692,25 +3618,25 @@ Module( }, ParameterWithDefault { range: 2328..2336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2328..2336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("y"), range: 2328..2329, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2331..2336, value: StringLiteralValue { inner: Single( StringLiteral { range: 2331..2336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "str", flags: StringLiteralFlags { quote_style: Double, @@ -3728,23 +3654,23 @@ Module( }, ParameterWithDefault { range: 2338..2346, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2338..2346, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("z"), range: 2338..2339, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2341..2346, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2341..2342, value: Int( 1, @@ -3754,7 +3680,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2345..2346, value: Int( 2, @@ -3776,7 +3702,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2353..2357, }, ), @@ -3785,33 +3711,31 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2360..2398, is_async: false, decorator_list: [], name: Identifier { id: Name("foo"), range: 2364..2367, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 2367..2388, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 2368..2372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2368..2372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("self"), range: 2368..2372, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3819,21 +3743,21 @@ Module( }, ParameterWithDefault { range: 2374..2377, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2374..2375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 2374..2375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2376..2377, value: Int( 1, @@ -3844,21 +3768,21 @@ Module( }, ParameterWithDefault { range: 2379..2382, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2379..2380, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 2379..2380, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2381..2382, value: Int( 2, @@ -3869,21 +3793,21 @@ Module( }, ParameterWithDefault { range: 2384..2387, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 2384..2385, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 2384..2385, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, default: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2386..2387, value: Int( 3, @@ -3901,7 +3825,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2394..2398, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap index 51edcda2945ba..8a4b8262da467 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__if.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/statement/if.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..375, body: [ If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, test: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3..4, value: Int( 1, @@ -26,11 +26,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..8, value: Int( 10, @@ -43,11 +43,11 @@ Module( elif_else_clauses: [ ElifElseClause { range: 9..19, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, value: Int( 2, @@ -58,11 +58,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..19, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 17..19, value: Int( 20, @@ -75,16 +75,16 @@ Module( }, ElifElseClause { range: 20..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..28, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 26..28, value: Int( 30, @@ -100,11 +100,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..52, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 33..37, value: true, }, @@ -112,11 +112,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, value: Int( 1, @@ -127,11 +127,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..52, }, ), @@ -143,15 +143,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..85, test: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..61, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("x"), ctx: Load, @@ -163,7 +163,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 60..61, value: Int( 1, @@ -176,11 +176,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..70, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..70, }, ), @@ -190,12 +190,12 @@ Module( elif_else_clauses: [ ElifElseClause { range: 71..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..85, }, ), @@ -206,11 +206,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..117, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("a"), ctx: Load, @@ -219,7 +219,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 97..101, }, ), @@ -227,11 +227,11 @@ Module( elif_else_clauses: [ ElifElseClause { range: 102..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..108, id: Name("b"), ctx: Load, @@ -241,11 +241,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..117, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..117, }, ), @@ -258,17 +258,17 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 119..203, test: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..129, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, id: Name("a"), ctx: Load, @@ -276,7 +276,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, id: Name("b"), ctx: Load, @@ -288,11 +288,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..138, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..138, }, ), @@ -302,11 +302,11 @@ Module( elif_else_clauses: [ ElifElseClause { range: 139..157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..148, value: true, }, @@ -315,11 +315,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..157, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..157, }, ), @@ -329,11 +329,11 @@ Module( }, ElifElseClause { range: 158..173, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..164, id: Name("c"), ctx: Load, @@ -343,11 +343,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..173, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..173, }, ), @@ -357,11 +357,11 @@ Module( }, ElifElseClause { range: 174..189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, id: Name("d"), ctx: Load, @@ -371,11 +371,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..189, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..189, }, ), @@ -385,20 +385,20 @@ Module( }, ElifElseClause { range: 190..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..203, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..203, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..201, id: Name("f"), ctx: Load, @@ -406,7 +406,7 @@ Module( ), arguments: Arguments { range: 201..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -421,15 +421,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 229..260, test: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..238, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..233, id: Name("a"), ctx: Store, @@ -437,7 +437,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 237..238, id: Name("b"), ctx: Load, @@ -448,11 +448,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..243, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 240..243, }, ), @@ -462,15 +462,15 @@ Module( elif_else_clauses: [ ElifElseClause { range: 244..260, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..255, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 249..250, id: Name("a"), ctx: Store, @@ -478,7 +478,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..255, id: Name("b"), ctx: Load, @@ -490,11 +490,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..260, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..260, }, ), @@ -507,30 +507,28 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 261..302, test: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 264..275, parameters: Some( Parameters { range: 271..272, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 271..272, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 271..272, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 271..272, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -544,7 +542,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 274..275, id: Name("x"), ctx: Load, @@ -555,11 +553,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..280, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..280, }, ), @@ -569,30 +567,28 @@ Module( elif_else_clauses: [ ElifElseClause { range: 281..302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..297, parameters: Some( Parameters { range: 293..294, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 293..294, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 293..294, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 293..294, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -606,7 +602,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 296..297, id: Name("x"), ctx: Load, @@ -618,11 +614,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..302, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 299..302, }, ), @@ -635,15 +631,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 303..336, test: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 306..313, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..313, id: Name("x"), ctx: Load, @@ -654,11 +650,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..318, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 315..318, }, ), @@ -668,15 +664,15 @@ Module( elif_else_clauses: [ ElifElseClause { range: 319..336, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..331, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 330..331, id: Name("x"), ctx: Load, @@ -688,11 +684,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..336, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 333..336, }, ), @@ -705,16 +701,16 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 337..374, test: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 341..348, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 347..348, id: Name("x"), ctx: Load, @@ -726,11 +722,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..354, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..354, }, ), @@ -740,16 +736,16 @@ Module( elif_else_clauses: [ ElifElseClause { range: 355..374, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 361..368, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..368, id: Name("x"), ctx: Load, @@ -762,11 +758,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 371..374, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 371..374, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap index 4d4d08b9635b8..56388f8862860 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__import.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/valid/statement/import.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..92, body: [ Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..8, names: [ Alias { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -30,16 +30,16 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..21, names: [ Alias { range: 16..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a.b.c"), range: 16..21, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -48,22 +48,22 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..39, names: [ Alias { range: 29..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a.b.c"), range: 29..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("d"), range: 38..39, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -72,36 +72,36 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 40..54, names: [ Alias { range: 47..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a"), range: 47..48, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("b"), range: 50..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, Alias { range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("c"), range: 53..54, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: None, }, @@ -110,38 +110,38 @@ Module( ), Import( StmtImport { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..91, names: [ Alias { range: 62..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("foo.bar"), range: 62..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("a"), range: 73..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, Alias { range: 76..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("a.b.c.d"), range: 76..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, asname: Some( Identifier { id: Name("abcd"), range: 87..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap index 1a7192474dcd7..f98896f399d27 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__match.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/statement/match.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..5770, body: [ Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..103, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("x"), ctx: Load, @@ -25,19 +25,19 @@ Module( cases: [ MatchCase { range: 80..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 85..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..88, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..88, value: Complex { real: 0.0, @@ -53,12 +53,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..103, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 98..99, id: Name("y"), ctx: Store, @@ -67,7 +67,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 102..103, value: Int( 0, @@ -83,11 +83,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 126..167, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("x"), ctx: Load, @@ -96,14 +96,14 @@ Module( cases: [ MatchCase { range: 139..167, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 144..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..149, id: Name("bytes"), ctx: Load, @@ -111,18 +111,18 @@ Module( ), arguments: PatternArguments { range: 149..152, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 150..151, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 150..151, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -136,12 +136,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..167, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 162..163, id: Name("y"), ctx: Store, @@ -150,7 +150,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..167, value: Int( 0, @@ -166,11 +166,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..260, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 196..197, id: Name("x"), ctx: Load, @@ -179,14 +179,14 @@ Module( cases: [ MatchCase { range: 203..229, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 208..209, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 208..209, value: Int( 0, @@ -198,7 +198,7 @@ Module( guard: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..214, value: Int( 0, @@ -209,12 +209,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..229, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 224..225, id: Name("y"), ctx: Store, @@ -223,7 +223,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..229, value: Int( 0, @@ -236,14 +236,14 @@ Module( }, MatchCase { range: 234..260, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 239..240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..240, value: Int( 0, @@ -255,7 +255,7 @@ Module( guard: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..245, value: Int( 1, @@ -266,12 +266,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..260, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..256, id: Name("y"), ctx: Store, @@ -280,7 +280,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..260, value: Int( 1, @@ -296,11 +296,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 283..332, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..290, value: Int( 3, @@ -310,19 +310,19 @@ Module( cases: [ MatchCase { range: 296..332, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 301..314, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 301..302, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..302, value: Int( 0, @@ -334,10 +334,10 @@ Module( MatchValue( PatternMatchValue { range: 305..306, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 305..306, value: Int( 1, @@ -349,10 +349,10 @@ Module( MatchValue( PatternMatchValue { range: 309..310, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 309..310, value: Int( 2, @@ -364,10 +364,10 @@ Module( MatchValue( PatternMatchValue { range: 313..314, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..314, value: Int( 3, @@ -383,12 +383,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..332, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 324..325, id: Name("x"), ctx: Store, @@ -397,7 +397,7 @@ Module( ], value: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..332, value: true, }, @@ -411,11 +411,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 355..403, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 361..362, id: Name("x"), ctx: Load, @@ -424,24 +424,24 @@ Module( cases: [ MatchCase { range: 368..403, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 373..388, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 373..379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 374..375, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 374..375, value: Int( 0, @@ -453,10 +453,10 @@ Module( MatchValue( PatternMatchValue { range: 377..378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 377..378, value: Int( 1, @@ -471,15 +471,15 @@ Module( MatchSequence( PatternMatchSequence { range: 382..388, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 383..384, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 383..384, value: Int( 1, @@ -491,10 +491,10 @@ Module( MatchValue( PatternMatchValue { range: 386..387, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 386..387, value: Int( 0, @@ -513,12 +513,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 398..403, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 398..399, id: Name("y"), ctx: Store, @@ -527,7 +527,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 402..403, value: Int( 0, @@ -543,11 +543,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 445..523, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 451..452, id: Name("x"), ctx: Load, @@ -556,16 +556,16 @@ Module( cases: [ MatchCase { range: 458..489, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 463..467, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 464..466, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -576,18 +576,18 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 477..489, value: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 484..489, value: StringLiteralValue { inner: Single( StringLiteral { range: 484..489, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "seq", flags: StringLiteralFlags { quote_style: Double, @@ -606,11 +606,11 @@ Module( }, MatchCase { range: 494..523, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 499..501, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -620,18 +620,18 @@ Module( body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 511..523, value: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 518..523, value: StringLiteralValue { inner: Single( StringLiteral { range: 518..523, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "map", flags: StringLiteralFlags { quote_style: Double, @@ -653,11 +653,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 546..714, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 552..553, id: Name("x"), ctx: Load, @@ -666,15 +666,15 @@ Module( cases: [ MatchCase { range: 559..594, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 564..579, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 565..566, value: Int( 0, @@ -686,15 +686,15 @@ Module( MatchSequence( PatternMatchSequence { range: 568..578, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 569..570, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 569..570, value: Int( 1, @@ -706,10 +706,10 @@ Module( MatchValue( PatternMatchValue { range: 572..573, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..573, value: Int( 2, @@ -721,7 +721,7 @@ Module( MatchMapping( PatternMatchMapping { range: 575..577, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -738,12 +738,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 589..594, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 589..590, id: Name("y"), ctx: Store, @@ -752,7 +752,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 593..594, value: Int( 0, @@ -765,20 +765,20 @@ Module( }, MatchCase { range: 599..687, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 604..672, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchMapping( PatternMatchMapping { range: 604..626, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 605..606, value: Int( 0, @@ -790,20 +790,20 @@ Module( MatchOr( PatternMatchOr { range: 608..625, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 608..618, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 609..610, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 609..610, value: Int( 1, @@ -815,10 +815,10 @@ Module( MatchValue( PatternMatchValue { range: 612..613, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 612..613, value: Int( 2, @@ -830,7 +830,7 @@ Module( MatchMapping( PatternMatchMapping { range: 615..617, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -842,7 +842,7 @@ Module( MatchSingleton( PatternMatchSingleton { range: 621..625, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: True, }, ), @@ -856,11 +856,11 @@ Module( MatchMapping( PatternMatchMapping { range: 629..638, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 630..631, value: Int( 1, @@ -872,12 +872,12 @@ Module( MatchSequence( PatternMatchSequence { range: 633..637, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 634..636, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], }, ), @@ -891,11 +891,11 @@ Module( MatchMapping( PatternMatchMapping { range: 641..656, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 642..643, value: Int( 0, @@ -907,15 +907,15 @@ Module( MatchSequence( PatternMatchSequence { range: 645..655, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 646..647, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 646..647, value: Int( 1, @@ -927,10 +927,10 @@ Module( MatchValue( PatternMatchValue { range: 649..650, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 649..650, value: Int( 2, @@ -942,7 +942,7 @@ Module( MatchMapping( PatternMatchMapping { range: 652..654, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -958,23 +958,23 @@ Module( MatchSequence( PatternMatchSequence { range: 659..661, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], }, ), MatchValue( PatternMatchValue { range: 664..667, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 664..667, value: StringLiteralValue { inner: Single( StringLiteral { range: 664..667, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "X", flags: StringLiteralFlags { quote_style: Double, @@ -991,7 +991,7 @@ Module( MatchMapping( PatternMatchMapping { range: 670..672, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -1004,12 +1004,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 682..687, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 682..683, id: Name("y"), ctx: Store, @@ -1018,7 +1018,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 686..687, value: Int( 1, @@ -1031,11 +1031,11 @@ Module( }, MatchCase { range: 692..714, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 697..699, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], }, ), @@ -1043,12 +1043,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 709..714, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 709..710, id: Name("y"), ctx: Store, @@ -1057,7 +1057,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 713..714, value: Int( 2, @@ -1073,11 +1073,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 737..782, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 743..744, id: Name("x"), ctx: Load, @@ -1086,18 +1086,18 @@ Module( cases: [ MatchCase { range: 750..782, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 755..767, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 755..767, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 755..759, value: Float( 0.25, @@ -1107,7 +1107,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 762..767, value: Complex { real: 0.0, @@ -1123,12 +1123,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 777..782, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 777..778, id: Name("y"), ctx: Store, @@ -1137,7 +1137,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 781..782, value: Int( 0, @@ -1153,11 +1153,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 805..841, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 811..812, id: Name("x"), ctx: Load, @@ -1166,19 +1166,19 @@ Module( cases: [ MatchCase { range: 818..841, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 823..826, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 823..826, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 824..826, value: Complex { real: 0.0, @@ -1194,12 +1194,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 836..841, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 836..837, id: Name("y"), ctx: Store, @@ -1208,7 +1208,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 840..841, value: Int( 0, @@ -1224,11 +1224,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 864..913, subject: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 870..871, value: Int( 4, @@ -1238,19 +1238,19 @@ Module( cases: [ MatchCase { range: 877..913, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 882..895, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 882..883, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 882..883, value: Int( 0, @@ -1262,10 +1262,10 @@ Module( MatchValue( PatternMatchValue { range: 886..887, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 886..887, value: Int( 1, @@ -1277,10 +1277,10 @@ Module( MatchValue( PatternMatchValue { range: 890..891, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 890..891, value: Int( 2, @@ -1292,10 +1292,10 @@ Module( MatchValue( PatternMatchValue { range: 894..895, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 894..895, value: Int( 3, @@ -1311,12 +1311,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 905..913, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 905..906, id: Name("x"), ctx: Store, @@ -1325,7 +1325,7 @@ Module( ], value: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 909..913, value: true, }, @@ -1339,11 +1339,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 936..975, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 942..943, id: Name("x"), ctx: Load, @@ -1352,14 +1352,14 @@ Module( cases: [ MatchCase { range: 949..975, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 954..955, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 954..955, value: Int( 0, @@ -1371,7 +1371,7 @@ Module( guard: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 959..960, id: Name("x"), ctx: Load, @@ -1381,12 +1381,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 970..975, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 970..971, id: Name("y"), ctx: Store, @@ -1395,7 +1395,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 974..975, value: Int( 0, @@ -1411,11 +1411,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 998..1098, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1004..1005, id: Name("x"), ctx: Load, @@ -1424,15 +1424,15 @@ Module( cases: [ MatchCase { range: 1011..1037, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 1016..1022, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1017..1018, value: Int( 1, @@ -1444,10 +1444,10 @@ Module( MatchValue( PatternMatchValue { range: 1020..1021, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1020..1021, value: Int( 0, @@ -1464,12 +1464,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1032..1037, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1032..1033, id: Name("y"), ctx: Store, @@ -1478,7 +1478,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1036..1037, value: Int( 0, @@ -1491,15 +1491,15 @@ Module( }, MatchCase { range: 1042..1068, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 1047..1053, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1048..1049, value: Int( 0, @@ -1511,10 +1511,10 @@ Module( MatchValue( PatternMatchValue { range: 1051..1052, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1051..1052, value: Int( 0, @@ -1531,12 +1531,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1063..1068, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1063..1064, id: Name("y"), ctx: Store, @@ -1545,7 +1545,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1067..1068, value: Int( 1, @@ -1558,18 +1558,18 @@ Module( }, MatchCase { range: 1073..1098, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 1078..1083, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: Some( Identifier { id: Name("z"), range: 1081..1082, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -1578,12 +1578,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1093..1098, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1093..1094, id: Name("y"), ctx: Store, @@ -1592,7 +1592,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1097..1098, value: Int( 2, @@ -1608,15 +1608,15 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1121..1162, subject: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1127..1132, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1127..1130, id: Name("Seq"), ctx: Load, @@ -1624,7 +1624,7 @@ Module( ), arguments: Arguments { range: 1130..1132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -1633,16 +1633,16 @@ Module( cases: [ MatchCase { range: 1138..1162, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 1143..1147, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 1144..1146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -1653,12 +1653,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1157..1162, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1157..1158, id: Name("y"), ctx: Store, @@ -1667,7 +1667,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1161..1162, value: Int( 0, @@ -1683,11 +1683,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1185..1245, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1191..1192, id: Name("x"), ctx: Load, @@ -1696,14 +1696,14 @@ Module( cases: [ MatchCase { range: 1198..1219, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 1203..1204, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1203..1204, value: Int( 1, @@ -1716,12 +1716,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1214..1219, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1214..1215, id: Name("y"), ctx: Store, @@ -1730,7 +1730,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1218..1219, value: Int( 0, @@ -1743,14 +1743,14 @@ Module( }, MatchCase { range: 1224..1245, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 1229..1230, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1229..1230, value: Int( 1, @@ -1763,12 +1763,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1240..1245, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1240..1241, id: Name("y"), ctx: Store, @@ -1777,7 +1777,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1244..1245, value: Int( 1, @@ -1793,11 +1793,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1268..1315, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1274..1275, id: Name("x"), ctx: Load, @@ -1806,21 +1806,21 @@ Module( cases: [ MatchCase { range: 1281..1315, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 1286..1298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1287..1292, value: StringLiteralValue { inner: Single( StringLiteral { range: 1287..1292, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "foo", flags: StringLiteralFlags { quote_style: Double, @@ -1837,13 +1837,13 @@ Module( MatchAs( PatternMatchAs { range: 1294..1297, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("bar"), range: 1294..1297, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -1856,12 +1856,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1308..1315, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1308..1309, id: Name("y"), ctx: Store, @@ -1870,7 +1870,7 @@ Module( ], value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1312..1315, id: Name("bar"), ctx: Load, @@ -1885,16 +1885,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1338..1392, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1344..1353, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1345..1346, value: Int( 0, @@ -1903,7 +1903,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1348..1349, value: Int( 1, @@ -1912,7 +1912,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1351..1352, value: Int( 2, @@ -1927,19 +1927,19 @@ Module( cases: [ MatchCase { range: 1359..1392, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 1364..1377, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 1365..1366, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1365..1366, value: Int( 0, @@ -1951,10 +1951,10 @@ Module( MatchValue( PatternMatchValue { range: 1368..1369, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1368..1369, value: Int( 1, @@ -1966,12 +1966,12 @@ Module( MatchStar( PatternMatchStar { range: 1371..1373, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("x"), range: 1372..1373, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -1979,10 +1979,10 @@ Module( MatchValue( PatternMatchValue { range: 1375..1376, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1375..1376, value: Int( 2, @@ -1998,12 +1998,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1387..1392, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1387..1388, id: Name("y"), ctx: Store, @@ -2012,7 +2012,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1391..1392, value: Int( 0, @@ -2028,11 +2028,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1415..1529, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1421..1422, id: Name("x"), ctx: Load, @@ -2041,19 +2041,19 @@ Module( cases: [ MatchCase { range: 1428..1451, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 1433..1436, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 1434..1435, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1434..1435, value: Int( 0, @@ -2069,12 +2069,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1446..1451, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1446..1447, id: Name("y"), ctx: Store, @@ -2083,7 +2083,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1450..1451, value: Int( 0, @@ -2096,19 +2096,19 @@ Module( }, MatchCase { range: 1456..1498, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 1461..1467, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 1462..1463, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1462..1463, value: Int( 1, @@ -2120,10 +2120,10 @@ Module( MatchValue( PatternMatchValue { range: 1465..1466, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1465..1466, value: Int( 0, @@ -2138,11 +2138,11 @@ Module( guard: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1472..1482, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1472..1473, id: Name("x"), ctx: Store, @@ -2150,11 +2150,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1477..1482, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1477..1478, id: Name("x"), ctx: Load, @@ -2162,13 +2162,13 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1479..1481, lower: None, upper: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1480..1481, value: Int( 0, @@ -2188,12 +2188,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1493..1498, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1493..1494, id: Name("y"), ctx: Store, @@ -2202,7 +2202,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1497..1498, value: Int( 1, @@ -2215,19 +2215,19 @@ Module( }, MatchCase { range: 1503..1529, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 1508..1514, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 1509..1510, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1509..1510, value: Int( 1, @@ -2239,10 +2239,10 @@ Module( MatchValue( PatternMatchValue { range: 1512..1513, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1512..1513, value: Int( 0, @@ -2258,12 +2258,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1524..1529, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1524..1525, id: Name("y"), ctx: Store, @@ -2272,7 +2272,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1528..1529, value: Int( 2, @@ -2288,11 +2288,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1552..1595, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1558..1559, id: Name("w"), ctx: Load, @@ -2301,22 +2301,22 @@ Module( cases: [ MatchCase { range: 1565..1595, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 1570..1580, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 1571..1572, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 1571..1572, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -2324,13 +2324,13 @@ Module( MatchAs( PatternMatchAs { range: 1574..1575, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 1574..1575, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -2338,7 +2338,7 @@ Module( MatchStar( PatternMatchStar { range: 1577..1579, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -2349,12 +2349,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1590..1595, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1590..1591, id: Name("z"), ctx: Store, @@ -2363,7 +2363,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1594..1595, value: Int( 0, @@ -2379,11 +2379,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1618..1664, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1624..1625, id: Name("x"), ctx: Load, @@ -2392,23 +2392,23 @@ Module( cases: [ MatchCase { range: 1631..1664, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 1636..1649, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1636..1649, left: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1636..1641, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1637..1641, value: Float( 0.25, @@ -2420,7 +2420,7 @@ Module( op: Sub, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1644..1649, value: Complex { real: 0.0, @@ -2436,12 +2436,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1659..1664, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1659..1660, id: Name("y"), ctx: Store, @@ -2450,7 +2450,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1663..1664, value: Int( 0, @@ -2466,16 +2466,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1687..1726, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1693..1697, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1694..1695, id: Name("x"), ctx: Load, @@ -2489,22 +2489,22 @@ Module( cases: [ MatchCase { range: 1703..1726, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 1708..1711, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 1709..1710, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 1709..1710, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -2516,12 +2516,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1721..1726, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1721..1722, id: Name("z"), ctx: Store, @@ -2530,7 +2530,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1725..1726, value: Int( 0, @@ -2546,11 +2546,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1749..1789, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1755..1756, id: Name("x"), ctx: Load, @@ -2559,26 +2559,26 @@ Module( cases: [ MatchCase { range: 1762..1789, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 1767..1774, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1767..1774, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1767..1772, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1767..1770, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1767..1768, id: Name("A"), ctx: Load, @@ -2587,7 +2587,7 @@ Module( attr: Identifier { id: Name("B"), range: 1769..1770, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2595,7 +2595,7 @@ Module( attr: Identifier { id: Name("C"), range: 1771..1772, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2603,7 +2603,7 @@ Module( attr: Identifier { id: Name("D"), range: 1773..1774, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2614,12 +2614,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1784..1789, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1784..1785, id: Name("y"), ctx: Store, @@ -2628,7 +2628,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1788..1789, value: Int( 0, @@ -2644,11 +2644,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1812..1849, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1818..1819, id: Name("x"), ctx: Load, @@ -2657,11 +2657,11 @@ Module( cases: [ MatchCase { range: 1825..1849, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSingleton( PatternMatchSingleton { range: 1830..1834, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: None, }, ), @@ -2669,12 +2669,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1844..1849, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1844..1845, id: Name("y"), ctx: Store, @@ -2683,7 +2683,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1848..1849, value: Int( 0, @@ -2699,11 +2699,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1872..1906, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1878..1879, id: Name("x"), ctx: Load, @@ -2712,14 +2712,14 @@ Module( cases: [ MatchCase { range: 1885..1906, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 1890..1891, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1890..1891, value: Int( 0, @@ -2732,12 +2732,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1901..1906, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1901..1902, id: Name("y"), ctx: Store, @@ -2746,7 +2746,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1905..1906, value: Int( 0, @@ -2762,11 +2762,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1929..1967, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1935..1936, id: Name("x"), ctx: Load, @@ -2775,11 +2775,11 @@ Module( cases: [ MatchCase { range: 1942..1967, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSingleton( PatternMatchSingleton { range: 1947..1952, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: False, }, ), @@ -2787,12 +2787,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1962..1967, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1962..1963, id: Name("y"), ctx: Store, @@ -2801,7 +2801,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1966..1967, value: Int( 0, @@ -2817,11 +2817,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1990..2081, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1996..1997, id: Name("x"), ctx: Load, @@ -2830,11 +2830,11 @@ Module( cases: [ MatchCase { range: 2003..2025, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2008..2010, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], }, ), @@ -2842,12 +2842,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2020..2025, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2020..2021, id: Name("y"), ctx: Store, @@ -2856,7 +2856,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2024..2025, value: Int( 0, @@ -2869,25 +2869,25 @@ Module( }, MatchCase { range: 2030..2054, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2035..2039, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 2036..2038, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2036..2038, value: StringLiteralValue { inner: Single( StringLiteral { range: 2036..2038, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Double, @@ -2908,12 +2908,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2049..2054, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2049..2050, id: Name("y"), ctx: Store, @@ -2922,7 +2922,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2053..2054, value: Int( 1, @@ -2935,20 +2935,20 @@ Module( }, MatchCase { range: 2059..2081, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 2064..2066, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2064..2066, value: StringLiteralValue { inner: Single( StringLiteral { range: 2064..2066, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Double, @@ -2966,12 +2966,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2076..2081, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2076..2077, id: Name("y"), ctx: Store, @@ -2980,7 +2980,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2080..2081, value: Int( 2, @@ -2996,11 +2996,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2104..2138, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2110..2111, id: Name("x"), ctx: Load, @@ -3009,17 +3009,17 @@ Module( cases: [ MatchCase { range: 2117..2138, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 2122..2123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 2122..2123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3028,12 +3028,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2133..2138, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2133..2134, id: Name("y"), ctx: Store, @@ -3042,7 +3042,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2137..2138, value: Int( 0, @@ -3058,11 +3058,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2161..2207, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2167..2168, id: Name("w"), ctx: Load, @@ -3071,22 +3071,22 @@ Module( cases: [ MatchCase { range: 2174..2207, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2179..2192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 2180..2181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("x"), range: 2180..2181, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3094,13 +3094,13 @@ Module( MatchAs( PatternMatchAs { range: 2183..2184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 2183..2184, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3108,12 +3108,12 @@ Module( MatchStar( PatternMatchStar { range: 2186..2191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("rest"), range: 2187..2191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3125,12 +3125,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2202..2207, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2202..2203, id: Name("z"), ctx: Store, @@ -3139,7 +3139,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2206..2207, value: Int( 0, @@ -3155,11 +3155,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2230..2307, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2236..2237, id: Name("x"), ctx: Load, @@ -3168,24 +3168,24 @@ Module( cases: [ MatchCase { range: 2243..2307, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 2248..2278, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 2249..2255, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchValue( PatternMatchValue { range: 2249..2250, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2249..2250, value: Int( 0, @@ -3199,7 +3199,7 @@ Module( Identifier { id: Name("z"), range: 2254..2255, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3207,15 +3207,15 @@ Module( MatchAs( PatternMatchAs { range: 2260..2266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchValue( PatternMatchValue { range: 2260..2261, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2260..2261, value: Int( 1, @@ -3229,7 +3229,7 @@ Module( Identifier { id: Name("z"), range: 2265..2266, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3237,15 +3237,15 @@ Module( MatchAs( PatternMatchAs { range: 2271..2277, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchValue( PatternMatchValue { range: 2271..2272, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2271..2272, value: Int( 2, @@ -3259,7 +3259,7 @@ Module( Identifier { id: Name("z"), range: 2276..2277, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3270,11 +3270,11 @@ Module( guard: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2282..2292, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2282..2283, id: Name("z"), ctx: Load, @@ -3286,11 +3286,11 @@ Module( comparators: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2287..2292, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2287..2288, id: Name("x"), ctx: Load, @@ -3299,7 +3299,7 @@ Module( op: Mod, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2291..2292, value: Int( 2, @@ -3315,12 +3315,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2302..2307, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2302..2303, id: Name("y"), ctx: Store, @@ -3329,7 +3329,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2306..2307, value: Int( 0, @@ -3345,11 +3345,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2330..2499, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2336..2337, id: Name("x"), ctx: Load, @@ -3358,15 +3358,15 @@ Module( cases: [ MatchCase { range: 2343..2378, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 2348..2363, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2349..2350, value: Int( 0, @@ -3378,15 +3378,15 @@ Module( MatchSequence( PatternMatchSequence { range: 2352..2362, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 2353..2354, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2353..2354, value: Int( 1, @@ -3398,10 +3398,10 @@ Module( MatchValue( PatternMatchValue { range: 2356..2357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2356..2357, value: Int( 2, @@ -3413,7 +3413,7 @@ Module( MatchMapping( PatternMatchMapping { range: 2359..2361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -3430,12 +3430,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2373..2378, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2373..2374, id: Name("y"), ctx: Store, @@ -3444,7 +3444,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2377..2378, value: Int( 0, @@ -3457,20 +3457,20 @@ Module( }, MatchCase { range: 2383..2472, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 2388..2457, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchMapping( PatternMatchMapping { range: 2388..2411, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2389..2390, value: Int( 0, @@ -3482,20 +3482,20 @@ Module( MatchOr( PatternMatchOr { range: 2392..2410, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 2392..2402, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 2393..2394, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2393..2394, value: Int( 1, @@ -3507,10 +3507,10 @@ Module( MatchValue( PatternMatchValue { range: 2396..2397, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2396..2397, value: Int( 2, @@ -3522,7 +3522,7 @@ Module( MatchMapping( PatternMatchMapping { range: 2399..2401, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -3534,7 +3534,7 @@ Module( MatchSingleton( PatternMatchSingleton { range: 2405..2410, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: False, }, ), @@ -3548,11 +3548,11 @@ Module( MatchMapping( PatternMatchMapping { range: 2414..2423, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2415..2416, value: Int( 1, @@ -3564,12 +3564,12 @@ Module( MatchSequence( PatternMatchSequence { range: 2418..2422, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 2419..2421, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], }, ), @@ -3583,11 +3583,11 @@ Module( MatchMapping( PatternMatchMapping { range: 2426..2441, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2427..2428, value: Int( 0, @@ -3599,15 +3599,15 @@ Module( MatchSequence( PatternMatchSequence { range: 2430..2440, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 2431..2432, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2431..2432, value: Int( 1, @@ -3619,10 +3619,10 @@ Module( MatchValue( PatternMatchValue { range: 2434..2435, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2434..2435, value: Int( 2, @@ -3634,7 +3634,7 @@ Module( MatchMapping( PatternMatchMapping { range: 2437..2439, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -3650,23 +3650,23 @@ Module( MatchSequence( PatternMatchSequence { range: 2444..2446, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], }, ), MatchValue( PatternMatchValue { range: 2449..2452, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2449..2452, value: StringLiteralValue { inner: Single( StringLiteral { range: 2449..2452, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "X", flags: StringLiteralFlags { quote_style: Double, @@ -3683,7 +3683,7 @@ Module( MatchMapping( PatternMatchMapping { range: 2455..2457, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: None, @@ -3696,12 +3696,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2467..2472, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2467..2468, id: Name("y"), ctx: Store, @@ -3710,7 +3710,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2471..2472, value: Int( 1, @@ -3723,11 +3723,11 @@ Module( }, MatchCase { range: 2477..2499, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2482..2484, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], }, ), @@ -3735,12 +3735,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2494..2499, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2494..2495, id: Name("y"), ctx: Store, @@ -3749,7 +3749,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2498..2499, value: Int( 2, @@ -3765,16 +3765,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2522..2568, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2528..2537, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2529..2530, value: Int( 0, @@ -3783,7 +3783,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2532..2533, value: Int( 1, @@ -3792,7 +3792,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2535..2536, value: Int( 2, @@ -3807,19 +3807,19 @@ Module( cases: [ MatchCase { range: 2543..2568, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2548..2553, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 2548..2549, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2548..2549, value: Int( 0, @@ -3831,12 +3831,12 @@ Module( MatchStar( PatternMatchStar { range: 2551..2553, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("x"), range: 2552..2553, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3848,12 +3848,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2563..2568, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2563..2564, id: Name("y"), ctx: Store, @@ -3862,7 +3862,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2567..2568, value: Int( 0, @@ -3878,16 +3878,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2591..2638, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2597..2606, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2598..2599, value: Int( 0, @@ -3896,7 +3896,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2601..2602, value: Int( 1, @@ -3905,7 +3905,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2604..2605, value: Int( 2, @@ -3920,21 +3920,21 @@ Module( cases: [ MatchCase { range: 2612..2638, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2617..2623, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 2617..2619, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("x"), range: 2618..2619, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -3942,10 +3942,10 @@ Module( MatchValue( PatternMatchValue { range: 2621..2622, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2621..2622, value: Int( 2, @@ -3961,12 +3961,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2633..2638, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2633..2634, id: Name("y"), ctx: Store, @@ -3975,7 +3975,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2637..2638, value: Int( 0, @@ -3991,16 +3991,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2661..2697, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2667..2669, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2667..2668, id: Name("x"), ctx: Load, @@ -4014,22 +4014,22 @@ Module( cases: [ MatchCase { range: 2675..2697, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2680..2682, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 2680..2681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 2680..2681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4041,12 +4041,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2692..2697, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2692..2693, id: Name("z"), ctx: Store, @@ -4055,7 +4055,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2696..2697, value: Int( 0, @@ -4071,16 +4071,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2720..2760, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2726..2730, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2726..2727, id: Name("w"), ctx: Load, @@ -4088,7 +4088,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2729..2730, id: Name("x"), ctx: Load, @@ -4102,22 +4102,22 @@ Module( cases: [ MatchCase { range: 2736..2760, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2741..2745, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 2741..2742, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 2741..2742, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4125,13 +4125,13 @@ Module( MatchAs( PatternMatchAs { range: 2744..2745, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 2744..2745, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4143,12 +4143,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2755..2760, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2755..2756, id: Name("v"), ctx: Store, @@ -4157,7 +4157,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2759..2760, value: Int( 0, @@ -4173,20 +4173,20 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2783..2829, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2789..2796, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2789..2795, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2789..2790, id: Name("w"), ctx: Store, @@ -4194,7 +4194,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2794..2795, id: Name("x"), ctx: Load, @@ -4210,27 +4210,27 @@ Module( cases: [ MatchCase { range: 2802..2829, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 2807..2814, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 2807..2813, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchAs( PatternMatchAs { range: 2807..2808, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("y"), range: 2807..2808, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4240,7 +4240,7 @@ Module( Identifier { id: Name("v"), range: 2812..2813, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4252,12 +4252,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2824..2829, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2824..2825, id: Name("z"), ctx: Store, @@ -4266,7 +4266,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2828..2829, value: Int( 0, @@ -4282,11 +4282,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2831..2952, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2837..2838, id: Name("x"), ctx: Load, @@ -4295,29 +4295,29 @@ Module( cases: [ MatchCase { range: 2927..2952, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 2932..2938, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2932..2938, value: FStringValue { inner: Single( FString( FString { range: 2932..2938, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 2934..2937, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2935..2936, id: Name("y"), ctx: Load, @@ -4346,7 +4346,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2948..2952, }, ), @@ -4357,24 +4357,24 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2953..3025, subject: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2959..2970, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2960..2966, value: StringLiteralValue { inner: Single( StringLiteral { range: 2960..2966, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "test", flags: StringLiteralFlags { quote_style: Double, @@ -4389,7 +4389,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 2968..2969, value: Int( 1, @@ -4403,18 +4403,18 @@ Module( cases: [ MatchCase { range: 2976..3025, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 2981..3004, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [], patterns: [], rest: Some( Identifier { id: Name("rest"), range: 2993..2997, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4423,15 +4423,15 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3014..3025, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3014..3025, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3014..3019, id: Name("print"), ctx: Load, @@ -4439,11 +4439,11 @@ Module( ), arguments: Arguments { range: 3019..3025, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3020..3024, id: Name("rest"), ctx: Load, @@ -4463,24 +4463,24 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3026..3129, subject: Dict( ExprDict { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3032..3049, items: [ DictItem { key: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3033..3040, value: StringLiteralValue { inner: Single( StringLiteral { range: 3033..3040, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "label", flags: StringLiteralFlags { quote_style: Double, @@ -4495,13 +4495,13 @@ Module( ), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3042..3048, value: StringLiteralValue { inner: Single( StringLiteral { range: 3042..3048, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "test", flags: StringLiteralFlags { quote_style: Double, @@ -4520,21 +4520,21 @@ Module( cases: [ MatchCase { range: 3055..3129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 3060..3107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3070..3077, value: StringLiteralValue { inner: Single( StringLiteral { range: 3070..3077, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "label", flags: StringLiteralFlags { quote_style: Double, @@ -4551,20 +4551,20 @@ Module( MatchAs( PatternMatchAs { range: 3079..3100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchOr( PatternMatchOr { range: 3079..3091, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchClass( PatternMatchClass { range: 3079..3084, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3079..3082, id: Name("str"), ctx: Load, @@ -4572,7 +4572,7 @@ Module( ), arguments: PatternArguments { range: 3082..3084, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [], }, @@ -4581,7 +4581,7 @@ Module( MatchSingleton( PatternMatchSingleton { range: 3087..3091, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: None, }, ), @@ -4593,7 +4593,7 @@ Module( Identifier { id: Name("label"), range: 3095..3100, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4606,15 +4606,15 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3117..3129, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3117..3129, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3117..3122, id: Name("print"), ctx: Load, @@ -4622,11 +4622,11 @@ Module( ), arguments: Arguments { range: 3122..3129, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3123..3128, id: Name("label"), ctx: Load, @@ -4646,11 +4646,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3130..3170, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3136..3137, id: Name("x"), ctx: Load, @@ -4659,19 +4659,19 @@ Module( cases: [ MatchCase { range: 3143..3170, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 3148..3155, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 3149..3150, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3149..3150, value: Int( 0, @@ -4683,10 +4683,10 @@ Module( MatchValue( PatternMatchValue { range: 3152..3153, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3152..3153, value: Int( 1, @@ -4702,12 +4702,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3165..3170, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3165..3166, id: Name("y"), ctx: Store, @@ -4716,7 +4716,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3169..3170, value: Int( 0, @@ -4732,11 +4732,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3171..3211, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3177..3178, id: Name("x"), ctx: Load, @@ -4745,19 +4745,19 @@ Module( cases: [ MatchCase { range: 3184..3211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 3189..3196, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 3190..3191, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3190..3191, value: Int( 0, @@ -4769,10 +4769,10 @@ Module( MatchValue( PatternMatchValue { range: 3193..3194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3193..3194, value: Int( 1, @@ -4788,12 +4788,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3206..3211, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3206..3207, id: Name("y"), ctx: Store, @@ -4802,7 +4802,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3210..3211, value: Int( 0, @@ -4818,11 +4818,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3212..3249, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3218..3219, id: Name("x"), ctx: Load, @@ -4831,19 +4831,19 @@ Module( cases: [ MatchCase { range: 3225..3249, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 3230..3234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 3231..3232, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3231..3232, value: Int( 0, @@ -4859,12 +4859,12 @@ Module( body: [ Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3244..3249, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3244..3245, id: Name("y"), ctx: Store, @@ -4873,7 +4873,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3248..3249, value: Int( 0, @@ -4889,16 +4889,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3250..3284, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3256..3258, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3256..3257, id: Name("x"), ctx: Load, @@ -4912,17 +4912,17 @@ Module( cases: [ MatchCase { range: 3264..3284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 3269..3270, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 3269..3270, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4931,7 +4931,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3280..3284, }, ), @@ -4942,16 +4942,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3285..3321, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3291..3295, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3291..3292, id: Name("x"), ctx: Load, @@ -4959,7 +4959,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3294..3295, id: Name("y"), ctx: Load, @@ -4973,17 +4973,17 @@ Module( cases: [ MatchCase { range: 3301..3321, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 3306..3307, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 3306..3307, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -4992,7 +4992,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3317..3321, }, ), @@ -5003,16 +5003,16 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3322..3359, subject: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3328..3333, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3328..3329, id: Name("x"), ctx: Load, @@ -5020,7 +5020,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3331..3332, id: Name("y"), ctx: Load, @@ -5034,17 +5034,17 @@ Module( cases: [ MatchCase { range: 3339..3359, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 3344..3345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("z"), range: 3344..3345, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -5053,7 +5053,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3355..3359, }, ), @@ -5064,11 +5064,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3385..3475, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3391..3392, id: Name("x"), ctx: Load, @@ -5077,11 +5077,11 @@ Module( cases: [ MatchCase { range: 3398..3420, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSingleton( PatternMatchSingleton { range: 3403..3407, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: None, }, ), @@ -5089,11 +5089,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3417..3420, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3417..3420, }, ), @@ -5103,11 +5103,11 @@ Module( }, MatchCase { range: 3425..3447, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSingleton( PatternMatchSingleton { range: 3430..3434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: True, }, ), @@ -5115,11 +5115,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3444..3447, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3444..3447, }, ), @@ -5129,11 +5129,11 @@ Module( }, MatchCase { range: 3452..3475, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSingleton( PatternMatchSingleton { range: 3457..3462, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: False, }, ), @@ -5141,11 +5141,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3472..3475, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3472..3475, }, ), @@ -5158,11 +5158,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3497..3821, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3503..3504, id: Name("x"), ctx: Load, @@ -5171,18 +5171,18 @@ Module( cases: [ MatchCase { range: 3510..3531, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3515..3518, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3515..3518, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3515..3516, id: Name("a"), ctx: Load, @@ -5191,7 +5191,7 @@ Module( attr: Identifier { id: Name("b"), range: 3517..3518, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -5202,11 +5202,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3528..3531, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3528..3531, }, ), @@ -5216,22 +5216,22 @@ Module( }, MatchCase { range: 3536..3559, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3541..3546, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3541..3546, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3541..3544, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3541..3542, id: Name("a"), ctx: Load, @@ -5240,7 +5240,7 @@ Module( attr: Identifier { id: Name("b"), range: 3543..3544, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -5248,7 +5248,7 @@ Module( attr: Identifier { id: Name("c"), range: 3545..3546, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -5259,11 +5259,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3556..3559, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3556..3559, }, ), @@ -5273,20 +5273,20 @@ Module( }, MatchCase { range: 3564..3584, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3569..3571, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3569..3571, value: StringLiteralValue { inner: Single( StringLiteral { range: 3569..3571, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -5304,11 +5304,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3581..3584, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3581..3584, }, ), @@ -5318,20 +5318,20 @@ Module( }, MatchCase { range: 3589..3610, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3594..3597, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BytesLiteral( ExprBytesLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3594..3597, value: BytesLiteralValue { inner: Single( BytesLiteral { range: 3594..3597, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: [], flags: BytesLiteralFlags { quote_style: Single, @@ -5349,11 +5349,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3607..3610, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3607..3610, }, ), @@ -5363,14 +5363,14 @@ Module( }, MatchCase { range: 3615..3634, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3620..3621, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3620..3621, value: Int( 1, @@ -5383,11 +5383,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3631..3634, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3631..3634, }, ), @@ -5397,14 +5397,14 @@ Module( }, MatchCase { range: 3639..3660, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3644..3647, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3644..3647, value: Float( 1.0, @@ -5417,11 +5417,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3657..3660, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3657..3660, }, ), @@ -5431,14 +5431,14 @@ Module( }, MatchCase { range: 3665..3687, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3670..3674, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3670..3674, value: Complex { real: 0.0, @@ -5452,11 +5452,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3684..3687, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3684..3687, }, ), @@ -5466,18 +5466,18 @@ Module( }, MatchCase { range: 3692..3716, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3697..3703, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3697..3703, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3697..3698, value: Int( 1, @@ -5487,7 +5487,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3701..3703, value: Complex { real: 0.0, @@ -5503,11 +5503,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3713..3716, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3713..3716, }, ), @@ -5517,19 +5517,19 @@ Module( }, MatchCase { range: 3721..3741, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3726..3728, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3726..3728, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3727..3728, value: Int( 1, @@ -5544,11 +5544,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3738..3741, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3738..3741, }, ), @@ -5558,19 +5558,19 @@ Module( }, MatchCase { range: 3746..3767, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3751..3754, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3751..3754, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3752..3754, value: Float( 1.0, @@ -5585,11 +5585,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3764..3767, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3764..3767, }, ), @@ -5599,19 +5599,19 @@ Module( }, MatchCase { range: 3772..3795, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3777..3782, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3777..3782, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3778..3782, value: Int( 1, @@ -5626,11 +5626,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3792..3795, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3792..3795, }, ), @@ -5640,14 +5640,14 @@ Module( }, MatchCase { range: 3800..3821, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 3806..3807, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3806..3807, value: Int( 1, @@ -5660,11 +5660,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3818..3821, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3818..3821, }, ), @@ -5677,11 +5677,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3840..3927, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3846..3847, id: Name("x"), ctx: Load, @@ -5690,19 +5690,19 @@ Module( cases: [ MatchCase { range: 3853..3876, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 3858..3863, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 3858..3859, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3858..3859, value: Int( 1, @@ -5714,10 +5714,10 @@ Module( MatchValue( PatternMatchValue { range: 3862..3863, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3862..3863, value: Int( 2, @@ -5733,11 +5733,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3873..3876, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3873..3876, }, ), @@ -5747,25 +5747,25 @@ Module( }, MatchCase { range: 3881..3927, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchOr( PatternMatchOr { range: 3886..3914, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 3886..3888, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3886..3888, value: StringLiteralValue { inner: Single( StringLiteral { range: 3886..3888, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -5782,10 +5782,10 @@ Module( MatchValue( PatternMatchValue { range: 3891..3894, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3891..3894, value: Float( 1.1, @@ -5797,15 +5797,15 @@ Module( MatchValue( PatternMatchValue { range: 3897..3899, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3897..3899, op: USub, operand: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3898..3899, value: Int( 1, @@ -5819,14 +5819,14 @@ Module( MatchValue( PatternMatchValue { range: 3902..3908, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3902..3908, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3902..3903, value: Int( 1, @@ -5836,7 +5836,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3906..3908, value: Complex { real: 0.0, @@ -5851,14 +5851,14 @@ Module( MatchValue( PatternMatchValue { range: 3911..3914, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3911..3914, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3911..3912, id: Name("a"), ctx: Load, @@ -5867,7 +5867,7 @@ Module( attr: Identifier { id: Name("b"), range: 3913..3914, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -5881,11 +5881,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3924..3927, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3924..3927, }, ), @@ -5898,11 +5898,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3946..3978, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3952..3953, id: Name("x"), ctx: Load, @@ -5911,17 +5911,17 @@ Module( cases: [ MatchCase { range: 3959..3978, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 3964..3965, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 3964..3965, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -5930,11 +5930,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3975..3978, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3975..3978, }, ), @@ -5947,11 +5947,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3979..4016, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 3985..3986, id: Name("x"), ctx: Load, @@ -5960,22 +5960,22 @@ Module( cases: [ MatchCase { range: 3992..4016, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 3997..4003, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchAs( PatternMatchAs { range: 3997..3998, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 3997..3998, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -5985,7 +5985,7 @@ Module( Identifier { id: Name("b"), range: 4002..4003, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -5994,11 +5994,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4013..4016, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4013..4016, }, ), @@ -6011,11 +6011,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4017..4157, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4023..4024, id: Name("x"), ctx: Load, @@ -6024,24 +6024,24 @@ Module( cases: [ MatchCase { range: 4030..4060, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 4035..4047, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchOr( PatternMatchOr { range: 4035..4040, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4035..4036, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4035..4036, value: Int( 1, @@ -6053,10 +6053,10 @@ Module( MatchValue( PatternMatchValue { range: 4039..4040, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4039..4040, value: Int( 2, @@ -6073,7 +6073,7 @@ Module( Identifier { id: Name("two"), range: 4044..4047, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6082,11 +6082,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4057..4060, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4057..4060, }, ), @@ -6096,23 +6096,23 @@ Module( }, MatchCase { range: 4065..4096, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 4070..4083, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchValue( PatternMatchValue { range: 4070..4076, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4070..4076, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4070..4071, value: Int( 1, @@ -6122,7 +6122,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4074..4076, value: Complex { real: 0.0, @@ -6139,7 +6139,7 @@ Module( Identifier { id: Name("sum"), range: 4080..4083, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6148,11 +6148,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4093..4096, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4093..4096, }, ), @@ -6162,23 +6162,23 @@ Module( }, MatchCase { range: 4101..4128, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 4106..4115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchValue( PatternMatchValue { range: 4106..4109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4106..4109, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4106..4107, id: Name("a"), ctx: Load, @@ -6187,7 +6187,7 @@ Module( attr: Identifier { id: Name("b"), range: 4108..4109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -6199,7 +6199,7 @@ Module( Identifier { id: Name("ab"), range: 4113..4115, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6208,11 +6208,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4125..4128, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4125..4128, }, ), @@ -6222,16 +6222,16 @@ Module( }, MatchCase { range: 4133..4157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 4138..4144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchAs( PatternMatchAs { range: 4138..4139, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -6241,7 +6241,7 @@ Module( Identifier { id: Name("x"), range: 4143..4144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6250,11 +6250,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4154..4157, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4154..4157, }, ), @@ -6267,11 +6267,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4158..4190, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4164..4165, id: Name("x"), ctx: Load, @@ -6280,11 +6280,11 @@ Module( cases: [ MatchCase { range: 4171..4190, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 4176..4177, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -6293,11 +6293,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4187..4190, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4187..4190, }, ), @@ -6310,11 +6310,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4215..4466, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4221..4222, id: Name("x"), ctx: Load, @@ -6323,19 +6323,19 @@ Module( cases: [ MatchCase { range: 4228..4253, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4233..4240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4233..4234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4233..4234, value: Int( 1, @@ -6347,10 +6347,10 @@ Module( MatchValue( PatternMatchValue { range: 4236..4237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4236..4237, value: Int( 2, @@ -6362,10 +6362,10 @@ Module( MatchValue( PatternMatchValue { range: 4239..4240, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4239..4240, value: Int( 3, @@ -6381,11 +6381,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4250..4253, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4250..4253, }, ), @@ -6395,19 +6395,19 @@ Module( }, MatchCase { range: 4258..4286, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4263..4273, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4264..4265, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4264..4265, value: Int( 1, @@ -6419,10 +6419,10 @@ Module( MatchValue( PatternMatchValue { range: 4267..4268, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4267..4268, value: Int( 2, @@ -6434,10 +6434,10 @@ Module( MatchValue( PatternMatchValue { range: 4270..4271, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4270..4271, value: Int( 3, @@ -6453,11 +6453,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4283..4286, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4283..4286, }, ), @@ -6467,23 +6467,23 @@ Module( }, MatchCase { range: 4291..4331, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4296..4318, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4297..4303, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4297..4303, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4297..4298, value: Int( 1, @@ -6493,7 +6493,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4301..4303, value: Complex { real: 0.0, @@ -6508,13 +6508,13 @@ Module( MatchAs( PatternMatchAs { range: 4305..4306, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 4305..4306, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6522,21 +6522,21 @@ Module( MatchSingleton( PatternMatchSingleton { range: 4308..4312, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: None, }, ), MatchValue( PatternMatchValue { range: 4314..4317, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4314..4317, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4314..4315, id: Name("a"), ctx: Load, @@ -6545,7 +6545,7 @@ Module( attr: Identifier { id: Name("b"), range: 4316..4317, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -6559,11 +6559,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4328..4331, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4328..4331, }, ), @@ -6573,29 +6573,29 @@ Module( }, MatchCase { range: 4336..4370, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 4341..4357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchSequence( PatternMatchSequence { range: 4341..4352, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchAs( PatternMatchAs { range: 4342..4348, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: Some( MatchValue( PatternMatchValue { range: 4342..4343, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4342..4343, value: Int( 1, @@ -6609,7 +6609,7 @@ Module( Identifier { id: Name("X"), range: 4347..4348, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6617,13 +6617,13 @@ Module( MatchAs( PatternMatchAs { range: 4350..4351, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("b"), range: 4350..4351, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6636,7 +6636,7 @@ Module( Identifier { id: Name("S"), range: 4356..4357, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6645,11 +6645,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4367..4370, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4367..4370, }, ), @@ -6659,19 +6659,19 @@ Module( }, MatchCase { range: 4375..4407, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4380..4394, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4381..4382, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4381..4382, value: Int( 1, @@ -6683,10 +6683,10 @@ Module( MatchValue( PatternMatchValue { range: 4384..4385, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4384..4385, value: Int( 2, @@ -6698,14 +6698,14 @@ Module( MatchValue( PatternMatchValue { range: 4387..4393, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4387..4393, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4387..4388, value: Int( 3, @@ -6715,7 +6715,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4391..4393, value: Complex { real: 0.0, @@ -6734,11 +6734,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4404..4407, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4404..4407, }, ), @@ -6748,24 +6748,24 @@ Module( }, MatchCase { range: 4412..4440, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4417..4427, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 4418..4423, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4419..4420, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4419..4420, value: Int( 1, @@ -6777,10 +6777,10 @@ Module( MatchValue( PatternMatchValue { range: 4421..4422, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4421..4422, value: Int( 2, @@ -6795,10 +6795,10 @@ Module( MatchValue( PatternMatchValue { range: 4425..4426, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4425..4426, value: Int( 3, @@ -6814,11 +6814,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4437..4440, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4437..4440, }, ), @@ -6828,19 +6828,19 @@ Module( }, MatchCase { range: 4445..4466, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4450..4453, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4451..4452, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4451..4452, value: Int( 1, @@ -6856,11 +6856,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4463..4466, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4463..4466, }, ), @@ -6873,11 +6873,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4487..4616, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4493..4494, id: Name("x"), ctx: Load, @@ -6886,21 +6886,21 @@ Module( cases: [ MatchCase { range: 4500..4521, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4505..4508, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 4505..4507, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("a"), range: 4506..4507, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -6912,11 +6912,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4518..4521, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4518..4521, }, ), @@ -6926,16 +6926,16 @@ Module( }, MatchCase { range: 4526..4547, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4531..4534, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 4531..4533, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), @@ -6946,11 +6946,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4544..4547, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4544..4547, }, ), @@ -6960,19 +6960,19 @@ Module( }, MatchCase { range: 4552..4583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4557..4570, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4558..4559, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4558..4559, value: Int( 1, @@ -6984,10 +6984,10 @@ Module( MatchValue( PatternMatchValue { range: 4561..4562, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4561..4562, value: Int( 2, @@ -6999,12 +6999,12 @@ Module( MatchStar( PatternMatchStar { range: 4564..4569, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Some( Identifier { id: Name("rest"), range: 4565..4569, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -7016,11 +7016,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4580..4583, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4580..4583, }, ), @@ -7030,26 +7030,26 @@ Module( }, MatchCase { range: 4588..4616, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchSequence( PatternMatchSequence { range: 4593..4603, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchStar( PatternMatchStar { range: 4594..4596, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: None, }, ), MatchValue( PatternMatchValue { range: 4598..4599, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4598..4599, value: Int( 1, @@ -7061,10 +7061,10 @@ Module( MatchValue( PatternMatchValue { range: 4601..4602, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4601..4602, value: Int( 2, @@ -7080,11 +7080,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4613..4616, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4613..4616, }, ), @@ -7097,11 +7097,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4638..4910, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4644..4645, id: Name("x"), ctx: Load, @@ -7110,14 +7110,14 @@ Module( cases: [ MatchCase { range: 4651..4676, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 4656..4663, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4656..4661, id: Name("Point"), ctx: Load, @@ -7125,7 +7125,7 @@ Module( ), arguments: PatternArguments { range: 4661..4663, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [], }, @@ -7135,11 +7135,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4673..4676, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4673..4676, }, ), @@ -7149,22 +7149,22 @@ Module( }, MatchCase { range: 4681..4710, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 4686..4697, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4686..4695, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4686..4689, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4686..4687, id: Name("a"), ctx: Load, @@ -7173,7 +7173,7 @@ Module( attr: Identifier { id: Name("b"), range: 4688..4689, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -7181,14 +7181,14 @@ Module( attr: Identifier { id: Name("Point"), range: 4690..4695, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: PatternArguments { range: 4695..4697, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [], }, @@ -7198,11 +7198,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4707..4710, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4707..4710, }, ), @@ -7212,14 +7212,14 @@ Module( }, MatchCase { range: 4715..4745, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 4720..4732, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4720..4727, id: Name("Point2D"), ctx: Load, @@ -7227,24 +7227,24 @@ Module( ), arguments: PatternArguments { range: 4727..4732, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 4728..4731, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 4728..4729, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 4730..4731, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4730..4731, value: Int( 0, @@ -7262,11 +7262,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4742..4745, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4742..4745, }, ), @@ -7276,14 +7276,14 @@ Module( }, MatchCase { range: 4750..4786, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 4755..4773, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4755..4762, id: Name("Point2D"), ctx: Load, @@ -7291,24 +7291,24 @@ Module( ), arguments: PatternArguments { range: 4762..4773, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 4763..4766, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 4763..4764, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 4765..4766, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4765..4766, value: Int( 0, @@ -7320,19 +7320,19 @@ Module( }, PatternKeyword { range: 4768..4771, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 4768..4769, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 4770..4771, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4770..4771, value: Int( 0, @@ -7350,11 +7350,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4783..4786, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4783..4786, }, ), @@ -7364,14 +7364,14 @@ Module( }, MatchCase { range: 4791..4822, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 4796..4809, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4796..4803, id: Name("Point2D"), ctx: Load, @@ -7379,15 +7379,15 @@ Module( ), arguments: PatternArguments { range: 4803..4809, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4804..4805, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4804..4805, value: Int( 0, @@ -7399,10 +7399,10 @@ Module( MatchValue( PatternMatchValue { range: 4807..4808, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4807..4808, value: Int( 1, @@ -7420,11 +7420,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4819..4822, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4819..4822, }, ), @@ -7434,14 +7434,14 @@ Module( }, MatchCase { range: 4827..4865, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 4832..4852, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4832..4839, id: Name("Point2D"), ctx: Load, @@ -7449,20 +7449,20 @@ Module( ), arguments: PatternArguments { range: 4839..4852, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchSequence( PatternMatchSequence { range: 4840..4846, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4841..4842, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4841..4842, value: Int( 0, @@ -7474,10 +7474,10 @@ Module( MatchValue( PatternMatchValue { range: 4844..4845, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4844..4845, value: Int( 1, @@ -7493,19 +7493,19 @@ Module( keywords: [ PatternKeyword { range: 4848..4851, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 4848..4849, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 4850..4851, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4850..4851, value: Int( 1, @@ -7523,11 +7523,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4862..4865, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4862..4865, }, ), @@ -7537,14 +7537,14 @@ Module( }, MatchCase { range: 4870..4910, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchClass( PatternMatchClass { range: 4875..4897, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), cls: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4875..4882, id: Name("Point2D"), ctx: Load, @@ -7552,29 +7552,29 @@ Module( ), arguments: PatternArguments { range: 4882..4897, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [], keywords: [ PatternKeyword { range: 4883..4891, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("x"), range: 4883..4884, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchSequence( PatternMatchSequence { range: 4885..4891, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 4886..4887, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4886..4887, value: Int( 0, @@ -7586,10 +7586,10 @@ Module( MatchValue( PatternMatchValue { range: 4889..4890, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4889..4890, value: Int( 1, @@ -7604,19 +7604,19 @@ Module( }, PatternKeyword { range: 4893..4896, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), attr: Identifier { id: Name("y"), range: 4893..4894, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, pattern: MatchValue( PatternMatchValue { range: 4895..4896, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4895..4896, value: Int( 1, @@ -7634,11 +7634,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4907..4910, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4907..4910, }, ), @@ -7651,15 +7651,15 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4934..5028, subject: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4940..4946, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4940..4941, id: Name("x"), ctx: Store, @@ -7667,7 +7667,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4945..4946, id: Name("b"), ctx: Load, @@ -7678,15 +7678,15 @@ Module( cases: [ MatchCase { range: 4952..4976, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 4957..4963, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4958..4959, value: Int( 1, @@ -7698,7 +7698,7 @@ Module( MatchAs( PatternMatchAs { range: 4961..4962, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: None, }, @@ -7711,11 +7711,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4973..4976, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4973..4976, }, ), @@ -7725,21 +7725,21 @@ Module( }, MatchCase { range: 4981..5028, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchMapping( PatternMatchMapping { range: 4986..5015, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), keys: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4987..4989, value: StringLiteralValue { inner: Single( StringLiteral { range: 4987..4989, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "", flags: StringLiteralFlags { quote_style: Single, @@ -7753,7 +7753,7 @@ Module( ), NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 4994..4998, }, ), @@ -7762,13 +7762,13 @@ Module( MatchAs( PatternMatchAs { range: 4991..4992, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 4991..4992, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -7776,15 +7776,15 @@ Module( MatchSequence( PatternMatchSequence { range: 5000..5006, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), patterns: [ MatchValue( PatternMatchValue { range: 5001..5002, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5001..5002, value: Int( 1, @@ -7796,10 +7796,10 @@ Module( MatchValue( PatternMatchValue { range: 5004..5005, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5004..5005, value: Int( 2, @@ -7816,7 +7816,7 @@ Module( Identifier { id: Name("rest"), range: 5010..5014, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -7825,11 +7825,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5025..5028, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5025..5028, }, ), @@ -7842,11 +7842,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5046..5106, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5052..5053, id: Name("y"), ctx: Load, @@ -7855,17 +7855,17 @@ Module( cases: [ MatchCase { range: 5059..5080, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 5064..5065, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("a"), range: 5064..5065, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -7873,11 +7873,11 @@ Module( guard: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5069..5075, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5069..5070, id: Name("b"), ctx: Store, @@ -7885,7 +7885,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5074..5075, id: Name("c"), ctx: Load, @@ -7897,11 +7897,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5077..5080, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5077..5080, }, ), @@ -7911,17 +7911,17 @@ Module( }, MatchCase { range: 5085..5106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchAs( PatternMatchAs { range: 5090..5091, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: None, name: Some( Identifier { id: Name("e"), range: 5090..5091, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), }, @@ -7929,11 +7929,11 @@ Module( guard: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5096..5101, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5096..5097, value: Int( 1, @@ -7946,7 +7946,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5100..5101, value: Int( 2, @@ -7960,11 +7960,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5103..5106, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5103..5106, }, ), @@ -7977,24 +7977,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5135..5150, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5135..5150, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5135..5147, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5135..5143, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5135..5140, id: Name("match"), ctx: Load, @@ -8003,7 +8003,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5142..5143, id: Name("a"), ctx: Load, @@ -8014,7 +8014,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5146..5147, id: Name("b"), ctx: Load, @@ -8024,7 +8024,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5149..5150, id: Name("c"), ctx: Load, @@ -8039,20 +8039,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5176..5193, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5176..5193, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5176..5190, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5176..5181, id: Name("match"), ctx: Load, @@ -8061,11 +8061,11 @@ Module( op: Mult, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5184..5189, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5184..5185, id: Name("a"), ctx: Load, @@ -8074,7 +8074,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5188..5189, id: Name("b"), ctx: Load, @@ -8086,7 +8086,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5192..5193, id: Name("c"), ctx: Load, @@ -8101,15 +8101,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5219..5236, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5219..5236, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5219..5224, id: Name("match"), ctx: Load, @@ -8117,19 +8117,19 @@ Module( ), arguments: Arguments { range: 5225..5236, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5226..5232, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5227..5232, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5227..5228, id: Name("a"), ctx: Load, @@ -8138,7 +8138,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5231..5232, id: Name("b"), ctx: Load, @@ -8151,7 +8151,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5234..5235, id: Name("c"), ctx: Load, @@ -8166,19 +8166,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5263..5279, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5263..5279, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5263..5275, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5263..5268, id: Name("match"), ctx: Load, @@ -8187,11 +8187,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5270..5275, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5270..5271, id: Name("a"), ctx: Load, @@ -8200,7 +8200,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5274..5275, id: Name("b"), ctx: Load, @@ -8213,7 +8213,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5278..5279, id: Name("c"), ctx: Load, @@ -8225,19 +8225,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5306..5324, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5306..5324, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5306..5320, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5306..5311, id: Name("match"), ctx: Load, @@ -8246,11 +8246,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5314..5319, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5314..5315, id: Name("a"), ctx: Load, @@ -8259,7 +8259,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5318..5319, id: Name("b"), ctx: Load, @@ -8272,7 +8272,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5323..5324, id: Name("c"), ctx: Load, @@ -8284,23 +8284,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5351..5369, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5351..5369, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5351..5365, left: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5351..5361, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5351..5356, id: Name("match"), ctx: Load, @@ -8308,16 +8308,16 @@ Module( ), arguments: Arguments { range: 5357..5361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5358..5360, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5359..5360, id: Name("a"), ctx: Load, @@ -8333,7 +8333,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5364..5365, id: Name("b"), ctx: Load, @@ -8344,7 +8344,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5368..5369, id: Name("c"), ctx: Load, @@ -8356,19 +8356,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5397..5407, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5397..5407, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5397..5405, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5397..5402, id: Name("match"), ctx: Load, @@ -8376,7 +8376,7 @@ Module( ), arguments: Arguments { range: 5403..5405, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -8385,7 +8385,7 @@ Module( attr: Identifier { id: Name("a"), range: 5406..5407, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -8394,19 +8394,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5424..5436, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5424..5436, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5424..5434, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5424..5429, id: Name("match"), ctx: Load, @@ -8414,11 +8414,11 @@ Module( ), arguments: Arguments { range: 5430..5434, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5431..5433, elts: [], ctx: Load, @@ -8433,7 +8433,7 @@ Module( attr: Identifier { id: Name("a"), range: 5435..5436, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -8442,19 +8442,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5455..5468, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5455..5468, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5455..5466, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5455..5460, id: Name("match"), ctx: Load, @@ -8462,11 +8462,11 @@ Module( ), arguments: Arguments { range: 5461..5466, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5462..5464, elts: [], ctx: Load, @@ -8481,7 +8481,7 @@ Module( attr: Identifier { id: Name("a"), range: 5467..5468, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -8490,19 +8490,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5487..5498, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5487..5498, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5487..5496, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5487..5492, id: Name("match"), ctx: Load, @@ -8510,7 +8510,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5494..5495, id: Name("a"), ctx: Load, @@ -8522,7 +8522,7 @@ Module( attr: Identifier { id: Name("b"), range: 5497..5498, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -8531,19 +8531,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5516..5528, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5516..5528, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5516..5526, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5516..5521, id: Name("match"), ctx: Load, @@ -8551,12 +8551,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5523..5525, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5523..5524, id: Name("a"), ctx: Load, @@ -8573,7 +8573,7 @@ Module( attr: Identifier { id: Name("b"), range: 5527..5528, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -8582,19 +8582,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5569..5583, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5569..5583, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5569..5581, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5569..5574, id: Name("match"), ctx: Load, @@ -8602,12 +8602,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5576..5580, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5577..5578, id: Name("a"), ctx: Load, @@ -8624,7 +8624,7 @@ Module( attr: Identifier { id: Name("b"), range: 5582..5583, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -8633,19 +8633,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5604..5621, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5604..5621, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5604..5611, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5604..5609, id: Name("match"), ctx: Load, @@ -8653,7 +8653,7 @@ Module( ), arguments: Arguments { range: 5609..5611, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -8661,12 +8661,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5612..5620, lower: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5612..5613, id: Name("a"), ctx: Load, @@ -8676,7 +8676,7 @@ Module( upper: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5619..5620, id: Name("b"), ctx: Load, @@ -8693,15 +8693,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5641..5660, test: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5644..5654, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5644..5649, id: Name("match"), ctx: Store, @@ -8709,7 +8709,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5653..5654, value: Int( 1, @@ -8721,7 +8721,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5656..5660, }, ), @@ -8731,11 +8731,11 @@ Module( ), Match( StmtMatch { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5661..5715, subject: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5667..5672, id: Name("match"), ctx: Load, @@ -8744,14 +8744,14 @@ Module( cases: [ MatchCase { range: 5678..5690, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 5683..5684, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5683..5684, value: Int( 1, @@ -8764,7 +8764,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5686..5690, }, ), @@ -8772,14 +8772,14 @@ Module( }, MatchCase { range: 5695..5715, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), pattern: MatchValue( PatternMatchValue { range: 5700..5701, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5700..5701, value: Int( 2, @@ -8792,7 +8792,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5711..5715, }, ), @@ -8803,12 +8803,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5716..5752, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5716..5721, id: Name("match"), ctx: Store, @@ -8817,26 +8817,24 @@ Module( ], value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5724..5752, parameters: Some( Parameters { range: 5731..5736, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 5731..5736, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 5731..5736, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("query"), range: 5731..5736, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -8850,11 +8848,11 @@ Module( ), body: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5738..5752, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5738..5743, id: Name("query"), ctx: Load, @@ -8866,7 +8864,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5747..5752, id: Name("event"), ctx: Load, @@ -8881,15 +8879,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5753..5769, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5753..5769, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5753..5758, id: Name("print"), ctx: Load, @@ -8897,15 +8895,15 @@ Module( ), arguments: Arguments { range: 5758..5769, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5759..5768, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5759..5764, id: Name("match"), ctx: Load, @@ -8913,11 +8911,11 @@ Module( ), arguments: Arguments { range: 5764..5768, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5765..5767, value: Int( 12, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap index 7329f1e3a9af8..698cce3151c08 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__raise.py.snap @@ -7,12 +7,12 @@ input_file: crates/ruff_python_parser/resources/valid/statement/raise.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..289, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..13, exc: None, cause: None, @@ -20,12 +20,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..21, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..21, id: Name("a"), ctx: Load, @@ -37,17 +37,17 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..34, exc: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..34, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, id: Name("a"), ctx: Load, @@ -55,7 +55,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..33, id: Name("b"), ctx: Load, @@ -72,16 +72,16 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 35..46, exc: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..46, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..42, value: Int( 1, @@ -94,7 +94,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..46, value: Int( 2, @@ -110,18 +110,18 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..60, exc: Some( BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..60, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, id: Name("a"), ctx: Load, @@ -129,7 +129,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..60, id: Name("b"), ctx: Load, @@ -144,31 +144,29 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..78, exc: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..78, parameters: Some( Parameters { range: 74..75, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -182,7 +180,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..78, id: Name("y"), ctx: Load, @@ -196,16 +194,16 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..92, exc: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..92, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..92, id: Name("x"), ctx: Load, @@ -219,23 +217,23 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..115, exc: Some( If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..115, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..108, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..100, id: Name("x"), ctx: Load, @@ -243,7 +241,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 114..115, id: Name("y"), ctx: Load, @@ -257,12 +255,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..152, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..145, id: Name("x"), ctx: Load, @@ -272,7 +270,7 @@ Module( cause: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, id: Name("a"), ctx: Load, @@ -283,12 +281,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..172, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..160, id: Name("x"), ctx: Load, @@ -298,12 +296,12 @@ Module( cause: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 166..172, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 167..168, id: Name("a"), ctx: Load, @@ -311,7 +309,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, id: Name("b"), ctx: Load, @@ -327,12 +325,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 173..191, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, id: Name("x"), ctx: Load, @@ -342,11 +340,11 @@ Module( cause: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..191, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..187, value: Int( 1, @@ -359,7 +357,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 190..191, value: Int( 2, @@ -374,12 +372,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..212, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..199, id: Name("x"), ctx: Load, @@ -389,13 +387,13 @@ Module( cause: Some( BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..212, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..206, id: Name("a"), ctx: Load, @@ -403,7 +401,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..212, id: Name("b"), ctx: Load, @@ -417,12 +415,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..237, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 219..220, id: Name("x"), ctx: Load, @@ -432,26 +430,24 @@ Module( cause: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..237, parameters: Some( Parameters { range: 233..234, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 233..234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 233..234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 233..234, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -465,7 +461,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("y"), ctx: Load, @@ -478,12 +474,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 238..258, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..245, id: Name("x"), ctx: Load, @@ -493,11 +489,11 @@ Module( cause: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..258, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 257..258, id: Name("x"), ctx: Load, @@ -510,12 +506,12 @@ Module( ), Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..288, exc: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 265..266, id: Name("x"), ctx: Load, @@ -525,18 +521,18 @@ Module( cause: Some( If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..288, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..281, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 272..273, id: Name("x"), ctx: Load, @@ -544,7 +540,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 287..288, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap index 7cb3690eadb00..cfedbc7332f91 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__return.py.snap @@ -7,24 +7,24 @@ input_file: crates/ruff_python_parser/resources/valid/statement/return.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..167, body: [ Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..6, value: None, }, ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 7..15, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..15, id: Name("x"), ctx: Load, @@ -35,21 +35,21 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..29, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..29, elts: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..25, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..25, id: Name("x"), ctx: Load, @@ -60,11 +60,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..29, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..29, id: Name("y"), ctx: Load, @@ -83,16 +83,16 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..45, value: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..44, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..39, id: Name("x"), ctx: Store, @@ -100,7 +100,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, value: Int( 1, @@ -114,12 +114,12 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..57, value: Some( NoneLiteral( ExprNoneLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..57, }, ), @@ -128,18 +128,18 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..72, value: Some( BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..72, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..66, id: Name("x"), ctx: Load, @@ -147,7 +147,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..72, id: Name("y"), ctx: Load, @@ -161,16 +161,16 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..85, value: Some( Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..85, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, value: Int( 1, @@ -183,7 +183,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, value: Int( 2, @@ -198,17 +198,17 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..98, value: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..98, elts: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, value: Int( 1, @@ -217,7 +217,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..97, value: Int( 2, @@ -234,16 +234,16 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..112, value: Some( Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..112, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..110, id: Name("call"), ctx: Load, @@ -251,7 +251,7 @@ Module( ), arguments: Arguments { range: 110..112, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -262,20 +262,20 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..132, value: Some( Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..132, func: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..130, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..124, id: Name("attr"), ctx: Load, @@ -284,14 +284,14 @@ Module( attr: Identifier { id: Name("value"), range: 125..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, ), arguments: Arguments { range: 130..132, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -302,16 +302,16 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..147, value: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 140..147, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..147, id: Name("x"), ctx: Load, @@ -324,31 +324,29 @@ Module( ), Return( StmtReturn { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..166, value: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 155..166, parameters: Some( Parameters { range: 162..163, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 162..163, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 162..163, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 162..163, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -362,7 +360,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, id: Name("y"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap index 3865245dce0f4..ee65e7f1fd4fe 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__simple.py.snap @@ -7,28 +7,28 @@ input_file: crates/ruff_python_parser/resources/valid/statement/simple.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..172, body: [ Continue( StmtContinue { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..69, }, ), Break( StmtBreak { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..75, }, ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..86, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 80..81, id: Name("x"), ctx: Load, @@ -37,11 +37,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..86, }, ), @@ -53,11 +53,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 87..100, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..94, value: true, }, @@ -65,7 +65,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..100, }, ), @@ -75,11 +75,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..102, value: Int( 1, @@ -90,11 +90,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, value: Int( 2, @@ -105,17 +105,17 @@ Module( ), Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 107..111, }, ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..113, value: Int( 1, @@ -126,11 +126,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..118, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..118, }, ), @@ -138,15 +138,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..133, value: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..133, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 125..126, id: Name("b"), ctx: Load, @@ -154,7 +154,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 120..121, id: Name("a"), ctx: Load, @@ -162,7 +162,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 132..133, id: Name("c"), ctx: Load, @@ -174,11 +174,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..157, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 138..139, id: Name("c"), ctx: Load, @@ -187,11 +187,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, id: Name("B"), ctx: Load, @@ -201,12 +201,12 @@ Module( ), Delete( StmtDelete { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 144..149, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..149, id: Name("A"), ctx: Del, @@ -219,16 +219,16 @@ Module( elif_else_clauses: [ ElifElseClause { range: 150..157, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 156..157, id: Name("C"), ctx: Load, @@ -243,11 +243,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 158..171, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 161..162, id: Name("x"), ctx: Load, @@ -256,16 +256,16 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..171, value: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..171, value: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 170..171, id: Name("x"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap index e6021299e9875..962d435263aff 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__try.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/valid/statement/try.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1223, body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..28, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, }, ), @@ -32,17 +32,17 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 13..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..28, }, ), @@ -59,16 +59,16 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 30..106, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 39..42, }, ), @@ -79,11 +79,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 43..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..60, id: Name("Exception1"), ctx: Load, @@ -94,17 +94,17 @@ Module( Identifier { id: Name("e"), range: 64..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..74, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 71..74, }, ), @@ -116,11 +116,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 75..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..92, id: Name("Exception2"), ctx: Load, @@ -131,17 +131,17 @@ Module( Identifier { id: Name("e"), range: 96..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..106, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 103..106, }, ), @@ -158,16 +158,16 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..184, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..120, }, ), @@ -178,11 +178,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 121..151, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..137, id: Name("Exception"), ctx: Load, @@ -193,17 +193,17 @@ Module( Identifier { id: Name("e"), range: 141..142, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..151, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..151, }, ), @@ -215,17 +215,17 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 152..167, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..167, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 164..167, }, ), @@ -239,11 +239,11 @@ Module( finalbody: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..184, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..184, }, ), @@ -255,16 +255,16 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 186..228, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 195..198, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 195..198, }, ), @@ -275,17 +275,17 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 199..214, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..214, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 211..214, }, ), @@ -298,11 +298,11 @@ Module( orelse: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..228, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 225..228, }, ), @@ -315,16 +315,16 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 230..289, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..242, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 239..242, }, ), @@ -335,17 +335,17 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 243..258, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: None, name: None, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..258, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..258, }, ), @@ -358,11 +358,11 @@ Module( orelse: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..272, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 269..272, }, ), @@ -372,11 +372,11 @@ Module( finalbody: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..289, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..289, }, ), @@ -388,16 +388,16 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 291..320, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..303, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 300..303, }, ), @@ -409,11 +409,11 @@ Module( finalbody: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..320, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..320, }, ), @@ -425,16 +425,16 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 322..365, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..334, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..334, }, ), @@ -445,11 +445,11 @@ Module( orelse: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..348, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..348, }, ), @@ -459,11 +459,11 @@ Module( finalbody: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 362..365, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 362..365, }, ), @@ -475,16 +475,16 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 367..441, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..379, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..379, }, ), @@ -495,11 +495,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 380..409, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 388..394, id: Name("GroupA"), ctx: Load, @@ -510,17 +510,17 @@ Module( Identifier { id: Name("eg"), range: 398..400, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 406..409, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 406..409, }, ), @@ -532,11 +532,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 410..441, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 418..432, id: Name("ExceptionGroup"), ctx: Load, @@ -547,11 +547,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 438..441, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 438..441, }, ), @@ -568,21 +568,21 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 443..577, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 452..471, exc: Some( Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..471, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 458..468, id: Name("ValueError"), ctx: Load, @@ -590,11 +590,11 @@ Module( ), arguments: Arguments { range: 468..471, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 469..470, value: Int( 1, @@ -615,11 +615,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 472..525, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 479..488, id: Name("TypeError"), ctx: Load, @@ -630,21 +630,21 @@ Module( Identifier { id: Name("e"), range: 492..493, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 499..525, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 499..525, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 499..504, id: Name("print"), ctx: Load, @@ -652,37 +652,37 @@ Module( ), arguments: Arguments { range: 504..525, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 505..524, value: FStringValue { inner: Single( FString( FString { range: 505..524, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 507..514, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "caught ", }, ), Interpolation( InterpolatedElement { range: 514..523, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 515..522, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 515..519, id: Name("type"), ctx: Load, @@ -690,11 +690,11 @@ Module( ), arguments: Arguments { range: 519..522, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 520..521, id: Name("e"), ctx: Load, @@ -735,11 +735,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 526..577, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 533..540, id: Name("OSError"), ctx: Load, @@ -750,21 +750,21 @@ Module( Identifier { id: Name("e"), range: 544..545, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..577, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..577, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 551..556, id: Name("print"), ctx: Load, @@ -772,37 +772,37 @@ Module( ), arguments: Arguments { range: 556..577, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 557..576, value: FStringValue { inner: Single( FString( FString { range: 557..576, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 559..566, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "caught ", }, ), Interpolation( InterpolatedElement { range: 566..575, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..574, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 567..571, id: Name("type"), ctx: Load, @@ -810,11 +810,11 @@ Module( ), arguments: Arguments { range: 571..574, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 572..573, id: Name("e"), ctx: Load, @@ -860,21 +860,21 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 579..831, body: [ Raise( StmtRaise { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 588..669, exc: Some( Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 594..669, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 594..608, id: Name("ExceptionGroup"), ctx: Load, @@ -882,17 +882,17 @@ Module( ), arguments: Arguments { range: 608..669, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 609..613, value: StringLiteralValue { inner: Single( StringLiteral { range: 609..613, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "eg", flags: StringLiteralFlags { quote_style: Double, @@ -906,16 +906,16 @@ Module( ), List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 615..668, elts: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 616..629, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 616..626, id: Name("ValueError"), ctx: Load, @@ -923,11 +923,11 @@ Module( ), arguments: Arguments { range: 626..629, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 627..628, value: Int( 1, @@ -941,11 +941,11 @@ Module( ), Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 631..643, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 631..640, id: Name("TypeError"), ctx: Load, @@ -953,11 +953,11 @@ Module( ), arguments: Arguments { range: 640..643, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 641..642, value: Int( 2, @@ -971,11 +971,11 @@ Module( ), Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 645..655, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 645..652, id: Name("OSError"), ctx: Load, @@ -983,11 +983,11 @@ Module( ), arguments: Arguments { range: 652..655, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 653..654, value: Int( 3, @@ -1001,11 +1001,11 @@ Module( ), Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 657..667, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 657..664, id: Name("OSError"), ctx: Load, @@ -1013,11 +1013,11 @@ Module( ), arguments: Arguments { range: 664..667, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 665..666, value: Int( 4, @@ -1047,11 +1047,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 670..751, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 678..687, id: Name("TypeError"), ctx: Load, @@ -1062,21 +1062,21 @@ Module( Identifier { id: Name("e"), range: 691..692, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 698..751, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 698..751, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 698..703, id: Name("print"), ctx: Load, @@ -1084,37 +1084,37 @@ Module( ), arguments: Arguments { range: 703..751, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 704..750, value: FStringValue { inner: Single( FString( FString { range: 704..750, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 706..713, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "caught ", }, ), Interpolation( InterpolatedElement { range: 713..722, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 714..721, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 714..718, id: Name("type"), ctx: Load, @@ -1122,11 +1122,11 @@ Module( ), arguments: Arguments { range: 718..721, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 719..720, id: Name("e"), ctx: Load, @@ -1145,21 +1145,21 @@ Module( Literal( InterpolatedStringLiteralElement { range: 722..735, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " with nested ", }, ), Interpolation( InterpolatedElement { range: 735..749, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 736..748, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 736..737, id: Name("e"), ctx: Load, @@ -1168,7 +1168,7 @@ Module( attr: Identifier { id: Name("exceptions"), range: 738..748, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -1203,11 +1203,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 752..831, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 760..767, id: Name("OSError"), ctx: Load, @@ -1218,21 +1218,21 @@ Module( Identifier { id: Name("e"), range: 771..772, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 778..831, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 778..831, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 778..783, id: Name("print"), ctx: Load, @@ -1240,37 +1240,37 @@ Module( ), arguments: Arguments { range: 783..831, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ FString( ExprFString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 784..830, value: FStringValue { inner: Single( FString( FString { range: 784..830, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 786..793, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "caught ", }, ), Interpolation( InterpolatedElement { range: 793..802, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 794..801, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 794..798, id: Name("type"), ctx: Load, @@ -1278,11 +1278,11 @@ Module( ), arguments: Arguments { range: 798..801, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 799..800, id: Name("e"), ctx: Load, @@ -1301,21 +1301,21 @@ Module( Literal( InterpolatedStringLiteralElement { range: 802..815, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: " with nested ", }, ), Interpolation( InterpolatedElement { range: 815..829, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 816..828, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 816..817, id: Name("e"), ctx: Load, @@ -1324,7 +1324,7 @@ Module( attr: Identifier { id: Name("exceptions"), range: 818..828, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -1364,12 +1364,12 @@ Module( ), Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 833..1075, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 842..846, }, ), @@ -1378,17 +1378,17 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 847..875, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 854..865, value: StringLiteralValue { inner: Single( StringLiteral { range: 854..865, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "exception", flags: StringLiteralFlags { quote_style: Double, @@ -1405,7 +1405,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 871..875, }, ), @@ -1415,11 +1415,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 876..894, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 883..884, value: Int( 1, @@ -1431,7 +1431,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 890..894, }, ), @@ -1441,11 +1441,11 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 895..916, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 902..906, value: true, }, @@ -1455,7 +1455,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 912..916, }, ), @@ -1465,15 +1465,15 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 917..939, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 924..929, left: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 924..925, value: Int( 1, @@ -1483,7 +1483,7 @@ Module( op: Add, right: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 928..929, value: Int( 1, @@ -1497,7 +1497,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 935..939, }, ), @@ -1507,15 +1507,15 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 940..962, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 947..952, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 947..948, id: Name("a"), ctx: Load, @@ -1524,7 +1524,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 951..952, id: Name("b"), ctx: Load, @@ -1537,7 +1537,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 958..962, }, ), @@ -1547,17 +1547,17 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 963..987, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 970..977, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 970..971, id: Name("x"), ctx: Load, @@ -1565,7 +1565,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 976..977, id: Name("y"), ctx: Load, @@ -1579,7 +1579,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 983..987, }, ), @@ -1589,15 +1589,15 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 988..1012, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 995..1002, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1001..1002, id: Name("x"), ctx: Load, @@ -1610,7 +1610,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1008..1012, }, ), @@ -1620,30 +1620,28 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 1013..1041, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1020..1031, parameters: Some( Parameters { range: 1027..1028, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1027..1028, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1027..1028, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 1027..1028, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -1657,7 +1655,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1030..1031, id: Name("x"), ctx: Load, @@ -1670,7 +1668,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1037..1041, }, ), @@ -1680,22 +1678,22 @@ Module( ExceptHandler( ExceptHandlerExceptHandler { range: 1042..1075, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_: Some( If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1049..1065, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1054..1058, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1049..1050, id: Name("x"), ctx: Load, @@ -1703,7 +1701,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1064..1065, id: Name("y"), ctx: Load, @@ -1716,7 +1714,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1071..1075, }, ), @@ -1731,11 +1729,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1077..1222, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1080..1084, value: true, }, @@ -1743,12 +1741,12 @@ Module( body: [ Try( StmtTry { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1090..1133, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1103..1107, }, ), @@ -1758,7 +1756,7 @@ Module( finalbody: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1129..1133, }, ), @@ -1770,12 +1768,12 @@ Module( elif_else_clauses: [ ElifElseClause { range: 1208..1222, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1218..1222, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap index ca837dcde3786..d12ea9725683a 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__type.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/statement/type.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..1828, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..12, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,7 +25,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 9..12, id: Name("int"), ctx: Load, @@ -35,11 +35,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..31, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..19, id: Name("X"), ctx: Store, @@ -48,11 +48,11 @@ Module( type_params: None, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..31, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 22..25, id: Name("int"), ctx: Load, @@ -61,7 +61,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 28..31, id: Name("str"), ctx: Load, @@ -73,11 +73,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 32..60, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..38, id: Name("X"), ctx: Store, @@ -86,11 +86,11 @@ Module( type_params: None, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..60, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 41..44, id: Name("int"), ctx: Load, @@ -99,13 +99,13 @@ Module( op: BitOr, right: StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..60, value: StringLiteralValue { inner: Single( StringLiteral { range: 47..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "ForwardRefY", flags: StringLiteralFlags { quote_style: Double, @@ -123,11 +123,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..87, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..67, id: Name("X"), ctx: Store, @@ -136,16 +136,16 @@ Module( type_params: Some( TypeParams { range: 67..70, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 68..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 68..69, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -156,11 +156,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..87, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("T"), ctx: Load, @@ -169,11 +169,11 @@ Module( op: BitOr, right: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..87, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..81, id: Name("list"), ctx: Load, @@ -181,11 +181,11 @@ Module( ), slice: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..86, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..83, id: Name("X"), ctx: Load, @@ -193,7 +193,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, id: Name("T"), ctx: Load, @@ -211,11 +211,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 101..116, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 106..107, id: Name("X"), ctx: Store, @@ -224,16 +224,16 @@ Module( type_params: Some( TypeParams { range: 107..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 108..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 108..109, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -244,7 +244,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..116, id: Name("int"), ctx: Load, @@ -254,11 +254,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 117..145, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..123, id: Name("X"), ctx: Store, @@ -267,16 +267,16 @@ Module( type_params: Some( TypeParams { range: 123..126, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 124..125, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -287,15 +287,15 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..145, left: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..136, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..133, id: Name("list"), ctx: Load, @@ -303,7 +303,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 134..135, id: Name("T"), ctx: Load, @@ -315,11 +315,11 @@ Module( op: BitOr, right: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..145, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 139..142, id: Name("set"), ctx: Load, @@ -327,7 +327,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..144, id: Name("T"), ctx: Load, @@ -342,11 +342,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 146..178, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 151..152, id: Name("X"), ctx: Store, @@ -355,16 +355,16 @@ Module( type_params: Some( TypeParams { range: 152..165, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 153..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 153..154, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -373,11 +373,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 156..159, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 157..159, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -385,11 +385,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 161..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 163..164, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -399,12 +399,12 @@ Module( ), value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..178, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 169..170, id: Name("T"), ctx: Load, @@ -412,7 +412,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..174, id: Name("Ts"), ctx: Load, @@ -420,7 +420,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 176..177, id: Name("P"), ctx: Load, @@ -435,11 +435,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..216, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..185, id: Name("X"), ctx: Store, @@ -448,21 +448,21 @@ Module( type_params: Some( TypeParams { range: 185..203, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 186..192, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 186..187, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 189..192, id: Name("int"), ctx: Load, @@ -475,11 +475,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 194..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 195..197, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -487,11 +487,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 199..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 201..202, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -501,12 +501,12 @@ Module( ), value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 206..216, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 207..208, id: Name("T"), ctx: Load, @@ -514,7 +514,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 210..212, id: Name("Ts"), ctx: Load, @@ -522,7 +522,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("P"), ctx: Load, @@ -537,11 +537,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..261, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..223, id: Name("X"), ctx: Store, @@ -550,26 +550,26 @@ Module( type_params: Some( TypeParams { range: 223..248, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 224..237, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 224..225, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..237, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..231, id: Name("int"), ctx: Load, @@ -577,7 +577,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..236, id: Name("str"), ctx: Load, @@ -595,11 +595,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 239..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 240..242, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -607,11 +607,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 244..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 246..247, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -621,12 +621,12 @@ Module( ), value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..261, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 252..253, id: Name("T"), ctx: Load, @@ -634,7 +634,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 255..257, id: Name("Ts"), ctx: Load, @@ -642,7 +642,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..260, id: Name("P"), ctx: Load, @@ -657,11 +657,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 262..287, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 267..268, id: Name("X"), ctx: Store, @@ -670,22 +670,22 @@ Module( type_params: Some( TypeParams { range: 268..277, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 269..276, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 269..270, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 273..276, id: Name("int"), ctx: Load, @@ -699,11 +699,11 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..287, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 280..281, id: Name("T"), ctx: Load, @@ -712,7 +712,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 284..287, id: Name("str"), ctx: Load, @@ -724,11 +724,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 288..330, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 293..294, id: Name("X"), ctx: Store, @@ -737,25 +737,25 @@ Module( type_params: Some( TypeParams { range: 294..314, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 295..313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 295..296, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 298..307, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 298..301, id: Name("int"), ctx: Load, @@ -764,7 +764,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 304..307, id: Name("str"), ctx: Load, @@ -776,7 +776,7 @@ Module( default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 310..313, id: Name("int"), ctx: Load, @@ -790,15 +790,15 @@ Module( ), value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..330, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..324, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 317..318, id: Name("T"), ctx: Load, @@ -807,7 +807,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 321..324, id: Name("int"), ctx: Load, @@ -818,7 +818,7 @@ Module( op: BitOr, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 327..330, id: Name("str"), ctx: Load, @@ -830,11 +830,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..384, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 336..337, id: Name("X"), ctx: Store, @@ -843,29 +843,29 @@ Module( type_params: Some( TypeParams { range: 337..361, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 338..360, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 339..341, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 344..360, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..360, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 345..350, id: Name("tuple"), ctx: Load, @@ -873,12 +873,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..359, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 351..354, id: Name("int"), ctx: Load, @@ -886,7 +886,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 356..359, id: Name("str"), ctx: Load, @@ -911,11 +911,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..384, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 364..369, id: Name("tuple"), ctx: Load, @@ -923,12 +923,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 370..383, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 370..373, id: Name("int"), ctx: Load, @@ -936,11 +936,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 375..378, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 376..378, id: Name("Ts"), ctx: Load, @@ -951,7 +951,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 380..383, id: Name("str"), ctx: Load, @@ -969,11 +969,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 385..428, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 390..391, id: Name("X"), ctx: Store, @@ -982,26 +982,26 @@ Module( type_params: Some( TypeParams { range: 391..409, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 392..408, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 394..395, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( List( ExprList { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 398..408, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 399..402, id: Name("int"), ctx: Load, @@ -1009,7 +1009,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 404..407, id: Name("str"), ctx: Load, @@ -1027,11 +1027,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 412..428, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 412..420, id: Name("Callable"), ctx: Load, @@ -1039,12 +1039,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..427, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 421..422, id: Name("P"), ctx: Load, @@ -1052,7 +1052,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 424..427, id: Name("str"), ctx: Load, @@ -1070,11 +1070,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 459..474, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 464..468, id: Name("type"), ctx: Store, @@ -1083,7 +1083,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 471..474, id: Name("int"), ctx: Load, @@ -1093,11 +1093,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 475..491, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 480..485, id: Name("match"), ctx: Store, @@ -1106,7 +1106,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 488..491, id: Name("int"), ctx: Load, @@ -1116,11 +1116,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 492..507, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 497..501, id: Name("case"), ctx: Store, @@ -1129,7 +1129,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 504..507, id: Name("int"), ctx: Load, @@ -1139,11 +1139,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 533..548, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 538..541, id: Name("foo"), ctx: Store, @@ -1152,7 +1152,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 544..548, id: Name("type"), ctx: Load, @@ -1162,11 +1162,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 549..565, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 554..557, id: Name("foo"), ctx: Store, @@ -1175,7 +1175,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 560..565, id: Name("match"), ctx: Load, @@ -1185,11 +1185,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 566..581, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 571..574, id: Name("foo"), ctx: Store, @@ -1198,7 +1198,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 577..581, id: Name("case"), ctx: Load, @@ -1208,11 +1208,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 605..620, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 613..614, id: Name("X"), ctx: Store, @@ -1221,7 +1221,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 617..620, id: Name("int"), ctx: Load, @@ -1231,11 +1231,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 621..636, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 626..627, id: Name("X"), ctx: Store, @@ -1244,7 +1244,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 633..636, id: Name("int"), ctx: Load, @@ -1254,11 +1254,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 637..652, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 642..643, id: Name("X"), ctx: Store, @@ -1267,7 +1267,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 649..652, id: Name("int"), ctx: Load, @@ -1277,11 +1277,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 653..673, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 658..659, id: Name("X"), ctx: Store, @@ -1290,7 +1290,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 668..671, id: Name("int"), ctx: Load, @@ -1300,11 +1300,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 674..693, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 685..686, id: Name("X"), ctx: Store, @@ -1313,16 +1313,16 @@ Module( type_params: Some( TypeParams { range: 686..689, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 687..688, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 687..688, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -1333,7 +1333,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 692..693, id: Name("T"), ctx: Load, @@ -1343,11 +1343,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 694..714, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 699..700, id: Name("X"), ctx: Store, @@ -1356,16 +1356,16 @@ Module( type_params: Some( TypeParams { range: 707..710, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 708..709, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 708..709, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -1376,7 +1376,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 713..714, id: Name("T"), ctx: Load, @@ -1386,11 +1386,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 715..734, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 720..721, id: Name("X"), ctx: Store, @@ -1399,16 +1399,16 @@ Module( type_params: Some( TypeParams { range: 721..724, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 722..723, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 722..723, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -1419,7 +1419,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 733..734, id: Name("T"), ctx: Load, @@ -1429,11 +1429,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 756..768, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 761..762, id: Name("X"), ctx: Store, @@ -1442,7 +1442,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 765..768, id: Name("int"), ctx: Load, @@ -1452,11 +1452,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 770..782, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 775..776, id: Name("X"), ctx: Store, @@ -1465,7 +1465,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 779..782, id: Name("str"), ctx: Load, @@ -1475,11 +1475,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 784..797, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 789..790, id: Name("X"), ctx: Store, @@ -1488,7 +1488,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 793..797, id: Name("type"), ctx: Load, @@ -1498,24 +1498,24 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 798..819, decorator_list: [], name: Identifier { id: Name("X"), range: 804..805, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: None, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 807..819, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 812..813, id: Name("X"), ctx: Store, @@ -1524,7 +1524,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 816..819, id: Name("int"), ctx: Load, @@ -1537,11 +1537,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 821..853, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 826..831, id: Name("Point"), ctx: Store, @@ -1550,11 +1550,11 @@ Module( type_params: None, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 834..853, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 834..839, id: Name("tuple"), ctx: Load, @@ -1562,12 +1562,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 840..852, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 840..845, id: Name("float"), ctx: Load, @@ -1575,7 +1575,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 847..852, id: Name("float"), ctx: Load, @@ -1593,11 +1593,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 854..881, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 859..864, id: Name("Point"), ctx: Store, @@ -1606,16 +1606,16 @@ Module( type_params: Some( TypeParams { range: 864..867, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 865..866, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 865..866, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -1626,11 +1626,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 870..881, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 870..875, id: Name("tuple"), ctx: Load, @@ -1638,12 +1638,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 876..880, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 876..877, id: Name("T"), ctx: Load, @@ -1651,7 +1651,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 879..880, id: Name("T"), ctx: Load, @@ -1669,11 +1669,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 882..918, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 887..894, id: Name("IntFunc"), ctx: Store, @@ -1682,16 +1682,16 @@ Module( type_params: Some( TypeParams { range: 894..899, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 895..898, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 897..898, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -1701,11 +1701,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 902..918, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 902..910, id: Name("Callable"), ctx: Load, @@ -1713,12 +1713,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 911..917, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 911..912, id: Name("P"), ctx: Load, @@ -1726,7 +1726,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 914..917, id: Name("int"), ctx: Load, @@ -1744,11 +1744,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 932..972, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 937..949, id: Name("LabeledTuple"), ctx: Store, @@ -1757,16 +1757,16 @@ Module( type_params: Some( TypeParams { range: 949..954, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 950..953, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 951..953, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -1776,11 +1776,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 957..972, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 957..962, id: Name("tuple"), ctx: Load, @@ -1788,12 +1788,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 963..971, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 963..966, id: Name("str"), ctx: Load, @@ -1801,11 +1801,11 @@ Module( ), Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 968..971, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 969..971, id: Name("Ts"), ctx: Load, @@ -1826,11 +1826,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 989..1037, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 994..1010, id: Name("HashableSequence"), ctx: Store, @@ -1839,21 +1839,21 @@ Module( type_params: Some( TypeParams { range: 1010..1023, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 1011..1022, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 1011..1012, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1014..1022, id: Name("Hashable"), ctx: Load, @@ -1868,11 +1868,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1026..1037, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1026..1034, id: Name("Sequence"), ctx: Load, @@ -1880,7 +1880,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1035..1036, id: Name("T"), ctx: Load, @@ -1893,11 +1893,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1060..1110, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1065..1081, id: Name("IntOrStrSequence"), ctx: Store, @@ -1906,26 +1906,26 @@ Module( type_params: Some( TypeParams { range: 1081..1096, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 1082..1095, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 1082..1083, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1085..1095, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1086..1089, id: Name("int"), ctx: Load, @@ -1933,7 +1933,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1091..1094, id: Name("str"), ctx: Load, @@ -1953,11 +1953,11 @@ Module( ), value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1099..1110, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1099..1107, id: Name("Sequence"), ctx: Load, @@ -1965,7 +1965,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1108..1109, id: Name("T"), ctx: Load, @@ -1978,24 +1978,24 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1164..1178, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1164..1178, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1164..1175, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1164..1171, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1164..1168, id: Name("type"), ctx: Load, @@ -2004,7 +2004,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1170..1171, id: Name("a"), ctx: Load, @@ -2015,7 +2015,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1174..1175, id: Name("b"), ctx: Load, @@ -2025,7 +2025,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1177..1178, id: Name("c"), ctx: Load, @@ -2040,20 +2040,20 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1203..1219, value: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1203..1219, elts: [ BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1203..1216, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1203..1207, id: Name("type"), ctx: Load, @@ -2062,11 +2062,11 @@ Module( op: Mult, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1210..1215, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1210..1211, id: Name("a"), ctx: Load, @@ -2075,7 +2075,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1214..1215, id: Name("b"), ctx: Load, @@ -2087,7 +2087,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1218..1219, id: Name("c"), ctx: Load, @@ -2102,15 +2102,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1244..1260, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1244..1260, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1244..1248, id: Name("type"), ctx: Load, @@ -2118,19 +2118,19 @@ Module( ), arguments: Arguments { range: 1249..1260, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1250..1256, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1251..1256, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1251..1252, id: Name("a"), ctx: Load, @@ -2139,7 +2139,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1255..1256, id: Name("b"), ctx: Load, @@ -2152,7 +2152,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1258..1259, id: Name("c"), ctx: Load, @@ -2167,19 +2167,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1286..1301, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1286..1301, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1286..1297, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1286..1290, id: Name("type"), ctx: Load, @@ -2188,11 +2188,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1292..1297, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1292..1293, id: Name("a"), ctx: Load, @@ -2201,7 +2201,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1296..1297, id: Name("b"), ctx: Load, @@ -2214,7 +2214,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1300..1301, id: Name("c"), ctx: Load, @@ -2226,19 +2226,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1327..1344, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1327..1344, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1327..1340, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1327..1331, id: Name("type"), ctx: Load, @@ -2247,11 +2247,11 @@ Module( op: Sub, right: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1334..1339, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1334..1335, id: Name("a"), ctx: Load, @@ -2260,7 +2260,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1338..1339, id: Name("b"), ctx: Load, @@ -2273,7 +2273,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1343..1344, id: Name("c"), ctx: Load, @@ -2285,23 +2285,23 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1370..1387, value: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1370..1387, left: BinOp( ExprBinOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1370..1383, left: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1370..1379, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1370..1374, id: Name("type"), ctx: Load, @@ -2309,16 +2309,16 @@ Module( ), arguments: Arguments { range: 1375..1379, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ UnaryOp( ExprUnaryOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1376..1378, op: USub, operand: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1377..1378, id: Name("a"), ctx: Load, @@ -2334,7 +2334,7 @@ Module( op: Mult, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1382..1383, id: Name("b"), ctx: Load, @@ -2345,7 +2345,7 @@ Module( op: Add, right: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1386..1387, id: Name("c"), ctx: Load, @@ -2357,19 +2357,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1414..1423, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1414..1423, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1414..1421, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1414..1418, id: Name("type"), ctx: Load, @@ -2377,7 +2377,7 @@ Module( ), arguments: Arguments { range: 1419..1421, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -2386,7 +2386,7 @@ Module( attr: Identifier { id: Name("a"), range: 1422..1423, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2395,19 +2395,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1439..1450, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1439..1450, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1439..1448, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1439..1443, id: Name("type"), ctx: Load, @@ -2415,11 +2415,11 @@ Module( ), arguments: Arguments { range: 1444..1448, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1445..1447, elts: [], ctx: Load, @@ -2434,7 +2434,7 @@ Module( attr: Identifier { id: Name("a"), range: 1449..1450, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2443,19 +2443,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1468..1480, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1468..1480, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1468..1478, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1468..1472, id: Name("type"), ctx: Load, @@ -2463,11 +2463,11 @@ Module( ), arguments: Arguments { range: 1473..1478, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1474..1476, elts: [], ctx: Load, @@ -2482,7 +2482,7 @@ Module( attr: Identifier { id: Name("a"), range: 1479..1480, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2491,19 +2491,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1498..1508, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1498..1508, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1498..1506, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1498..1502, id: Name("type"), ctx: Load, @@ -2511,7 +2511,7 @@ Module( ), slice: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1504..1505, id: Name("a"), ctx: Load, @@ -2523,7 +2523,7 @@ Module( attr: Identifier { id: Name("b"), range: 1507..1508, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2532,19 +2532,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1525..1536, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1525..1536, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1525..1534, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1525..1529, id: Name("type"), ctx: Load, @@ -2552,12 +2552,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1531..1533, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1531..1532, id: Name("a"), ctx: Load, @@ -2574,7 +2574,7 @@ Module( attr: Identifier { id: Name("b"), range: 1535..1536, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2583,19 +2583,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1575..1588, value: Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1575..1588, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1575..1586, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1575..1579, id: Name("type"), ctx: Load, @@ -2603,12 +2603,12 @@ Module( ), slice: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1581..1585, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1582..1583, id: Name("a"), ctx: Load, @@ -2625,7 +2625,7 @@ Module( attr: Identifier { id: Name("b"), range: 1587..1588, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Load, }, @@ -2634,19 +2634,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1608..1624, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1608..1624, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1608..1614, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1608..1612, id: Name("type"), ctx: Load, @@ -2654,7 +2654,7 @@ Module( ), arguments: Arguments { range: 1612..1614, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -2662,12 +2662,12 @@ Module( ), slice: Slice( ExprSlice { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1615..1623, lower: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1615..1616, id: Name("a"), ctx: Load, @@ -2677,7 +2677,7 @@ Module( upper: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1622..1623, id: Name("b"), ctx: Load, @@ -2694,15 +2694,15 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1643..1661, test: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1646..1655, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1646..1650, id: Name("type"), ctx: Store, @@ -2710,7 +2710,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1654..1655, value: Int( 1, @@ -2722,7 +2722,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1657..1661, }, ), @@ -2732,12 +2732,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1662..1697, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1662..1666, id: Name("type"), ctx: Store, @@ -2746,26 +2746,24 @@ Module( ], value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1669..1697, parameters: Some( Parameters { range: 1676..1681, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1676..1681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1676..1681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("query"), range: 1676..1681, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -2779,11 +2777,11 @@ Module( ), body: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1683..1697, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1683..1688, id: Name("query"), ctx: Load, @@ -2795,7 +2793,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1692..1697, id: Name("event"), ctx: Load, @@ -2810,15 +2808,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1698..1713, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1698..1713, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1698..1703, id: Name("print"), ctx: Load, @@ -2826,15 +2824,15 @@ Module( ), arguments: Arguments { range: 1703..1713, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1704..1712, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1704..1708, id: Name("type"), ctx: Load, @@ -2842,11 +2840,11 @@ Module( ), arguments: Arguments { range: 1708..1712, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1709..1711, value: Int( 12, @@ -2867,15 +2865,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1714..1724, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1714..1724, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1714..1718, id: Name("type"), ctx: Load, @@ -2883,11 +2881,11 @@ Module( ), arguments: Arguments { range: 1718..1724, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1719..1723, id: Name("type"), ctx: Load, @@ -2902,12 +2900,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1725..1743, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1725..1726, id: Name("a"), ctx: Store, @@ -2916,11 +2914,11 @@ Module( ], value: Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1732..1741, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1732..1736, id: Name("type"), ctx: Load, @@ -2932,7 +2930,7 @@ Module( comparators: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1740..1741, id: Name("C"), ctx: Load, @@ -2945,12 +2943,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1744..1760, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1744..1745, id: Name("a"), ctx: Store, @@ -2959,11 +2957,11 @@ Module( ], value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1751..1758, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1751..1755, id: Name("type"), ctx: Load, @@ -2971,11 +2969,11 @@ Module( ), arguments: Arguments { range: 1755..1758, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1756..1757, id: Name("b"), ctx: Load, @@ -2990,15 +2988,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1761..1778, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1761..1778, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1761..1765, id: Name("type"), ctx: Load, @@ -3006,22 +3004,22 @@ Module( ), arguments: Arguments { range: 1766..1778, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [ Keyword { range: 1769..1776, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), arg: Some( Identifier { id: Name("X"), range: 1769..1770, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1773..1776, id: Name("int"), ctx: Load, @@ -3036,12 +3034,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1779..1787, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1779..1783, id: Name("type"), ctx: Store, @@ -3050,7 +3048,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1786..1787, value: Int( 1, @@ -3061,12 +3059,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1788..1800, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1788..1792, id: Name("type"), ctx: Store, @@ -3074,7 +3072,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1795..1796, id: Name("x"), ctx: Store, @@ -3083,7 +3081,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1799..1800, value: Int( 1, @@ -3094,12 +3092,12 @@ Module( ), Assign( StmtAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1801..1813, targets: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1801..1802, id: Name("x"), ctx: Store, @@ -3107,7 +3105,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1805..1809, id: Name("type"), ctx: Store, @@ -3116,7 +3114,7 @@ Module( ], value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1812..1813, value: Int( 1, @@ -3127,30 +3125,28 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1814..1828, value: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1814..1828, parameters: Some( Parameters { range: 1821..1822, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 1821..1822, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 1821..1822, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 1821..1822, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -3164,7 +3160,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 1824..1828, id: Name("type"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap index 5c2e2603e1965..ca6b03c547a12 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__while.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/valid/statement/while.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..314, body: [ While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..16, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 6..7, id: Name("x"), ctx: Load, @@ -25,11 +25,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..16, }, ), @@ -41,21 +41,21 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..61, test: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..37, op: And, values: [ Compare( ExprCompare { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..30, left: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 25..26, id: Name("x"), ctx: Load, @@ -67,7 +67,7 @@ Module( comparators: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 29..30, value: Int( 1, @@ -79,7 +79,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 36..37, id: Name("y"), ctx: Load, @@ -91,7 +91,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..47, }, ), @@ -99,11 +99,11 @@ Module( orelse: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..61, }, ), @@ -114,17 +114,17 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..152, test: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..76, op: And, values: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..70, id: Name("x"), ctx: Load, @@ -132,7 +132,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..76, id: Name("y"), ctx: Load, @@ -144,11 +144,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 82..85, }, ), @@ -156,15 +156,15 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..111, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..111, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..95, id: Name("print"), ctx: Load, @@ -172,17 +172,17 @@ Module( ), arguments: Arguments { range: 95..111, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 96..110, value: StringLiteralValue { inner: Single( StringLiteral { range: 96..110, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Hello World!", flags: StringLiteralFlags { quote_style: Single, @@ -205,15 +205,15 @@ Module( orelse: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..144, value: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..144, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..128, id: Name("print"), ctx: Load, @@ -221,17 +221,17 @@ Module( ), arguments: Arguments { range: 128..144, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ StringLiteral( ExprStringLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..143, value: StringLiteralValue { inner: Single( StringLiteral { range: 129..143, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "Olá, Mundo!", flags: StringLiteralFlags { quote_style: Single, @@ -252,11 +252,11 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..152, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 149..152, }, ), @@ -267,15 +267,15 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 154..171, test: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..166, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 160..161, id: Name("a"), ctx: Store, @@ -283,7 +283,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, id: Name("b"), ctx: Load, @@ -294,11 +294,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, }, ), @@ -310,21 +310,21 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..197, test: BoolOp( ExprBoolOp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 178..192, op: And, values: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..185, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 179..180, id: Name("a"), ctx: Store, @@ -332,7 +332,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..185, id: Name("b"), ctx: Load, @@ -342,7 +342,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..192, id: Name("c"), ctx: Load, @@ -354,11 +354,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..197, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 194..197, }, ), @@ -370,30 +370,28 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 198..220, test: Lambda( ExprLambda { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 204..215, parameters: Some( Parameters { range: 211..212, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 211..212, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: None, }, @@ -407,7 +405,7 @@ Module( ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 214..215, id: Name("x"), ctx: Load, @@ -418,11 +416,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..220, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..220, }, ), @@ -434,15 +432,15 @@ Module( ), While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 221..239, test: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 227..234, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 233..234, id: Name("x"), ctx: Load, @@ -453,11 +451,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..239, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..239, }, ), @@ -469,11 +467,11 @@ Module( ), If( StmtIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..313, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 244..248, value: true, }, @@ -481,11 +479,11 @@ Module( body: [ While( StmtWhile { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..298, test: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 260..261, id: Name("x"), ctx: Load, @@ -494,7 +492,7 @@ Module( body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..275, }, ), @@ -502,7 +500,7 @@ Module( orelse: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 294..298, }, ), @@ -513,12 +511,12 @@ Module( elif_else_clauses: [ ElifElseClause { range: 299..313, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), test: None, body: [ Pass( StmtPass { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 309..313, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap index 993b8cc48ad03..7919e803c86e6 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@statement__with.py.snap @@ -7,21 +7,21 @@ input_file: crates/ruff_python_parser/resources/valid/statement/with.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..361, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 137..151, is_async: false, items: [ WithItem { range: 142..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 142..146, id: Name("item"), ctx: Load, @@ -33,11 +33,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..151, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 148..151, }, ), @@ -48,16 +48,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 152..171, is_async: false, items: [ WithItem { range: 157..166, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 157..161, id: Name("item"), ctx: Load, @@ -66,7 +66,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 165..166, id: Name("f"), ctx: Store, @@ -78,11 +78,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 168..171, }, ), @@ -93,16 +93,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 172..194, is_async: false, items: [ WithItem { range: 177..182, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 177..182, id: Name("item1"), ctx: Load, @@ -112,10 +112,10 @@ Module( }, WithItem { range: 184..189, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 184..189, id: Name("item2"), ctx: Load, @@ -127,11 +127,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..194, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 191..194, }, ), @@ -142,16 +142,16 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 195..229, is_async: false, items: [ WithItem { range: 200..211, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 200..205, id: Name("item1"), ctx: Load, @@ -160,7 +160,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 209..211, id: Name("f1"), ctx: Store, @@ -170,10 +170,10 @@ Module( }, WithItem { range: 213..224, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 213..218, id: Name("item2"), ctx: Load, @@ -182,7 +182,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 222..224, id: Name("f2"), ctx: Store, @@ -194,11 +194,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..229, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 226..229, }, ), @@ -209,27 +209,27 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 231..257, is_async: false, items: [ WithItem { range: 236..252, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..252, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 241..245, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..237, id: Name("x"), ctx: Load, @@ -237,7 +237,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 251..252, id: Name("y"), ctx: Load, @@ -251,11 +251,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..257, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 254..257, }, ), @@ -266,27 +266,27 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 258..289, is_async: false, items: [ WithItem { range: 263..284, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: If( ExprIf { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..279, test: BooleanLiteral( ExprBooleanLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 268..272, value: true, }, ), body: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 263..264, id: Name("x"), ctx: Load, @@ -294,7 +294,7 @@ Module( ), orelse: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 278..279, id: Name("y"), ctx: Load, @@ -305,7 +305,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 283..284, id: Name("f"), ctx: Store, @@ -317,11 +317,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..289, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 286..289, }, ), @@ -332,20 +332,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 313..334, is_async: false, items: [ WithItem { range: 318..329, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..324, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 318..322, id: Name("open"), ctx: Load, @@ -353,7 +353,7 @@ Module( ), arguments: Arguments { range: 322..324, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -362,7 +362,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 328..329, id: Name("f"), ctx: Store, @@ -374,11 +374,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..334, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 331..334, }, ), @@ -389,20 +389,20 @@ Module( ), With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 335..361, is_async: false, items: [ WithItem { range: 340..356, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..346, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 340..344, id: Name("open"), ctx: Load, @@ -410,7 +410,7 @@ Module( ), arguments: Arguments { range: 344..346, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -419,11 +419,11 @@ Module( optional_vars: Some( Attribute( ExprAttribute { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 350..356, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 350..351, id: Name("f"), ctx: Load, @@ -432,7 +432,7 @@ Module( attr: Identifier { id: Name("attr"), range: 352..356, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, ctx: Store, }, @@ -443,11 +443,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 358..361, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 358..361, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@template_strings_py314.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@template_strings_py314.py.snap index ba9ecb9c20e80..dda530ea46323 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@template_strings_py314.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@template_strings_py314.py.snap @@ -7,30 +7,30 @@ input_file: crates/ruff_python_parser/resources/inline/ok/template_strings_py314 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..89, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..52, value: TStringValue { inner: Single( TString { range: 44..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 46..51, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..50, id: Name("hey"), ctx: Load, @@ -56,25 +56,25 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..63, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..63, value: TStringValue { inner: Single( TString { range: 53..63, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Interpolation( InterpolatedElement { range: 55..62, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), expression: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..61, id: Name("there"), ctx: Load, @@ -100,22 +100,22 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..88, value: TString( ExprTString { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 64..88, value: TStringValue { inner: Single( TString { range: 64..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), elements: [ Literal( InterpolatedStringLiteralElement { range: 68..85, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), value: "what's\nhappening?", }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@tuple_context_manager_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@tuple_context_manager_py38.py.snap index 46550ad2312b1..230855ad42411 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@tuple_context_manager_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@tuple_context_manager_py38.py.snap @@ -7,26 +7,26 @@ input_file: crates/ruff_python_parser/resources/inline/ok/tuple_context_manager_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..85, body: [ With( StmtWith { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..84, is_async: false, items: [ WithItem { range: 48..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), context_expr: Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..72, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..55, id: Name("foo"), ctx: Load, @@ -34,7 +34,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, id: Name("bar"), ctx: Load, @@ -42,7 +42,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..69, id: Name("baz"), ctx: Load, @@ -56,7 +56,7 @@ Module( optional_vars: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, id: Name("tup"), ctx: Store, @@ -68,11 +68,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap index 8387c4e874640..f673f2901a954 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_default_py313.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/type_param_default_py3 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..112, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..65, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("X"), ctx: Store, @@ -25,22 +25,22 @@ Module( type_params: Some( TypeParams { range: 50..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 51..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 51..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..58, id: Name("int"), ctx: Load, @@ -54,7 +54,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 62..65, id: Name("int"), ctx: Load, @@ -64,34 +64,34 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 66..87, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 71..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 72..79, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, id: Name("int"), ctx: Load, @@ -105,9 +105,7 @@ Module( ), parameters: Parameters { range: 80..82, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -118,11 +116,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..87, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..87, }, ), @@ -133,33 +131,33 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..111, decorator_list: [], name: Identifier { id: Name("C"), range: 94..95, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: Some( TypeParams { range: 95..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 96..103, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 96..97, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 100..103, id: Name("int"), ctx: Load, @@ -174,7 +172,7 @@ Module( arguments: Some( Arguments { range: 104..106, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [], keywords: [], }, @@ -182,11 +180,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..111, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap index 18801458d7b05..8ce68efabf4d8 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_param_spec.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/type_param_param_spec. ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..90, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 9..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -44,7 +44,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..41, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("X"), ctx: Store, @@ -67,21 +67,21 @@ Module( type_params: Some( TypeParams { range: 24..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ ParamSpec( TypeParamParamSpec { range: 25..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 27..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, id: Name("int"), ctx: Load, @@ -95,7 +95,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, id: Name("int"), ctx: Load, @@ -105,11 +105,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..62, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("X"), ctx: Store, @@ -118,16 +118,16 @@ Module( type_params: Some( TypeParams { range: 48..56, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 49..50, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -136,11 +136,11 @@ Module( ParamSpec( TypeParamParamSpec { range: 52..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 54..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -150,7 +150,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..62, id: Name("int"), ctx: Load, @@ -160,11 +160,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..89, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 68..69, id: Name("X"), ctx: Store, @@ -173,16 +173,16 @@ Module( type_params: Some( TypeParams { range: 69..83, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 70..71, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -191,16 +191,16 @@ Module( ParamSpec( TypeParamParamSpec { range: 73..82, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("P"), range: 75..76, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 79..82, id: Name("int"), ctx: Load, @@ -214,7 +214,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..89, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap index 1e340b41b1bb1..39808ecfd6f78 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/type_param_type_var.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..147, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..15, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..9, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 7..8, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -45,7 +45,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 12..15, id: Name("int"), ctx: Load, @@ -55,11 +55,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 16..37, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 21..22, id: Name("X"), ctx: Store, @@ -68,22 +68,22 @@ Module( type_params: Some( TypeParams { range: 22..31, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 23..30, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 23..24, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 27..30, id: Name("int"), ctx: Load, @@ -97,7 +97,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 34..37, id: Name("int"), ctx: Load, @@ -107,11 +107,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..64, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..44, id: Name("X"), ctx: Store, @@ -120,21 +120,21 @@ Module( type_params: Some( TypeParams { range: 44..58, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 45..57, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 45..46, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..51, id: Name("int"), ctx: Load, @@ -144,7 +144,7 @@ Module( default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 54..57, id: Name("int"), ctx: Load, @@ -158,7 +158,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..64, id: Name("int"), ctx: Load, @@ -168,11 +168,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..98, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 70..71, id: Name("X"), ctx: Store, @@ -181,26 +181,26 @@ Module( type_params: Some( TypeParams { range: 71..92, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 72..91, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 72..73, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 75..85, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 76..79, id: Name("int"), ctx: Load, @@ -208,7 +208,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..84, id: Name("int"), ctx: Load, @@ -223,7 +223,7 @@ Module( default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..91, id: Name("int"), ctx: Load, @@ -237,7 +237,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..98, id: Name("int"), ctx: Load, @@ -247,11 +247,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 99..146, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..105, id: Name("X"), ctx: Store, @@ -260,21 +260,21 @@ Module( type_params: Some( TypeParams { range: 105..140, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 106..118, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 106..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 109..112, id: Name("int"), ctx: Load, @@ -284,7 +284,7 @@ Module( default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 115..118, id: Name("int"), ctx: Load, @@ -296,21 +296,21 @@ Module( TypeVar( TypeParamTypeVar { range: 120..139, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("U"), range: 120..121, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: Some( Tuple( ExprTuple { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 123..133, elts: [ Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 124..127, id: Name("int"), ctx: Load, @@ -318,7 +318,7 @@ Module( ), Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 129..132, id: Name("int"), ctx: Load, @@ -333,7 +333,7 @@ Module( default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 136..139, id: Name("int"), ctx: Load, @@ -347,7 +347,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 143..146, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap index aa50926d78221..5aab990b65528 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_param_type_var_tuple.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/type_param_type_var_tu ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..115, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..17, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 5..6, id: Name("X"), ctx: Store, @@ -25,16 +25,16 @@ Module( type_params: Some( TypeParams { range: 6..11, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 7..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 8..10, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -44,7 +44,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 14..17, id: Name("int"), ctx: Load, @@ -54,11 +54,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 18..41, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 23..24, id: Name("X"), ctx: Store, @@ -67,21 +67,21 @@ Module( type_params: Some( TypeParams { range: 24..35, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 25..34, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 26..28, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 31..34, id: Name("int"), ctx: Load, @@ -95,7 +95,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 38..41, id: Name("int"), ctx: Load, @@ -105,11 +105,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 42..66, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("X"), ctx: Store, @@ -118,25 +118,25 @@ Module( type_params: Some( TypeParams { range: 48..60, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVarTuple( TypeParamTypeVarTuple { range: 49..59, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 50..52, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Starred( ExprStarred { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..59, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..59, id: Name("int"), ctx: Load, @@ -153,7 +153,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 63..66, id: Name("int"), ctx: Load, @@ -163,11 +163,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..87, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 72..73, id: Name("X"), ctx: Store, @@ -176,16 +176,16 @@ Module( type_params: Some( TypeParams { range: 73..81, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 74..75, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -194,11 +194,11 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 77..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 78..80, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: None, }, @@ -208,7 +208,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..87, id: Name("int"), ctx: Load, @@ -218,11 +218,11 @@ Module( ), TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 88..114, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 93..94, id: Name("X"), ctx: Store, @@ -231,16 +231,16 @@ Module( type_params: Some( TypeParams { range: 94..108, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), type_params: [ TypeVar( TypeParamTypeVar { range: 95..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("T"), range: 95..96, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, bound: None, default: None, @@ -249,16 +249,16 @@ Module( TypeVarTuple( TypeParamTypeVarTuple { range: 98..107, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("Ts"), range: 99..101, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, default: Some( Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 104..107, id: Name("int"), ctx: Load, @@ -272,7 +272,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 111..114, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_stmt_py312.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_stmt_py312.py.snap index 7e590b4515a15..c1849f86cc312 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_stmt_py312.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@type_stmt_py312.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/type_stmt_py312.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..57, body: [ TypeAlias( StmtTypeAlias { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..56, name: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, id: Name("x"), ctx: Store, @@ -25,7 +25,7 @@ Module( type_params: None, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..56, id: Name("int"), ctx: Load, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_index_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_index_py39.py.snap index 92c7cefb8639b..1f121dbd2d856 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_index_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_index_py39.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/unparenthesized_named_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..53, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..52, value: Subscript( ExprSubscript { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..52, value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..46, id: Name("lst"), ctx: Load, @@ -28,11 +28,11 @@ Module( ), slice: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..51, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 47..48, id: Name("x"), ctx: Store, @@ -40,7 +40,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 50..51, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap index 0f8b9f47b721d..e95fef868f1a9 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@unparenthesized_named_expr_py39.py.snap @@ -7,25 +7,25 @@ input_file: crates/ruff_python_parser/resources/inline/ok/unparenthesized_named_ ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..88, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..57, value: Set( ExprSet { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 43..57, elts: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..50, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("x"), ctx: Store, @@ -33,7 +33,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 49..50, value: Int( 1, @@ -44,7 +44,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, value: Int( 2, @@ -53,7 +53,7 @@ Module( ), NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 55..56, value: Int( 3, @@ -67,19 +67,19 @@ Module( ), Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..87, value: SetComp( ExprSetComp { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 58..87, elt: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..68, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 59..63, id: Name("last"), ctx: Store, @@ -87,7 +87,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 67..68, id: Name("x"), ctx: Load, @@ -98,10 +98,10 @@ Module( generators: [ Comprehension { range: 69..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("x"), ctx: Store, @@ -109,11 +109,11 @@ Module( ), iter: Call( ExprCall { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..86, func: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 78..83, id: Name("range"), ctx: Load, @@ -121,11 +121,11 @@ Module( ), arguments: Arguments { range: 83..86, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 84..85, value: Int( 3, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap index f4de814c8daad..87c63be67c450 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_class.py.snap @@ -7,32 +7,32 @@ input_file: crates/ruff_python_parser/resources/inline/ok/valid_annotation_class ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..137, body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..23, decorator_list: [], name: Identifier { id: Name("F"), range: 6..7, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 7..18, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..17, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 8..9, id: Name("y"), ctx: Store, @@ -40,7 +40,7 @@ Module( ), value: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 13..17, id: Name("list"), ctx: Load, @@ -55,11 +55,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 20..23, }, ), @@ -70,21 +70,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 24..93, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 28..29, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 29..31, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -95,28 +93,28 @@ Module( body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 37..60, decorator_list: [], name: Identifier { id: Name("G"), range: 43..44, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 44..55, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..53, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 52..53, value: Int( 1, @@ -133,11 +131,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 57..60, }, ), @@ -148,27 +146,27 @@ Module( ), ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..93, decorator_list: [], name: Identifier { id: Name("H"), range: 71..72, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 72..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 74..86, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 85..86, value: Int( 1, @@ -184,11 +182,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..93, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..93, }, ), @@ -202,21 +200,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..136, is_async: true, decorator_list: [], name: Identifier { id: Name("f"), range: 104..105, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 105..107, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -227,27 +223,27 @@ Module( body: [ ClassDef( StmtClassDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 113..136, decorator_list: [], name: Identifier { id: Name("G"), range: 119..120, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, arguments: Some( Arguments { range: 120..131, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), args: [ Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..129, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, value: Int( 1, @@ -263,11 +259,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..136, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..136, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_function_py313.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_function_py313.py.snap index c1c32f560556f..c70dedf89f148 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_function_py313.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_function_py313.py.snap @@ -7,26 +7,24 @@ input_file: crates/ruff_python_parser/resources/inline/ok/valid_annotation_funct ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..316, body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..68, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 48..49, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 49..51, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -36,11 +34,11 @@ Module( returns: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..62, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..57, id: Name("y"), ctx: Store, @@ -48,7 +46,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 61..62, value: Int( 3, @@ -61,11 +59,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 65..68, }, ), @@ -76,42 +74,40 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 69..94, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 73..74, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 74..89, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 75..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 75..88, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 75..78, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..87, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 81..82, id: Name("x"), ctx: Store, @@ -119,7 +115,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 86..87, value: Int( 1, @@ -141,11 +137,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 91..94, }, ), @@ -156,21 +152,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 95..235, is_async: false, decorator_list: [], name: Identifier { id: Name("outer"), range: 99..104, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 104..106, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -181,43 +175,41 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 112..136, is_async: false, decorator_list: [], name: Identifier { id: Name("i"), range: 116..117, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 117..131, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 118..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 118..130, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 118..119, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 122..129, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 128..129, value: Int( 1, @@ -240,11 +232,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..136, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 133..136, }, ), @@ -255,21 +247,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..166, is_async: false, decorator_list: [], name: Identifier { id: Name("k"), range: 145..146, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 146..148, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -279,12 +269,12 @@ Module( returns: Some( Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 153..160, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 159..160, value: Int( 1, @@ -298,11 +288,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..166, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 163..166, }, ), @@ -313,42 +303,40 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 171..200, is_async: false, decorator_list: [], name: Identifier { id: Name("m"), range: 175..176, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 176..195, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 177..194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 177..194, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("x"), range: 177..178, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 181..193, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 192..193, value: Int( 1, @@ -370,11 +358,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..200, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 197..200, }, ), @@ -385,21 +373,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 205..235, is_async: false, decorator_list: [], name: Identifier { id: Name("o"), range: 209..210, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 210..212, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -409,11 +395,11 @@ Module( returns: Some( YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 217..229, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 228..229, value: Int( 1, @@ -426,11 +412,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..235, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 232..235, }, ), @@ -444,21 +430,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 236..315, is_async: true, decorator_list: [], name: Identifier { id: Name("outer"), range: 246..251, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 251..253, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -469,21 +453,19 @@ Module( body: [ FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 259..284, is_async: false, decorator_list: [], name: Identifier { id: Name("f"), range: 263..264, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 264..266, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -493,11 +475,11 @@ Module( returns: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 271..278, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 277..278, value: Int( 1, @@ -510,11 +492,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..284, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 281..284, }, ), @@ -525,42 +507,40 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 289..315, is_async: false, decorator_list: [], name: Identifier { id: Name("g"), range: 293..294, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 294..310, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [ ParameterWithDefault { range: 295..309, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), parameter: Parameter { range: 295..309, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), name: Identifier { id: Name("arg"), range: 295..298, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, annotation: Some( Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 301..308, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 307..308, value: Int( 1, @@ -582,11 +562,11 @@ Module( body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..315, value: EllipsisLiteral( ExprEllipsisLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 312..315, }, ), diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_py313.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_py313.py.snap index be4b3961e8e84..b8f364cf8bed0 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_py313.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@valid_annotation_py313.py.snap @@ -7,16 +7,16 @@ input_file: crates/ruff_python_parser/resources/inline/ok/valid_annotation_py313 ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..144, body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..55, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 44..45, id: Name("a"), ctx: Store, @@ -24,11 +24,11 @@ Module( ), annotation: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..54, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 48..49, id: Name("x"), ctx: Store, @@ -36,7 +36,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 53..54, value: Int( 1, @@ -51,21 +51,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 56..107, is_async: false, decorator_list: [], name: Identifier { id: Name("outer"), range: 60..65, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 65..67, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -76,11 +74,11 @@ Module( body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..85, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 73..74, id: Name("b"), ctx: Store, @@ -88,12 +86,12 @@ Module( ), annotation: Yield( ExprYield { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 77..84, value: Some( NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 83..84, value: Int( 1, @@ -109,11 +107,11 @@ Module( ), AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..107, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 90..91, id: Name("c"), ctx: Store, @@ -121,11 +119,11 @@ Module( ), annotation: YieldFrom( ExprYieldFrom { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 94..106, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 105..106, value: Int( 1, @@ -143,21 +141,19 @@ Module( ), FunctionDef( StmtFunctionDef { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 108..143, is_async: true, decorator_list: [], name: Identifier { id: Name("outer"), range: 118..123, - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), }, type_params: None, parameters: Parameters { range: 123..125, - node_index: AtomicNodeIndex( - 0, - ), + node_index: NodeIndex(None), posonlyargs: [], args: [], vararg: None, @@ -168,11 +164,11 @@ Module( body: [ AnnAssign( StmtAnnAssign { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..143, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 131..132, id: Name("d"), ctx: Store, @@ -180,11 +176,11 @@ Module( ), annotation: Await( ExprAwait { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 135..142, value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 141..142, value: Int( 1, diff --git a/crates/ruff_python_parser/tests/snapshots/valid_syntax@walrus_py38.py.snap b/crates/ruff_python_parser/tests/snapshots/valid_syntax@walrus_py38.py.snap index 16008f3821501..0dba7ff0cd00e 100644 --- a/crates/ruff_python_parser/tests/snapshots/valid_syntax@walrus_py38.py.snap +++ b/crates/ruff_python_parser/tests/snapshots/valid_syntax@walrus_py38.py.snap @@ -7,20 +7,20 @@ input_file: crates/ruff_python_parser/resources/inline/ok/walrus_py38.py ``` Module( ModModule { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 0..54, body: [ Expr( StmtExpr { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 45..53, value: Named( ExprNamed { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..52, target: Name( ExprName { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 46..47, id: Name("x"), ctx: Store, @@ -28,7 +28,7 @@ Module( ), value: NumberLiteral( ExprNumberLiteral { - node_index: AtomicNodeIndex(..), + node_index: NodeIndex(None), range: 51..52, value: Int( 1, diff --git a/crates/ty_python_semantic/src/ast_node_ref.rs b/crates/ty_python_semantic/src/ast_node_ref.rs index c5f7f115cc80c..9d1dd604330d5 100644 --- a/crates/ty_python_semantic/src/ast_node_ref.rs +++ b/crates/ty_python_semantic/src/ast_node_ref.rs @@ -32,17 +32,19 @@ use ruff_text_size::Ranged; /// run on every AST change. All other queries only run when the expression's identity changes. #[derive(Clone)] pub struct AstNodeRef { - /// A pointer to the [`ruff_db::parsed::ParsedModule`] that this node was created from. - module_ptr: *const (), + /// The index of the node in the AST. + index: NodeIndex, /// Debug information. #[cfg(debug_assertions)] kind: ruff_python_ast::NodeKind, #[cfg(debug_assertions)] range: ruff_text_size::TextRange, - - /// The index of the node in the AST. - index: NodeIndex, + // Note that because the module address is not stored in release builds, `AstNodeRef` + // cannot implement `Eq`, as indices are only unique within a given instance of the + // AST. + #[cfg(debug_assertions)] + module_addr: usize, _node: PhantomData, } @@ -63,7 +65,8 @@ where Self { index, - module_ptr: module_ref.module().as_ptr(), + #[cfg(debug_assertions)] + module_addr: module_ref.module().addr(), #[cfg(debug_assertions)] kind: AnyNodeRef::from(node).kind(), #[cfg(debug_assertions)] @@ -77,10 +80,11 @@ where /// This method may panic or produce unspecified results if the provided module is from a /// different file or Salsa revision than the module to which the node belongs. pub fn node<'ast>(&self, module_ref: &'ast ParsedModuleRef) -> &'ast T { - debug_assert_eq!(module_ref.module().as_ptr(), self.module_ptr); + #[cfg(debug_assertions)] + assert_eq!(module_ref.module().addr(), self.module_addr); - // Note that the module pointer is guaranteed to be stable within the Salsa - // revision, so the file contents cannot have changed by the above assertion. + // The user guarantees that the module is from the same file and Salsa + // revision, so the file contents cannot have changed. module_ref .get_by_index(self.index) .try_into() @@ -89,6 +93,20 @@ where } } +#[expect(unsafe_code)] +unsafe impl salsa::Update for AstNodeRef { + unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool { + let old_ref = unsafe { &mut (*old_pointer) }; + + // The equality of an `AstNodeRef` depends on both the module address and the node index, + // but the former is not stored in release builds to save memory. As such, AST nodes + // are always considered change when the AST is reparsed, which is acceptable because + // any change to the AST is likely to invalidate most node indices anyways. + *old_ref = new_value; + true + } +} + impl get_size2::GetSize for AstNodeRef {} #[allow(clippy::missing_fields_in_debug)] @@ -113,26 +131,3 @@ where } } } - -#[expect(unsafe_code)] -unsafe impl salsa::Update for AstNodeRef { - unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool { - let old_ref = unsafe { &mut (*old_pointer) }; - - // Two nodes are guaranteed to be equal as long as they refer to the same node index - // within the same module. Note that the module pointer is guaranteed to be stable - // within the Salsa revision, so the file contents cannot have changed. - if old_ref.module_ptr == new_value.module_ptr && old_ref.index == new_value.index { - false - } else { - *old_ref = new_value; - true - } - } -} - -// SAFETY: The `module_ptr` is only used for pointer equality and never accessed directly. -#[expect(unsafe_code)] -unsafe impl Send for AstNodeRef where T: Send {} -#[expect(unsafe_code)] -unsafe impl Sync for AstNodeRef where T: Sync {} From b3cc733f068c93166dd58c01240b862b400ccc89 Mon Sep 17 00:00:00 2001 From: Ibraheem Ahmed Date: Fri, 22 Aug 2025 19:43:12 -0400 Subject: [PATCH 102/160] [ty] Remove duplicate global lint registry (#20053) ## Summary Looks like an oversight at some point that led to two identical globals, the one in `ty_project` just calls `ty_python_semantic::register_lints`. --- Cargo.lock | 1 + crates/ruff_dev/Cargo.toml | 1 + crates/ruff_dev/src/generate_ty_rules.rs | 2 +- crates/ty_project/src/db.rs | 7 +++---- crates/ty_project/src/lib.rs | 13 ++----------- crates/ty_project/src/metadata/options.rs | 3 +-- 6 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55388f373f912..573188cfb2d16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2935,6 +2935,7 @@ dependencies = [ "tracing-subscriber", "ty", "ty_project", + "ty_python_semantic", "ty_static", "url", ] diff --git a/crates/ruff_dev/Cargo.toml b/crates/ruff_dev/Cargo.toml index b7068640f50a5..17d494e4a7969 100644 --- a/crates/ruff_dev/Cargo.toml +++ b/crates/ruff_dev/Cargo.toml @@ -13,6 +13,7 @@ license = { workspace = true } [dependencies] ty = { workspace = true } ty_project = { workspace = true, features = ["schemars"] } +ty_python_semantic = { workspace = true } ty_static = { workspace = true } ruff = { workspace = true } ruff_formatter = { workspace = true } diff --git a/crates/ruff_dev/src/generate_ty_rules.rs b/crates/ruff_dev/src/generate_ty_rules.rs index 1f379b69a3fac..aaa1021d96db6 100644 --- a/crates/ruff_dev/src/generate_ty_rules.rs +++ b/crates/ruff_dev/src/generate_ty_rules.rs @@ -52,7 +52,7 @@ pub(crate) fn main(args: &Args) -> Result<()> { } fn generate_markdown() -> String { - let registry = &*ty_project::DEFAULT_LINT_REGISTRY; + let registry = ty_python_semantic::default_lint_registry(); let mut output = String::new(); diff --git a/crates/ty_project/src/db.rs b/crates/ty_project/src/db.rs index a59006689bbac..a312586fb6d00 100644 --- a/crates/ty_project/src/db.rs +++ b/crates/ty_project/src/db.rs @@ -4,8 +4,8 @@ use std::sync::Arc; use std::{cmp, fmt}; pub use self::changes::ChangeResult; +use crate::CollectReporter; use crate::metadata::settings::file_settings; -use crate::{CollectReporter, DEFAULT_LINT_REGISTRY}; use crate::{ProgressReporter, Project, ProjectMetadata}; use ruff_db::Db as SourceDb; use ruff_db::diagnostic::Diagnostic; @@ -455,7 +455,7 @@ impl SemanticDb for ProjectDatabase { } fn lint_registry(&self) -> &LintRegistry { - &DEFAULT_LINT_REGISTRY + ty_python_semantic::default_lint_registry() } } @@ -518,7 +518,6 @@ pub(crate) mod tests { use ty_python_semantic::Program; use ty_python_semantic::lint::{LintRegistry, RuleSelection}; - use crate::DEFAULT_LINT_REGISTRY; use crate::db::Db; use crate::{Project, ProjectMetadata}; @@ -608,7 +607,7 @@ pub(crate) mod tests { } fn lint_registry(&self) -> &LintRegistry { - &DEFAULT_LINT_REGISTRY + ty_python_semantic::default_lint_registry() } } diff --git a/crates/ty_project/src/lib.rs b/crates/ty_project/src/lib.rs index 53fd6ad3da8ff..b98917dbf5c4a 100644 --- a/crates/ty_project/src/lib.rs +++ b/crates/ty_project/src/lib.rs @@ -28,9 +28,9 @@ use std::panic::{AssertUnwindSafe, UnwindSafe}; use std::sync::Arc; use thiserror::Error; use tracing::error; -use ty_python_semantic::lint::{LintRegistry, LintRegistryBuilder, RuleSelection}; +use ty_python_semantic::add_inferred_python_version_hint_to_diagnostic; +use ty_python_semantic::lint::RuleSelection; use ty_python_semantic::types::check_types; -use ty_python_semantic::{add_inferred_python_version_hint_to_diagnostic, register_lints}; mod db; mod files; @@ -39,15 +39,6 @@ pub mod metadata; mod walk; pub mod watch; -pub static DEFAULT_LINT_REGISTRY: std::sync::LazyLock = - std::sync::LazyLock::new(default_lints_registry); - -pub fn default_lints_registry() -> LintRegistry { - let mut builder = LintRegistryBuilder::default(); - register_lints(&mut builder); - builder.build() -} - /// The project as a Salsa ingredient. /// /// ## How is a project different from a program? diff --git a/crates/ty_project/src/metadata/options.rs b/crates/ty_project/src/metadata/options.rs index 5d21320049181..6e5d614de4430 100644 --- a/crates/ty_project/src/metadata/options.rs +++ b/crates/ty_project/src/metadata/options.rs @@ -1457,7 +1457,6 @@ impl std::error::Error for ToSettingsError {} #[cfg(feature = "schemars")] mod schema { - use crate::DEFAULT_LINT_REGISTRY; use schemars::JsonSchema; use schemars::r#gen::SchemaGenerator; use schemars::schema::{ @@ -1473,7 +1472,7 @@ mod schema { } fn json_schema(generator: &mut SchemaGenerator) -> Schema { - let registry = &*DEFAULT_LINT_REGISTRY; + let registry = ty_python_semantic::default_lint_registry(); let level_schema = generator.subschema_for::(); From 85931ab5946af3c35a3f982b0e5a3dae41c6ea23 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 22 Aug 2025 08:07:05 -0400 Subject: [PATCH 103/160] [ty] Add a TODO for linting on `todo!` --- crates/ty_python_semantic/src/types/infer.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 5d3b21cc7edd2..0cb21ae2f9729 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -10040,6 +10040,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { // ================================================================================= // Branches where we probably should emit diagnostics in some context, but don't yet // ================================================================================= + // TODO: When this case is implemented and the `todo!` usage + // is removed, consider adding `todo = "warn"` to the Clippy + // lint configuration in `Cargo.toml`. At time of writing, + // 2025-08-22, this was the only usage of `todo!` in ruff/ty. + // ---AG ast::Expr::IpyEscapeCommand(_) => todo!("Implement Ipy escape command support"), ast::Expr::EllipsisLiteral(_) => { From 06dbec84796c6eaac43ba1bb2063fbe006574989 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 21 Aug 2025 12:35:05 -0400 Subject: [PATCH 104/160] [ty] Add debug trace for workspace symbol elapsed time Useful for ad hoc debugging, but it's also useful to have permanently to enable serendipitous discovery of performance problems. --- .../ty_server/src/server/api/requests/workspace_symbols.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crates/ty_server/src/server/api/requests/workspace_symbols.rs b/crates/ty_server/src/server/api/requests/workspace_symbols.rs index e6b170a2640d3..a964954546d99 100644 --- a/crates/ty_server/src/server/api/requests/workspace_symbols.rs +++ b/crates/ty_server/src/server/api/requests/workspace_symbols.rs @@ -29,7 +29,13 @@ impl BackgroundRequestHandler for WorkspaceSymbolRequestHandler { // Iterate through all projects in the session for db in snapshot.projects() { // Get workspace symbols matching the query + let start = std::time::Instant::now(); let workspace_symbol_infos = workspace_symbols(db, query); + tracing::debug!( + "Found {len} workspace symbols in {elapsed:?}", + len = workspace_symbol_infos.len(), + elapsed = std::time::Instant::now().duration_since(start) + ); // Convert to LSP SymbolInformation for workspace_symbol_info in workspace_symbol_infos { From ad8c98117af5f61628a96702fb2a399c7f4aa6fa Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 21 Aug 2025 13:48:46 -0400 Subject: [PATCH 105/160] [ty] Move query filtering outside of symbol visitor This is prep work for turning this into a Salsa query. Specifically, we don't want the Salsa query to be dependent upon the query string. --- crates/ty_ide/src/symbols.rs | 55 +++++++++++++++++------------------- 1 file changed, 26 insertions(+), 29 deletions(-) diff --git a/crates/ty_ide/src/symbols.rs b/crates/ty_ide/src/symbols.rs index f9c76bcb95604..e434b36fab294 100644 --- a/crates/ty_ide/src/symbols.rs +++ b/crates/ty_ide/src/symbols.rs @@ -86,7 +86,11 @@ pub(crate) fn symbols_for_file( let mut visitor = SymbolVisitor::new(options); visitor.visit_body(&module.syntax().body); - visitor.symbols + let mut symbols = visitor.symbols; + if let Some(ref query) = options.query_string { + symbols.retain(|symbol| is_pattern_in_symbol(query, &symbol.name)); + } + symbols } struct SymbolVisitor<'a> { @@ -115,13 +119,6 @@ impl<'a> SymbolVisitor<'a> { } fn add_symbol(&mut self, symbol: SymbolInfo) { - // Filter by query string if provided - if let Some(ref query) = self.options.query_string { - if !Self::is_pattern_in_symbol(query, &symbol.name) { - return; - } - } - if self.options.hierarchical { if let Some(parent) = self.symbol_stack.last_mut() { parent.children.push(symbol); @@ -152,27 +149,6 @@ impl<'a> SymbolVisitor<'a> { fn is_constant_name(name: &str) -> bool { name.chars().all(|c| c.is_ascii_uppercase() || c == '_') } - - /// Returns true if symbol name contains all characters in the query - /// string in order. The comparison is case insensitive. - fn is_pattern_in_symbol(query_string: &str, symbol_name: &str) -> bool { - let typed_lower = query_string.to_lowercase(); - let symbol_lower = symbol_name.to_lowercase(); - let typed_chars: Vec = typed_lower.chars().collect(); - let symbol_chars: Vec = symbol_lower.chars().collect(); - - let mut typed_pos = 0; - let mut symbol_pos = 0; - - while typed_pos < typed_chars.len() && symbol_pos < symbol_chars.len() { - if typed_chars[typed_pos] == symbol_chars[symbol_pos] { - typed_pos += 1; - } - symbol_pos += 1; - } - - typed_pos == typed_chars.len() - } } impl SourceOrderVisitor<'_> for SymbolVisitor<'_> { @@ -307,3 +283,24 @@ impl SourceOrderVisitor<'_> for SymbolVisitor<'_> { } } } + +/// Returns true if symbol name contains all characters in the query +/// string in order. The comparison is case insensitive. +fn is_pattern_in_symbol(query_string: &str, symbol_name: &str) -> bool { + let typed_lower = query_string.to_lowercase(); + let symbol_lower = symbol_name.to_lowercase(); + let typed_chars: Vec = typed_lower.chars().collect(); + let symbol_chars: Vec = symbol_lower.chars().collect(); + + let mut typed_pos = 0; + let mut symbol_pos = 0; + + while typed_pos < typed_chars.len() && symbol_pos < symbol_chars.len() { + if typed_chars[typed_pos] == symbol_chars[symbol_pos] { + typed_pos += 1; + } + symbol_pos += 1; + } + + typed_pos == typed_chars.len() +} From 330bb4efbf6c8724ab604cc612241baa63b06769 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 21 Aug 2025 14:07:26 -0400 Subject: [PATCH 106/160] [ty] Add some unit tests for "query matches symbol" There is a small amount of subtlety to this matching routine, and it could be implemented in a faster way. So let's right some tests for what we have to ensure we don't break anything when we optimize it. --- crates/ty_ide/src/symbols.rs | 38 ++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/crates/ty_ide/src/symbols.rs b/crates/ty_ide/src/symbols.rs index e434b36fab294..0764a39322282 100644 --- a/crates/ty_ide/src/symbols.rs +++ b/crates/ty_ide/src/symbols.rs @@ -304,3 +304,41 @@ fn is_pattern_in_symbol(query_string: &str, symbol_name: &str) -> bool { typed_pos == typed_chars.len() } + +#[cfg(test)] +mod tests { + fn matches(query: &str, symbol: &str) -> bool { + super::is_pattern_in_symbol(query, symbol) + } + + #[test] + fn various_yes() { + assert!(matches("", "")); + assert!(matches("", "a")); + assert!(matches("", "abc")); + + assert!(matches("a", "a")); + assert!(matches("a", "abc")); + assert!(matches("a", "xaz")); + assert!(matches("a", "xza")); + + assert!(matches("abc", "abc")); + assert!(matches("abc", "axbyc")); + assert!(matches("abc", "waxbycz")); + assert!(matches("abc", "WAXBYCZ")); + assert!(matches("ABC", "waxbycz")); + assert!(matches("ABC", "WAXBYCZ")); + assert!(matches("aBc", "wAXbyCZ")); + + assert!(matches("δ", "Δ")); + assert!(matches("δΘπ", "ΔθΠ")); + } + + #[test] + fn various_no() { + assert!(!matches("a", "")); + assert!(!matches("abc", "bac")); + assert!(!matches("abcd", "abc")); + assert!(!matches("δΘπ", "θΔΠ")); + } +} From 8ead02e0b1186f04ee7df8bb92bdb674feef8a17 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 21 Aug 2025 14:37:35 -0400 Subject: [PATCH 107/160] [ty] Optimize query string matching While this doesn't typically matter, when ty returns a very large list of symbols, this can have an impact. Specifically, when searching `async` in home-assistant, this gets times closer to 500ms versus closer to 600ms before this change. It looks like an overall ~50ms improvement (so around 10%), but variance is all over the place and I didn't do any statistical tests. But this does make intuitive sense. Previously, we were allocating intermediate strings, doing UTF-8 decoding and consulting Unicode casing tables. Now we're just doing what is likely a single DFA scan. In effect, we front load all of the Unicode junk into regex compilation. --- crates/ty_ide/src/symbols.rs | 81 ++++++++++++++++++-------- crates/ty_ide/src/workspace_symbols.rs | 2 +- 2 files changed, 58 insertions(+), 25 deletions(-) diff --git a/crates/ty_ide/src/symbols.rs b/crates/ty_ide/src/symbols.rs index 0764a39322282..ef4614b3fc448 100644 --- a/crates/ty_ide/src/symbols.rs +++ b/crates/ty_ide/src/symbols.rs @@ -1,6 +1,8 @@ //! Implements logic used by the document symbol provider, workspace symbol //! provider, and auto-import feature of the completion provider. +use regex::Regex; + use ruff_db::files::File; use ruff_db::parsed::parsed_module; use ruff_python_ast::visitor::source_order::{self, SourceOrderVisitor}; @@ -16,7 +18,59 @@ pub struct SymbolsOptions { /// Include only symbols in the global scope pub global_only: bool, /// Query string for filtering symbol names - pub query_string: Option, + pub query_string: Option, +} + +#[derive(Clone, Debug)] +pub struct QueryPattern { + re: Option, + original: String, +} + +impl QueryPattern { + pub fn new(literal_query_string: &str) -> QueryPattern { + let mut pattern = "(?i)".to_string(); + for ch in literal_query_string.chars() { + pattern.push_str(®ex::escape(ch.encode_utf8(&mut [0; 4]))); + pattern.push_str(".*"); + } + // In theory regex compilation could fail if the pattern string + // was long enough to exceed the default regex compilation size + // limit. But this length would be approaching ~10MB or so. + QueryPattern { + re: Regex::new(&pattern).ok(), + original: literal_query_string.to_string(), + } + } + + fn is_match(&self, symbol: &SymbolInfo) -> bool { + self.is_match_symbol_name(&symbol.name) + } + + fn is_match_symbol_name(&self, symbol_name: &str) -> bool { + if let Some(ref re) = self.re { + re.is_match(symbol_name) + } else { + // This is a degenerate case. The only way + // we should get here is if the query string + // was thousands (or more) characters long. + symbol_name.contains(&self.original) + } + } +} + +impl From<&str> for QueryPattern { + fn from(literal_query_string: &str) -> QueryPattern { + QueryPattern::new(literal_query_string) + } +} + +impl Eq for QueryPattern {} + +impl PartialEq for QueryPattern { + fn eq(&self, rhs: &QueryPattern) -> bool { + self.original == rhs.original + } } /// Symbol information for IDE features like document outline. @@ -88,7 +142,7 @@ pub(crate) fn symbols_for_file( visitor.visit_body(&module.syntax().body); let mut symbols = visitor.symbols; if let Some(ref query) = options.query_string { - symbols.retain(|symbol| is_pattern_in_symbol(query, &symbol.name)); + symbols.retain(|symbol| query.is_match(symbol)); } symbols } @@ -284,31 +338,10 @@ impl SourceOrderVisitor<'_> for SymbolVisitor<'_> { } } -/// Returns true if symbol name contains all characters in the query -/// string in order. The comparison is case insensitive. -fn is_pattern_in_symbol(query_string: &str, symbol_name: &str) -> bool { - let typed_lower = query_string.to_lowercase(); - let symbol_lower = symbol_name.to_lowercase(); - let typed_chars: Vec = typed_lower.chars().collect(); - let symbol_chars: Vec = symbol_lower.chars().collect(); - - let mut typed_pos = 0; - let mut symbol_pos = 0; - - while typed_pos < typed_chars.len() && symbol_pos < symbol_chars.len() { - if typed_chars[typed_pos] == symbol_chars[symbol_pos] { - typed_pos += 1; - } - symbol_pos += 1; - } - - typed_pos == typed_chars.len() -} - #[cfg(test)] mod tests { fn matches(query: &str, symbol: &str) -> bool { - super::is_pattern_in_symbol(query, symbol) + super::QueryPattern::new(query).is_match_symbol_name(symbol) } #[test] diff --git a/crates/ty_ide/src/workspace_symbols.rs b/crates/ty_ide/src/workspace_symbols.rs index 6ac203327a9c8..5bda7090e54fa 100644 --- a/crates/ty_ide/src/workspace_symbols.rs +++ b/crates/ty_ide/src/workspace_symbols.rs @@ -16,7 +16,7 @@ pub fn workspace_symbols(db: &dyn Db, query: &str) -> Vec { let options = SymbolsOptions { hierarchical: false, // Workspace symbols are always flat global_only: false, - query_string: Some(query.to_string()), + query_string: Some(query.into()), }; // Get all files in the project From fb2d0af18cfd68c0bd129f23148994c33526840a Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Thu, 21 Aug 2025 14:50:01 -0400 Subject: [PATCH 108/160] [ty] Optimize "workspace symbols" retrieval Basically, this splits the implementation into two pieces: the first piece does the traversal and finds *all* symbols across the workspace. The second piece does filtering based on a user provided query string. Only the first piece is cached by Salsa. This brings warm "workspace symbols" requests down from 500-600ms to 100-200ms. --- Cargo.lock | 2 + crates/ty_ide/Cargo.toml | 2 + crates/ty_ide/src/document_symbols.rs | 12 ++--- crates/ty_ide/src/symbols.rs | 63 ++++++++++++++++---------- crates/ty_ide/src/workspace_symbols.rs | 2 +- 5 files changed, 51 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 573188cfb2d16..1e53684735e9c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4245,12 +4245,14 @@ dependencies = [ "itertools 0.14.0", "regex", "ruff_db", + "ruff_memory_usage", "ruff_python_ast", "ruff_python_parser", "ruff_python_trivia", "ruff_source_file", "ruff_text_size", "rustc-hash", + "salsa", "smallvec", "tracing", "ty_project", diff --git a/crates/ty_ide/Cargo.toml b/crates/ty_ide/Cargo.toml index 5f1b2453970f8..3b423ff1cb5c8 100644 --- a/crates/ty_ide/Cargo.toml +++ b/crates/ty_ide/Cargo.toml @@ -13,6 +13,7 @@ license = { workspace = true } [dependencies] bitflags = { workspace = true } ruff_db = { workspace = true } +ruff_memory_usage = { workspace = true } ruff_python_ast = { workspace = true } ruff_python_parser = { workspace = true } ruff_python_trivia = { workspace = true } @@ -24,6 +25,7 @@ ty_project = { workspace = true, features = ["testing"] } itertools = { workspace = true } regex = { workspace = true } rustc-hash = { workspace = true } +salsa = { workspace = true, features = ["compact_str"] } smallvec = { workspace = true } tracing = { workspace = true } diff --git a/crates/ty_ide/src/document_symbols.rs b/crates/ty_ide/src/document_symbols.rs index e9d5096c07047..2edb70241bd98 100644 --- a/crates/ty_ide/src/document_symbols.rs +++ b/crates/ty_ide/src/document_symbols.rs @@ -8,7 +8,7 @@ pub fn document_symbols_with_options( file: File, options: &SymbolsOptions, ) -> Vec { - symbols_for_file(db, file, options) + symbols_for_file(db, file, options).cloned().collect() } /// Get all document symbols for a file (hierarchical by default). @@ -94,13 +94,13 @@ class MyClass: class_var = 100 typed_class_var: str = 'class_typed' annotated_class_var: float - + def __init__(self): self.instance_var = 0 - + def public_method(self): return self.instance_var - + def _private_method(self): pass @@ -256,10 +256,10 @@ def standalone_function(): " class OuterClass: OUTER_CONSTANT = 100 - + def outer_method(self): return self.OUTER_CONSTANT - + class InnerClass: def inner_method(self): pass diff --git a/crates/ty_ide/src/symbols.rs b/crates/ty_ide/src/symbols.rs index ef4614b3fc448..4d4e72ea1fc9a 100644 --- a/crates/ty_ide/src/symbols.rs +++ b/crates/ty_ide/src/symbols.rs @@ -125,47 +125,64 @@ impl SymbolKind { } } -pub(crate) fn symbols_for_file( - db: &dyn Db, +pub(crate) fn symbols_for_file<'db>( + db: &'db dyn Db, file: File, options: &SymbolsOptions, -) -> Vec { +) -> impl Iterator { assert!( !options.hierarchical || options.query_string.is_none(), "Cannot use hierarchical mode with a query string" ); + let ingredient = SymbolsOptionsWithoutQuery { + hierarchical: options.hierarchical, + global_only: options.global_only, + }; + symbols_for_file_inner(db, file, ingredient) + .iter() + .filter(|symbol| { + let Some(ref query) = options.query_string else { + return true; + }; + query.is_match(symbol) + }) +} + +#[derive(Clone, Debug, Eq, Hash, PartialEq)] +struct SymbolsOptionsWithoutQuery { + hierarchical: bool, + global_only: bool, +} + +#[salsa::tracked(returns(deref))] +fn symbols_for_file_inner<'db>( + db: &'db dyn Db, + file: File, + options: SymbolsOptionsWithoutQuery, +) -> Vec { let parsed = parsed_module(db, file); let module = parsed.load(db); - let mut visitor = SymbolVisitor::new(options); + let mut visitor = SymbolVisitor { + symbols: vec![], + symbol_stack: vec![], + in_function: false, + options, + }; visitor.visit_body(&module.syntax().body); - let mut symbols = visitor.symbols; - if let Some(ref query) = options.query_string { - symbols.retain(|symbol| query.is_match(symbol)); - } - symbols + visitor.symbols } -struct SymbolVisitor<'a> { +struct SymbolVisitor { symbols: Vec, symbol_stack: Vec, /// Track if we're currently inside a function (to exclude local variables) in_function: bool, - /// Options controlling symbol collection - options: &'a SymbolsOptions, + options: SymbolsOptionsWithoutQuery, } -impl<'a> SymbolVisitor<'a> { - fn new(options: &'a SymbolsOptions) -> Self { - Self { - symbols: Vec::new(), - symbol_stack: Vec::new(), - in_function: false, - options, - } - } - +impl SymbolVisitor { fn visit_body(&mut self, body: &[Stmt]) { for stmt in body { self.visit_stmt(stmt); @@ -205,7 +222,7 @@ impl<'a> SymbolVisitor<'a> { } } -impl SourceOrderVisitor<'_> for SymbolVisitor<'_> { +impl SourceOrderVisitor<'_> for SymbolVisitor { fn visit_stmt(&mut self, stmt: &Stmt) { match stmt { Stmt::FunctionDef(func_def) => { diff --git a/crates/ty_ide/src/workspace_symbols.rs b/crates/ty_ide/src/workspace_symbols.rs index 5bda7090e54fa..96a65e92a17c9 100644 --- a/crates/ty_ide/src/workspace_symbols.rs +++ b/crates/ty_ide/src/workspace_symbols.rs @@ -28,7 +28,7 @@ pub fn workspace_symbols(db: &dyn Db, query: &str) -> Vec { for symbol in file_symbols { results.push(WorkspaceSymbolInfo { - symbol, + symbol: symbol.clone(), file: *file, }); } From f407f12f4c2fcdfd8d491faecea262649d24aa6e Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 22 Aug 2025 09:07:30 -0400 Subject: [PATCH 109/160] [ty] Parallelize workspace symbols This is a pretty naive approach, but it makes cold times for listing workspace symbols in home-assistant under 1s on my machine. Courtesy of Micha: https://github.com/astral-sh/ruff/pull/20030#discussion_r2292924171 --- Cargo.lock | 1 + crates/ty_ide/Cargo.toml | 1 + crates/ty_ide/src/workspace_symbols.rs | 39 +++++++++++++++++--------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1e53684735e9c..57df633a4d63d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4243,6 +4243,7 @@ dependencies = [ "bitflags 2.9.2", "insta", "itertools 0.14.0", + "rayon", "regex", "ruff_db", "ruff_memory_usage", diff --git a/crates/ty_ide/Cargo.toml b/crates/ty_ide/Cargo.toml index 3b423ff1cb5c8..bf6d0db7915b7 100644 --- a/crates/ty_ide/Cargo.toml +++ b/crates/ty_ide/Cargo.toml @@ -23,6 +23,7 @@ ty_python_semantic = { workspace = true } ty_project = { workspace = true, features = ["testing"] } itertools = { workspace = true } +rayon = { workspace = true } regex = { workspace = true } rustc-hash = { workspace = true } salsa = { workspace = true, features = ["compact_str"] } diff --git a/crates/ty_ide/src/workspace_symbols.rs b/crates/ty_ide/src/workspace_symbols.rs index 96a65e92a17c9..738c208bcb9d2 100644 --- a/crates/ty_ide/src/workspace_symbols.rs +++ b/crates/ty_ide/src/workspace_symbols.rs @@ -10,7 +10,6 @@ pub fn workspace_symbols(db: &dyn Db, query: &str) -> Vec { return Vec::new(); } - let mut results = Vec::new(); let project = db.project(); let options = SymbolsOptions { @@ -19,22 +18,34 @@ pub fn workspace_symbols(db: &dyn Db, query: &str) -> Vec { query_string: Some(query.into()), }; - // Get all files in the project let files = project.files(db); - - // For each file, extract symbols and add them to results - for file in files.iter() { - let file_symbols = symbols_for_file(db, *file, &options); - - for symbol in file_symbols { - results.push(WorkspaceSymbolInfo { - symbol: symbol.clone(), - file: *file, - }); - } + let results = std::sync::Mutex::new(Vec::new()); + { + let db = db.dyn_clone(); + let files = &files; + let options = &options; + let results = &results; + + rayon::scope(move |s| { + // For each file, extract symbols and add them to results + for file in files.iter() { + let db = db.dyn_clone(); + s.spawn(move |_| { + for symbol in symbols_for_file(&*db, *file, options) { + // It seems like we could do better here than + // locking `results` for every single symbol, + // but this works pretty well as it is. + results.lock().unwrap().push(WorkspaceSymbolInfo { + symbol: symbol.clone(), + file: *file, + }); + } + }); + } + }); } - results + results.into_inner().unwrap() } /// A symbol found in the workspace, including the file it was found in. From 205eae14d29eba390676cd36e6f9f641eae85519 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 23 Aug 2025 08:11:39 -0400 Subject: [PATCH 110/160] [ty] Rejigger workspace symbols for more efficient caching In effect, we make the Salsa query aspect keyed only on whether we want global symbols. We move everything else (hierarchical and querying) to an aggregate step *after* the query. This was a somewhat involved change since we want to return a flattened list from visiting the source while also preserving enough information to reform the symbols into a hierarchical structure that the LSP expects. But I think overall the API has gotten simpler and we encode more invariants into the type system. (For example, previously you got a runtime assertion if you tried to provide a query string while enabling hierarchical mode. But now that's prevented by construction.) --- Cargo.lock | 2 + crates/ty_ide/Cargo.toml | 2 + crates/ty_ide/src/document_symbols.rs | 54 ++- crates/ty_ide/src/lib.rs | 4 +- crates/ty_ide/src/symbols.rs | 352 +++++++++++++----- crates/ty_ide/src/workspace_symbols.rs | 17 +- .../server/api/requests/document_symbols.rs | 40 +- crates/ty_server/src/server/api/symbols.rs | 4 +- 8 files changed, 314 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57df633a4d63d..46071311fd3a6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4241,11 +4241,13 @@ name = "ty_ide" version = "0.0.0" dependencies = [ "bitflags 2.9.2", + "get-size2", "insta", "itertools 0.14.0", "rayon", "regex", "ruff_db", + "ruff_index", "ruff_memory_usage", "ruff_python_ast", "ruff_python_parser", diff --git a/crates/ty_ide/Cargo.toml b/crates/ty_ide/Cargo.toml index bf6d0db7915b7..e00b8db200c66 100644 --- a/crates/ty_ide/Cargo.toml +++ b/crates/ty_ide/Cargo.toml @@ -13,6 +13,7 @@ license = { workspace = true } [dependencies] bitflags = { workspace = true } ruff_db = { workspace = true } +ruff_index = { workspace = true } ruff_memory_usage = { workspace = true } ruff_python_ast = { workspace = true } ruff_python_parser = { workspace = true } @@ -22,6 +23,7 @@ ruff_text_size = { workspace = true } ty_python_semantic = { workspace = true } ty_project = { workspace = true, features = ["testing"] } +get-size2 = { workspace = true } itertools = { workspace = true } rayon = { workspace = true } regex = { workspace = true } diff --git a/crates/ty_ide/src/document_symbols.rs b/crates/ty_ide/src/document_symbols.rs index 2edb70241bd98..8e426168dc807 100644 --- a/crates/ty_ide/src/document_symbols.rs +++ b/crates/ty_ide/src/document_symbols.rs @@ -1,29 +1,16 @@ -use crate::symbols::{SymbolInfo, SymbolsOptions, symbols_for_file}; +use crate::symbols::{FlatSymbols, symbols_for_file}; use ruff_db::files::File; use ty_project::Db; /// Get all document symbols for a file with the given options. -pub fn document_symbols_with_options( - db: &dyn Db, - file: File, - options: &SymbolsOptions, -) -> Vec { - symbols_for_file(db, file, options).cloned().collect() -} - -/// Get all document symbols for a file (hierarchical by default). -pub fn document_symbols(db: &dyn Db, file: File) -> Vec { - let options = SymbolsOptions { - hierarchical: true, - global_only: false, - query_string: None, - }; - document_symbols_with_options(db, file, &options) +pub fn document_symbols(db: &dyn Db, file: File) -> &FlatSymbols { + symbols_for_file(db, file) } #[cfg(test)] mod tests { use super::*; + use crate::symbols::{HierarchicalSymbols, SymbolId, SymbolInfo}; use crate::tests::{CursorTest, IntoDiagnostic, cursor_test}; use insta::assert_snapshot; use ruff_db::diagnostic::{ @@ -324,42 +311,45 @@ class OuterClass: impl CursorTest { fn document_symbols(&self) -> String { - let symbols = document_symbols(&self.db, self.cursor.file); + let symbols = document_symbols(&self.db, self.cursor.file).to_hierarchical(); if symbols.is_empty() { return "No symbols found".to_string(); } - self.render_diagnostics( - symbols - .into_iter() - .flat_map(|symbol| symbol_to_diagnostics(symbol, self.cursor.file)), - ) + self.render_diagnostics(symbols.iter().flat_map(|(id, symbol)| { + symbol_to_diagnostics(&symbols, id, symbol, self.cursor.file) + })) } } - fn symbol_to_diagnostics(symbol: SymbolInfo, file: File) -> Vec { + fn symbol_to_diagnostics<'db>( + symbols: &'db HierarchicalSymbols, + id: SymbolId, + symbol: SymbolInfo<'db>, + file: File, + ) -> Vec> { // Output the symbol and recursively output all child symbols - let mut diagnostics = vec![DocumentSymbolDiagnostic::new(symbol.clone(), file)]; + let mut diagnostics = vec![DocumentSymbolDiagnostic::new(symbol, file)]; - for child in symbol.children { - diagnostics.extend(symbol_to_diagnostics(child, file)); + for (child_id, child) in symbols.children(id) { + diagnostics.extend(symbol_to_diagnostics(symbols, child_id, child, file)); } diagnostics } - struct DocumentSymbolDiagnostic { - symbol: SymbolInfo, + struct DocumentSymbolDiagnostic<'db> { + symbol: SymbolInfo<'db>, file: File, } - impl DocumentSymbolDiagnostic { - fn new(symbol: SymbolInfo, file: File) -> Self { + impl<'db> DocumentSymbolDiagnostic<'db> { + fn new(symbol: SymbolInfo<'db>, file: File) -> Self { Self { symbol, file } } } - impl IntoDiagnostic for DocumentSymbolDiagnostic { + impl IntoDiagnostic for DocumentSymbolDiagnostic<'_> { fn into_diagnostic(self) -> Diagnostic { let symbol_kind_str = self.symbol.kind.to_string(); diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index 922c551ebd7cb..c2567ece0da23 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -26,7 +26,7 @@ mod workspace_symbols; pub use completion::completion; pub use doc_highlights::document_highlights; -pub use document_symbols::{document_symbols, document_symbols_with_options}; +pub use document_symbols::document_symbols; pub use goto::{goto_declaration, goto_definition, goto_type_definition}; pub use goto_references::goto_references; pub use hover::hover; @@ -39,7 +39,7 @@ pub use semantic_tokens::{ SemanticToken, SemanticTokenModifier, SemanticTokenType, SemanticTokens, semantic_tokens, }; pub use signature_help::{ParameterDetails, SignatureDetails, SignatureHelpInfo, signature_help}; -pub use symbols::{SymbolInfo, SymbolKind, SymbolsOptions}; +pub use symbols::{FlatSymbols, HierarchicalSymbols, SymbolId, SymbolInfo, SymbolKind}; pub use workspace_symbols::{WorkspaceSymbolInfo, workspace_symbols}; use ruff_db::files::{File, FileRange}; diff --git a/crates/ty_ide/src/symbols.rs b/crates/ty_ide/src/symbols.rs index 4d4e72ea1fc9a..e787a0c0c067f 100644 --- a/crates/ty_ide/src/symbols.rs +++ b/crates/ty_ide/src/symbols.rs @@ -1,26 +1,22 @@ //! Implements logic used by the document symbol provider, workspace symbol //! provider, and auto-import feature of the completion provider. +use std::borrow::Cow; +use std::ops::Range; + use regex::Regex; use ruff_db::files::File; use ruff_db::parsed::parsed_module; +use ruff_index::{IndexVec, newtype_index}; use ruff_python_ast::visitor::source_order::{self, SourceOrderVisitor}; use ruff_python_ast::{Expr, Stmt}; use ruff_text_size::{Ranged, TextRange}; use ty_project::Db; -/// Options that control which symbols are returned -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct SymbolsOptions { - /// Return a hierarchy of symbols or a flattened list? - pub hierarchical: bool, - /// Include only symbols in the global scope - pub global_only: bool, - /// Query string for filtering symbol names - pub query_string: Option, -} - +/// A compiled query pattern used for searching symbols. +/// +/// This can be used with the `FlatSymbols::search` API. #[derive(Clone, Debug)] pub struct QueryPattern { re: Option, @@ -28,6 +24,7 @@ pub struct QueryPattern { } impl QueryPattern { + /// Create a new query pattern from a literal search string given. pub fn new(literal_query_string: &str) -> QueryPattern { let mut pattern = "(?i)".to_string(); for ch in literal_query_string.chars() { @@ -36,14 +33,16 @@ impl QueryPattern { } // In theory regex compilation could fail if the pattern string // was long enough to exceed the default regex compilation size - // limit. But this length would be approaching ~10MB or so. + // limit. But this length would be approaching ~10MB or so. If + // is does somehow fail, we'll just fall back to simple substring + // search using `original`. QueryPattern { re: Regex::new(&pattern).ok(), original: literal_query_string.to_string(), } } - fn is_match(&self, symbol: &SymbolInfo) -> bool { + fn is_match(&self, symbol: &SymbolInfo<'_>) -> bool { self.is_match_symbol_name(&symbol.name) } @@ -73,23 +72,183 @@ impl PartialEq for QueryPattern { } } +/// A flat list of indexed symbols for a single file. +#[derive(Clone, Debug, Default, PartialEq, Eq, get_size2::GetSize)] +pub struct FlatSymbols { + symbols: IndexVec, +} + +impl FlatSymbols { + /// Get the symbol info for the symbol identified by the given ID. + /// + /// Returns `None` when the given ID does not reference a symbol in this + /// collection. + pub fn get(&self, id: SymbolId) -> Option> { + self.symbols.get(id).map(Into::into) + } + + /// Returns true if and only if this collection is empty. + pub fn is_empty(&self) -> bool { + self.symbols.is_empty() + } + + /// Returns the total number of symbols in this collection. + pub fn len(&self) -> usize { + self.symbols.len() + } + + /// Returns an iterator over every symbol along with its ID. + pub fn iter(&self) -> impl Iterator)> { + self.symbols + .iter_enumerated() + .map(|(id, symbol)| (id, symbol.into())) + } + + /// Returns a sequence of symbols that matches the given query. + pub fn search(&self, query: &QueryPattern) -> impl Iterator)> { + self.iter().filter(|(_, symbol)| query.is_match(symbol)) + } + + /// Turns this flat sequence of symbols into a hierarchy of symbols. + pub fn to_hierarchical(&self) -> HierarchicalSymbols { + let mut children_ids: IndexVec> = IndexVec::new(); + for (id, symbol) in self.symbols.iter_enumerated() { + children_ids.push(vec![]); + let Some(parent_id) = symbol.parent else { + continue; + }; + // OK because the symbol visitor guarantees that + // all parents are ordered before their children. + assert!(parent_id.index() < id.index()); + children_ids[parent_id].push(id); + } + + // Now flatten our map of symbol ID to its children + // IDs into a single vec that doesn't nest allocations. + let mut symbols = IndexVec::new(); + let mut children: Vec = vec![]; + let mut last_end: usize = 0; + for (tree, child_symbol_ids) in self.symbols.iter().zip(children_ids) { + let start = last_end; + let end = start + child_symbol_ids.len(); + symbols.push(SymbolTreeWithChildren { + tree: tree.clone(), + children: start..end, + }); + children.extend_from_slice(&child_symbol_ids); + last_end = end; + } + + HierarchicalSymbols { symbols, children } + } +} + +/// A collection of hierarchical indexed symbols for a single file. +#[derive(Clone, Debug, Default, PartialEq, Eq)] +pub struct HierarchicalSymbols { + symbols: IndexVec, + children: Vec, +} + +impl HierarchicalSymbols { + /// Get the symbol info for the symbol identified by the given ID. + /// + /// Returns `None` when the given ID does not reference a symbol in this + /// collection. + pub fn get(&self, id: SymbolId) -> Option> { + self.symbols.get(id).map(Into::into) + } + + /// Returns true if and only if this collection is empty. + pub fn is_empty(&self) -> bool { + self.symbols.is_empty() + } + + /// Returns the total number of symbols in this collection. + pub fn len(&self) -> usize { + self.symbols.len() + } + + /// Returns an iterator over every top-level symbol along with its ID. + pub fn iter(&self) -> impl Iterator)> { + self.symbols + .iter_enumerated() + .filter(|(_, symbol)| symbol.tree.parent.is_none()) + .map(|(id, symbol)| (id, symbol.into())) + } + + /// Returns an iterator over the child symbols for the symbol + /// identified by the given ID. + /// + /// Returns `None` when there aren't any children or when the given + /// ID does not reference a symbol in this collection. + pub fn children(&self, id: SymbolId) -> impl Iterator)> { + self.symbols + .get(id) + .into_iter() + .flat_map(|symbol| self.children[symbol.children.clone()].iter()) + .copied() + .map(|id| (id, SymbolInfo::from(&self.symbols[id]))) + } +} + +#[derive(Clone, Debug, PartialEq, Eq)] +struct SymbolTreeWithChildren { + tree: SymbolTree, + /// The index range into `HierarchicalSymbols::children` + /// corresponding to the children symbol IDs for this + /// symbol. + children: Range, +} + +/// Uniquely identifies a symbol. +#[newtype_index] +#[derive(get_size2::GetSize)] +pub struct SymbolId; + /// Symbol information for IDE features like document outline. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct SymbolInfo { +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct SymbolInfo<'a> { /// The name of the symbol - pub name: String, + pub name: Cow<'a, str>, /// The kind of symbol (function, class, variable, etc.) pub kind: SymbolKind, /// The range of the symbol name pub name_range: TextRange, /// The full range of the symbol (including body) pub full_range: TextRange, - /// Child symbols (e.g., methods in a class) - pub children: Vec, +} + +impl SymbolInfo<'_> { + pub fn to_owned(&self) -> SymbolInfo<'static> { + SymbolInfo { + name: Cow::Owned(self.name.to_string()), + kind: self.kind, + name_range: self.name_range, + full_range: self.full_range, + } + } +} + +impl<'a> From<&'a SymbolTree> for SymbolInfo<'a> { + fn from(symbol: &'a SymbolTree) -> SymbolInfo<'a> { + SymbolInfo { + name: Cow::Borrowed(&symbol.name), + kind: symbol.kind, + name_range: symbol.name_range, + full_range: symbol.full_range, + } + } +} + +impl<'a> From<&'a SymbolTreeWithChildren> for SymbolInfo<'a> { + fn from(symbol: &'a SymbolTreeWithChildren) -> SymbolInfo<'a> { + SymbolInfo::from(&symbol.tree) + } } /// The kind of symbol -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, get_size2::GetSize)] pub enum SymbolKind { Module, Class, @@ -125,61 +284,68 @@ impl SymbolKind { } } -pub(crate) fn symbols_for_file<'db>( - db: &'db dyn Db, - file: File, - options: &SymbolsOptions, -) -> impl Iterator { - assert!( - !options.hierarchical || options.query_string.is_none(), - "Cannot use hierarchical mode with a query string" - ); - - let ingredient = SymbolsOptionsWithoutQuery { - hierarchical: options.hierarchical, - global_only: options.global_only, - }; - symbols_for_file_inner(db, file, ingredient) - .iter() - .filter(|symbol| { - let Some(ref query) = options.query_string else { - return true; - }; - query.is_match(symbol) - }) -} +/// Returns a flat list of symbols in the file given. +/// +/// The flattened list includes parent/child information and can be +/// converted into a hierarchical collection of symbols. +#[salsa::tracked(returns(ref), heap_size=ruff_memory_usage::heap_size)] +pub(crate) fn symbols_for_file(db: &dyn Db, file: File) -> FlatSymbols { + let parsed = parsed_module(db, file); + let module = parsed.load(db); -#[derive(Clone, Debug, Eq, Hash, PartialEq)] -struct SymbolsOptionsWithoutQuery { - hierarchical: bool, - global_only: bool, + let mut visitor = SymbolVisitor { + symbols: IndexVec::new(), + symbol_stack: vec![], + in_function: false, + global_only: false, + }; + visitor.visit_body(&module.syntax().body); + FlatSymbols { + symbols: visitor.symbols, + } } -#[salsa::tracked(returns(deref))] -fn symbols_for_file_inner<'db>( - db: &'db dyn Db, - file: File, - options: SymbolsOptionsWithoutQuery, -) -> Vec { +/// Returns a flat list of *only global* symbols in the file given. +/// +/// While callers can convert this into a hierarchical collection of +/// symbols, it won't result in anything meaningful since the flat list +/// returned doesn't include children. +#[salsa::tracked(returns(ref), heap_size=ruff_memory_usage::heap_size)] +pub(crate) fn symbols_for_file_global_only(db: &dyn Db, file: File) -> FlatSymbols { let parsed = parsed_module(db, file); let module = parsed.load(db); let mut visitor = SymbolVisitor { - symbols: vec![], + symbols: IndexVec::new(), symbol_stack: vec![], in_function: false, - options, + global_only: true, }; visitor.visit_body(&module.syntax().body); - visitor.symbols + FlatSymbols { + symbols: visitor.symbols, + } +} + +#[derive(Debug, Clone, PartialEq, Eq, get_size2::GetSize)] +struct SymbolTree { + parent: Option, + name: String, + kind: SymbolKind, + name_range: TextRange, + full_range: TextRange, } +/// A visitor over all symbols in a single file. +/// +/// This guarantees that child symbols have a symbol ID greater +/// than all of its parents. struct SymbolVisitor { - symbols: Vec, - symbol_stack: Vec, + symbols: IndexVec, + symbol_stack: Vec, /// Track if we're currently inside a function (to exclude local variables) in_function: bool, - options: SymbolsOptionsWithoutQuery, + global_only: bool, } impl SymbolVisitor { @@ -189,32 +355,33 @@ impl SymbolVisitor { } } - fn add_symbol(&mut self, symbol: SymbolInfo) { - if self.options.hierarchical { - if let Some(parent) = self.symbol_stack.last_mut() { - parent.children.push(symbol); - } else { - self.symbols.push(symbol); - } - } else { - self.symbols.push(symbol); + fn add_symbol(&mut self, mut symbol: SymbolTree) -> SymbolId { + if let Some(&parent_id) = self.symbol_stack.last() { + symbol.parent = Some(parent_id); } + // It's important that we push the symbol and allocate + // an ID before visiting its child. This preserves the + // guarantee that parent IDs are always less than their + // children IDs. + let symbol_id = self.symbols.next_index(); + self.symbols.push(symbol); + symbol_id } - fn push_symbol(&mut self, symbol: SymbolInfo) { - if self.options.hierarchical { - self.symbol_stack.push(symbol); - } else { - self.add_symbol(symbol); - } + fn push_symbol(&mut self, symbol: SymbolTree) { + let symbol_id = self.add_symbol(symbol); + self.symbol_stack.push(symbol_id); } fn pop_symbol(&mut self) { - if self.options.hierarchical { - if let Some(symbol) = self.symbol_stack.pop() { - self.add_symbol(symbol); - } - } + self.symbol_stack.pop().unwrap(); + } + + fn iter_symbol_stack(&self) -> impl Iterator { + self.symbol_stack + .iter() + .copied() + .map(|id| &self.symbols[id]) } fn is_constant_name(name: &str) -> bool { @@ -227,8 +394,7 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { match stmt { Stmt::FunctionDef(func_def) => { let kind = if self - .symbol_stack - .iter() + .iter_symbol_stack() .any(|s| s.kind == SymbolKind::Class) { if func_def.name.as_str() == "__init__" { @@ -240,15 +406,15 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { SymbolKind::Function }; - let symbol = SymbolInfo { + let symbol = SymbolTree { + parent: None, name: func_def.name.to_string(), kind, name_range: func_def.name.range(), full_range: stmt.range(), - children: Vec::new(), }; - if self.options.global_only { + if self.global_only { self.add_symbol(symbol); // If global_only, don't walk function bodies return; @@ -269,15 +435,15 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { } Stmt::ClassDef(class_def) => { - let symbol = SymbolInfo { + let symbol = SymbolTree { + parent: None, name: class_def.name.to_string(), kind: SymbolKind::Class, name_range: class_def.name.range(), full_range: stmt.range(), - children: Vec::new(), }; - if self.options.global_only { + if self.global_only { self.add_symbol(symbol); // If global_only, don't walk class bodies return; @@ -296,8 +462,7 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { let kind = if Self::is_constant_name(name.id.as_str()) { SymbolKind::Constant } else if self - .symbol_stack - .iter() + .iter_symbol_stack() .any(|s| s.kind == SymbolKind::Class) { SymbolKind::Field @@ -305,12 +470,12 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { SymbolKind::Variable }; - let symbol = SymbolInfo { + let symbol = SymbolTree { + parent: None, name: name.id.to_string(), kind, name_range: name.range(), full_range: stmt.range(), - children: Vec::new(), }; self.add_symbol(symbol); @@ -326,8 +491,7 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { let kind = if Self::is_constant_name(name.id.as_str()) { SymbolKind::Constant } else if self - .symbol_stack - .iter() + .iter_symbol_stack() .any(|s| s.kind == SymbolKind::Class) { SymbolKind::Field @@ -335,12 +499,12 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { SymbolKind::Variable }; - let symbol = SymbolInfo { + let symbol = SymbolTree { + parent: None, name: name.id.to_string(), kind, name_range: name.range(), full_range: stmt.range(), - children: Vec::new(), }; self.add_symbol(symbol); diff --git a/crates/ty_ide/src/workspace_symbols.rs b/crates/ty_ide/src/workspace_symbols.rs index 738c208bcb9d2..9d490bd7006ed 100644 --- a/crates/ty_ide/src/workspace_symbols.rs +++ b/crates/ty_ide/src/workspace_symbols.rs @@ -1,4 +1,4 @@ -use crate::symbols::{SymbolInfo, SymbolsOptions, symbols_for_file}; +use crate::symbols::{QueryPattern, SymbolInfo, symbols_for_file_global_only}; use ruff_db::files::File; use ty_project::Db; @@ -12,31 +12,26 @@ pub fn workspace_symbols(db: &dyn Db, query: &str) -> Vec { let project = db.project(); - let options = SymbolsOptions { - hierarchical: false, // Workspace symbols are always flat - global_only: false, - query_string: Some(query.into()), - }; - + let query = QueryPattern::new(query); let files = project.files(db); let results = std::sync::Mutex::new(Vec::new()); { let db = db.dyn_clone(); let files = &files; - let options = &options; let results = &results; + let query = &query; rayon::scope(move |s| { // For each file, extract symbols and add them to results for file in files.iter() { let db = db.dyn_clone(); s.spawn(move |_| { - for symbol in symbols_for_file(&*db, *file, options) { + for (_, symbol) in symbols_for_file_global_only(&*db, *file).search(query) { // It seems like we could do better here than // locking `results` for every single symbol, // but this works pretty well as it is. results.lock().unwrap().push(WorkspaceSymbolInfo { - symbol: symbol.clone(), + symbol: symbol.to_owned(), file: *file, }); } @@ -52,7 +47,7 @@ pub fn workspace_symbols(db: &dyn Db, query: &str) -> Vec { #[derive(Debug, Clone, PartialEq, Eq)] pub struct WorkspaceSymbolInfo { /// The symbol information - pub symbol: SymbolInfo, + pub symbol: SymbolInfo<'static>, /// The file containing the symbol pub file: File, } diff --git a/crates/ty_server/src/server/api/requests/document_symbols.rs b/crates/ty_server/src/server/api/requests/document_symbols.rs index eb19c5826cf2b..46c4c3eb2ead4 100644 --- a/crates/ty_server/src/server/api/requests/document_symbols.rs +++ b/crates/ty_server/src/server/api/requests/document_symbols.rs @@ -4,7 +4,7 @@ use lsp_types::request::DocumentSymbolRequest; use lsp_types::{DocumentSymbol, DocumentSymbolParams, SymbolInformation, Url}; use ruff_db::source::{line_index, source_text}; use ruff_source_file::LineIndex; -use ty_ide::{SymbolInfo, SymbolsOptions, document_symbols_with_options}; +use ty_ide::{HierarchicalSymbols, SymbolId, SymbolInfo, document_symbols}; use ty_project::ProjectDatabase; use crate::document::{PositionEncoding, ToRangeExt}; @@ -51,24 +51,19 @@ impl BackgroundDocumentRequestHandler for DocumentSymbolRequestHandler { .resolved_client_capabilities() .supports_hierarchical_document_symbols(); - let options = SymbolsOptions { - hierarchical: supports_hierarchical, - global_only: false, - query_string: None, - }; - - let symbols = document_symbols_with_options(db, file, &options); - + let symbols = document_symbols(db, file); if symbols.is_empty() { return Ok(None); } if supports_hierarchical { - // Return hierarchical symbols + let symbols = symbols.to_hierarchical(); let lsp_symbols: Vec = symbols - .into_iter() - .map(|symbol| { + .iter() + .map(|(id, symbol)| { convert_to_lsp_document_symbol( + &symbols, + id, symbol, &source, &line_index, @@ -81,8 +76,8 @@ impl BackgroundDocumentRequestHandler for DocumentSymbolRequestHandler { } else { // Return flattened symbols as SymbolInformation let lsp_symbols: Vec = symbols - .into_iter() - .map(|symbol| { + .iter() + .map(|(_, symbol)| { convert_to_lsp_symbol_information( symbol, ¶ms.text_document.uri, @@ -101,7 +96,9 @@ impl BackgroundDocumentRequestHandler for DocumentSymbolRequestHandler { impl RetriableRequestHandler for DocumentSymbolRequestHandler {} fn convert_to_lsp_document_symbol( - symbol: SymbolInfo, + symbols: &HierarchicalSymbols, + id: SymbolId, + symbol: SymbolInfo<'_>, source: &str, line_index: &LineIndex, encoding: PositionEncoding, @@ -109,7 +106,7 @@ fn convert_to_lsp_document_symbol( let symbol_kind = convert_symbol_kind(symbol.kind); DocumentSymbol { - name: symbol.name, + name: symbol.name.into_owned(), detail: None, kind: symbol_kind, tags: None, @@ -118,10 +115,13 @@ fn convert_to_lsp_document_symbol( range: symbol.full_range.to_lsp_range(source, line_index, encoding), selection_range: symbol.name_range.to_lsp_range(source, line_index, encoding), children: Some( - symbol - .children - .into_iter() - .map(|child| convert_to_lsp_document_symbol(child, source, line_index, encoding)) + symbols + .children(id) + .map(|(child_id, child)| { + convert_to_lsp_document_symbol( + symbols, child_id, child, source, line_index, encoding, + ) + }) .collect(), ), } diff --git a/crates/ty_server/src/server/api/symbols.rs b/crates/ty_server/src/server/api/symbols.rs index 39a701e2faca8..396f236e8dfd4 100644 --- a/crates/ty_server/src/server/api/symbols.rs +++ b/crates/ty_server/src/server/api/symbols.rs @@ -27,7 +27,7 @@ pub(crate) fn convert_symbol_kind(kind: ty_ide::SymbolKind) -> SymbolKind { /// Convert a `ty_ide` `SymbolInfo` to LSP `SymbolInformation` pub(crate) fn convert_to_lsp_symbol_information( - symbol: SymbolInfo, + symbol: SymbolInfo<'_>, uri: &Url, source: &str, line_index: &LineIndex, @@ -36,7 +36,7 @@ pub(crate) fn convert_to_lsp_symbol_information( let symbol_kind = convert_symbol_kind(symbol.kind); SymbolInformation { - name: symbol.name, + name: symbol.name.into_owned(), kind: symbol_kind, tags: None, #[allow(deprecated)] From e7237652a9048e5fa0e6ec002855d89f9554833b Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Sat, 23 Aug 2025 08:33:59 -0400 Subject: [PATCH 111/160] [ty] Lightly refactor document symbols AST visitor This makes use of early continue/return to keep rightward drift under control. (I also find it easier to read.) --- crates/ty_ide/src/symbols.rs | 96 ++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/crates/ty_ide/src/symbols.rs b/crates/ty_ide/src/symbols.rs index e787a0c0c067f..646c89537bbd6 100644 --- a/crates/ty_ide/src/symbols.rs +++ b/crates/ty_ide/src/symbols.rs @@ -456,60 +456,60 @@ impl SourceOrderVisitor<'_> for SymbolVisitor { Stmt::Assign(assign) => { // Include assignments only when we're in global or class scope - if !self.in_function { - for target in &assign.targets { - if let Expr::Name(name) = target { - let kind = if Self::is_constant_name(name.id.as_str()) { - SymbolKind::Constant - } else if self - .iter_symbol_stack() - .any(|s| s.kind == SymbolKind::Class) - { - SymbolKind::Field - } else { - SymbolKind::Variable - }; - - let symbol = SymbolTree { - parent: None, - name: name.id.to_string(), - kind, - name_range: name.range(), - full_range: stmt.range(), - }; - - self.add_symbol(symbol); - } - } + if self.in_function { + return; + } + for target in &assign.targets { + let Expr::Name(name) = target else { continue }; + let kind = if Self::is_constant_name(name.id.as_str()) { + SymbolKind::Constant + } else if self + .iter_symbol_stack() + .any(|s| s.kind == SymbolKind::Class) + { + SymbolKind::Field + } else { + SymbolKind::Variable + }; + + let symbol = SymbolTree { + parent: None, + name: name.id.to_string(), + kind, + name_range: name.range(), + full_range: stmt.range(), + }; + self.add_symbol(symbol); } } Stmt::AnnAssign(ann_assign) => { // Include assignments only when we're in global or class scope - if !self.in_function { - if let Expr::Name(name) = &*ann_assign.target { - let kind = if Self::is_constant_name(name.id.as_str()) { - SymbolKind::Constant - } else if self - .iter_symbol_stack() - .any(|s| s.kind == SymbolKind::Class) - { - SymbolKind::Field - } else { - SymbolKind::Variable - }; - - let symbol = SymbolTree { - parent: None, - name: name.id.to_string(), - kind, - name_range: name.range(), - full_range: stmt.range(), - }; - - self.add_symbol(symbol); - } + if self.in_function { + return; } + let Expr::Name(name) = &*ann_assign.target else { + return; + }; + let kind = if Self::is_constant_name(name.id.as_str()) { + SymbolKind::Constant + } else if self + .iter_symbol_stack() + .any(|s| s.kind == SymbolKind::Class) + { + SymbolKind::Field + } else { + SymbolKind::Variable + }; + + let symbol = SymbolTree { + parent: None, + name: name.id.to_string(), + kind, + name_range: name.range(), + full_range: stmt.range(), + }; + self.add_symbol(symbol); } _ => { From ec86a4e960199b527b6645c40c7c4e7a56f70e6c Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 23 Aug 2025 11:20:56 -0700 Subject: [PATCH 112/160] [ty] Add Top[] and Bottom[] special forms, replacing top_materialization_of() function (#20054) Part of astral-sh/ty#994 ## Summary Add new special forms to `ty_extensions`, `Top[T]` and `Bottom[T]`. Remove `ty_extensions.top_materialization` and `ty_extensions.bottom_materialization`. ## Test Plan Converted the existing `materialization.md` mdtest to the new syntax. Added some tests for invalid use of the new special form. --- .../mdtest/type_properties/materialization.md | 365 +++++++++++------- crates/ty_python_semantic/src/types.rs | 17 +- .../ty_python_semantic/src/types/call/bind.rs | 12 - .../src/types/class_base.rs | 2 + .../ty_python_semantic/src/types/function.rs | 8 - crates/ty_python_semantic/src/types/infer.rs | 48 +++ .../src/types/special_form.rs | 12 + .../ty_extensions/ty_extensions.pyi | 12 +- 8 files changed, 291 insertions(+), 185 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md b/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md index e6009f2b5b1f9..2190fd879645b 100644 --- a/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md +++ b/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md @@ -29,22 +29,25 @@ The dynamic type at the top-level is replaced with `object`. ```py from typing import Any, Callable -from ty_extensions import Unknown, top_materialization +from ty_extensions import Unknown, Top -reveal_type(top_materialization(Any)) # revealed: object -reveal_type(top_materialization(Unknown)) # revealed: object +def _(top_any: Top[Any], top_unknown: Top[Unknown]): + reveal_type(top_any) # revealed: object + reveal_type(top_unknown) # revealed: object ``` The contravariant position is replaced with `Never`. ```py -reveal_type(top_materialization(Callable[[Any], None])) # revealed: (Never, /) -> None +def _(top_callable: Top[Callable[[Any], None]]): + reveal_type(top_callable) # revealed: (Never, /) -> None ``` The invariant position is replaced with an unresolved type variable. ```py -reveal_type(top_materialization(list[Any])) # revealed: list[T_all] +def _(top_list: Top[list[Any]]): + reveal_type(top_list) # revealed: list[T_all] ``` ### Bottom materialization @@ -53,24 +56,26 @@ The dynamic type at the top-level is replaced with `Never`. ```py from typing import Any, Callable -from ty_extensions import Unknown, bottom_materialization +from ty_extensions import Unknown, Bottom -reveal_type(bottom_materialization(Any)) # revealed: Never -reveal_type(bottom_materialization(Unknown)) # revealed: Never +def _(bottom_any: Bottom[Any], bottom_unknown: Bottom[Unknown]): + reveal_type(bottom_any) # revealed: Never + reveal_type(bottom_unknown) # revealed: Never ``` The contravariant position is replaced with `object`. ```py -# revealed: (object, object, /) -> None -reveal_type(bottom_materialization(Callable[[Any, Unknown], None])) +def _(bottom_callable: Bottom[Callable[[Any, Unknown], None]]): + reveal_type(bottom_callable) # revealed: (object, object, /) -> None ``` The invariant position is replaced in the same way as the top materialization, with an unresolved type variable. ```py -reveal_type(bottom_materialization(list[Any])) # revealed: list[T_all] +def _(bottom_list: Bottom[list[Any]]): + reveal_type(bottom_list) # revealed: list[T_all] ``` ## Fully static types @@ -79,30 +84,30 @@ The top / bottom (and only) materialization of any fully static type is just its ```py from typing import Any, Literal -from ty_extensions import TypeOf, bottom_materialization, top_materialization +from ty_extensions import TypeOf, Bottom, Top, is_equivalent_to, static_assert from enum import Enum class Answer(Enum): NO = 0 YES = 1 -reveal_type(top_materialization(int)) # revealed: int -reveal_type(bottom_materialization(int)) # revealed: int +static_assert(is_equivalent_to(Top[int], int)) +static_assert(is_equivalent_to(Bottom[int], int)) -reveal_type(top_materialization(Literal[1])) # revealed: Literal[1] -reveal_type(bottom_materialization(Literal[1])) # revealed: Literal[1] +static_assert(is_equivalent_to(Top[Literal[1]], Literal[1])) +static_assert(is_equivalent_to(Bottom[Literal[1]], Literal[1])) -reveal_type(top_materialization(Literal[True])) # revealed: Literal[True] -reveal_type(bottom_materialization(Literal[True])) # revealed: Literal[True] +static_assert(is_equivalent_to(Top[Literal[True]], Literal[True])) +static_assert(is_equivalent_to(Bottom[Literal[True]], Literal[True])) -reveal_type(top_materialization(Literal["abc"])) # revealed: Literal["abc"] -reveal_type(bottom_materialization(Literal["abc"])) # revealed: Literal["abc"] +static_assert(is_equivalent_to(Top[Literal["abc"]], Literal["abc"])) +static_assert(is_equivalent_to(Bottom[Literal["abc"]], Literal["abc"])) -reveal_type(top_materialization(Literal[Answer.YES])) # revealed: Literal[Answer.YES] -reveal_type(bottom_materialization(Literal[Answer.YES])) # revealed: Literal[Answer.YES] +static_assert(is_equivalent_to(Top[Literal[Answer.YES]], Literal[Answer.YES])) +static_assert(is_equivalent_to(Bottom[Literal[Answer.YES]], Literal[Answer.YES])) -reveal_type(top_materialization(int | str)) # revealed: int | str -reveal_type(bottom_materialization(int | str)) # revealed: int | str +static_assert(is_equivalent_to(Top[int | str], int | str)) +static_assert(is_equivalent_to(Bottom[int | str], int | str)) ``` We currently treat function literals as fully static types, so they remain unchanged even though the @@ -114,11 +119,17 @@ def function(x: Any) -> None: ... class A: def method(self, x: Any) -> None: ... -reveal_type(top_materialization(TypeOf[function])) # revealed: def function(x: Any) -> None -reveal_type(bottom_materialization(TypeOf[function])) # revealed: def function(x: Any) -> None - -reveal_type(top_materialization(TypeOf[A().method])) # revealed: bound method A.method(x: Any) -> None -reveal_type(bottom_materialization(TypeOf[A().method])) # revealed: bound method A.method(x: Any) -> None +def _( + top_func: Top[TypeOf[function]], + bottom_func: Bottom[TypeOf[function]], + top_meth: Top[TypeOf[A().method]], + bottom_meth: Bottom[TypeOf[A().method]], +): + reveal_type(top_func) # revealed: def function(x: Any) -> None + reveal_type(bottom_func) # revealed: def function(x: Any) -> None + + reveal_type(top_meth) # revealed: bound method A.method(x: Any) -> None + reveal_type(bottom_meth) # revealed: bound method A.method(x: Any) -> None ``` ## Callable @@ -126,27 +137,30 @@ reveal_type(bottom_materialization(TypeOf[A().method])) # revealed: bound metho For a callable, the parameter types are in a contravariant position, and the return type is in a covariant position. +```toml +[environment] +python-version = "3.12" +``` + ```py from typing import Any, Callable -from ty_extensions import TypeOf, Unknown, bottom_materialization, top_materialization +from ty_extensions import TypeOf, Unknown, Bottom, Top -def _(callable: Callable[[Any, Unknown], Any]) -> None: - # revealed: (Never, Never, /) -> object - reveal_type(top_materialization(TypeOf[callable])) +type C1 = Callable[[Any, Unknown], Any] - # revealed: (object, object, /) -> Never - reveal_type(bottom_materialization(TypeOf[callable])) +def _(top: Top[C1], bottom: Bottom[C1]) -> None: + reveal_type(top) # revealed: (Never, Never, /) -> object + reveal_type(bottom) # revealed: (object, object, /) -> Never ``` The parameter types in a callable inherits the contravariant position. ```py -def _(callable: Callable[[int, tuple[int | Any]], tuple[Any]]) -> None: - # revealed: (int, tuple[int], /) -> tuple[object] - reveal_type(top_materialization(TypeOf[callable])) +type C2 = Callable[[int, tuple[int | Any]], tuple[Any]] - # revealed: (int, tuple[object], /) -> Never - reveal_type(bottom_materialization(TypeOf[callable])) +def _(top: Top[C2], bottom: Bottom[C2]) -> None: + reveal_type(top) # revealed: (int, tuple[int], /) -> tuple[object] + reveal_type(bottom) # revealed: (int, tuple[object], /) -> Never ``` But, if the callable itself is in a contravariant position, then the variance is flipped i.e., if @@ -154,30 +168,37 @@ the outer variance is covariant, it's flipped to contravariant, and if it's cont flipped to covariant, invariant remains invariant. ```py -def _(callable: Callable[[Any, Callable[[Unknown], Any]], Callable[[Any, int], Any]]) -> None: +type C3 = Callable[[Any, Callable[[Unknown], Any]], Callable[[Any, int], Any]] + +def _(top: Top[C3], bottom: Bottom[C3]) -> None: # revealed: (Never, (object, /) -> Never, /) -> (Never, int, /) -> object - reveal_type(top_materialization(TypeOf[callable])) + reveal_type(top) # revealed: (object, (Never, /) -> object, /) -> (object, int, /) -> Never - reveal_type(bottom_materialization(TypeOf[callable])) + reveal_type(bottom) ``` ## Tuple All positions in a tuple are covariant. +```toml +[environment] +python-version = "3.12" +``` + ```py -from typing import Any -from ty_extensions import Unknown, bottom_materialization, top_materialization +from typing import Any, Never +from ty_extensions import Unknown, Bottom, Top, is_equivalent_to, static_assert -reveal_type(top_materialization(tuple[Any, int])) # revealed: tuple[object, int] -reveal_type(bottom_materialization(tuple[Any, int])) # revealed: Never +static_assert(is_equivalent_to(Top[tuple[Any, int]], tuple[object, int])) +static_assert(is_equivalent_to(Bottom[tuple[Any, int]], Never)) -reveal_type(top_materialization(tuple[Unknown, int])) # revealed: tuple[object, int] -reveal_type(bottom_materialization(tuple[Unknown, int])) # revealed: Never +static_assert(is_equivalent_to(Top[tuple[Unknown, int]], tuple[object, int])) +static_assert(is_equivalent_to(Bottom[tuple[Unknown, int]], Never)) -reveal_type(top_materialization(tuple[Any, int, Unknown])) # revealed: tuple[object, int, object] -reveal_type(bottom_materialization(tuple[Any, int, Unknown])) # revealed: Never +static_assert(is_equivalent_to(Top[tuple[Any, int, Unknown]], tuple[object, int, object])) +static_assert(is_equivalent_to(Bottom[tuple[Any, int, Unknown]], Never)) ``` Except for when the tuple itself is in a contravariant position, then all positions in the tuple @@ -187,43 +208,59 @@ inherit the contravariant position. from typing import Callable from ty_extensions import TypeOf -def _(callable: Callable[[tuple[Any, int], tuple[str, Unknown]], None]) -> None: - # revealed: (Never, Never, /) -> None - reveal_type(top_materialization(TypeOf[callable])) +type C = Callable[[tuple[Any, int], tuple[str, Unknown]], None] - # revealed: (tuple[object, int], tuple[str, object], /) -> None - reveal_type(bottom_materialization(TypeOf[callable])) +def _(top: Top[C], bottom: Bottom[C]) -> None: + reveal_type(top) # revealed: (Never, Never, /) -> None + reveal_type(bottom) # revealed: (tuple[object, int], tuple[str, object], /) -> None ``` And, similarly for an invariant position. ```py -reveal_type(top_materialization(list[tuple[Any, int]])) # revealed: list[tuple[T_all, int]] -reveal_type(bottom_materialization(list[tuple[Any, int]])) # revealed: list[tuple[T_all, int]] - -reveal_type(top_materialization(list[tuple[str, Unknown]])) # revealed: list[tuple[str, T_all]] -reveal_type(bottom_materialization(list[tuple[str, Unknown]])) # revealed: list[tuple[str, T_all]] - -reveal_type(top_materialization(list[tuple[Any, int, Unknown]])) # revealed: list[tuple[T_all, int, T_all]] -reveal_type(bottom_materialization(list[tuple[Any, int, Unknown]])) # revealed: list[tuple[T_all, int, T_all]] +type LTAnyInt = list[tuple[Any, int]] +type LTStrUnknown = list[tuple[str, Unknown]] +type LTAnyIntUnknown = list[tuple[Any, int, Unknown]] + +def _( + top_ai: Top[LTAnyInt], + bottom_ai: Bottom[LTAnyInt], + top_su: Top[LTStrUnknown], + bottom_su: Bottom[LTStrUnknown], + top_aiu: Top[LTAnyIntUnknown], + bottom_aiu: Bottom[LTAnyIntUnknown], +): + reveal_type(top_ai) # revealed: list[tuple[T_all, int]] + reveal_type(bottom_ai) # revealed: list[tuple[T_all, int]] + + reveal_type(top_su) # revealed: list[tuple[str, T_all]] + reveal_type(bottom_su) # revealed: list[tuple[str, T_all]] + + reveal_type(top_aiu) # revealed: list[tuple[T_all, int, T_all]] + reveal_type(bottom_aiu) # revealed: list[tuple[T_all, int, T_all]] ``` ## Union All positions in a union are covariant. +```toml +[environment] +python-version = "3.12" +``` + ```py from typing import Any -from ty_extensions import Unknown, bottom_materialization, top_materialization +from ty_extensions import Unknown, Bottom, Top, static_assert, is_equivalent_to -reveal_type(top_materialization(Any | int)) # revealed: object -reveal_type(bottom_materialization(Any | int)) # revealed: int +static_assert(is_equivalent_to(Top[Any | int], object)) +static_assert(is_equivalent_to(Bottom[Any | int], int)) -reveal_type(top_materialization(Unknown | int)) # revealed: object -reveal_type(bottom_materialization(Unknown | int)) # revealed: int +static_assert(is_equivalent_to(Top[Unknown | int], object)) +static_assert(is_equivalent_to(Bottom[Unknown | int], int)) -reveal_type(top_materialization(int | str | Any)) # revealed: object -reveal_type(bottom_materialization(int | str | Any)) # revealed: int | str +static_assert(is_equivalent_to(Top[int | str | Any], object)) +static_assert(is_equivalent_to(Bottom[int | str | Any], int | str)) ``` Except for when the union itself is in a contravariant position, then all positions in the union @@ -234,24 +271,29 @@ from typing import Callable from ty_extensions import TypeOf def _(callable: Callable[[Any | int, str | Unknown], None]) -> None: - # revealed: (int, str, /) -> None - reveal_type(top_materialization(TypeOf[callable])) - - # revealed: (object, object, /) -> None - reveal_type(bottom_materialization(TypeOf[callable])) + static_assert(is_equivalent_to(Top[TypeOf[callable]], Callable[[int, str], None])) + static_assert(is_equivalent_to(Bottom[TypeOf[callable]], Callable[[object, object], None])) ``` And, similarly for an invariant position. ```py -reveal_type(top_materialization(list[Any | int])) # revealed: list[T_all | int] -reveal_type(bottom_materialization(list[Any | int])) # revealed: list[T_all | int] - -reveal_type(top_materialization(list[str | Unknown])) # revealed: list[str | T_all] -reveal_type(bottom_materialization(list[str | Unknown])) # revealed: list[str | T_all] - -reveal_type(top_materialization(list[Any | int | Unknown])) # revealed: list[T_all | int] -reveal_type(bottom_materialization(list[Any | int | Unknown])) # revealed: list[T_all | int] +def _( + top_ai: Top[list[Any | int]], + bottom_ai: Bottom[list[Any | int]], + top_su: Top[list[str | Unknown]], + bottom_su: Bottom[list[str | Unknown]], + top_aiu: Top[list[Any | int | Unknown]], + bottom_aiu: Bottom[list[Any | int | Unknown]], +): + reveal_type(top_ai) # revealed: list[T_all | int] + reveal_type(bottom_ai) # revealed: list[T_all | int] + + reveal_type(top_su) # revealed: list[str | T_all] + reveal_type(bottom_su) # revealed: list[str | T_all] + + reveal_type(top_aiu) # revealed: list[T_all | int] + reveal_type(bottom_aiu) # revealed: list[T_all | int] ``` ## Intersection @@ -260,24 +302,26 @@ All positions in an intersection are covariant. ```py from typing import Any -from ty_extensions import Intersection, Unknown, bottom_materialization, top_materialization +from typing_extensions import Never +from ty_extensions import Intersection, Unknown, Bottom, Top, static_assert, is_equivalent_to -reveal_type(top_materialization(Intersection[Any, int])) # revealed: int -reveal_type(bottom_materialization(Intersection[Any, int])) # revealed: Never +static_assert(is_equivalent_to(Top[Intersection[Any, int]], int)) +static_assert(is_equivalent_to(Bottom[Intersection[Any, int]], Never)) # Here, the top materialization of `Any | int` is `object` and the intersection of it with tuple -# revealed: tuple[str, object] -reveal_type(top_materialization(Intersection[Any | int, tuple[str, Unknown]])) -# revealed: Never -reveal_type(bottom_materialization(Intersection[Any | int, tuple[str, Unknown]])) +static_assert(is_equivalent_to(Top[Intersection[Any | int, tuple[str, Unknown]]], tuple[str, object])) +static_assert(is_equivalent_to(Bottom[Intersection[Any | int, tuple[str, Unknown]]], Never)) class Foo: ... -# revealed: Foo & tuple[str] -reveal_type(bottom_materialization(Intersection[Any | Foo, tuple[str]])) +static_assert(is_equivalent_to(Bottom[Intersection[Any | Foo, tuple[str]]], Intersection[Foo, tuple[str]])) -reveal_type(top_materialization(Intersection[list[Any], list[int]])) # revealed: list[T_all] & list[int] -reveal_type(bottom_materialization(Intersection[list[Any], list[int]])) # revealed: list[T_all] & list[int] +def _( + top: Top[Intersection[list[Any], list[int]]], + bottom: Bottom[Intersection[list[Any], list[int]]], +): + reveal_type(top) # revealed: list[T_all] & list[int] + reveal_type(bottom) # revealed: list[T_all] & list[int] ``` ## Negation (via `Not`) @@ -286,38 +330,44 @@ All positions in a negation are contravariant. ```py from typing import Any -from ty_extensions import Not, Unknown, bottom_materialization, top_materialization +from typing_extensions import Never +from ty_extensions import Not, Unknown, Bottom, Top, static_assert, is_equivalent_to # ~Any is still Any, so the top materialization is object -reveal_type(top_materialization(Not[Any])) # revealed: object -reveal_type(bottom_materialization(Not[Any])) # revealed: Never +static_assert(is_equivalent_to(Top[Not[Any]], object)) +static_assert(is_equivalent_to(Bottom[Not[Any]], Never)) # tuple[Any, int] is in a contravariant position, so the # top materialization is Never and the negation of it -# revealed: object -reveal_type(top_materialization(Not[tuple[Any, int]])) -# revealed: ~tuple[object, int] -reveal_type(bottom_materialization(Not[tuple[Any, int]])) +static_assert(is_equivalent_to(Top[Not[tuple[Any, int]]], object)) +static_assert(is_equivalent_to(Bottom[Not[tuple[Any, int]]], Not[tuple[object, int]])) ``` ## `type` +```toml +[environment] +python-version = "3.12" +``` + ```py from typing import Any -from ty_extensions import Unknown, bottom_materialization, top_materialization +from typing_extensions import Never +from ty_extensions import Unknown, Bottom, Top, static_assert, is_equivalent_to -reveal_type(top_materialization(type[Any])) # revealed: type -reveal_type(bottom_materialization(type[Any])) # revealed: Never +static_assert(is_equivalent_to(Top[type[Any]], type)) +static_assert(is_equivalent_to(Bottom[type[Any]], Never)) -reveal_type(top_materialization(type[Unknown])) # revealed: type -reveal_type(bottom_materialization(type[Unknown])) # revealed: Never +static_assert(is_equivalent_to(Top[type[Unknown]], type)) +static_assert(is_equivalent_to(Bottom[type[Unknown]], Never)) -reveal_type(top_materialization(type[int | Any])) # revealed: type -reveal_type(bottom_materialization(type[int | Any])) # revealed: type[int] +static_assert(is_equivalent_to(Top[type[int | Any]], type)) +static_assert(is_equivalent_to(Bottom[type[int | Any]], type[int])) # Here, `T` has an upper bound of `type` -reveal_type(top_materialization(list[type[Any]])) # revealed: list[T_all] -reveal_type(bottom_materialization(list[type[Any]])) # revealed: list[T_all] +def _(top: Top[list[type[Any]]], bottom: Bottom[list[type[Any]]]): + reveal_type(top) # revealed: list[T_all] + reveal_type(bottom) # revealed: list[T_all] ``` ## Type variables @@ -329,26 +379,19 @@ python-version = "3.12" ```py from typing import Any, Never, TypeVar -from ty_extensions import ( - TypeOf, - Unknown, - bottom_materialization, - top_materialization, - static_assert, - is_subtype_of, -) +from ty_extensions import Unknown, Bottom, Top, static_assert, is_subtype_of def bounded_by_gradual[T: Any](t: T) -> None: # Top materialization of `T: Any` is `T: object` # Bottom materialization of `T: Any` is `T: Never` - static_assert(is_subtype_of(TypeOf[bottom_materialization(T)], Never)) + static_assert(is_subtype_of(Bottom[T], Never)) def constrained_by_gradual[T: (int, Any)](t: T) -> None: # Top materialization of `T: (int, Any)` is `T: (int, object)` # Bottom materialization of `T: (int, Any)` is `T: (int, Never)` - static_assert(is_subtype_of(TypeOf[bottom_materialization(T)], int)) + static_assert(is_subtype_of(Bottom[T], int)) ``` ## Generics @@ -361,9 +404,14 @@ variable itself. - If the type variable is contravariant, the materialization happens as per the surrounding variance, but the variance is flipped +```toml +[environment] +python-version = "3.12" +``` + ```py -from typing import Any, Generic, TypeVar -from ty_extensions import bottom_materialization, top_materialization +from typing import Any, Generic, TypeVar, Never +from ty_extensions import Bottom, Top, static_assert, is_equivalent_to T = TypeVar("T") T_co = TypeVar("T_co", covariant=True) @@ -378,14 +426,15 @@ class GenericCovariant(Generic[T_co]): class GenericContravariant(Generic[T_contra]): pass -reveal_type(top_materialization(GenericInvariant[Any])) # revealed: GenericInvariant[T_all] -reveal_type(bottom_materialization(GenericInvariant[Any])) # revealed: GenericInvariant[T_all] +def _(top: Top[GenericInvariant[Any]], bottom: Bottom[GenericInvariant[Any]]): + reveal_type(top) # revealed: GenericInvariant[T_all] + reveal_type(bottom) # revealed: GenericInvariant[T_all] -reveal_type(top_materialization(GenericCovariant[Any])) # revealed: GenericCovariant[object] -reveal_type(bottom_materialization(GenericCovariant[Any])) # revealed: GenericCovariant[Never] +static_assert(is_equivalent_to(Top[GenericCovariant[Any]], GenericCovariant[object])) +static_assert(is_equivalent_to(Bottom[GenericCovariant[Any]], GenericCovariant[Never])) -reveal_type(top_materialization(GenericContravariant[Any])) # revealed: GenericContravariant[Never] -reveal_type(bottom_materialization(GenericContravariant[Any])) # revealed: GenericContravariant[object] +static_assert(is_equivalent_to(Top[GenericContravariant[Any]], GenericContravariant[Never])) +static_assert(is_equivalent_to(Bottom[GenericContravariant[Any]], GenericContravariant[object])) ``` Parameters in callable are contravariant, so the variance should be flipped: @@ -394,24 +443,52 @@ Parameters in callable are contravariant, so the variance should be flipped: from typing import Callable from ty_extensions import TypeOf -def invariant(callable: Callable[[GenericInvariant[Any]], None]) -> None: - # revealed: (GenericInvariant[T_all], /) -> None - reveal_type(top_materialization(TypeOf[callable])) +type InvariantCallable = Callable[[GenericInvariant[Any]], None] +type CovariantCallable = Callable[[GenericCovariant[Any]], None] +type ContravariantCallable = Callable[[GenericContravariant[Any]], None] + +def invariant(top: Top[InvariantCallable], bottom: Bottom[InvariantCallable]) -> None: + reveal_type(top) # revealed: (GenericInvariant[T_all], /) -> None + reveal_type(bottom) # revealed: (GenericInvariant[T_all], /) -> None - # revealed: (GenericInvariant[T_all], /) -> None - reveal_type(bottom_materialization(TypeOf[callable])) +def covariant(top: Top[CovariantCallable], bottom: Bottom[CovariantCallable]) -> None: + reveal_type(top) # revealed: (GenericCovariant[Never], /) -> None + reveal_type(bottom) # revealed: (GenericCovariant[object], /) -> None -def covariant(callable: Callable[[GenericCovariant[Any]], None]) -> None: - # revealed: (GenericCovariant[Never], /) -> None - reveal_type(top_materialization(TypeOf[callable])) +def contravariant(top: Top[ContravariantCallable], bottom: Bottom[ContravariantCallable]) -> None: + reveal_type(top) # revealed: (GenericContravariant[object], /) -> None + reveal_type(bottom) # revealed: (GenericContravariant[Never], /) -> None +``` - # revealed: (GenericCovariant[object], /) -> None - reveal_type(bottom_materialization(TypeOf[callable])) +## Invalid use -def contravariant(callable: Callable[[GenericContravariant[Any]], None]) -> None: - # revealed: (GenericContravariant[object], /) -> None - reveal_type(top_materialization(TypeOf[callable])) +`Top[]` and `Bottom[]` are special forms that take a single argument. - # revealed: (GenericContravariant[Never], /) -> None - reveal_type(bottom_materialization(TypeOf[callable])) +It is invalid to use them without a type argument. + +```py +from ty_extensions import Bottom, Top + +def _( + just_top: Top, # error: [invalid-type-form] + just_bottom: Bottom, # error: [invalid-type-form] +): ... +``` + +It is also invalid to use multiple arguments: + +```py +def _( + top_two: Top[int, str], # error: [invalid-type-form] + bottom_two: Bottom[int, str], # error: [invalid-type-form] +): ... +``` + +The argument must be a type expression: + +```py +def _( + top_1: Top[1], # error: [invalid-type-form] + bottom_1: Bottom[1], # error: [invalid-type-form] +): ... ``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index fe88b3fa7d6b1..b1fb7dddc67d5 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -4143,21 +4143,6 @@ impl<'db> Type<'db> { .into() } - Some(KnownFunction::TopMaterialization | KnownFunction::BottomMaterialization) => { - Binding::single( - self, - Signature::new( - Parameters::new([Parameter::positional_only(Some(Name::new_static( - "type", - ))) - .type_form() - .with_annotated_type(Type::any())]), - Some(Type::any()), - ), - ) - .into() - } - Some(KnownFunction::AssertType) => Binding::single( self, Signature::new( @@ -5741,6 +5726,8 @@ impl<'db> Type<'db> { SpecialFormType::Optional | SpecialFormType::Not + | SpecialFormType::Top + | SpecialFormType::Bottom | SpecialFormType::TypeOf | SpecialFormType::TypeIs | SpecialFormType::TypeGuard diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index 8d728840d9b45..d2d46a2baabb6 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -726,18 +726,6 @@ impl<'db> Bindings<'db> { } } - Some(KnownFunction::TopMaterialization) => { - if let [Some(ty)] = overload.parameter_types() { - overload.set_return_type(ty.top_materialization(db)); - } - } - - Some(KnownFunction::BottomMaterialization) => { - if let [Some(ty)] = overload.parameter_types() { - overload.set_return_type(ty.bottom_materialization(db)); - } - } - Some(KnownFunction::Len) => { if let [Some(first_arg)] = overload.parameter_types() { if let Some(len_ty) = first_arg.len(db) { diff --git a/crates/ty_python_semantic/src/types/class_base.rs b/crates/ty_python_semantic/src/types/class_base.rs index 2d05ca04cebce..eeb83a3cbb2b3 100644 --- a/crates/ty_python_semantic/src/types/class_base.rs +++ b/crates/ty_python_semantic/src/types/class_base.rs @@ -192,6 +192,8 @@ impl<'db> ClassBase<'db> { | SpecialFormType::ReadOnly | SpecialFormType::Optional | SpecialFormType::Not + | SpecialFormType::Top + | SpecialFormType::Bottom | SpecialFormType::Intersection | SpecialFormType::TypeOf | SpecialFormType::CallableTypeOf diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index dde034efc4587..8f71854fd8974 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -1168,10 +1168,6 @@ pub enum KnownFunction { AllMembers, /// `ty_extensions.has_member` HasMember, - /// `ty_extensions.top_materialization` - TopMaterialization, - /// `ty_extensions.bottom_materialization` - BottomMaterialization, /// `ty_extensions.reveal_protocol_interface` RevealProtocolInterface, } @@ -1232,8 +1228,6 @@ impl KnownFunction { | Self::IsSingleValued | Self::IsSingleton | Self::IsSubtypeOf - | Self::TopMaterialization - | Self::BottomMaterialization | Self::GenericContext | Self::DunderAllNames | Self::EnumMembers @@ -1569,8 +1563,6 @@ pub(crate) mod tests { | KnownFunction::IsSingleValued | KnownFunction::IsAssignableTo | KnownFunction::IsEquivalentTo - | KnownFunction::TopMaterialization - | KnownFunction::BottomMaterialization | KnownFunction::HasMember | KnownFunction::RevealProtocolInterface | KnownFunction::AllMembers => KnownModule::TyExtensions, diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 0cb21ae2f9729..9b8b43103e35e 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -10599,6 +10599,54 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } ty } + SpecialFormType::Top => { + let arguments = if let ast::Expr::Tuple(tuple) = arguments_slice { + &*tuple.elts + } else { + std::slice::from_ref(arguments_slice) + }; + let num_arguments = arguments.len(); + let arg = if num_arguments == 1 { + self.infer_type_expression(&arguments[0]) + } else { + for argument in arguments { + self.infer_type_expression(argument); + } + report_invalid_argument_number_to_special_form( + &self.context, + subscript, + special_form, + num_arguments, + 1, + ); + Type::unknown() + }; + arg.top_materialization(db) + } + SpecialFormType::Bottom => { + let arguments = if let ast::Expr::Tuple(tuple) = arguments_slice { + &*tuple.elts + } else { + std::slice::from_ref(arguments_slice) + }; + let num_arguments = arguments.len(); + let arg = if num_arguments == 1 { + self.infer_type_expression(&arguments[0]) + } else { + for argument in arguments { + self.infer_type_expression(argument); + } + report_invalid_argument_number_to_special_form( + &self.context, + subscript, + special_form, + num_arguments, + 1, + ); + Type::unknown() + }; + arg.bottom_materialization(db) + } SpecialFormType::TypeOf => { let arguments = if let ast::Expr::Tuple(tuple) = arguments_slice { &*tuple.elts diff --git a/crates/ty_python_semantic/src/types/special_form.rs b/crates/ty_python_semantic/src/types/special_form.rs index 3683283dfab0a..494e7331ce22e 100644 --- a/crates/ty_python_semantic/src/types/special_form.rs +++ b/crates/ty_python_semantic/src/types/special_form.rs @@ -77,6 +77,10 @@ pub enum SpecialFormType { TypeOf, /// The symbol `ty_extensions.CallableTypeOf` CallableTypeOf, + /// The symbol `ty_extensions.Top` + Top, + /// The symbol `ty_extensions.Bottom` + Bottom, /// The symbol `typing.Callable` /// (which can also be found as `typing_extensions.Callable` or as `collections.abc.Callable`) Callable, @@ -151,6 +155,8 @@ impl SpecialFormType { | Self::TypeIs | Self::TypeOf | Self::Not + | Self::Top + | Self::Bottom | Self::Intersection | Self::CallableTypeOf | Self::Protocol // actually `_ProtocolMeta` at runtime but this is what typeshed says @@ -247,6 +253,8 @@ impl SpecialFormType { | Self::AlwaysTruthy | Self::AlwaysFalsy | Self::Not + | Self::Top + | Self::Bottom | Self::Intersection | Self::TypeOf | Self::CallableTypeOf => module.is_ty_extensions(), @@ -291,6 +299,8 @@ impl SpecialFormType { | Self::AlwaysTruthy | Self::AlwaysFalsy | Self::Not + | Self::Top + | Self::Bottom | Self::Intersection | Self::TypeOf | Self::CallableTypeOf @@ -352,6 +362,8 @@ impl SpecialFormType { SpecialFormType::Intersection => "ty_extensions.Intersection", SpecialFormType::TypeOf => "ty_extensions.TypeOf", SpecialFormType::CallableTypeOf => "ty_extensions.CallableTypeOf", + SpecialFormType::Top => "ty_extensions.Top", + SpecialFormType::Bottom => "ty_extensions.Bottom", SpecialFormType::Protocol => "typing.Protocol", SpecialFormType::Generic => "typing.Generic", SpecialFormType::NamedTuple => "typing.NamedTuple", diff --git a/crates/ty_vendored/ty_extensions/ty_extensions.pyi b/crates/ty_vendored/ty_extensions/ty_extensions.pyi index 6968bcb75a89d..92526934020b2 100644 --- a/crates/ty_vendored/ty_extensions/ty_extensions.pyi +++ b/crates/ty_vendored/ty_extensions/ty_extensions.pyi @@ -24,6 +24,12 @@ Not: _SpecialForm Intersection: _SpecialForm TypeOf: _SpecialForm CallableTypeOf: _SpecialForm +# Top[T] evaluates to the top materialization of T, a type that is a supertype +# of every materialization of T. +Top: _SpecialForm +# Bottom[T] evaluates to the bottom materialization of T, a type that is a subtype +# of every materialization of T. +Bottom: _SpecialForm # ty treats annotations of `float` to mean `float | int`, and annotations of `complex` # to mean `complex | float | int`. This is to support a typing-system special case [1]. @@ -56,12 +62,6 @@ def dunder_all_names(module: Any) -> Any: ... # List all members of an enum. def enum_members[E: type[Enum]](enum: E) -> tuple[str, ...]: ... -# Returns the type that's an upper bound of materializing the given (gradual) type. -def top_materialization(type: Any) -> Any: ... - -# Returns the type that's a lower bound of materializing the given (gradual) type. -def bottom_materialization(type: Any) -> Any: ... - # Returns a tuple of all members of the given object, similar to `dir(obj)` and # `inspect.getmembers(obj)`, with at least the following differences: # From 48edf46f3b364572bb9f6fa8043a1d93ec172ef6 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:19:34 -0400 Subject: [PATCH 113/160] Update Rust crate filetime to v0.2.26 (#20064) --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46071311fd3a6..a44375bb13c46 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1084,14 +1084,14 @@ dependencies = [ [[package]] name = "filetime" -version = "0.2.25" +version = "0.2.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35c0522e981e68cbfa8c3f978441a5f34b30b96e146b33cd3359176b50fe8586" +checksum = "bc0505cd1b6fa6580283f6bdf70a73fcf4aba1184038c90902b92b3dd0df63ed" dependencies = [ "cfg-if", "libc", "libredox", - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] From 862d2d0687df99254bcc26778df5faccfb40601f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:19:44 -0400 Subject: [PATCH 114/160] Update dependency ruff to v0.12.10 (#20062) --- docs/requirements-insiders.txt | 2 +- docs/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/requirements-insiders.txt b/docs/requirements-insiders.txt index 3da4b69557420..56638e8d4b3be 100644 --- a/docs/requirements-insiders.txt +++ b/docs/requirements-insiders.txt @@ -1,5 +1,5 @@ PyYAML==6.0.2 -ruff==0.12.9 +ruff==0.12.10 mkdocs==1.6.1 mkdocs-material @ git+ssh://git@github.com/astral-sh/mkdocs-material-insiders.git@39da7a5e761410349e9a1b8abf593b0cdd5453ff mkdocs-redirects==1.2.2 diff --git a/docs/requirements.txt b/docs/requirements.txt index baf3c32b4fe48..5187d559d44c9 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ PyYAML==6.0.2 -ruff==0.12.9 +ruff==0.12.10 mkdocs==1.6.1 mkdocs-material==9.5.38 mkdocs-redirects==1.2.2 From 59f7102606359d0c57d19543f40d84fd6e075911 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:19:54 -0400 Subject: [PATCH 115/160] Update Rust crate bitflags to v2.9.3 (#20063) --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a44375bb13c46..2f006ea524b58 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -257,9 +257,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.2" +version = "2.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a65b545ab31d687cff52899d4890855fec459eb6afe0da6417b8a18da87aa29" +checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" [[package]] name = "bitvec" @@ -1241,7 +1241,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "ignore", "walkdir", ] @@ -1521,7 +1521,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f37dccff2791ab604f9babef0ba14fbe0be30bd368dc541e2b08d07c8aa908f3" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "inotify-sys", "libc", ] @@ -1809,7 +1809,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "libc", "redox_syscall", ] @@ -2014,7 +2014,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "cfg-if", "cfg_aliases", "libc", @@ -2026,7 +2026,7 @@ version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "cfg-if", "cfg_aliases", "libc", @@ -2054,7 +2054,7 @@ version = "8.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d3d07927151ff8575b7087f245456e549fea62edf0ec4e565a5ee50c8402bc3" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "fsevent-sys", "inotify", "kqueue", @@ -2666,7 +2666,7 @@ version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5407465600fb0548f1442edf71dd20683c6ed326200ace4b1ef0763521bb3b77" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", ] [[package]] @@ -2749,7 +2749,7 @@ dependencies = [ "argfile", "assert_fs", "bincode 2.0.1", - "bitflags 2.9.2", + "bitflags 2.9.3", "cachedir", "clap", "clap_complete_command", @@ -3002,7 +3002,7 @@ version = "0.12.10" dependencies = [ "aho-corasick", "anyhow", - "bitflags 2.9.2", + "bitflags 2.9.3", "clap", "colored 3.0.0", "fern", @@ -3108,7 +3108,7 @@ name = "ruff_python_ast" version = "0.0.0" dependencies = [ "aho-corasick", - "bitflags 2.9.2", + "bitflags 2.9.3", "compact_str", "get-size2", "is-macro", @@ -3196,7 +3196,7 @@ dependencies = [ name = "ruff_python_literal" version = "0.0.0" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "itertools 0.14.0", "ruff_python_ast", "unic-ucd-category", @@ -3207,7 +3207,7 @@ name = "ruff_python_parser" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.2", + "bitflags 2.9.3", "bstr", "compact_str", "get-size2", @@ -3232,7 +3232,7 @@ dependencies = [ name = "ruff_python_semantic" version = "0.0.0" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "insta", "is-macro", "ruff_cache", @@ -3253,7 +3253,7 @@ dependencies = [ name = "ruff_python_stdlib" version = "0.0.0" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "unicode-ident", ] @@ -3430,7 +3430,7 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "errno", "libc", "linux-raw-sys", @@ -4240,7 +4240,7 @@ dependencies = [ name = "ty_ide" version = "0.0.0" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", "get-size2", "insta", "itertools 0.14.0", @@ -4304,7 +4304,7 @@ name = "ty_python_semantic" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.2", + "bitflags 2.9.3", "bitvec", "camino", "colored 3.0.0", @@ -4357,7 +4357,7 @@ name = "ty_server" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.2", + "bitflags 2.9.3", "crossbeam", "dunce", "insta", @@ -4400,7 +4400,7 @@ name = "ty_test" version = "0.0.0" dependencies = [ "anyhow", - "bitflags 2.9.2", + "bitflags 2.9.3", "camino", "colored 3.0.0", "insta", @@ -5150,7 +5150,7 @@ version = "0.39.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" dependencies = [ - "bitflags 2.9.2", + "bitflags 2.9.3", ] [[package]] From f9bfc9ab5b1268303f90636054d001771abca61d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:20:17 -0400 Subject: [PATCH 116/160] Update Rust crate ordermap to v0.5.9 (#20065) --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2f006ea524b58..86cc629765173 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1486,9 +1486,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" +checksum = "f2481980430f9f78649238835720ddccc57e52df14ffce1c6f37391d61b563e9" dependencies = [ "equivalent", "hashbrown 0.15.5", @@ -2127,9 +2127,9 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "ordermap" -version = "0.5.8" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d6bff06e4a5dc6416bead102d3e63c480dd852ffbb278bf8cfeb4966b329609" +checksum = "2fd6fedcd996c8c97932075cc3811d83f53280f48d5620e4e3cab7f6a12678c4" dependencies = [ "indexmap", "serde", From 87f0da139a6e8e04b5dae2c78472de5f96fe4707 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:20:24 -0400 Subject: [PATCH 117/160] Update Rust crate proc-macro2 to v1.0.101 (#20066) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 86cc629765173..cb401d30cdb88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2473,9 +2473,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.96" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beef09f85ae72cea1ef96ba6870c51e6382ebfa4f0e85b643459331f3daa5be0" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] From 41bb24a87eca3eae072de298d18f89917eaf72b5 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Sun, 24 Aug 2025 22:20:39 -0400 Subject: [PATCH 118/160] Update Rust crate serde_json to v1.0.143 (#20069) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb401d30cdb88..2a9b9c1d93b85 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3578,9 +3578,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.142" +version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" dependencies = [ "itoa", "memchr", From 3eb3c3572b7ffdf3e659977fb99d94219e9bf43d Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:40:46 +0530 Subject: [PATCH 119/160] Update astral-sh/setup-uv action to v6.6.0 (#20074) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [astral-sh/setup-uv](https://github.com/astral-sh/setup-uv) | action | minor | `v6.4.3` -> `v6.6.0` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
astral-sh/setup-uv (astral-sh/setup-uv) ### [`v6.6.0`](https://github.com/astral-sh/setup-uv/releases/tag/v6.6.0): 🌈 Support for .tools-versions [Compare Source](https://github.com/astral-sh/setup-uv/compare/v6.5.0...v6.6.0) ##### Changes This release adds support for [asdf](https://asdf-vm.com/) `.tool-versions` in the `version-file` input ##### 🐛 Bug fixes - Add log message before long API calls to GitHub [@​eifinger](https://github.com/eifinger) ([#​530](https://github.com/astral-sh/setup-uv/issues/530)) ##### 🚀 Enhancements - Add support for .tools-versions [@​eifinger](https://github.com/eifinger) ([#​531](https://github.com/astral-sh/setup-uv/issues/531)) ##### 🧰 Maintenance - Bump dependencies [@​eifinger](https://github.com/eifinger) ([#​532](https://github.com/astral-sh/setup-uv/issues/532)) - chore: update known versions for 0.8.12 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​529](https://github.com/astral-sh/setup-uv/issues/529)) - chore: update known versions for 0.8.11 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​526](https://github.com/astral-sh/setup-uv/issues/526)) - chore: update known versions for 0.8.10 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​525](https://github.com/astral-sh/setup-uv/issues/525)) ### [`v6.5.0`](https://github.com/astral-sh/setup-uv/releases/tag/v6.5.0): 🌈 Better error messages, bug fixes and copilot agent settings [Compare Source](https://github.com/astral-sh/setup-uv/compare/v6.4.3...v6.5.0) ##### Changes This release brings better error messages in case the GitHub API is impacted, fixes a few bugs and allows to disable [problem matchers](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md) for better use in Copilot Agent workspaces. ##### 🐛 Bug fixes - Improve error messages on GitHub API errors [@​eifinger](https://github.com/eifinger) ([#​518](https://github.com/astral-sh/setup-uv/issues/518)) - Ignore backslashes and whitespace in requirements [@​axm2](https://github.com/axm2) ([#​501](https://github.com/astral-sh/setup-uv/issues/501)) ##### 🚀 Enhancements - Add input add-problem-matchers [@​eifinger](https://github.com/eifinger) ([#​517](https://github.com/astral-sh/setup-uv/issues/517)) ##### 🧰 Maintenance - chore: update known versions for 0.8.9 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​512](https://github.com/astral-sh/setup-uv/issues/512)) - chore: update known versions for 0.8.6-0.8.8 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​510](https://github.com/astral-sh/setup-uv/issues/510)) - chore: update known versions for 0.8.5 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​509](https://github.com/astral-sh/setup-uv/issues/509)) - chore: update known versions for 0.8.4 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​505](https://github.com/astral-sh/setup-uv/issues/505)) - chore: update known versions for 0.8.3 @​[github-actions\[bot\]](https://github.com/apps/github-actions) ([#​502](https://github.com/astral-sh/setup-uv/issues/502)) ##### 📚 Documentation - add note on caching to read disable-cache-pruning [@​eifinger](https://github.com/eifinger) ([#​506](https://github.com/astral-sh/setup-uv/issues/506)) ##### ⬆️ Dependency updates - Bump actions/checkout from 4 to 5 @​[dependabot\[bot\]](https://github.com/apps/dependabot) ([#​514](https://github.com/astral-sh/setup-uv/issues/514)) - bump dependencies [@​eifinger](https://github.com/eifinger) ([#​516](https://github.com/astral-sh/setup-uv/issues/516)) - Bump biome to v2 [@​eifinger](https://github.com/eifinger) ([#​515](https://github.com/astral-sh/setup-uv/issues/515))
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yaml | 12 ++++++------ .github/workflows/daily_fuzz.yaml | 2 +- .github/workflows/mypy_primer.yaml | 4 ++-- .github/workflows/publish-pypi.yml | 2 +- .github/workflows/sync_typeshed.yaml | 6 +++--- .github/workflows/ty-ecosystem-analyzer.yaml | 2 +- .github/workflows/ty-ecosystem-report.yaml | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ac4c7b62b59e..73f5161ce2b9c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -463,7 +463,7 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 name: Download Ruff binary to test id: download-cached-binary @@ -664,7 +664,7 @@ jobs: branch: ${{ github.event.pull_request.base.ref }} workflow: "ci.yaml" check_artifacts: true - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: Fuzz env: FORCE_COLOR: 1 @@ -734,7 +734,7 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: @@ -777,7 +777,7 @@ jobs: - name: "Install Rust toolchain" run: rustup show - name: Install uv - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: "Install Insiders dependencies" if: ${{ env.MKDOCS_INSIDERS_SSH_KEY_EXISTS == 'true' }} run: uv pip install -r docs/requirements-insiders.txt --system @@ -909,7 +909,7 @@ jobs: persist-credentials: false - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: "Install Rust toolchain" run: rustup show @@ -942,7 +942,7 @@ jobs: persist-credentials: false - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: "Install Rust toolchain" run: rustup show diff --git a/.github/workflows/daily_fuzz.yaml b/.github/workflows/daily_fuzz.yaml index a32ed2a80d851..b40285d1ad5f7 100644 --- a/.github/workflows/daily_fuzz.yaml +++ b/.github/workflows/daily_fuzz.yaml @@ -34,7 +34,7 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: "Install Rust toolchain" run: rustup show - name: "Install mold" diff --git a/.github/workflows/mypy_primer.yaml b/.github/workflows/mypy_primer.yaml index 3d91decb11623..40245d6e19568 100644 --- a/.github/workflows/mypy_primer.yaml +++ b/.github/workflows/mypy_primer.yaml @@ -39,7 +39,7 @@ jobs: persist-credentials: false - name: Install the latest version of uv - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 with: @@ -82,7 +82,7 @@ jobs: persist-credentials: false - name: Install the latest version of uv - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 with: diff --git a/.github/workflows/publish-pypi.yml b/.github/workflows/publish-pypi.yml index 300e6f8585aae..f49ad1ebfdfea 100644 --- a/.github/workflows/publish-pypi.yml +++ b/.github/workflows/publish-pypi.yml @@ -22,7 +22,7 @@ jobs: id-token: write steps: - name: "Install uv" - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4.3.0 with: pattern: wheels-* diff --git a/.github/workflows/sync_typeshed.yaml b/.github/workflows/sync_typeshed.yaml index c75cc9af6e8ff..8db8a60f4ce62 100644 --- a/.github/workflows/sync_typeshed.yaml +++ b/.github/workflows/sync_typeshed.yaml @@ -65,7 +65,7 @@ jobs: run: | git config --global user.name typeshedbot git config --global user.email '<>' - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: Sync typeshed stubs run: | rm -rf "ruff/${VENDORED_TYPESHED}" @@ -117,7 +117,7 @@ jobs: with: persist-credentials: true ref: ${{ env.UPSTREAM_BRANCH}} - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: Setup git run: | git config --global user.name typeshedbot @@ -155,7 +155,7 @@ jobs: with: persist-credentials: true ref: ${{ env.UPSTREAM_BRANCH}} - - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + - uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - name: Setup git run: | git config --global user.name typeshedbot diff --git a/.github/workflows/ty-ecosystem-analyzer.yaml b/.github/workflows/ty-ecosystem-analyzer.yaml index 1d6f1482ee17a..615c5e09970a3 100644 --- a/.github/workflows/ty-ecosystem-analyzer.yaml +++ b/.github/workflows/ty-ecosystem-analyzer.yaml @@ -33,7 +33,7 @@ jobs: persist-credentials: false - name: Install the latest version of uv - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 with: diff --git a/.github/workflows/ty-ecosystem-report.yaml b/.github/workflows/ty-ecosystem-report.yaml index 6ddbaa972753d..0514561883050 100644 --- a/.github/workflows/ty-ecosystem-report.yaml +++ b/.github/workflows/ty-ecosystem-report.yaml @@ -29,7 +29,7 @@ jobs: persist-credentials: false - name: Install the latest version of uv - uses: astral-sh/setup-uv@e92bafb6253dcd438e0484186d7669ea7a8ca1cc # v6.4.3 + uses: astral-sh/setup-uv@4959332f0f014c5280e7eac8b70c90cb574c9f9b # v6.6.0 - uses: Swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0 with: From 1eab4dbd9597ef4b9820cb90bd32aea4a49f5896 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:41:18 +0530 Subject: [PATCH 120/160] Update Rust crate thiserror to v2.0.16 (#20071) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [thiserror](https://github.com/dtolnay/thiserror) | workspace.dependencies | patch | `2.0.12` -> `2.0.16` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
dtolnay/thiserror (thiserror) ### [`v2.0.16`](https://github.com/dtolnay/thiserror/releases/tag/2.0.16) [Compare Source](https://github.com/dtolnay/thiserror/compare/2.0.15...2.0.16) - Add to "no-std" crates.io category ([#​429](https://github.com/dtolnay/thiserror/issues/429)) ### [`v2.0.15`](https://github.com/dtolnay/thiserror/releases/tag/2.0.15) [Compare Source](https://github.com/dtolnay/thiserror/compare/2.0.14...2.0.15) - Prevent `Error::provide` API becoming unavailable from a future new compiler lint ([#​427](https://github.com/dtolnay/thiserror/issues/427)) ### [`v2.0.14`](https://github.com/dtolnay/thiserror/releases/tag/2.0.14) [Compare Source](https://github.com/dtolnay/thiserror/compare/2.0.13...2.0.14) - Allow build-script cleanup failure with NFSv3 output directory to be non-fatal ([#​426](https://github.com/dtolnay/thiserror/issues/426)) ### [`v2.0.13`](https://github.com/dtolnay/thiserror/releases/tag/2.0.13) [Compare Source](https://github.com/dtolnay/thiserror/compare/2.0.12...2.0.13) - Documentation improvements
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2a9b9c1d93b85..5b8bcab387495 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,7 +485,7 @@ checksum = "85a8ab73a1c02b0c15597b22e09c7dc36e63b2f601f9d1e83ac0c3decd38b1ae" dependencies = [ "nix 0.29.0", "terminfo", - "thiserror 2.0.12", + "thiserror 2.0.16", "which", "windows-sys 0.59.0", ] @@ -1780,7 +1780,7 @@ dependencies = [ "paste", "peg", "regex", - "thiserror 2.0.12", + "thiserror 2.0.16", ] [[package]] @@ -2294,7 +2294,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1db05f56d34358a8b1066f67cbb203ee3e7ed2ba674a6263a1d5ec6db2204323" dependencies = [ "memchr", - "thiserror 2.0.12", + "thiserror 2.0.16", "ucd-trie", ] @@ -2490,7 +2490,7 @@ dependencies = [ "pep440_rs", "pep508_rs", "serde", - "thiserror 2.0.12", + "thiserror 2.0.16", "toml 0.8.23", ] @@ -2505,7 +2505,7 @@ dependencies = [ "newtype-uuid", "quick-xml", "strip-ansi-escapes", - "thiserror 2.0.12", + "thiserror 2.0.16", "uuid", ] @@ -2677,7 +2677,7 @@ checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ "getrandom 0.2.16", "libredox", - "thiserror 2.0.12", + "thiserror 2.0.16", ] [[package]] @@ -2793,7 +2793,7 @@ dependencies = [ "strum", "tempfile", "test-case", - "thiserror 2.0.12", + "thiserror 2.0.16", "tikv-jemallocator", "toml 0.9.5", "tracing", @@ -2888,7 +2888,7 @@ dependencies = [ "serde_json", "similar", "tempfile", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", "tracing-subscriber", "ty_static", @@ -3049,7 +3049,7 @@ dependencies = [ "strum_macros", "tempfile", "test-case", - "thiserror 2.0.12", + "thiserror 2.0.16", "toml 0.9.5", "typed-arena", "unicode-normalization", @@ -3092,7 +3092,7 @@ dependencies = [ "serde_json", "serde_with", "test-case", - "thiserror 2.0.12", + "thiserror 2.0.16", "uuid", ] @@ -3123,7 +3123,7 @@ dependencies = [ "salsa", "schemars", "serde", - "thiserror 2.0.12", + "thiserror 2.0.16", ] [[package]] @@ -3177,7 +3177,7 @@ dependencies = [ "similar", "smallvec", "static_assertions", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", ] @@ -3307,7 +3307,7 @@ dependencies = [ "serde", "serde_json", "shellexpand", - "thiserror 2.0.12", + "thiserror 2.0.16", "toml 0.9.5", "tracing", "tracing-log", @@ -3917,11 +3917,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.12" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" +checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 2.0.12", + "thiserror-impl 2.0.16", ] [[package]] @@ -3937,9 +3937,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" dependencies = [ "proc-macro2", "quote", @@ -4291,7 +4291,7 @@ dependencies = [ "salsa", "schemars", "serde", - "thiserror 2.0.12", + "thiserror 2.0.16", "toml 0.9.5", "tracing", "ty_combine", @@ -4344,7 +4344,7 @@ dependencies = [ "strum_macros", "tempfile", "test-case", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", "ty_python_semantic", "ty_static", @@ -4378,7 +4378,7 @@ dependencies = [ "serde_json", "shellexpand", "tempfile", - "thiserror 2.0.12", + "thiserror 2.0.16", "tracing", "tracing-subscriber", "ty_combine", @@ -4419,7 +4419,7 @@ dependencies = [ "serde", "smallvec", "tempfile", - "thiserror 2.0.12", + "thiserror 2.0.16", "toml 0.9.5", "tracing", "ty_python_semantic", From a0bba718f695eefbe04ad4ade9a154c0f98eab0a Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:41:33 +0530 Subject: [PATCH 121/160] Update Rust crate tracing-indicatif to v0.3.13 (#20072) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [tracing-indicatif](https://github.com/emersonford/tracing-indicatif) | workspace.dependencies | patch | `0.3.12` -> `0.3.13` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
emersonford/tracing-indicatif (tracing-indicatif) ### [`v0.3.13`](https://github.com/emersonford/tracing-indicatif/blob/HEAD/CHANGELOG.md#0313---2025-08-15) [Compare Source](https://github.com/emersonford/tracing-indicatif/compare/0.3.12...0.3.13) - eliminate panics on internal lock poison
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5b8bcab387495..f8e0613bccd07 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -955,7 +955,7 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys 0.60.2", + "windows-sys 0.59.0", ] [[package]] @@ -1035,7 +1035,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.59.0", ] [[package]] @@ -3434,7 +3434,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.60.2", + "windows-sys 0.59.0", ] [[package]] @@ -4138,9 +4138,9 @@ dependencies = [ [[package]] name = "tracing-indicatif" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1983afead46ff13a3c93581e0cec31d20b29efdd22cbdaa8b9f850eccf2c352" +checksum = "04d4e11e0e27acef25a47f27e9435355fecdc488867fa2bc90e75b0700d2823d" dependencies = [ "indicatif", "tracing", From c65029f9a5a8bf70d082a397a5fe08df400ebffc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:41:48 +0530 Subject: [PATCH 122/160] Update Rust crate syn to v2.0.106 (#20070) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [syn](https://github.com/dtolnay/syn) | workspace.dependencies | patch | `2.0.104` -> `2.0.106` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
dtolnay/syn (syn) ### [`v2.0.106`](https://github.com/dtolnay/syn/releases/tag/2.0.106) [Compare Source](https://github.com/dtolnay/syn/compare/2.0.105...2.0.106) - Replace `~const` syntax with `[const]` conditionally const syntax in trait bounds ([#​1896](https://github.com/dtolnay/syn/issues/1896), [rust-lang/rust#139858](https://github.com/rust-lang/rust/pull/139858)) - Support conditionally const impl Trait types ([#​1897](https://github.com/dtolnay/syn/issues/1897)) - Reject polarity modifier and lifetime binder used in the same trait bound ([#​1899](https://github.com/dtolnay/syn/issues/1899), [rust-lang/rust#127054](https://github.com/rust-lang/rust/pull/127054)) - Parse const trait bounds with bound lifetimes ([#​1902](https://github.com/dtolnay/syn/issues/1902)) - Parse bound lifetimes with lifetime bounds ([#​1903](https://github.com/dtolnay/syn/issues/1903)) - Allow type parameters and const parameters in trait bounds and generic closures ([#​1904](https://github.com/dtolnay/syn/issues/1904), [#​1907](https://github.com/dtolnay/syn/issues/1907), [#​1908](https://github.com/dtolnay/syn/issues/1908), [#​1909](https://github.com/dtolnay/syn/issues/1909)) ### [`v2.0.105`](https://github.com/dtolnay/syn/releases/tag/2.0.105) [Compare Source](https://github.com/dtolnay/syn/compare/2.0.104...2.0.105) - Disallow "negative" inherent impls like `impl !T {}` ([#​1881](https://github.com/dtolnay/syn/issues/1881), [rust-lang/rust#144386](https://github.com/rust-lang/rust/pull/144386))
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f8e0613bccd07..65e85a8bc7fbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3791,9 +3791,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.104" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", From c6dfdb1d39640491e725adb7a0fb98fc3a3718d1 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:42:38 +0530 Subject: [PATCH 123/160] Update Rust crate url to v2.5.7 (#20073) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [url](https://github.com/servo/rust-url) | workspace.dependencies | patch | `2.5.4` -> `2.5.7` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
servo/rust-url (url) ### [`v2.5.5`](https://github.com/servo/rust-url/releases/tag/v2.5.5) [Compare Source](https://github.com/servo/rust-url/compare/v2.5.4...v2.5.5) ##### What's Changed - ci: downgrade crates when building for Rust 1.67.0 by [@​mxinden](https://github.com/mxinden) in [https://github.com/servo/rust-url/pull/1003](https://github.com/servo/rust-url/pull/1003) - ci: run unit tests with sanitizers by [@​mxinden](https://github.com/mxinden) in [https://github.com/servo/rust-url/pull/1002](https://github.com/servo/rust-url/pull/1002) - fix small typo by [@​hkBst](https://github.com/hkBst) in [https://github.com/servo/rust-url/pull/1011](https://github.com/servo/rust-url/pull/1011) - chore: fix clippy errors on main by [@​dsherret](https://github.com/dsherret) in [https://github.com/servo/rust-url/pull/1019](https://github.com/servo/rust-url/pull/1019) - perf: remove heap allocation in parse\_query by [@​dsherret](https://github.com/dsherret) in [https://github.com/servo/rust-url/pull/1020](https://github.com/servo/rust-url/pull/1020) - perf: slightly improve parsing a port by [@​dsherret](https://github.com/dsherret) in [https://github.com/servo/rust-url/pull/1022](https://github.com/servo/rust-url/pull/1022) - perf: improve to\_file\_path() by [@​dsherret](https://github.com/dsherret) in [https://github.com/servo/rust-url/pull/1018](https://github.com/servo/rust-url/pull/1018) - perf: make parse\_scheme slightly faster by [@​dsherret](https://github.com/dsherret) in [https://github.com/servo/rust-url/pull/1025](https://github.com/servo/rust-url/pull/1025) - update LICENSE-MIT by [@​wmjae](https://github.com/wmjae) in [https://github.com/servo/rust-url/pull/1029](https://github.com/servo/rust-url/pull/1029) - perf: url encode path segments in longer string slices by [@​dsherret](https://github.com/dsherret) in [https://github.com/servo/rust-url/pull/1026](https://github.com/servo/rust-url/pull/1026) - Disable the default features on serde by [@​rilipco](https://github.com/rilipco) in [https://github.com/servo/rust-url/pull/1033](https://github.com/servo/rust-url/pull/1033) - docs: base url relative join by [@​tisonkun](https://github.com/tisonkun) in [https://github.com/servo/rust-url/pull/1013](https://github.com/servo/rust-url/pull/1013) - perf: remove heap allocation in parse\_host by [@​dsherret](https://github.com/dsherret) in [https://github.com/servo/rust-url/pull/1021](https://github.com/servo/rust-url/pull/1021) - Update tests to Unicode 16.0 by [@​hsivonen](https://github.com/hsivonen) in [https://github.com/servo/rust-url/pull/1045](https://github.com/servo/rust-url/pull/1045) - Add some some basic functions to `Mime` by [@​mrobinson](https://github.com/mrobinson) in [https://github.com/servo/rust-url/pull/1047](https://github.com/servo/rust-url/pull/1047) - ran `cargo clippy --fix -- -Wclippy::use_self` by [@​mrobinson](https://github.com/mrobinson) in [https://github.com/servo/rust-url/pull/1048](https://github.com/servo/rust-url/pull/1048) - Fix MSRV and clippy CI by [@​Manishearth](https://github.com/Manishearth) in [https://github.com/servo/rust-url/pull/1058](https://github.com/servo/rust-url/pull/1058) - Update `Url::domain` docs to show that it includes subdomain by [@​supercoolspy](https://github.com/supercoolspy) in [https://github.com/servo/rust-url/pull/1057](https://github.com/servo/rust-url/pull/1057) - set\_hostname should error when encountering colon ':' by [@​edgul](https://github.com/edgul) in [https://github.com/servo/rust-url/pull/1060](https://github.com/servo/rust-url/pull/1060) - version bump to 2.5.5 by [@​edgul](https://github.com/edgul) in [https://github.com/servo/rust-url/pull/1061](https://github.com/servo/rust-url/pull/1061) ##### New Contributors - [@​mxinden](https://github.com/mxinden) made their first contribution in [https://github.com/servo/rust-url/pull/1003](https://github.com/servo/rust-url/pull/1003) - [@​hkBst](https://github.com/hkBst) made their first contribution in [https://github.com/servo/rust-url/pull/1011](https://github.com/servo/rust-url/pull/1011) - [@​wmjae](https://github.com/wmjae) made their first contribution in [https://github.com/servo/rust-url/pull/1029](https://github.com/servo/rust-url/pull/1029) - [@​rilipco](https://github.com/rilipco) made their first contribution in [https://github.com/servo/rust-url/pull/1033](https://github.com/servo/rust-url/pull/1033) - [@​tisonkun](https://github.com/tisonkun) made their first contribution in [https://github.com/servo/rust-url/pull/1013](https://github.com/servo/rust-url/pull/1013) - [@​supercoolspy](https://github.com/supercoolspy) made their first contribution in [https://github.com/servo/rust-url/pull/1057](https://github.com/servo/rust-url/pull/1057) **Full Changelog**: https://github.com/servo/rust-url/compare/v2.5.4...v2.5.5
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 65e85a8bc7fbc..d13f3e099c8e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1118,9 +1118,9 @@ checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" [[package]] name = "form_urlencoded" -version = "1.2.1" +version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" dependencies = [ "percent-encoding", ] @@ -1430,9 +1430,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" dependencies = [ "idna_adapter", "smallvec", @@ -2283,9 +2283,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.3.1" +version = "2.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" [[package]] name = "pest" @@ -4596,9 +4596,9 @@ checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" [[package]] name = "url" -version = "2.5.4" +version = "2.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" +checksum = "08bc136a29a3d1758e07a9cca267be308aeebf5cfd5a10f3f67ab2097683ef5b" dependencies = [ "form_urlencoded", "idna", From dbbcb7f452d43746af6b19735b5b4d153d6f66b7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:43:27 +0530 Subject: [PATCH 124/160] Update cargo-bins/cargo-binstall action to v1.15.1 (#20075) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [cargo-bins/cargo-binstall](https://github.com/cargo-bins/cargo-binstall) | action | minor | `v1.14.4` -> `v1.15.1` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
cargo-bins/cargo-binstall (cargo-bins/cargo-binstall) ### [`v1.15.1`](https://github.com/cargo-bins/cargo-binstall/releases/tag/v1.15.1) [Compare Source](https://github.com/cargo-bins/cargo-binstall/compare/v1.15.0...v1.15.1) *Binstall is a tool to fetch and install Rust-based executables as binaries. It aims to be a drop-in replacement for `cargo install` in most cases. Install it today with `cargo install cargo-binstall`, from the binaries below, or if you already have it, upgrade with `cargo binstall cargo-binstall`.* ##### In this release: - fix failure to create settings manifest file ([#​2268](https://github.com/cargo-bins/cargo-binstall/issues/2268) [#​2271](https://github.com/cargo-bins/cargo-binstall/issues/2271)) - fix race condition in creating, loading and writing of settings manifest file ([#​2272](https://github.com/cargo-bins/cargo-binstall/issues/2272)) - fix infinite hang on `--self-install` due to the quickinstall consent ([#​2269](https://github.com/cargo-bins/cargo-binstall/issues/2269) [#​2273](https://github.com/cargo-bins/cargo-binstall/issues/2273)) ### [`v1.15.0`](https://github.com/cargo-bins/cargo-binstall/releases/tag/v1.15.0) [Compare Source](https://github.com/cargo-bins/cargo-binstall/compare/v1.14.4...v1.15.0) *Binstall is a tool to fetch and install Rust-based executables as binaries. It aims to be a drop-in replacement for `cargo install` in most cases. Install it today with `cargo install cargo-binstall`, from the binaries below, or if you already have it, upgrade with `cargo binstall cargo-binstall`.* ##### In this release: - confirm on the first time using quickinstall ([#​2223](https://github.com/cargo-bins/cargo-binstall/issues/2223)) ##### Other changes: - upgrade dependencies
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- .github/workflows/ci.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 73f5161ce2b9c..8c425034676f9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -441,7 +441,7 @@ jobs: - name: "Install Rust toolchain" run: rustup show - name: "Install cargo-binstall" - uses: cargo-bins/cargo-binstall@79e4beb1e02f733a26129a6bf26c37dab4ab3307 # v1.14.4 + uses: cargo-bins/cargo-binstall@0dca8cf8dfb40cb77a29cece06933ce674674523 # v1.15.1 with: tool: cargo-fuzz@0.11.2 - name: "Install cargo-fuzz" @@ -694,7 +694,7 @@ jobs: - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 with: persist-credentials: false - - uses: cargo-bins/cargo-binstall@79e4beb1e02f733a26129a6bf26c37dab4ab3307 # v1.14.4 + - uses: cargo-bins/cargo-binstall@0dca8cf8dfb40cb77a29cece06933ce674674523 # v1.15.1 - run: cargo binstall --no-confirm cargo-shear - run: cargo shear From e4289deb5a31855b27a5cb5182e2a4ed92f60403 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:44:47 +0530 Subject: [PATCH 125/160] Update Rust crate regex to v1.11.2 (#20067) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [regex](https://github.com/rust-lang/regex) | workspace.dependencies | patch | `1.11.1` -> `1.11.2` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
rust-lang/regex (regex) ### [`v1.11.2`](https://github.com/rust-lang/regex/blob/HEAD/CHANGELOG.md#1112-2025-08-24) [Compare Source](https://github.com/rust-lang/regex/compare/1.11.1...1.11.2) \=================== This is a new patch release of `regex` with some minor fixes. A larger number of typo or lint fix patches were merged. Also, we now finally recommend using `std::sync::LazyLock`. Improvements: - [BUG #​1217](https://github.com/rust-lang/regex/issues/1217): Switch recommendation from `once_cell` to `std::sync::LazyLock`. - [BUG #​1225](https://github.com/rust-lang/regex/issues/1225): Add `DFA::set_prefilter` to `regex-automata`. Bug fixes: - [BUG #​1165](https://github.com/rust-lang/regex/pull/1150): Remove `std` dependency from `perf-literal-multisubstring` crate feature. - [BUG #​1165](https://github.com/rust-lang/regex/pull/1165): Clarify the meaning of `(?R)$` in the documentation. - [BUG #​1281](https://github.com/rust-lang/regex/pull/1281): Remove `fuzz/` and `record/` directories from published crate on crates.io.
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d13f3e099c8e0..e1b78aaf2f3fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2682,9 +2682,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.1" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" dependencies = [ "aho-corasick", "memchr", From 3c1fe12259cf2615d3510742d2e6b7ae05ab3dff Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 10:44:59 +0530 Subject: [PATCH 126/160] Update Rust crate regex-automata to v0.4.10 (#20068) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [regex-automata](https://github.com/rust-lang/regex/tree/master/regex-automata) ([source](https://github.com/rust-lang/regex)) | workspace.dependencies | patch | `0.4.9` -> `0.4.10` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Release Notes
rust-lang/regex (regex-automata) ### [`v0.4.10`](https://github.com/rust-lang/regex/compare/regex-automata-0.4.9...regex-automata-0.4.10) [Compare Source](https://github.com/rust-lang/regex/compare/regex-automata-0.4.9...regex-automata-0.4.10)
--- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- Cargo.lock | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1b78aaf2f3fc..609eae3468475 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -295,7 +295,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "234113d19d0d7d613b40e86fb654acf958910802bcceab913a4f9e7cda03b1a4" dependencies = [ "memchr", - "regex-automata 0.4.9", + "regex-automata 0.4.10", "serde", ] @@ -1231,7 +1231,7 @@ dependencies = [ "aho-corasick", "bstr", "log", - "regex-automata 0.4.9", + "regex-automata 0.4.10", "regex-syntax 0.8.5", ] @@ -1459,7 +1459,7 @@ dependencies = [ "globset", "log", "memchr", - "regex-automata 0.4.9", + "regex-automata 0.4.10", "same-file", "walkdir", "winapi-util", @@ -2688,7 +2688,7 @@ checksum = "23d7fd106d8c02486a8d64e778353d1cffe08ce79ac2e82f540c86d0facf6912" dependencies = [ "aho-corasick", "memchr", - "regex-automata 0.4.9", + "regex-automata 0.4.10", "regex-syntax 0.8.5", ] @@ -2703,9 +2703,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "6b9458fa0bfeeac22b5ca447c63aaf45f28439a709ccd244698632f9aa6394d6" dependencies = [ "aho-corasick", "memchr", @@ -4278,7 +4278,7 @@ dependencies = [ "pep440_rs", "rayon", "regex", - "regex-automata 0.4.9", + "regex-automata 0.4.10", "ruff_cache", "ruff_db", "ruff_macros", From b57cc5be330847bb6f83f9af4bf5364dc3ac4ffe Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 11:04:07 +0530 Subject: [PATCH 127/160] Update actions/checkout digest to ff7abcd (#20061) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | actions/checkout | action | digest | `08c6903` -> `ff7abcd` | --- > [!WARNING] > Some dependencies could not be looked up. Check the Dependency Dashboard for more information. --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on Monday" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/astral-sh/ruff). --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala --- .github/workflows/release.yml | 8 ++++---- dist-workspace.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 218f07b9a8d19..b53ce5a2d0b29 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + - uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 with: persist-credentials: false submodules: recursive @@ -124,7 +124,7 @@ jobs: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} BUILD_MANIFEST_NAME: target/distrib/global-dist-manifest.json steps: - - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + - uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 with: persist-credentials: false submodules: recursive @@ -175,7 +175,7 @@ jobs: outputs: val: ${{ steps.host.outputs.manifest }} steps: - - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + - uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 with: persist-credentials: false submodules: recursive @@ -251,7 +251,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 + - uses: actions/checkout@ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493 with: persist-credentials: false submodules: recursive diff --git a/dist-workspace.toml b/dist-workspace.toml index ebbf36ab20626..1f23f1118bb8b 100644 --- a/dist-workspace.toml +++ b/dist-workspace.toml @@ -70,7 +70,7 @@ install-path = ["$XDG_BIN_HOME/", "$XDG_DATA_HOME/../bin", "~/.local/bin"] global = "depot-ubuntu-latest-4" [dist.github-action-commits] -"actions/checkout" = "08c6903cd8c0fde910a37f88322edcfb5dd907a8" # v5.0.0 +"actions/checkout" = "ff7abcd0c3c05ccf6adc123a8cd1fd4fb30fb493" # v5.0.0 "actions/upload-artifact" = "6027e3dd177782cd8ab9af838c04fd81a07f1d47" # v4.6.2 "actions/download-artifact" = "634f93cb2916e3fdff6788551b99b062d0335ce0" # v5.0.0 "actions/attest-build-provenance" = "c074443f1aee8d4aeeae555aebba3282517141b2" #v2.2.3 From 376e3ff39519d3c0563dd8f7a1d0daf9db52e98a Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Mon, 25 Aug 2025 15:13:04 +0530 Subject: [PATCH 128/160] [ty] Limit argument expansion size for overload call evaluation (#20041) ## Summary This PR limits the argument type expansion size for an overload call evaluation to 512. The limit chosen is arbitrary but I've taken the 256 limit from Pyright into account and bumped it x2 to start with. Initially, I actually started out by trying to refactor the entire argument type expansion to be lazy. Currently, expanding a single argument at any position eagerly creates the combination (argument lists) and returns that (`Vec`) but I thought we could make it lazier by converting the return type of `expand` from `Iterator>` to `Iterator>` but that's proving to be difficult to implement mainly because we **need** to maintain the previous expansion to generate the next expansion which is the main reason to use `std::iter::successors` in the first place. Another approach would be to eagerly expand all the argument types and then use the `combinations` from `itertools` to generate the combinations but we would need to find the "boundary" between arguments lists produced from expanding argument at position 1 and position 2 because that's important for the algorithm. Closes: https://github.com/astral-sh/ty/issues/868 ## Test Plan Add test case to demonstrate the limit along with the diagnostic snapshot stating that the limit has been reached. --- .../resources/mdtest/call/overloads.md | 76 +++++++- ...imit_\342\200\246_(cd61048adbc17331).snap" | 183 ++++++++++++++++++ .../src/types/call/arguments.rs | 120 ++++++++---- .../ty_python_semantic/src/types/call/bind.rs | 36 +++- 4 files changed, 372 insertions(+), 43 deletions(-) create mode 100644 "crates/ty_python_semantic/resources/mdtest/snapshots/overloads.md_-_Overloads_-_Argument_type_expans\342\200\246_-_Optimization___Limit_\342\200\246_(cd61048adbc17331).snap" diff --git a/crates/ty_python_semantic/resources/mdtest/call/overloads.md b/crates/ty_python_semantic/resources/mdtest/call/overloads.md index d6fbf08b3a039..c2cc47d1eed39 100644 --- a/crates/ty_python_semantic/resources/mdtest/call/overloads.md +++ b/crates/ty_python_semantic/resources/mdtest/call/overloads.md @@ -660,9 +660,9 @@ class Foo: ```py from overloaded import A, B, C, Foo, f -from typing_extensions import reveal_type +from typing_extensions import Any, reveal_type -def _(ab: A | B, a=1): +def _(ab: A | B, a: int | Any): reveal_type(f(a1=a, a2=a, a3=a)) # revealed: C reveal_type(f(A(), a1=a, a2=a, a3=a)) # revealed: A reveal_type(f(B(), a1=a, a2=a, a3=a)) # revealed: B @@ -750,7 +750,7 @@ def _(ab: A | B, a=1): ) ) -def _(foo: Foo, ab: A | B, a=1): +def _(foo: Foo, ab: A | B, a: int | Any): reveal_type(foo.f(a1=a, a2=a, a3=a)) # revealed: C reveal_type(foo.f(A(), a1=a, a2=a, a3=a)) # revealed: A reveal_type(foo.f(B(), a1=a, a2=a, a3=a)) # revealed: B @@ -831,6 +831,76 @@ def _(foo: Foo, ab: A | B, a=1): ) ``` +### Optimization: Limit expansion size + + + +To prevent combinatorial explosion, ty limits the number of argument lists created by expanding a +single argument. + +`overloaded.pyi`: + +```pyi +from typing import overload + +class A: ... +class B: ... +class C: ... + +@overload +def f() -> None: ... +@overload +def f(**kwargs: int) -> C: ... +@overload +def f(x: A, /, **kwargs: int) -> A: ... +@overload +def f(x: B, /, **kwargs: int) -> B: ... +``` + +```py +from overloaded import A, B, f +from typing_extensions import reveal_type + +def _(a: int | None): + reveal_type( + # error: [no-matching-overload] + # revealed: Unknown + f( + A(), + a1=a, + a2=a, + a3=a, + a4=a, + a5=a, + a6=a, + a7=a, + a8=a, + a9=a, + a10=a, + a11=a, + a12=a, + a13=a, + a14=a, + a15=a, + a16=a, + a17=a, + a18=a, + a19=a, + a20=a, + a21=a, + a22=a, + a23=a, + a24=a, + a25=a, + a26=a, + a27=a, + a28=a, + a29=a, + a30=a, + ) + ) +``` + ## Filtering based on `Any` / `Unknown` This is the step 5 of the overload call evaluation algorithm which specifies that: diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/overloads.md_-_Overloads_-_Argument_type_expans\342\200\246_-_Optimization___Limit_\342\200\246_(cd61048adbc17331).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/overloads.md_-_Overloads_-_Argument_type_expans\342\200\246_-_Optimization___Limit_\342\200\246_(cd61048adbc17331).snap" new file mode 100644 index 0000000000000..cf278f43286c2 --- /dev/null +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/overloads.md_-_Overloads_-_Argument_type_expans\342\200\246_-_Optimization___Limit_\342\200\246_(cd61048adbc17331).snap" @@ -0,0 +1,183 @@ +--- +source: crates/ty_test/src/lib.rs +expression: snapshot +--- +--- +mdtest name: overloads.md - Overloads - Argument type expansion - Optimization: Limit expansion size +mdtest path: crates/ty_python_semantic/resources/mdtest/call/overloads.md +--- + +# Python source files + +## overloaded.pyi + +``` + 1 | from typing import overload + 2 | + 3 | class A: ... + 4 | class B: ... + 5 | class C: ... + 6 | + 7 | @overload + 8 | def f() -> None: ... + 9 | @overload +10 | def f(**kwargs: int) -> C: ... +11 | @overload +12 | def f(x: A, /, **kwargs: int) -> A: ... +13 | @overload +14 | def f(x: B, /, **kwargs: int) -> B: ... +``` + +## mdtest_snippet.py + +``` + 1 | from overloaded import A, B, f + 2 | from typing_extensions import reveal_type + 3 | + 4 | def _(a: int | None): + 5 | reveal_type( + 6 | # error: [no-matching-overload] + 7 | # revealed: Unknown + 8 | f( + 9 | A(), +10 | a1=a, +11 | a2=a, +12 | a3=a, +13 | a4=a, +14 | a5=a, +15 | a6=a, +16 | a7=a, +17 | a8=a, +18 | a9=a, +19 | a10=a, +20 | a11=a, +21 | a12=a, +22 | a13=a, +23 | a14=a, +24 | a15=a, +25 | a16=a, +26 | a17=a, +27 | a18=a, +28 | a19=a, +29 | a20=a, +30 | a21=a, +31 | a22=a, +32 | a23=a, +33 | a24=a, +34 | a25=a, +35 | a26=a, +36 | a27=a, +37 | a28=a, +38 | a29=a, +39 | a30=a, +40 | ) +41 | ) +``` + +# Diagnostics + +``` +error[no-matching-overload]: No overload of function `f` matches arguments + --> src/mdtest_snippet.py:8:9 + | + 6 | # error: [no-matching-overload] + 7 | # revealed: Unknown + 8 | / f( + 9 | | A(), +10 | | a1=a, +11 | | a2=a, +12 | | a3=a, +13 | | a4=a, +14 | | a5=a, +15 | | a6=a, +16 | | a7=a, +17 | | a8=a, +18 | | a9=a, +19 | | a10=a, +20 | | a11=a, +21 | | a12=a, +22 | | a13=a, +23 | | a14=a, +24 | | a15=a, +25 | | a16=a, +26 | | a17=a, +27 | | a18=a, +28 | | a19=a, +29 | | a20=a, +30 | | a21=a, +31 | | a22=a, +32 | | a23=a, +33 | | a24=a, +34 | | a25=a, +35 | | a26=a, +36 | | a27=a, +37 | | a28=a, +38 | | a29=a, +39 | | a30=a, +40 | | ) + | |_________^ +41 | ) + | +info: Limit of argument type expansion reached at argument 10 +info: First overload defined here + --> src/overloaded.pyi:8:5 + | + 7 | @overload + 8 | def f() -> None: ... + | ^^^^^^^^^^^ + 9 | @overload +10 | def f(**kwargs: int) -> C: ... + | +info: Possible overloads for function `f`: +info: () -> None +info: (**kwargs: int) -> C +info: (x: A, /, **kwargs: int) -> A +info: (x: B, /, **kwargs: int) -> B +info: rule `no-matching-overload` is enabled by default + +``` + +``` +info[revealed-type]: Revealed type + --> src/mdtest_snippet.py:8:9 + | + 6 | # error: [no-matching-overload] + 7 | # revealed: Unknown + 8 | / f( + 9 | | A(), +10 | | a1=a, +11 | | a2=a, +12 | | a3=a, +13 | | a4=a, +14 | | a5=a, +15 | | a6=a, +16 | | a7=a, +17 | | a8=a, +18 | | a9=a, +19 | | a10=a, +20 | | a11=a, +21 | | a12=a, +22 | | a13=a, +23 | | a14=a, +24 | | a15=a, +25 | | a16=a, +26 | | a17=a, +27 | | a18=a, +28 | | a19=a, +29 | | a20=a, +30 | | a21=a, +31 | | a22=a, +32 | | a23=a, +33 | | a24=a, +34 | | a25=a, +35 | | a26=a, +36 | | a27=a, +37 | | a28=a, +38 | | a29=a, +39 | | a30=a, +40 | | ) + | |_________^ `Unknown` +41 | ) + | + +``` diff --git a/crates/ty_python_semantic/src/types/call/arguments.rs b/crates/ty_python_semantic/src/types/call/arguments.rs index 648b0cdab932a..3bf78c6a75627 100644 --- a/crates/ty_python_semantic/src/types/call/arguments.rs +++ b/crates/ty_python_semantic/src/types/call/arguments.rs @@ -127,31 +127,39 @@ impl<'a, 'db> CallArguments<'a, 'db> { /// contains the same arguments, but with one or more of the argument types expanded. /// /// [argument type expansion]: https://typing.python.org/en/latest/spec/overload.html#argument-type-expansion - pub(crate) fn expand( - &self, - db: &'db dyn Db, - ) -> impl Iterator>> + '_ { + pub(super) fn expand(&self, db: &'db dyn Db) -> impl Iterator> + '_ { + /// Maximum number of argument lists that can be generated in a single expansion step. + static MAX_EXPANSIONS: usize = 512; + /// Represents the state of the expansion process. + enum State<'a, 'b, 'db> { + LimitReached(usize), + Expanding(ExpandingState<'a, 'b, 'db>), + } + + /// Represents the expanding state with either the initial types or the expanded types. /// /// This is useful to avoid cloning the initial types vector if none of the types can be /// expanded. - enum State<'a, 'b, 'db> { + enum ExpandingState<'a, 'b, 'db> { Initial(&'b Vec>>), Expanded(Vec>), } - impl<'db> State<'_, '_, 'db> { + impl<'db> ExpandingState<'_, '_, 'db> { fn len(&self) -> usize { match self { - State::Initial(_) => 1, - State::Expanded(expanded) => expanded.len(), + ExpandingState::Initial(_) => 1, + ExpandingState::Expanded(expanded) => expanded.len(), } } fn iter(&self) -> impl Iterator>]> + '_ { match self { - State::Initial(types) => Either::Left(std::iter::once(types.as_slice())), - State::Expanded(expanded) => { + ExpandingState::Initial(types) => { + Either::Left(std::iter::once(types.as_slice())) + } + ExpandingState::Expanded(expanded) => { Either::Right(expanded.iter().map(CallArguments::types)) } } @@ -160,44 +168,82 @@ impl<'a, 'db> CallArguments<'a, 'db> { let mut index = 0; - std::iter::successors(Some(State::Initial(&self.types)), move |previous| { - // Find the next type that can be expanded. - let expanded_types = loop { - let arg_type = self.types.get(index)?; - if let Some(arg_type) = arg_type { - if let Some(expanded_types) = expand_type(db, *arg_type) { - break expanded_types; + std::iter::successors( + Some(State::Expanding(ExpandingState::Initial(&self.types))), + move |previous| { + let state = match previous { + State::LimitReached(index) => return Some(State::LimitReached(*index)), + State::Expanding(expanding_state) => expanding_state, + }; + + // Find the next type that can be expanded. + let expanded_types = loop { + let arg_type = self.types.get(index)?; + if let Some(arg_type) = arg_type { + if let Some(expanded_types) = expand_type(db, *arg_type) { + break expanded_types; + } } + index += 1; + }; + + let expansion_size = expanded_types.len() * state.len(); + if expansion_size > MAX_EXPANSIONS { + tracing::debug!( + "Skipping argument type expansion as it would exceed the \ + maximum number of expansions ({MAX_EXPANSIONS})" + ); + return Some(State::LimitReached(index)); } - index += 1; - }; - - let mut expanded_arguments = Vec::with_capacity(expanded_types.len() * previous.len()); - - for pre_expanded_types in previous.iter() { - for subtype in &expanded_types { - let mut new_expanded_types = pre_expanded_types.to_vec(); - new_expanded_types[index] = Some(*subtype); - expanded_arguments.push(CallArguments::new( - self.arguments.clone(), - new_expanded_types, - )); + + let mut expanded_arguments = Vec::with_capacity(expansion_size); + + for pre_expanded_types in state.iter() { + for subtype in &expanded_types { + let mut new_expanded_types = pre_expanded_types.to_vec(); + new_expanded_types[index] = Some(*subtype); + expanded_arguments.push(CallArguments::new( + self.arguments.clone(), + new_expanded_types, + )); + } } - } - // Increment the index to move to the next argument type for the next iteration. - index += 1; + // Increment the index to move to the next argument type for the next iteration. + index += 1; - Some(State::Expanded(expanded_arguments)) - }) + Some(State::Expanding(ExpandingState::Expanded( + expanded_arguments, + ))) + }, + ) .skip(1) // Skip the initial state, which has no expanded types. .map(|state| match state { - State::Initial(_) => unreachable!("initial state should be skipped"), - State::Expanded(expanded) => expanded, + State::LimitReached(index) => Expansion::LimitReached(index), + State::Expanding(ExpandingState::Initial(_)) => { + unreachable!("initial state should be skipped") + } + State::Expanding(ExpandingState::Expanded(expanded)) => Expansion::Expanded(expanded), }) } } +/// Represents a single element of the expansion process for argument types for [`expand`]. +/// +/// [`expand`]: CallArguments::expand +pub(super) enum Expansion<'a, 'db> { + /// Indicates that the expansion process has reached the maximum number of argument lists + /// that can be generated in a single step. + /// + /// The contained `usize` is the index of the argument type which would have been expanded + /// next, if not for the limit. + LimitReached(usize), + + /// Contains the expanded argument lists, where each list contains the same arguments, but with + /// one or more of the argument types expanded. + Expanded(Vec>), +} + impl<'a, 'db> FromIterator<(Argument<'a>, Option>)> for CallArguments<'a, 'db> { fn from_iter(iter: T) -> Self where diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index d2d46a2baabb6..da1d962f9999b 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -16,7 +16,7 @@ use crate::Program; use crate::db::Db; use crate::dunder_all::dunder_all_names; use crate::place::{Boundness, Place}; -use crate::types::call::arguments::is_expandable_type; +use crate::types::call::arguments::{Expansion, is_expandable_type}; use crate::types::diagnostic::{ CALL_NON_CALLABLE, CONFLICTING_ARGUMENT_FORMS, INVALID_ARGUMENT_TYPE, MISSING_ARGUMENT, NO_MATCHING_OVERLOAD, PARAMETER_ALREADY_ASSIGNED, TOO_MANY_POSITIONAL_ARGUMENTS, @@ -1368,7 +1368,18 @@ impl<'db> CallableBinding<'db> { } } - for expanded_argument_lists in expansions { + for expansion in expansions { + let expanded_argument_lists = match expansion { + Expansion::LimitReached(index) => { + snapshotter.restore(self, post_evaluation_snapshot); + self.overload_call_return_type = Some( + OverloadCallReturnType::ArgumentTypeExpansionLimitReached(index), + ); + return; + } + Expansion::Expanded(argument_lists) => argument_lists, + }; + // This is the merged state of the bindings after evaluating all of the expanded // argument lists. This will be the final state to restore the bindings to if all of // the expanded argument lists evaluated successfully. @@ -1667,7 +1678,8 @@ impl<'db> CallableBinding<'db> { if let Some(overload_call_return_type) = self.overload_call_return_type { return match overload_call_return_type { OverloadCallReturnType::ArgumentTypeExpansion(return_type) => return_type, - OverloadCallReturnType::Ambiguous => Type::unknown(), + OverloadCallReturnType::ArgumentTypeExpansionLimitReached(_) + | OverloadCallReturnType::Ambiguous => Type::unknown(), }; } if let Some((_, first_overload)) = self.matching_overloads().next() { @@ -1778,6 +1790,23 @@ impl<'db> CallableBinding<'db> { String::new() } )); + + if let Some(index) = + self.overload_call_return_type + .and_then( + |overload_call_return_type| match overload_call_return_type { + OverloadCallReturnType::ArgumentTypeExpansionLimitReached( + index, + ) => Some(index), + _ => None, + }, + ) + { + diag.info(format_args!( + "Limit of argument type expansion reached at argument {index}" + )); + } + if let Some((kind, function)) = function_type_and_kind { let (overloads, implementation) = function.overloads_and_implementation(context.db()); @@ -1844,6 +1873,7 @@ impl<'a, 'db> IntoIterator for &'a CallableBinding<'db> { #[derive(Debug, Copy, Clone)] enum OverloadCallReturnType<'db> { ArgumentTypeExpansion(Type<'db>), + ArgumentTypeExpansionLimitReached(usize), Ambiguous, } From f9bbee33f62bfb4bb4a8764d6ba4895f72b1c9d9 Mon Sep 17 00:00:00 2001 From: Eric Jolibois Date: Mon, 25 Aug 2025 14:45:52 +0200 Subject: [PATCH 129/160] [ty] validate constructor call of `TypedDict` (#19810) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Implement validation for `TypedDict` constructor calls and dictionary literal assignments, including support for `total=False` and proper field management. Also add support for `Required` and `NotRequired` type qualifiers in `TypedDict` classes, along with proper inheritance behavior and the `total=` parameter. Support both constructor calls and dict literal syntax part of https://github.com/astral-sh/ty/issues/154 ### Basic Required Field Validation ```py class Person(TypedDict): name: str age: int | None # Error: Missing required field 'name' in TypedDict `Person` constructor incomplete = Person(age=25) # Error: Invalid argument to key "name" with declared type `str` on TypedDict `Person` wrong_type = Person(name=123, age=25) # Error: Invalid key access on TypedDict `Person`: Unknown key "extra" extra_field = Person(name="Bob", age=25, extra=True) ``` Screenshot 2025-08-07 at 17 59 22 ### Support for `total=False` ```py class OptionalPerson(TypedDict, total=False): name: str age: int | None # All valid - all fields are optional with total=False charlie = OptionalPerson() david = OptionalPerson(name="David") emily = OptionalPerson(age=30) frank = OptionalPerson(name="Frank", age=25) # But type validation and extra fields still apply invalid_type = OptionalPerson(name=123) # Error: Invalid argument type invalid_extra = OptionalPerson(extra=True) # Error: Invalid key access ``` ### Dictionary Literal Validation ```py # Type checking works for both constructors and dict literals person: Person = {"name": "Alice", "age": 30} reveal_type(person["name"]) # revealed: str reveal_type(person["age"]) # revealed: int | None # Error: Invalid key access on TypedDict `Person`: Unknown key "non_existing" reveal_type(person["non_existing"]) # revealed: Unknown ``` ### `Required`, `NotRequired`, `total` ```python from typing import TypedDict from typing_extensions import Required, NotRequired class PartialUser(TypedDict, total=False): name: Required[str] # Required despite total=False age: int # Optional due to total=False email: NotRequired[str] # Explicitly optional (redundant) class User(TypedDict): name: Required[str] # Explicitly required (redundant) age: int # Required due to total=True bio: NotRequired[str] # Optional despite total=True # Valid constructions partial = PartialUser(name="Alice") # name required, age optional full = User(name="Bob", age=25) # name and age required, bio optional # Inheritance maintains original field requirements class Employee(PartialUser): department: str # Required (new field) # name: still Required (inherited) # age: still optional (inherited) emp = Employee(name="Charlie", department="Engineering") # ✅ Employee(department="Engineering") # ❌ e: Employee = {"age": 1} # ❌ ``` Screenshot 2025-08-11 at 22 02 57 ## Implementation The implementation reuses existing validation logic done in https://github.com/astral-sh/ruff/pull/19782 ### ℹ️ Why I did NOT synthesize an `__init__` for `TypedDict`: `TypedDict` inherits `dict.__init__(self, *args, **kwargs)` that accepts all arguments. The type resolution system finds this inherited signature **before** looking for synthesized members. So `own_synthesized_member()` is never called because a signature already exists. To force synthesis, you'd have to override Python’s inheritance mechanism, which would break compatibility with the existing ecosystem. This is why I went with ad-hoc validation. IMO it's the only viable approach that respects Python’s inheritance semantics while providing the required validation. ### Refacto of `Field` **Before:** ```rust struct Field<'db> { declared_ty: Type<'db>, default_ty: Option>, // NamedTuple and dataclass only init_only: bool, // dataclass only init: bool, // dataclass only is_required: Option, // TypedDict only } ``` **After:** ```rust struct Field<'db> { declared_ty: Type<'db>, kind: FieldKind<'db>, } enum FieldKind<'db> { NamedTuple { default_ty: Option> }, Dataclass { default_ty: Option>, init_only: bool, init: bool }, TypedDict { is_required: bool }, } ``` ## Test Plan Updated Markdown tests --------- Co-authored-by: David Peter --- crates/ty/docs/environment.md | 4 + crates/ty/docs/rules.md | 157 +++++--- .../unsupported_type_qualifiers.md | 29 +- .../resources/mdtest/typed_dict.md | 371 +++++++++++++++++- crates/ty_python_semantic/src/place.rs | 10 + crates/ty_python_semantic/src/types.rs | 58 +-- crates/ty_python_semantic/src/types/class.rs | 144 +++++-- .../src/types/class_base.rs | 3 +- .../src/types/diagnostic.rs | 63 ++- .../ty_python_semantic/src/types/display.rs | 2 +- crates/ty_python_semantic/src/types/infer.rs | 147 ++++--- .../src/types/type_ordering.rs | 2 +- .../src/types/typed_dict.rs | 361 +++++++++++++++++ ty.schema.json | 10 + 14 files changed, 1113 insertions(+), 248 deletions(-) create mode 100644 crates/ty_python_semantic/src/types/typed_dict.rs diff --git a/crates/ty/docs/environment.md b/crates/ty/docs/environment.md index 30935a8a094ff..c4552f2e58b49 100644 --- a/crates/ty/docs/environment.md +++ b/crates/ty/docs/environment.md @@ -33,6 +33,10 @@ when necessary, e.g. to watch for file system changes or a dedicated UI thread. ty also reads the following externally defined environment variables: +### `CONDA_DEFAULT_ENV` + +Used to determine if an active Conda environment is the base environment or not. + ### `CONDA_PREFIX` Used to detect an activated Conda environment location. diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index cd207b21f3dcd..3043c84eaa500 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -36,7 +36,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-non-callable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L109) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L110) **What it does** @@ -58,7 +58,7 @@ Calling a non-callable object will raise a `TypeError` at runtime. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-argument-forms) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L153) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L154) **What it does** @@ -88,7 +88,7 @@ f(int) # error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-declarations) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L179) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L180) **What it does** @@ -117,7 +117,7 @@ a = 1 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L204) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L205) **What it does** @@ -147,7 +147,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20cyclic-class-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L230) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L231) **What it does** @@ -177,7 +177,7 @@ class B(A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L295) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L296) **What it does** @@ -202,7 +202,7 @@ class B(A, A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-kw-only) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L316) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L317) **What it does** @@ -306,7 +306,7 @@ def test(): -> "Literal[5]": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20inconsistent-mro) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L519) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L520) **What it does** @@ -334,7 +334,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20index-out-of-bounds) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L543) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L544) **What it does** @@ -358,7 +358,7 @@ t[3] # IndexError: tuple index out of range Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20instance-layout-conflict) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L348) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L349) **What it does** @@ -445,7 +445,7 @@ an atypical memory layout. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-argument-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L588) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L589) **What it does** @@ -470,7 +470,7 @@ func("foo") # error: [invalid-argument-type] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-assignment) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L628) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L629) **What it does** @@ -496,7 +496,7 @@ a: int = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-attribute-access) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1662) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1663) **What it does** @@ -528,7 +528,7 @@ C.instance_var = 3 # error: Cannot assign to instance variable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-await) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L650) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L651) **What it does** @@ -562,7 +562,7 @@ asyncio.run(main()) Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L680) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L681) **What it does** @@ -584,7 +584,7 @@ class A(42): ... # error: [invalid-base] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-context-manager) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L731) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L732) **What it does** @@ -609,7 +609,7 @@ with 1: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-declaration) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L752) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L753) **What it does** @@ -636,7 +636,7 @@ a: str Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-exception-caught) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L775) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L776) **What it does** @@ -678,7 +678,7 @@ except ZeroDivisionError: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-generic-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L811) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L812) **What it does** @@ -709,7 +709,7 @@ class C[U](Generic[T]): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-key) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L563) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L564) **What it does** @@ -738,7 +738,7 @@ alice["height"] # KeyError: 'height' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-legacy-type-variable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L837) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L838) **What it does** @@ -771,7 +771,7 @@ def f(t: TypeVar("U")): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L886) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L887) **What it does** @@ -803,7 +803,7 @@ class B(metaclass=f): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-named-tuple) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L493) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L494) **What it does** @@ -833,7 +833,7 @@ TypeError: can only inherit from a NamedTuple type and Generic Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L913) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L914) **What it does** @@ -881,7 +881,7 @@ def foo(x: int) -> int: ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-parameter-default) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L956) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L957) **What it does** @@ -905,7 +905,7 @@ def f(a: int = ''): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-protocol) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L430) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L431) **What it does** @@ -937,7 +937,7 @@ TypeError: Protocols can only inherit from other protocols, got Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-raise) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L976) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L977) Checks for `raise` statements that raise non-exceptions or use invalid @@ -984,7 +984,7 @@ def g(): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-return-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L609) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L610) **What it does** @@ -1007,7 +1007,7 @@ def func() -> int: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-super-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1019) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1020) **What it does** @@ -1061,7 +1061,7 @@ TODO #14889 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-alias-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L865) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L866) **What it does** @@ -1086,7 +1086,7 @@ NewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name mus Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-checking-constant) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1058) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1059) **What it does** @@ -1114,7 +1114,7 @@ TYPE_CHECKING = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-form) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1082) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1083) **What it does** @@ -1142,7 +1142,7 @@ b: Annotated[int] # `Annotated` expects at least two arguments Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1134) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1135) **What it does** @@ -1174,7 +1174,7 @@ f(10) # Error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1106) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1107) **What it does** @@ -1206,7 +1206,7 @@ class C: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-variable-constraints) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1162) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1163) **What it does** @@ -1239,7 +1239,7 @@ T = TypeVar('T', bound=str) # valid bound TypeVar Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1191) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1192) **What it does** @@ -1257,12 +1257,43 @@ def func(x: int): ... func() # TypeError: func() missing 1 required positional argument: 'x' ``` +## `missing-typed-dict-key` + + +Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · +[Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-typed-dict-key) · +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1762) + + +**What it does** + +Detects missing required keys in `TypedDict` constructor calls. + +**Why is this bad?** + +`TypedDict` requires all non-optional keys to be provided during construction. +Missing items can lead to a `KeyError` at runtime. + +**Example** + +```python +from typing import TypedDict + +class Person(TypedDict): + name: str + age: int + +alice: Person = {"name": "Alice"} # missing required key 'age' + +alice["age"] # KeyError +``` + ## `no-matching-overload` Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20no-matching-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1210) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1211) **What it does** @@ -1289,7 +1320,7 @@ func("string") # error: [no-matching-overload] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20non-subscriptable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1233) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1234) **What it does** @@ -1311,7 +1342,7 @@ Subscripting an object that does not support it will raise a `TypeError` at runt Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20not-iterable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1251) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1252) **What it does** @@ -1335,7 +1366,7 @@ for i in 34: # TypeError: 'int' object is not iterable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20parameter-already-assigned) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1302) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1303) **What it does** @@ -1389,7 +1420,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20static-assert-error) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1638) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1639) **What it does** @@ -1417,7 +1448,7 @@ static_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known tr Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20subclass-of-final-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1393) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1394) **What it does** @@ -1444,7 +1475,7 @@ class B(A): ... # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20too-many-positional-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1438) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1439) **What it does** @@ -1469,7 +1500,7 @@ f("foo") # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20type-assertion-failure) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1416) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1417) **What it does** @@ -1495,7 +1526,7 @@ def _(x: int): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unavailable-implicit-super-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1459) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1460) **What it does** @@ -1539,7 +1570,7 @@ class A: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unknown-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1516) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1517) **What it does** @@ -1564,7 +1595,7 @@ f(x=1, y=2) # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1537) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1538) **What it does** @@ -1590,7 +1621,7 @@ A().foo # AttributeError: 'A' object has no attribute 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1559) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1560) **What it does** @@ -1613,7 +1644,7 @@ import foo # ModuleNotFoundError: No module named 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1578) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1579) **What it does** @@ -1636,7 +1667,7 @@ print(x) # NameError: name 'x' is not defined Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-bool-conversion) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1271) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1272) **What it does** @@ -1671,7 +1702,7 @@ b1 < b2 < b1 # exception raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-operator) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1597) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1598) **What it does** @@ -1697,7 +1728,7 @@ A() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20zero-stepsize-in-slice) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1619) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1620) **What it does** @@ -1720,7 +1751,7 @@ l[1:10:0] # ValueError: slice step cannot be zero Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20ambiguous-protocol-member) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L458) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L459) **What it does** @@ -1759,7 +1790,7 @@ class SubProto(BaseProto, Protocol): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20deprecated) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L274) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L275) **What it does** @@ -1812,7 +1843,7 @@ a = 20 / 0 # type: ignore Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1323) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1324) **What it does** @@ -1838,7 +1869,7 @@ A.c # AttributeError: type object 'A' has no attribute 'c' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-implicit-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L127) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L128) **What it does** @@ -1868,7 +1899,7 @@ A()[0] # TypeError: 'A' object is not subscriptable Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1345) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1346) **What it does** @@ -1898,7 +1929,7 @@ from module import a # ImportError: cannot import name 'a' from 'module' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20redundant-cast) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1690) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1691) **What it does** @@ -1923,7 +1954,7 @@ cast(int, f()) # Redundant Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20undefined-reveal) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1498) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1499) **What it does** @@ -1974,7 +2005,7 @@ a = 20 / 0 # ty: ignore[division-by-zero] Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-global) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1711) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1712) **What it does** @@ -2028,7 +2059,7 @@ def g(): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L698) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L699) **What it does** @@ -2065,7 +2096,7 @@ class D(C): ... # error: [unsupported-base] Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20division-by-zero) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L256) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L257) **What it does** @@ -2087,7 +2118,7 @@ Dividing by zero raises a `ZeroDivisionError` at runtime. Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1371) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1372) **What it does** diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/unsupported_type_qualifiers.md b/crates/ty_python_semantic/resources/mdtest/annotations/unsupported_type_qualifiers.md index 271b6fd014c3c..1c02eac9f0bf9 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/unsupported_type_qualifiers.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/unsupported_type_qualifiers.md @@ -6,14 +6,12 @@ Several type qualifiers are unsupported by ty currently. However, we also don't errors if you use one in an annotation: ```py -from typing_extensions import Final, Required, NotRequired, ReadOnly, TypedDict +from typing_extensions import Final, ReadOnly, TypedDict X: Final = 42 Y: Final[int] = 42 class Bar(TypedDict): - x: Required[int] - y: NotRequired[str] z: ReadOnly[bytes] ``` @@ -25,23 +23,16 @@ One thing that is supported is error messages for using type qualifiers in type from typing_extensions import Final, ClassVar, Required, NotRequired, ReadOnly def _( - a: ( - Final # error: [invalid-type-form] "Type qualifier `typing.Final` is not allowed in type expressions (only in annotation expressions)" - | int - ), - b: ( - ClassVar # error: [invalid-type-form] "Type qualifier `typing.ClassVar` is not allowed in type expressions (only in annotation expressions)" - | int - ), - c: Required, # error: [invalid-type-form] "Type qualifier `typing.Required` is not allowed in type expressions (only in annotation expressions, and only with exactly one argument)" - d: NotRequired, # error: [invalid-type-form] "Type qualifier `typing.NotRequired` is not allowed in type expressions (only in annotation expressions, and only with exactly one argument)" - e: ReadOnly, # error: [invalid-type-form] "Type qualifier `typing.ReadOnly` is not allowed in type expressions (only in annotation expressions, and only with exactly one argument)" + # error: [invalid-type-form] "Type qualifier `typing.Final` is not allowed in type expressions (only in annotation expressions)" + a: Final | int, + # error: [invalid-type-form] "Type qualifier `typing.ClassVar` is not allowed in type expressions (only in annotation expressions)" + b: ClassVar | int, + # error: [invalid-type-form] "Type qualifier `typing.ReadOnly` is not allowed in type expressions (only in annotation expressions, and only with exactly one argument)" + c: ReadOnly | int, ) -> None: reveal_type(a) # revealed: Unknown | int reveal_type(b) # revealed: Unknown | int - reveal_type(c) # revealed: Unknown - reveal_type(d) # revealed: Unknown - reveal_type(e) # revealed: Unknown + reveal_type(c) # revealed: Unknown | int ``` ## Inheritance @@ -53,7 +44,5 @@ from typing_extensions import Final, ClassVar, Required, NotRequired, ReadOnly class A(Final): ... # error: [invalid-base] class B(ClassVar): ... # error: [invalid-base] -class C(Required): ... # error: [invalid-base] -class D(NotRequired): ... # error: [invalid-base] -class E(ReadOnly): ... # error: [invalid-base] +class C(ReadOnly): ... # error: [invalid-base] ``` diff --git a/crates/ty_python_semantic/resources/mdtest/typed_dict.md b/crates/ty_python_semantic/resources/mdtest/typed_dict.md index cdc8329816a9e..19c53533a4654 100644 --- a/crates/ty_python_semantic/resources/mdtest/typed_dict.md +++ b/crates/ty_python_semantic/resources/mdtest/typed_dict.md @@ -21,12 +21,10 @@ inferred based on the `TypedDict` definition: ```py alice: Person = {"name": "Alice", "age": 30} -# TODO: this should be `str` -reveal_type(alice["name"]) # revealed: Unknown -# TODO: this should be `int | None` -reveal_type(alice["age"]) # revealed: Unknown +reveal_type(alice["name"]) # revealed: str +reveal_type(alice["age"]) # revealed: int | None -# TODO: this should reveal `Unknown`, and it should emit an error +# error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "non_existing"" reveal_type(alice["non_existing"]) # revealed: Unknown ``` @@ -51,23 +49,26 @@ bob.update(age=26) The construction of a `TypedDict` is checked for type correctness: ```py -# TODO: these should be errors (invalid argument type) +# error: [invalid-argument-type] "Invalid argument to key "name" with declared type `str` on TypedDict `Person`" eve1a: Person = {"name": b"Eve", "age": None} +# error: [invalid-argument-type] "Invalid argument to key "name" with declared type `str` on TypedDict `Person`" eve1b = Person(name=b"Eve", age=None) -# TODO: these should be errors (missing required key) +# error: [missing-typed-dict-key] "Missing required key 'name' in TypedDict `Person` constructor" eve2a: Person = {"age": 22} +# error: [missing-typed-dict-key] "Missing required key 'name' in TypedDict `Person` constructor" eve2b = Person(age=22) -# TODO: these should be errors (additional key) +# error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "extra"" eve3a: Person = {"name": "Eve", "age": 25, "extra": True} +# error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "extra"" eve3b = Person(name="Eve", age=25, extra=True) ``` Assignments to keys are also validated: ```py -# TODO: this should be an error +# error: [invalid-assignment] "Invalid assignment to key "name" with declared type `str` on TypedDict `Person`: value of type `None`" alice["name"] = None # error: [invalid-assignment] "Invalid assignment to key "name" with declared type `str` on TypedDict `Person`: value of type `None`" @@ -77,13 +78,221 @@ bob["name"] = None Assignments to non-existing keys are disallowed: ```py -# TODO: this should be an error +# error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "extra"" alice["extra"] = True # error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "extra"" bob["extra"] = True ``` +## Validation of `TypedDict` construction + +```py +from typing import TypedDict + +class Person(TypedDict): + name: str + age: int | None + +class House: + owner: Person + +house = House() + +def accepts_person(p: Person) -> None: + pass +``` + +The following constructions of `Person` are all valid: + +```py +alice1: Person = {"name": "Alice", "age": 30} +Person(name="Alice", age=30) +Person({"name": "Alice", "age": 30}) + +accepts_person({"name": "Alice", "age": 30}) +house.owner = {"name": "Alice", "age": 30} +``` + +All of these are missing the required `age` field: + +```py +# error: [missing-typed-dict-key] "Missing required key 'age' in TypedDict `Person` constructor" +alice2: Person = {"name": "Alice"} +# error: [missing-typed-dict-key] "Missing required key 'age' in TypedDict `Person` constructor" +Person(name="Alice") +# error: [missing-typed-dict-key] "Missing required key 'age' in TypedDict `Person` constructor" +Person({"name": "Alice"}) + +# TODO: this should be an error, similar to the above +accepts_person({"name": "Alice"}) +# TODO: this should be an error, similar to the above +house.owner = {"name": "Alice"} +``` + +All of these have an invalid type for the `name` field: + +```py +# error: [invalid-argument-type] "Invalid argument to key "name" with declared type `str` on TypedDict `Person`: value of type `None`" +alice3: Person = {"name": None, "age": 30} +# error: [invalid-argument-type] "Invalid argument to key "name" with declared type `str` on TypedDict `Person`: value of type `None`" +Person(name=None, age=30) +# error: [invalid-argument-type] "Invalid argument to key "name" with declared type `str` on TypedDict `Person`: value of type `None`" +Person({"name": None, "age": 30}) + +# TODO: this should be an error, similar to the above +accepts_person({"name": None, "age": 30}) +# TODO: this should be an error, similar to the above +house.owner = {"name": None, "age": 30} +``` + +All of these have an extra field that is not defined in the `TypedDict`: + +```py +# error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "extra"" +alice4: Person = {"name": "Alice", "age": 30, "extra": True} +# error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "extra"" +Person(name="Alice", age=30, extra=True) +# error: [invalid-key] "Invalid key access on TypedDict `Person`: Unknown key "extra"" +Person({"name": "Alice", "age": 30, "extra": True}) + +# TODO: this should be an error +accepts_person({"name": "Alice", "age": 30, "extra": True}) +# TODO: this should be an error +house.owner = {"name": "Alice", "age": 30, "extra": True} +``` + +## Type ignore compatibility issues + +Users should be able to ignore TypedDict validation errors with `# type: ignore` + +```py +from typing import TypedDict + +class Person(TypedDict): + name: str + age: int + +alice_bad: Person = {"name": None} # type: ignore +Person(name=None, age=30) # type: ignore +Person(name="Alice", age=30, extra=True) # type: ignore +``` + +## Positional dictionary constructor pattern + +The positional dictionary constructor pattern (used by libraries like strawberry) should work +correctly: + +```py +from typing import TypedDict + +class User(TypedDict): + name: str + age: int + +# Valid usage - all required fields provided +user1 = User({"name": "Alice", "age": 30}) + +# error: [missing-typed-dict-key] "Missing required key 'age' in TypedDict `User` constructor" +user2 = User({"name": "Bob"}) + +# error: [invalid-argument-type] "Invalid argument to key "name" with declared type `str` on TypedDict `User`: value of type `None`" +user3 = User({"name": None, "age": 25}) + +# error: [invalid-key] "Invalid key access on TypedDict `User`: Unknown key "extra"" +user4 = User({"name": "Charlie", "age": 30, "extra": True}) +``` + +## Optional fields with `total=False` + +By default, all fields in a `TypedDict` are required (`total=True`). You can make all fields +optional by setting `total=False`: + +```py +from typing import TypedDict + +class OptionalPerson(TypedDict, total=False): + name: str + age: int | None + +# All fields are optional with total=False +charlie = OptionalPerson() +david = OptionalPerson(name="David") +emily = OptionalPerson(age=30) +frank = OptionalPerson(name="Frank", age=25) + +# TODO: we could emit an error here, because these fields are not guaranteed to exist +reveal_type(charlie["name"]) # revealed: str +reveal_type(david["age"]) # revealed: int | None +``` + +Type validation still applies to provided fields: + +```py +# error: [invalid-argument-type] "Invalid argument to key "name" with declared type `str` on TypedDict `OptionalPerson`" +invalid = OptionalPerson(name=123) +``` + +Extra fields are still not allowed, even with `total=False`: + +```py +# error: [invalid-key] "Invalid key access on TypedDict `OptionalPerson`: Unknown key "extra"" +invalid_extra = OptionalPerson(name="George", extra=True) +``` + +## `Required` and `NotRequired` + +You can have fine-grained control over field requirements using `Required` and `NotRequired` +qualifiers, which override the class-level `total=` setting: + +```py +from typing_extensions import TypedDict, Required, NotRequired + +# total=False by default, but id is explicitly Required +class Message(TypedDict, total=False): + id: Required[int] # Always required, even though total=False + content: str # Optional due to total=False + timestamp: NotRequired[str] # Explicitly optional (redundant here) + +# total=True by default, but content is explicitly NotRequired +class User(TypedDict): + name: str # Required due to total=True (default) + email: Required[str] # Explicitly required (redundant here) + bio: NotRequired[str] # Optional despite total=True + +# Valid Message constructions +msg1 = Message(id=1) # id required, content optional +msg2 = Message(id=2, content="Hello") # both provided +msg3 = Message(id=3, timestamp="2024-01-01") # id required, timestamp optional + +# Valid User constructions +user1 = User(name="Alice", email="alice@example.com") # required fields +user2 = User(name="Bob", email="bob@example.com", bio="Developer") # with optional bio + +reveal_type(msg1["id"]) # revealed: int +reveal_type(msg1["content"]) # revealed: str +reveal_type(user1["name"]) # revealed: str +reveal_type(user1["bio"]) # revealed: str +``` + +Constructor validation respects `Required`/`NotRequired` overrides: + +```py +# error: [missing-typed-dict-key] "Missing required key 'id' in TypedDict `Message` constructor" +invalid_msg = Message(content="Hello") # Missing required id + +# error: [missing-typed-dict-key] "Missing required key 'name' in TypedDict `User` constructor" +# error: [missing-typed-dict-key] "Missing required key 'email' in TypedDict `User` constructor" +invalid_user = User(bio="No name provided") # Missing required name and email +``` + +Type validation still applies to all fields when provided: + +```py +# error: [invalid-argument-type] "Invalid argument to key "id" with declared type `int` on TypedDict `Message`" +invalid_type = Message(id="not-an-int", content="Hello") +``` + ## Structural assignability Assignability between `TypedDict` types is structural, that is, it is based on the presence of keys @@ -134,8 +343,7 @@ alice: Person = {"name": "Alice"} # TODO: this should be an invalid-assignment error dangerous(alice) -# TODO: this should be `str` -reveal_type(alice["name"]) # revealed: Unknown +reveal_type(alice["name"]) # revealed: str ``` ## Key-based access @@ -224,6 +432,20 @@ def _(person: Person, unknown_key: Any): person[unknown_key] = "Eve" ``` +## `ReadOnly` + +`ReadOnly` is not supported yet, but this test makes sure that we do not emit any false positive +diagnostics: + +```py +from typing_extensions import TypedDict, ReadOnly, Required + +class Person(TypedDict, total=False): + id: ReadOnly[Required[int]] + name: str + age: int | None +``` + ## Methods on `TypedDict` ```py @@ -340,10 +562,79 @@ class Employee(Person): alice: Employee = {"name": "Alice", "employee_id": 1} -# TODO: this should be an error (missing required key) +# error: [missing-typed-dict-key] "Missing required key 'employee_id' in TypedDict `Employee` constructor" eve: Employee = {"name": "Eve"} ``` +When inheriting from a `TypedDict` with a different `total` setting, inherited fields maintain their +original requirement status, while new fields follow the child class's `total` setting: + +```py +from typing import TypedDict + +# Case 1: total=True parent, total=False child +class PersonBase(TypedDict): + id: int # required (from total=True) + name: str # required (from total=True) + +class PersonOptional(PersonBase, total=False): + age: int # optional (from total=False) + email: str # optional (from total=False) + +# Inherited fields keep their original requirement status +person1 = PersonOptional(id=1, name="Alice") # Valid - id/name still required +person2 = PersonOptional(id=1, name="Alice", age=25) # Valid - age optional +person3 = PersonOptional(id=1, name="Alice", email="alice@test.com") # Valid + +# These should be errors - missing required inherited fields +# error: [missing-typed-dict-key] "Missing required key 'id' in TypedDict `PersonOptional` constructor" +person_invalid1 = PersonOptional(name="Bob") + +# error: [missing-typed-dict-key] "Missing required key 'name' in TypedDict `PersonOptional` constructor" +person_invalid2 = PersonOptional(id=2) + +# Case 2: total=False parent, total=True child +class PersonBaseOptional(TypedDict, total=False): + id: int # optional (from total=False) + name: str # optional (from total=False) + +class PersonRequired(PersonBaseOptional): # total=True by default + age: int # required (from total=True) + +# New fields in child are required, inherited fields stay optional +person4 = PersonRequired(age=30) # Valid - only age required, id/name optional +person5 = PersonRequired(id=1, name="Charlie", age=35) # Valid - all provided + +# This should be an error - missing required new field +# error: [missing-typed-dict-key] "Missing required key 'age' in TypedDict `PersonRequired` constructor" +person_invalid3 = PersonRequired(id=3, name="David") +``` + +This also works with `Required` and `NotRequired`: + +```py +from typing_extensions import TypedDict, Required, NotRequired + +# Case 3: Mixed inheritance with Required/NotRequired +class PersonMixed(TypedDict, total=False): + id: Required[int] # required despite total=False + name: str # optional due to total=False + +class Employee(PersonMixed): # total=True by default + department: str # required due to total=True + +# id stays required (Required override), name stays optional, department is required +emp1 = Employee(id=1, department="Engineering") # Valid +emp2 = Employee(id=2, name="Eve", department="Sales") # Valid + +# Errors for missing required keys +# error: [missing-typed-dict-key] "Missing required key 'id' in TypedDict `Employee` constructor" +emp_invalid1 = Employee(department="HR") + +# error: [missing-typed-dict-key] "Missing required key 'department' in TypedDict `Employee` constructor" +emp_invalid2 = Employee(id=3) +``` + ## Generic `TypedDict` `TypedDict`s can also be generic. @@ -362,7 +653,7 @@ class TaggedData(TypedDict, Generic[T]): p1: TaggedData[int] = {"data": 42, "tag": "number"} p2: TaggedData[str] = {"data": "Hello", "tag": "text"} -# TODO: this should be an error (type mismatch) +# error: [invalid-argument-type] "Invalid argument to key "data" with declared type `int` on TypedDict `TaggedData`: value of type `Literal["not a number"]`" p3: TaggedData[int] = {"data": "not a number", "tag": "number"} ``` @@ -383,7 +674,7 @@ class TaggedData[T](TypedDict): p1: TaggedData[int] = {"data": 42, "tag": "number"} p2: TaggedData[str] = {"data": "Hello", "tag": "text"} -# TODO: this should be an error (type mismatch) +# error: [invalid-argument-type] "Invalid argument to key "data" with declared type `int` on TypedDict `TaggedData`: value of type `Literal["not a number"]`" p3: TaggedData[int] = {"data": "not a number", "tag": "number"} ``` @@ -475,4 +766,54 @@ def write_to_non_literal_string_key(person: Person, str_key: str): person[str_key] = "Alice" # error: [invalid-key] ``` +## Import aliases + +`TypedDict` can be imported with aliases and should work correctly: + +```py +from typing import TypedDict as TD +from typing_extensions import Required + +class UserWithAlias(TD, total=False): + name: Required[str] + age: int + +user_empty = UserWithAlias(name="Alice") # name is required +user_partial = UserWithAlias(name="Alice", age=30) + +# error: [missing-typed-dict-key] "Missing required key 'name' in TypedDict `UserWithAlias` constructor" +user_invalid = UserWithAlias(age=30) + +reveal_type(user_empty["name"]) # revealed: str +reveal_type(user_partial["age"]) # revealed: int +``` + +## Shadowing behavior + +When a local class shadows the `TypedDict` import, only the actual `TypedDict` import should be +treated as a `TypedDict`: + +```py +from typing import TypedDict as TD + +class TypedDict: + def __init__(self): + pass + +class NotActualTypedDict(TypedDict, total=True): + name: str + +class ActualTypedDict(TD, total=True): + name: str + +not_td = NotActualTypedDict() +reveal_type(not_td) # revealed: NotActualTypedDict + +# error: [missing-typed-dict-key] "Missing required key 'name' in TypedDict `ActualTypedDict` constructor" +actual_td = ActualTypedDict() +actual_td = ActualTypedDict(name="Alice") +reveal_type(actual_td) # revealed: ActualTypedDict +reveal_type(actual_td["name"]) # revealed: str +``` + [`typeddict`]: https://typing.python.org/en/latest/spec/typeddict.html diff --git a/crates/ty_python_semantic/src/place.rs b/crates/ty_python_semantic/src/place.rs index 41fc651dc113a..56e5637e32372 100644 --- a/crates/ty_python_semantic/src/place.rs +++ b/crates/ty_python_semantic/src/place.rs @@ -574,6 +574,16 @@ impl<'db> PlaceAndQualifiers<'db> { self.qualifiers.contains(TypeQualifiers::INIT_VAR) } + /// Returns `true` if the place has a `Required` type qualifier. + pub(crate) fn is_required(&self) -> bool { + self.qualifiers.contains(TypeQualifiers::REQUIRED) + } + + /// Returns `true` if the place has a `NotRequired` type qualifier. + pub(crate) fn is_not_required(&self) -> bool { + self.qualifiers.contains(TypeQualifiers::NOT_REQUIRED) + } + /// Returns `Some(…)` if the place is qualified with `typing.Final` without a specified type. pub(crate) fn is_bare_final(&self) -> Option { match self { diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index b1fb7dddc67d5..f8fbda0850e61 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -37,7 +37,6 @@ use crate::semantic_index::scope::ScopeId; use crate::semantic_index::{imported_modules, place_table, semantic_index}; use crate::suppression::check_suppressions; use crate::types::call::{Binding, Bindings, CallArguments, CallableBinding}; -use crate::types::class::{CodeGeneratorKind, Field}; pub(crate) use crate::types::class_base::ClassBase; use crate::types::constraints::{ Constraints, IteratorConstraintsExtension, OptionConstraintsExtension, @@ -63,10 +62,11 @@ use crate::types::mro::{Mro, MroError, MroIterator}; pub(crate) use crate::types::narrow::infer_narrowing_constraint; use crate::types::signatures::{Parameter, ParameterForm, Parameters, walk_signature}; use crate::types::tuple::TupleSpec; +pub(crate) use crate::types::typed_dict::{TypedDictParams, TypedDictType, walk_typed_dict_type}; use crate::types::variance::{TypeVarVariance, VarianceInferable}; use crate::unpack::EvaluationMode; pub use crate::util::diagnostics::add_inferred_python_version_hint_to_diagnostic; -use crate::{Db, FxOrderMap, FxOrderSet, Module, Program}; +use crate::{Db, FxOrderSet, Module, Program}; pub(crate) use class::{ClassLiteral, ClassType, GenericAlias, KnownClass}; use instance::Protocol; pub use instance::{NominalInstanceType, ProtocolInstanceType}; @@ -96,6 +96,7 @@ mod string_annotation; mod subclass_of; mod tuple; mod type_ordering; +mod typed_dict; mod unpacker; mod variance; mod visitor; @@ -1039,9 +1040,7 @@ impl<'db> Type<'db> { } pub(crate) fn typed_dict(defining_class: impl Into>) -> Self { - Self::TypedDict(TypedDictType { - defining_class: defining_class.into(), - }) + Self::TypedDict(TypedDictType::new(defining_class.into())) } #[must_use] @@ -5899,7 +5898,7 @@ impl<'db> Type<'db> { Type::AlwaysTruthy | Type::AlwaysFalsy => KnownClass::Type.to_instance(db), Type::BoundSuper(_) => KnownClass::Super.to_class_literal(db), Type::ProtocolInstance(protocol) => protocol.to_meta_type(db), - Type::TypedDict(typed_dict) => SubclassOfType::from(db, typed_dict.defining_class), + Type::TypedDict(typed_dict) => SubclassOfType::from(db, typed_dict.defining_class()), Type::TypeAlias(alias) => alias.value_type(db).to_meta_type(db), } } @@ -6366,7 +6365,7 @@ impl<'db> Type<'db> { }, Type::TypedDict(typed_dict) => { - Some(TypeDefinition::Class(typed_dict.defining_class.definition(db))) + Some(TypeDefinition::Class(typed_dict.defining_class().definition(db))) } Self::Union(_) | Self::Intersection(_) => None, @@ -6879,6 +6878,12 @@ bitflags! { const FINAL = 1 << 1; /// `dataclasses.InitVar` const INIT_VAR = 1 << 2; + /// `typing_extensions.Required` + const REQUIRED = 1 << 3; + /// `typing_extensions.NotRequired` + const NOT_REQUIRED = 1 << 4; + /// `typing_extensions.ReadOnly` + const READ_ONLY = 1 << 5; } } @@ -6894,6 +6899,8 @@ impl TypeQualifiers { Self::CLASS_VAR => "ClassVar", Self::FINAL => "Final", Self::INIT_VAR => "InitVar", + Self::REQUIRED => "Required", + Self::NOT_REQUIRED => "NotRequired", _ => { unreachable!("Only a single bit should be set when calling `TypeQualifiers::name`") } @@ -9849,43 +9856,6 @@ impl<'db> EnumLiteralType<'db> { } } -/// Type that represents the set of all inhabitants (`dict` instances) that conform to -/// a given `TypedDict` schema. -#[derive(Debug, Copy, Clone, PartialEq, Eq, salsa::Update, Hash, get_size2::GetSize)] -pub struct TypedDictType<'db> { - /// A reference to the class (inheriting from `typing.TypedDict`) that specifies the - /// schema of this `TypedDict`. - defining_class: ClassType<'db>, -} - -impl<'db> TypedDictType<'db> { - pub(crate) fn items(self, db: &'db dyn Db) -> FxOrderMap> { - let (class_literal, specialization) = self.defining_class.class_literal(db); - class_literal.fields(db, specialization, CodeGeneratorKind::TypedDict) - } - - pub(crate) fn apply_type_mapping_impl<'a>( - self, - db: &'db dyn Db, - type_mapping: &TypeMapping<'a, 'db>, - visitor: &ApplyTypeMappingVisitor<'db>, - ) -> Self { - Self { - defining_class: self - .defining_class - .apply_type_mapping_impl(db, type_mapping, visitor), - } - } -} - -fn walk_typed_dict_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( - db: &'db dyn Db, - typed_dict: TypedDictType<'db>, - visitor: &V, -) { - visitor.visit_type(db, typed_dict.defining_class.into()); -} - #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) enum BoundSuperError<'db> { InvalidPivotClassType { diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 1c736dfc4b6b3..58fe067963a9d 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -27,13 +27,14 @@ use crate::types::generics::{GenericContext, Specialization, walk_specialization use crate::types::infer::nearest_enclosing_class; use crate::types::signatures::{CallableSignature, Parameter, Parameters, Signature}; use crate::types::tuple::{TupleSpec, TupleType}; +use crate::types::typed_dict::typed_dict_params_from_class_def; use crate::types::{ ApplyTypeMappingVisitor, Binding, BoundSuperError, BoundSuperType, CallableType, DataclassParams, DeprecatedInstance, HasRelationToVisitor, IsEquivalentVisitor, KnownInstanceType, ManualPEP695TypeAliasType, NormalizedVisitor, PropertyInstanceType, StringLiteralType, TypeAliasType, TypeMapping, TypeRelation, TypeVarBoundOrConstraints, - TypeVarInstance, TypeVarKind, VarianceInferable, declaration_type, infer_definition_types, - todo_type, + TypeVarInstance, TypeVarKind, TypedDictParams, VarianceInferable, declaration_type, + infer_definition_types, todo_type, }; use crate::{ Db, FxIndexMap, FxOrderSet, Program, @@ -1241,24 +1242,51 @@ impl MethodDecorator { } } +/// Kind-specific metadata for different types of fields +#[derive(Debug, Clone, PartialEq, Eq)] +pub(crate) enum FieldKind<'db> { + /// `NamedTuple` field metadata + NamedTuple { default_ty: Option> }, + /// dataclass field metadata + Dataclass { + /// The type of the default value for this field + default_ty: Option>, + /// Whether or not this field is "init-only". If this is true, it only appears in the + /// `__init__` signature, but is not accessible as a real field + init_only: bool, + /// Whether or not this field should appear in the signature of `__init__`. + init: bool, + /// Whether or not this field can only be passed as a keyword argument to `__init__`. + kw_only: Option, + }, + /// `TypedDict` field metadata + TypedDict { + /// Whether this field is required + is_required: bool, + }, +} + /// Metadata regarding a dataclass field/attribute or a `TypedDict` "item" / key-value pair. #[derive(Debug, Clone, PartialEq, Eq)] pub(crate) struct Field<'db> { /// The declared type of the field pub(crate) declared_ty: Type<'db>, + /// Kind-specific metadata for this field + pub(crate) kind: FieldKind<'db>, +} - /// The type of the default value for this field - pub(crate) default_ty: Option>, - - /// Whether or not this field is "init-only". If this is true, it only appears in the - /// `__init__` signature, but is not accessible as a real field - pub(crate) init_only: bool, - - /// Whether or not this field should appear in the signature of `__init__`. - pub(crate) init: bool, - - /// Whether or not this field can only be passed as a keyword argument to `__init__`. - pub(crate) kw_only: Option, +impl Field<'_> { + pub(crate) const fn is_required(&self) -> bool { + match &self.kind { + FieldKind::NamedTuple { default_ty } => default_ty.is_none(), + // A dataclass field is NOT required if `default` (or `default_factory`) is set + // or if `init` has been set to `False`. + FieldKind::Dataclass { + init, default_ty, .. + } => default_ty.is_none() && *init, + FieldKind::TypedDict { is_required } => *is_required, + } + } } impl<'db> Field<'db> { @@ -1664,6 +1692,17 @@ impl<'db> ClassLiteral<'db> { .any(|base| matches!(base, ClassBase::TypedDict)) } + /// Compute `TypedDict` parameters dynamically based on MRO detection and AST parsing. + fn typed_dict_params(self, db: &'db dyn Db) -> Option { + if !self.is_typed_dict(db) { + return None; + } + + let module = parsed_module(db, self.file(db)).load(db); + let class_stmt = self.node(db, &module); + Some(typed_dict_params_from_class_def(class_stmt)) + } + /// Return the explicit `metaclass` of this class, if one is defined. /// /// ## Note @@ -1967,7 +2006,10 @@ impl<'db> ClassLiteral<'db> { } if CodeGeneratorKind::NamedTuple.matches(db, self) { - if let Some(field) = self.own_fields(db, specialization).get(name) { + if let Some(field) = self + .own_fields(db, specialization, CodeGeneratorKind::NamedTuple) + .get(name) + { let property_getter_signature = Signature::new( Parameters::new([Parameter::positional_only(Some(Name::new_static("self")))]), Some(field.declared_ty), @@ -2033,17 +2075,19 @@ impl<'db> ClassLiteral<'db> { Type::instance(db, self.apply_optional_specialization(db, specialization)); let signature_from_fields = |mut parameters: Vec<_>, return_ty: Option>| { - for ( - field_name, - field @ Field { - declared_ty: mut field_ty, - mut default_ty, - init_only: _, - init, - kw_only, - }, - ) in self.fields(db, specialization, field_policy) - { + for (field_name, field) in self.fields(db, specialization, field_policy) { + let (init, mut default_ty, kw_only) = match field.kind { + FieldKind::NamedTuple { default_ty } => (true, default_ty, None), + FieldKind::Dataclass { + init, + default_ty, + kw_only, + .. + } => (init, default_ty, kw_only), + FieldKind::TypedDict { .. } => continue, + }; + let mut field_ty = field.declared_ty; + if name == "__init__" && !init { // Skip fields with `init=False` continue; @@ -2351,7 +2395,7 @@ impl<'db> ClassLiteral<'db> { if field_policy == CodeGeneratorKind::NamedTuple { // NamedTuples do not allow multiple inheritance, so it is sufficient to enumerate the // fields of this class only. - return self.own_fields(db, specialization); + return self.own_fields(db, specialization, field_policy); } let matching_classes_in_mro: Vec<_> = self @@ -2374,7 +2418,7 @@ impl<'db> ClassLiteral<'db> { matching_classes_in_mro .into_iter() .rev() - .flat_map(|(class, specialization)| class.own_fields(db, specialization)) + .flat_map(|(class, specialization)| class.own_fields(db, specialization, field_policy)) // We collect into a FxOrderMap here to deduplicate attributes .collect() } @@ -2394,6 +2438,7 @@ impl<'db> ClassLiteral<'db> { self, db: &'db dyn Db, specialization: Option>, + field_policy: CodeGeneratorKind, ) -> FxOrderMap> { let mut attributes = FxOrderMap::default(); @@ -2401,7 +2446,10 @@ impl<'db> ClassLiteral<'db> { let table = place_table(db, class_body_scope); let use_def = use_def_map(db, class_body_scope); + + let typed_dict_params = self.typed_dict_params(db); let mut kw_only_sentinel_field_seen = false; + for (symbol_id, declarations) in use_def.all_end_of_scope_symbol_declarations() { // Here, we exclude all declarations that are not annotated assignments. We need this because // things like function definitions and nested classes would otherwise be considered dataclass @@ -2456,12 +2504,34 @@ impl<'db> ClassLiteral<'db> { } } + let kind = match field_policy { + CodeGeneratorKind::NamedTuple => FieldKind::NamedTuple { default_ty }, + CodeGeneratorKind::DataclassLike => FieldKind::Dataclass { + default_ty, + init_only: attr.is_init_var(), + init, + kw_only, + }, + CodeGeneratorKind::TypedDict => { + let is_required = if attr.is_required() { + // Explicit Required[T] annotation - always required + true + } else if attr.is_not_required() { + // Explicit NotRequired[T] annotation - never required + false + } else { + // No explicit qualifier - use class default (`total` parameter) + typed_dict_params + .expect("TypedDictParams should be available for CodeGeneratorKind::TypedDict") + .contains(TypedDictParams::TOTAL) + }; + FieldKind::TypedDict { is_required } + } + }; + let mut field = Field { declared_ty: attr_ty.apply_optional_specialization(db, specialization), - default_ty, - init_only: attr.is_init_var(), - init, - kw_only, + kind, }; // Check if this is a KW_ONLY sentinel and mark subsequent fields as keyword-only @@ -2470,8 +2540,14 @@ impl<'db> ClassLiteral<'db> { } // If no explicit kw_only setting and we've seen KW_ONLY sentinel, mark as keyword-only - if field.kw_only.is_none() && kw_only_sentinel_field_seen { - field.kw_only = Some(true); + if kw_only_sentinel_field_seen { + if let FieldKind::Dataclass { + kw_only: ref mut kw @ None, + .. + } = field.kind + { + *kw = Some(true); + } } attributes.insert(symbol.name().clone(), field); diff --git a/crates/ty_python_semantic/src/types/class_base.rs b/crates/ty_python_semantic/src/types/class_base.rs index eeb83a3cbb2b3..08eda64f0934c 100644 --- a/crates/ty_python_semantic/src/types/class_base.rs +++ b/crates/ty_python_semantic/src/types/class_base.rs @@ -1,4 +1,5 @@ use crate::Db; +use crate::types::class::CodeGeneratorKind; use crate::types::generics::Specialization; use crate::types::tuple::TupleType; use crate::types::{ @@ -206,7 +207,7 @@ impl<'db> ClassBase<'db> { SpecialFormType::Generic => Some(Self::Generic), SpecialFormType::NamedTuple => { - let fields = subclass.own_fields(db, None); + let fields = subclass.own_fields(db, None, CodeGeneratorKind::NamedTuple); Self::try_from_type( db, TupleType::heterogeneous( diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index 4930dd4f9e5f6..bc2fcfb2e3b2c 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -96,6 +96,7 @@ pub(crate) fn register_lints(registry: &mut LintRegistryBuilder) { registry.register_lint(&INVALID_ATTRIBUTE_ACCESS); registry.register_lint(&REDUNDANT_CAST); registry.register_lint(&UNRESOLVED_GLOBAL); + registry.register_lint(&MISSING_TYPED_DICT_KEY); // String annotations registry.register_lint(&BYTE_STRING_TYPE_ANNOTATION); @@ -1758,6 +1759,33 @@ declare_lint! { } } +declare_lint! { + /// ## What it does + /// Detects missing required keys in `TypedDict` constructor calls. + /// + /// ## Why is this bad? + /// `TypedDict` requires all non-optional keys to be provided during construction. + /// Missing items can lead to a `KeyError` at runtime. + /// + /// ## Example + /// ```python + /// from typing import TypedDict + /// + /// class Person(TypedDict): + /// name: str + /// age: int + /// + /// alice: Person = {"name": "Alice"} # missing required key 'age' + /// + /// alice["age"] # KeyError + /// ``` + pub(crate) static MISSING_TYPED_DICT_KEY = { + summary: "detects missing required keys in `TypedDict` constructors", + status: LintStatus::preview("1.0.0"), + default_level: Level::Error, + } +} + /// A collection of type check diagnostics. #[derive(Default, Eq, PartialEq, get_size2::GetSize)] pub struct TypeCheckDiagnostics { @@ -2761,18 +2789,18 @@ fn report_invalid_base<'ctx, 'db>( pub(crate) fn report_invalid_key_on_typed_dict<'db>( context: &InferContext<'db, '_>, - value_node: AnyNodeRef, - slice_node: AnyNodeRef, - value_ty: Type<'db>, - slice_ty: Type<'db>, + typed_dict_node: AnyNodeRef, + key_node: AnyNodeRef, + typed_dict_ty: Type<'db>, + key_ty: Type<'db>, items: &FxOrderMap>, ) { let db = context.db(); - if let Some(builder) = context.report_lint(&INVALID_KEY, slice_node) { - match slice_ty { + if let Some(builder) = context.report_lint(&INVALID_KEY, key_node) { + match key_ty { Type::StringLiteral(key) => { let key = key.value(db); - let typed_dict_name = value_ty.display(db); + let typed_dict_name = typed_dict_ty.display(db); let mut diagnostic = builder.into_diagnostic(format_args!( "Invalid key access on TypedDict `{typed_dict_name}`", @@ -2780,7 +2808,7 @@ pub(crate) fn report_invalid_key_on_typed_dict<'db>( diagnostic.annotate( context - .secondary(value_node) + .secondary(typed_dict_node) .message(format_args!("TypedDict `{typed_dict_name}`")), ); @@ -2799,8 +2827,8 @@ pub(crate) fn report_invalid_key_on_typed_dict<'db>( } _ => builder.into_diagnostic(format_args!( "TypedDict `{}` cannot be indexed with a key of type `{}`", - value_ty.display(db), - slice_ty.display(db), + typed_dict_ty.display(db), + key_ty.display(db), )), }; } @@ -2860,6 +2888,21 @@ pub(super) fn report_namedtuple_field_without_default_after_field_with_default<' } } +pub(crate) fn report_missing_typed_dict_key<'db>( + context: &InferContext<'db, '_>, + constructor_node: AnyNodeRef, + typed_dict_ty: Type<'db>, + missing_field: &str, +) { + let db = context.db(); + if let Some(builder) = context.report_lint(&MISSING_TYPED_DICT_KEY, constructor_node) { + let typed_dict_name = typed_dict_ty.display(db); + builder.into_diagnostic(format_args!( + "Missing required key '{missing_field}' in TypedDict `{typed_dict_name}` constructor", + )); + } +} + /// This function receives an unresolved `from foo import bar` import, /// where `foo` can be resolved to a module but that module does not /// have a `bar` member or submodule. diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index dd8412f4cf6c3..b8ec4bd61aaaa 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -315,7 +315,7 @@ impl Display for DisplayRepresentation<'_> { } f.write_str("]") } - Type::TypedDict(typed_dict) => f.write_str(typed_dict.defining_class.name(self.db)), + Type::TypedDict(typed_dict) => f.write_str(typed_dict.defining_class().name(self.db)), Type::TypeAlias(alias) => f.write_str(alias.name(self.db)), } } diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 9b8b43103e35e..43c1abed21527 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -90,7 +90,7 @@ use crate::semantic_index::{ ApplicableConstraints, EnclosingSnapshotResult, SemanticIndex, place_table, semantic_index, }; use crate::types::call::{Binding, Bindings, CallArguments, CallError, CallErrorKind}; -use crate::types::class::{CodeGeneratorKind, MetaclassErrorKind}; +use crate::types::class::{CodeGeneratorKind, FieldKind, MetaclassErrorKind}; use crate::types::diagnostic::{ self, CALL_NON_CALLABLE, CONFLICTING_DECLARATIONS, CONFLICTING_METACLASS, CYCLIC_CLASS_DEFINITION, DIVISION_BY_ZERO, DUPLICATE_KW_ONLY, INCONSISTENT_MRO, @@ -117,6 +117,10 @@ use crate::types::instance::SliceLiteral; use crate::types::mro::MroErrorKind; use crate::types::signatures::{CallableSignature, Signature}; use crate::types::tuple::{Tuple, TupleSpec, TupleSpecBuilder, TupleType}; +use crate::types::typed_dict::{ + TypedDictAssignmentKind, validate_typed_dict_constructor, validate_typed_dict_dict_literal, + validate_typed_dict_key_assignment, +}; use crate::types::unpacker::{UnpackResult, Unpacker}; use crate::types::{ CallDunderError, CallableType, ClassLiteral, ClassType, DataclassParams, DynamicType, @@ -1118,8 +1122,15 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if is_named_tuple { let mut field_with_default_encountered = None; - for (field_name, field) in class.own_fields(self.db(), None) { - if field.default_ty.is_some() { + for (field_name, field) in + class.own_fields(self.db(), None, CodeGeneratorKind::NamedTuple) + { + if matches!( + field.kind, + FieldKind::NamedTuple { + default_ty: Some(_) + } + ) { field_with_default_encountered = Some(field_name); } else if let Some(field_with_default) = field_with_default_encountered.as_ref() { @@ -3804,47 +3815,16 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if let Some(typed_dict) = value_ty.into_typed_dict() { if let Some(key) = slice_ty.into_string_literal() { let key = key.value(self.db()); - let items = typed_dict.items(self.db()); - if let Some((_, item)) = - items.iter().find(|(name, _)| *name == key) - { - if let Some(builder) = - context.report_lint(&INVALID_ASSIGNMENT, rhs) - { - let mut diagnostic = builder.into_diagnostic(format_args!( - "Invalid assignment to key \"{key}\" with declared type `{}` on TypedDict `{value_d}`", - item.declared_ty.display(db), - )); - - diagnostic.set_primary_message(format_args!( - "value of type `{assigned_d}`" - )); - - diagnostic.annotate( - self.context - .secondary(value.as_ref()) - .message(format_args!("TypedDict `{value_d}`")), - ); - - diagnostic.annotate( - self.context.secondary(slice.as_ref()).message( - format_args!( - "key has declared type `{}`", - item.declared_ty.display(db), - ), - ), - ); - } - } else { - report_invalid_key_on_typed_dict( - &self.context, - value.as_ref().into(), - slice.as_ref().into(), - value_ty, - slice_ty, - &items, - ); - } + validate_typed_dict_key_assignment( + &self.context, + typed_dict, + key, + assigned_ty, + value.as_ref(), + slice.as_ref(), + rhs, + TypedDictAssignmentKind::Subscript, + ); } else { // Check if the key has a valid type. We only allow string literals, a union of string literals, // or a dynamic type like `Any`. We can do this by checking assignability to `LiteralString`, @@ -4695,7 +4675,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { if let Some(value) = value { let inferred_ty = self.infer_maybe_standalone_expression(value); - let inferred_ty = if target + let mut inferred_ty = if target .as_name_expr() .is_some_and(|name| &name.id == "TYPE_CHECKING") { @@ -4705,6 +4685,25 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } else { inferred_ty }; + + // Validate `TypedDict` dictionary literal assignments + if let Some(typed_dict) = declared.inner_type().into_typed_dict() { + if let Some(dict_expr) = value.as_dict_expr() { + validate_typed_dict_dict_literal( + &self.context, + typed_dict, + dict_expr, + target.into(), + |expr| self.expression_type(expr), + ); + + // Override the inferred type of the dict literal to be the `TypedDict` type + // This ensures that the dict literal gets the correct type for key access + let typed_dict_type = Type::TypedDict(typed_dict); + inferred_ty = typed_dict_type; + } + } + self.add_declaration_with_binding( target.into(), definition, @@ -6269,6 +6268,22 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { .match_parameters(&call_arguments); self.infer_argument_types(arguments, &mut call_arguments, &bindings.argument_forms); + // Validate `TypedDict` constructor calls after argument type inference + if let Some(class_literal) = callable_type.into_class_literal() { + if class_literal.is_typed_dict(self.db()) { + let typed_dict_type = Type::typed_dict(ClassType::NonGeneric(class_literal)); + if let Some(typed_dict) = typed_dict_type.into_typed_dict() { + validate_typed_dict_constructor( + &self.context, + typed_dict, + arguments, + func.as_ref().into(), + |expr| self.expression_type(expr), + ); + } + } + } + let mut bindings = match bindings.check_types(self.db(), &call_arguments) { Ok(bindings) => bindings, Err(CallError(_, bindings)) => { @@ -9422,6 +9437,15 @@ impl<'db> TypeInferenceBuilder<'db, '_> { Type::SpecialForm(SpecialFormType::Final) => { TypeAndQualifiers::new(Type::unknown(), TypeQualifiers::FINAL) } + Type::SpecialForm(SpecialFormType::Required) => { + TypeAndQualifiers::new(Type::unknown(), TypeQualifiers::REQUIRED) + } + Type::SpecialForm(SpecialFormType::NotRequired) => { + TypeAndQualifiers::new(Type::unknown(), TypeQualifiers::NOT_REQUIRED) + } + Type::SpecialForm(SpecialFormType::ReadOnly) => { + TypeAndQualifiers::new(Type::unknown(), TypeQualifiers::READ_ONLY) + } Type::ClassLiteral(class) if class.is_known(self.db(), KnownClass::InitVar) => { @@ -9497,7 +9521,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } } Type::SpecialForm( - type_qualifier @ (SpecialFormType::ClassVar | SpecialFormType::Final), + type_qualifier @ (SpecialFormType::ClassVar + | SpecialFormType::Final + | SpecialFormType::Required + | SpecialFormType::NotRequired + | SpecialFormType::ReadOnly), ) => { let arguments = if let ast::Expr::Tuple(tuple) = slice { &*tuple.elts @@ -9516,6 +9544,15 @@ impl<'db> TypeInferenceBuilder<'db, '_> { SpecialFormType::Final => { type_and_qualifiers.add_qualifier(TypeQualifiers::FINAL); } + SpecialFormType::Required => { + type_and_qualifiers.add_qualifier(TypeQualifiers::REQUIRED); + } + SpecialFormType::NotRequired => { + type_and_qualifiers.add_qualifier(TypeQualifiers::NOT_REQUIRED); + } + SpecialFormType::ReadOnly => { + type_and_qualifiers.add_qualifier(TypeQualifiers::READ_ONLY); + } _ => unreachable!(), } type_and_qualifiers @@ -10802,15 +10839,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { KnownClass::Deque, ), - SpecialFormType::ReadOnly => { - self.infer_type_expression(arguments_slice); - todo_type!("`ReadOnly[]` type qualifier") - } - SpecialFormType::NotRequired => { - self.infer_type_expression(arguments_slice); - todo_type!("`NotRequired[]` type qualifier") - } - SpecialFormType::ClassVar | SpecialFormType::Final => { + SpecialFormType::ClassVar + | SpecialFormType::Final + | SpecialFormType::Required + | SpecialFormType::NotRequired + | SpecialFormType::ReadOnly => { if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) { let diag = builder.into_diagnostic(format_args!( "Type qualifier `{special_form}` is not allowed in type expressions \ @@ -10820,10 +10853,6 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } self.infer_type_expression(arguments_slice) } - SpecialFormType::Required => { - self.infer_type_expression(arguments_slice); - todo_type!("`Required[]` type qualifier") - } SpecialFormType::TypeIs => match arguments_slice { ast::Expr::Tuple(_) => { self.infer_type_expression(arguments_slice); diff --git a/crates/ty_python_semantic/src/types/type_ordering.rs b/crates/ty_python_semantic/src/types/type_ordering.rs index 21612c36148ac..d1262802e9a9d 100644 --- a/crates/ty_python_semantic/src/types/type_ordering.rs +++ b/crates/ty_python_semantic/src/types/type_ordering.rs @@ -245,7 +245,7 @@ pub(super) fn union_or_intersection_elements_ordering<'db>( } (Type::TypedDict(left), Type::TypedDict(right)) => { - left.defining_class.cmp(&right.defining_class) + left.defining_class().cmp(&right.defining_class()) } (Type::TypedDict(_), _) => Ordering::Less, (_, Type::TypedDict(_)) => Ordering::Greater, diff --git a/crates/ty_python_semantic/src/types/typed_dict.rs b/crates/ty_python_semantic/src/types/typed_dict.rs new file mode 100644 index 0000000000000..f6b03a225a828 --- /dev/null +++ b/crates/ty_python_semantic/src/types/typed_dict.rs @@ -0,0 +1,361 @@ +use bitflags::bitflags; +use ruff_python_ast::Arguments; +use ruff_python_ast::{self as ast, AnyNodeRef, StmtClassDef, name::Name}; + +use super::class::{ClassType, CodeGeneratorKind, Field}; +use super::context::InferContext; +use super::diagnostic::{ + INVALID_ARGUMENT_TYPE, INVALID_ASSIGNMENT, report_invalid_key_on_typed_dict, + report_missing_typed_dict_key, +}; +use super::{ApplyTypeMappingVisitor, Type, TypeMapping, visitor}; +use crate::{Db, FxOrderMap}; + +use ordermap::OrderSet; + +bitflags! { + /// Used for `TypedDict` class parameters. + /// Keeps track of the keyword arguments that were passed-in during class definition. + /// (see https://typing.python.org/en/latest/spec/typeddict.html) + #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] + pub struct TypedDictParams: u8 { + /// Whether keys are required by default (`total=True`) + const TOTAL = 1 << 0; + } +} + +impl get_size2::GetSize for TypedDictParams {} + +impl Default for TypedDictParams { + fn default() -> Self { + Self::TOTAL + } +} + +/// Type that represents the set of all inhabitants (`dict` instances) that conform to +/// a given `TypedDict` schema. +#[derive(Debug, Copy, Clone, PartialEq, Eq, salsa::Update, Hash, get_size2::GetSize)] +pub struct TypedDictType<'db> { + /// A reference to the class (inheriting from `typing.TypedDict`) that specifies the + /// schema of this `TypedDict`. + defining_class: ClassType<'db>, +} + +impl<'db> TypedDictType<'db> { + pub(crate) fn new(defining_class: ClassType<'db>) -> Self { + Self { defining_class } + } + + pub(crate) fn defining_class(self) -> ClassType<'db> { + self.defining_class + } + + pub(crate) fn items(self, db: &'db dyn Db) -> FxOrderMap> { + let (class_literal, specialization) = self.defining_class.class_literal(db); + class_literal.fields(db, specialization, CodeGeneratorKind::TypedDict) + } + + pub(crate) fn apply_type_mapping_impl<'a>( + self, + db: &'db dyn Db, + type_mapping: &TypeMapping<'a, 'db>, + visitor: &ApplyTypeMappingVisitor<'db>, + ) -> Self { + Self { + defining_class: self + .defining_class + .apply_type_mapping_impl(db, type_mapping, visitor), + } + } +} + +pub(crate) fn walk_typed_dict_type<'db, V: visitor::TypeVisitor<'db> + ?Sized>( + db: &'db dyn Db, + typed_dict: TypedDictType<'db>, + visitor: &V, +) { + visitor.visit_type(db, typed_dict.defining_class.into()); +} + +pub(super) fn typed_dict_params_from_class_def(class_stmt: &StmtClassDef) -> TypedDictParams { + let mut typed_dict_params = TypedDictParams::default(); + + // Check for `total` keyword argument in the class definition + // Note that it is fine to only check for Boolean literals here + // (https://typing.python.org/en/latest/spec/typeddict.html#totality) + if let Some(arguments) = &class_stmt.arguments { + for keyword in &arguments.keywords { + if keyword.arg.as_deref() == Some("total") + && matches!( + &keyword.value, + ast::Expr::BooleanLiteral(ast::ExprBooleanLiteral { value: false, .. }) + ) + { + typed_dict_params.remove(TypedDictParams::TOTAL); + } + } + } + + typed_dict_params +} + +#[derive(Debug, Clone, Copy)] +pub(super) enum TypedDictAssignmentKind { + /// For subscript assignments like `d["key"] = value` + Subscript, + /// For constructor arguments like `MyTypedDict(key=value)` + Constructor, +} + +impl TypedDictAssignmentKind { + fn diagnostic_name(self) -> &'static str { + match self { + Self::Subscript => "assignment", + Self::Constructor => "argument", + } + } + + fn diagnostic_type(self) -> &'static crate::lint::LintMetadata { + match self { + Self::Subscript => &INVALID_ASSIGNMENT, + Self::Constructor => &INVALID_ARGUMENT_TYPE, + } + } +} + +/// Validates assignment of a value to a specific key on a `TypedDict`. +/// Returns true if the assignment is valid, false otherwise. +#[allow(clippy::too_many_arguments)] +pub(super) fn validate_typed_dict_key_assignment<'db, 'ast>( + context: &InferContext<'db, 'ast>, + typed_dict: TypedDictType<'db>, + key: &str, + value_ty: Type<'db>, + typed_dict_node: impl Into>, + key_node: impl Into>, + value_node: impl Into>, + assignment_kind: TypedDictAssignmentKind, +) -> bool { + let db = context.db(); + let items = typed_dict.items(db); + + // Check if key exists in `TypedDict` + let Some((_, item)) = items.iter().find(|(name, _)| *name == key) else { + report_invalid_key_on_typed_dict( + context, + typed_dict_node.into(), + key_node.into(), + Type::TypedDict(typed_dict), + Type::string_literal(db, key), + &items, + ); + return false; + }; + + // Key exists, check if value type is assignable to declared type + if value_ty.is_assignable_to(db, item.declared_ty) { + return true; + } + + // Invalid assignment - emit diagnostic + if let Some(builder) = context.report_lint(assignment_kind.diagnostic_type(), value_node.into()) + { + let typed_dict_ty = Type::TypedDict(typed_dict); + let typed_dict_d = typed_dict_ty.display(db); + let value_d = value_ty.display(db); + let item_type_d = item.declared_ty.display(db); + + let mut diagnostic = builder.into_diagnostic(format_args!( + "Invalid {} to key \"{key}\" with declared type `{item_type_d}` on TypedDict `{typed_dict_d}`", + assignment_kind.diagnostic_name(), + )); + + diagnostic.set_primary_message(format_args!("value of type `{value_d}`")); + + diagnostic.annotate( + context + .secondary(typed_dict_node.into()) + .message(format_args!("TypedDict `{typed_dict_d}`")), + ); + + diagnostic.annotate( + context + .secondary(key_node.into()) + .message(format_args!("key has declared type `{item_type_d}`")), + ); + } + + false +} + +/// Validates that all required keys are provided in a `TypedDict` construction. +/// Reports errors for any keys that are required but not provided. +pub(super) fn validate_typed_dict_required_keys<'db, 'ast>( + context: &InferContext<'db, 'ast>, + typed_dict: TypedDictType<'db>, + provided_keys: &OrderSet<&str>, + error_node: AnyNodeRef<'ast>, +) { + let db = context.db(); + let items = typed_dict.items(db); + + let required_keys: OrderSet<&str> = items + .iter() + .filter_map(|(key_name, field)| field.is_required().then_some(key_name.as_str())) + .collect(); + + for missing_key in required_keys.difference(provided_keys) { + report_missing_typed_dict_key( + context, + error_node, + Type::TypedDict(typed_dict), + missing_key, + ); + } +} + +pub(super) fn validate_typed_dict_constructor<'db, 'ast>( + context: &InferContext<'db, 'ast>, + typed_dict: TypedDictType<'db>, + arguments: &'ast Arguments, + error_node: AnyNodeRef<'ast>, + expression_type_fn: impl Fn(&ast::Expr) -> Type<'db>, +) { + let has_positional_dict = arguments.args.len() == 1 && arguments.args[0].is_dict_expr(); + + let provided_keys = if has_positional_dict { + validate_from_dict_literal( + context, + typed_dict, + arguments, + error_node, + &expression_type_fn, + ) + } else { + validate_from_keywords( + context, + typed_dict, + arguments, + error_node, + &expression_type_fn, + ) + }; + + validate_typed_dict_required_keys(context, typed_dict, &provided_keys, error_node); +} + +/// Validates a `TypedDict` constructor call with a single positional dictionary argument +/// e.g. `Person({"name": "Alice", "age": 30})` +fn validate_from_dict_literal<'db, 'ast>( + context: &InferContext<'db, 'ast>, + typed_dict: TypedDictType<'db>, + arguments: &'ast Arguments, + error_node: AnyNodeRef<'ast>, + expression_type_fn: &impl Fn(&ast::Expr) -> Type<'db>, +) -> OrderSet<&'ast str> { + let mut provided_keys = OrderSet::new(); + + if let ast::Expr::Dict(dict_expr) = &arguments.args[0] { + // Validate dict entries + for dict_item in &dict_expr.items { + if let Some(ref key_expr) = dict_item.key { + if let ast::Expr::StringLiteral(ast::ExprStringLiteral { + value: key_value, .. + }) = key_expr + { + let key_str = key_value.to_str(); + provided_keys.insert(key_str); + + // Get the already-inferred argument type + let value_type = expression_type_fn(&dict_item.value); + validate_typed_dict_key_assignment( + context, + typed_dict, + key_str, + value_type, + error_node, + key_expr, + &dict_item.value, + TypedDictAssignmentKind::Constructor, + ); + } + } + } + } + + provided_keys +} + +/// Validates a `TypedDict` constructor call with keywords +/// e.g. `Person(name="Alice", age=30)` +fn validate_from_keywords<'db, 'ast>( + context: &InferContext<'db, 'ast>, + typed_dict: TypedDictType<'db>, + arguments: &'ast Arguments, + error_node: AnyNodeRef<'ast>, + expression_type_fn: &impl Fn(&ast::Expr) -> Type<'db>, +) -> OrderSet<&'ast str> { + let provided_keys: OrderSet<&str> = arguments + .keywords + .iter() + .filter_map(|kw| kw.arg.as_ref().map(|arg| arg.id.as_str())) + .collect(); + + // Validate that each key is assigned a type that is compatible with the keys's value type + for keyword in &arguments.keywords { + if let Some(arg_name) = &keyword.arg { + // Get the already-inferred argument type + let arg_type = expression_type_fn(&keyword.value); + validate_typed_dict_key_assignment( + context, + typed_dict, + arg_name.as_str(), + arg_type, + error_node, + keyword, + &keyword.value, + TypedDictAssignmentKind::Constructor, + ); + } + } + + provided_keys +} + +/// Validates a `TypedDict` dictionary literal assignment +/// e.g. `person: Person = {"name": "Alice", "age": 30}` +pub(super) fn validate_typed_dict_dict_literal<'db, 'ast>( + context: &InferContext<'db, 'ast>, + typed_dict: TypedDictType<'db>, + dict_expr: &'ast ast::ExprDict, + error_node: AnyNodeRef<'ast>, + expression_type_fn: impl Fn(&ast::Expr) -> Type<'db>, +) -> OrderSet<&'ast str> { + let mut provided_keys = OrderSet::new(); + + // Validate each key-value pair in the dictionary literal + for item in &dict_expr.items { + if let Some(key_expr) = &item.key { + if let ast::Expr::StringLiteral(key_literal) = key_expr { + let key_str = key_literal.value.to_str(); + provided_keys.insert(key_str); + + let value_type = expression_type_fn(&item.value); + validate_typed_dict_key_assignment( + context, + typed_dict, + key_str, + value_type, + error_node, + key_expr, + &item.value, + TypedDictAssignmentKind::Constructor, + ); + } + } + } + + validate_typed_dict_required_keys(context, typed_dict, &provided_keys, error_node); + + provided_keys +} diff --git a/ty.schema.json b/ty.schema.json index c8b9668506900..6b5540697714b 100644 --- a/ty.schema.json +++ b/ty.schema.json @@ -721,6 +721,16 @@ } ] }, + "missing-typed-dict-key": { + "title": "detects missing required keys in `TypedDict` constructors", + "description": "## What it does\nDetects missing required keys in `TypedDict` constructor calls.\n\n## Why is this bad?\n`TypedDict` requires all non-optional keys to be provided during construction.\nMissing items can lead to a `KeyError` at runtime.\n\n## Example\n```python\nfrom typing import TypedDict\n\nclass Person(TypedDict):\n name: str\n age: int\n\nalice: Person = {\"name\": \"Alice\"} # missing required key 'age'\n\nalice[\"age\"] # KeyError\n```", + "default": "error", + "oneOf": [ + { + "$ref": "#/definitions/Level" + } + ] + }, "no-matching-overload": { "title": "detects calls that do not match any overload", "description": "## What it does\nChecks for calls to an overloaded function that do not match any of the overloads.\n\n## Why is this bad?\nFailing to provide the correct arguments to one of the overloads will raise a `TypeError`\nat runtime.\n\n## Examples\n```python\n@overload\ndef func(x: int): ...\n@overload\ndef func(x: bool): ...\nfunc(\"string\") # error: [no-matching-overload]\n```", From d0bcf56bd94a9525a818fd593606b4f5a62add7b Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Mon, 25 Aug 2025 09:20:42 -0400 Subject: [PATCH 130/160] Improve diff rendering for notebooks (#20036) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary As noted in a code TODO, our `Diff` rendering code previously didn't have any special handling for notebooks. This was particularly obvious when the diffs were rendered right next to the corresponding diagnostic because the diagnostic used cell-based line numbers, while the diff was still using line numbers from the concatenated source. This PR updates the diff rendering to handle notebooks too. The main improvements shown in the example below are: - Line numbers are now remapped to be relative to their cell - Context lines from other cells are suppressed ``` error[unused-import][*]: `math` imported but unused --> notebook.ipynb:cell 2:2:8 | 1 | # cell 2 2 | import math | ^^^^ 3 | 4 | print('hello world') | help: Remove unused import: `math` ℹ Safe fix 1 1 | # cell 2 2 |-import math 3 2 | 4 3 | print('hello world') ``` I tried a few different approaches here before finally just splitting the notebook into separate text ranges by cell and diffing each one separately. It seems to work and passes all of our tests, but I don't know if it's actually enforced anywhere that a single edit doesn't span cells. Such an edit would silently be dropped right now since it would fail the `contains_range` check. I also feel like I may have overlooked an existing way to partition a file into cells like this. ## Test Plan Existing notebook tests, plus a new one in `ruff_db` --- crates/ruff_db/src/diagnostic/mod.rs | 5 + crates/ruff_db/src/diagnostic/render.rs | 7 + crates/ruff_db/src/diagnostic/render/full.rs | 281 +++++++++++++----- ...linter__linter__tests__import_sorting.snap | 53 ++-- ...er__linter__tests__ipy_escape_command.snap | 9 +- ...inter__linter__tests__unused_variable.snap | 28 +- ...er__linter__tests__vscode_language_id.snap | 1 + crates/ruff_notebook/src/index.rs | 8 + 8 files changed, 274 insertions(+), 118 deletions(-) diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index db6befc9aa1f2..a7e85edaf3cc4 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -325,6 +325,11 @@ impl Diagnostic { self.inner.fix.as_ref() } + #[cfg(test)] + pub(crate) fn fix_mut(&mut self) -> Option<&mut Fix> { + Arc::make_mut(&mut self.inner).fix.as_mut() + } + /// Set the fix for this diagnostic. pub fn set_fix(&mut self, fix: Fix) { debug_assert!( diff --git a/crates/ruff_db/src/diagnostic/render.rs b/crates/ruff_db/src/diagnostic/render.rs index 2b5230117e911..35cf2ff0514de 100644 --- a/crates/ruff_db/src/diagnostic/render.rs +++ b/crates/ruff_db/src/diagnostic/render.rs @@ -2622,6 +2622,13 @@ watermelon self.config = config; } + /// Show a diff for the fix when rendering. + pub(super) fn show_fix_diff(&mut self, yes: bool) { + let mut config = std::mem::take(&mut self.config); + config = config.show_fix_diff(yes); + self.config = config; + } + /// The lowest fix applicability to show when rendering. pub(super) fn fix_applicability(&mut self, applicability: Applicability) { let mut config = std::mem::take(&mut self.config); diff --git a/crates/ruff_db/src/diagnostic/render/full.rs b/crates/ruff_db/src/diagnostic/render/full.rs index 951b812562b60..847386a0f5f2c 100644 --- a/crates/ruff_db/src/diagnostic/render/full.rs +++ b/crates/ruff_db/src/diagnostic/render/full.rs @@ -2,12 +2,13 @@ use std::borrow::Cow; use std::num::NonZeroUsize; use anstyle::Style; +use ruff_notebook::NotebookIndex; use similar::{ChangeTag, TextDiff}; use ruff_annotate_snippets::Renderer as AnnotateRenderer; use ruff_diagnostics::{Applicability, Fix}; use ruff_source_file::OneIndexed; -use ruff_text_size::{Ranged, TextRange, TextSize}; +use ruff_text_size::{Ranged, TextLen, TextRange, TextSize}; use crate::diagnostic::render::{FileResolver, Resolved}; use crate::diagnostic::stylesheet::{DiagnosticStylesheet, fmt_styled}; @@ -81,6 +82,7 @@ impl<'a> FullRenderer<'a> { struct Diff<'a> { fix: &'a Fix, diagnostic_source: DiagnosticSource, + notebook_index: Option, stylesheet: &'a DiagnosticStylesheet, } @@ -90,12 +92,11 @@ impl<'a> Diff<'a> { stylesheet: &'a DiagnosticStylesheet, resolver: &'a dyn FileResolver, ) -> Option> { + let file = &diagnostic.primary_span_ref()?.file; Some(Diff { fix: diagnostic.fix()?, - diagnostic_source: diagnostic - .primary_span_ref()? - .file - .diagnostic_source(resolver), + diagnostic_source: file.diagnostic_source(resolver), + notebook_index: resolver.notebook_index(file), stylesheet, }) } @@ -106,19 +107,24 @@ impl std::fmt::Display for Diff<'_> { let source_code = self.diagnostic_source.as_source_code(); let source_text = source_code.text(); - // TODO(dhruvmanila): Add support for Notebook cells once it's user-facing - let mut output = String::with_capacity(source_text.len()); - let mut last_end = TextSize::default(); - - for edit in self.fix.edits() { - output.push_str(source_code.slice(TextRange::new(last_end, edit.start()))); - output.push_str(edit.content().unwrap_or_default()); - last_end = edit.end(); - } - - output.push_str(&source_text[usize::from(last_end)..]); - - let diff = TextDiff::from_lines(source_text, &output); + // Partition the source code into end offsets for each cell. If `self.notebook_index` is + // `None`, indicating a regular script file, all the lines will be in one "cell" under the + // `None` key. + let cells = if let Some(notebook_index) = &self.notebook_index { + let mut last_cell = OneIndexed::MIN; + let mut cells: Vec<(Option, TextSize)> = Vec::new(); + for (row, cell) in notebook_index.iter() { + if cell != last_cell { + let offset = source_code.line_start(row); + cells.push((Some(last_cell), offset)); + last_cell = cell; + } + } + cells.push((Some(last_cell), source_text.text_len())); + cells + } else { + vec![(None, source_text.text_len())] + }; let message = match self.fix.applicability() { // TODO(zanieb): Adjust this messaging once it's user-facing @@ -133,59 +139,97 @@ impl std::fmt::Display for Diff<'_> { // tests, which is the only place these are currently used. writeln!(f, "ℹ {}", fmt_styled(message, self.stylesheet.separator))?; - let (largest_old, largest_new) = diff - .ops() - .last() - .map(|op| (op.old_range().start, op.new_range().start)) - .unwrap_or_default(); + let mut last_end = TextSize::ZERO; + for (cell, offset) in cells { + let range = TextRange::new(last_end, offset); + last_end = offset; + let input = source_code.slice(range); + + let mut output = String::with_capacity(input.len()); + let mut last_end = range.start(); + + let mut applied = 0; + for edit in self.fix.edits() { + if range.contains_range(edit.range()) { + output.push_str(source_code.slice(TextRange::new(last_end, edit.start()))); + output.push_str(edit.content().unwrap_or_default()); + last_end = edit.end(); + applied += 1; + } + } - let digit_with = OneIndexed::from_zero_indexed(largest_new.max(largest_old)).digits(); + // No edits were applied, so there's no need to diff. + if applied == 0 { + continue; + } + + output.push_str(&source_text[usize::from(last_end)..usize::from(range.end())]); + + let diff = TextDiff::from_lines(input, &output); + + let (largest_old, largest_new) = diff + .ops() + .last() + .map(|op| (op.old_range().start, op.new_range().start)) + .unwrap_or_default(); + + let digit_with = OneIndexed::from_zero_indexed(largest_new.max(largest_old)).digits(); - for (idx, group) in diff.grouped_ops(3).iter().enumerate() { - if idx > 0 { - writeln!(f, "{:-^1$}", "-", 80)?; + if let Some(cell) = cell { + // Room for 2 digits, 2 x 1 space before each digit, 1 space, and 1 `|`. This + // centers the three colons on the pipe. + writeln!(f, "{:>1$} cell {cell}", ":::", 2 * digit_with.get() + 4)?; } - for op in group { - for change in diff.iter_inline_changes(op) { - let sign = match change.tag() { - ChangeTag::Delete => "-", - ChangeTag::Insert => "+", - ChangeTag::Equal => " ", - }; - - let line_style = LineStyle::from(change.tag(), self.stylesheet); - - let old_index = change.old_index().map(OneIndexed::from_zero_indexed); - let new_index = change.new_index().map(OneIndexed::from_zero_indexed); - - write!( - f, - "{} {} |{}", - Line { - index: old_index, - width: digit_with - }, - Line { - index: new_index, - width: digit_with - }, - fmt_styled(line_style.apply_to(sign), self.stylesheet.emphasis), - )?; - - for (emphasized, value) in change.iter_strings_lossy() { - let value = show_nonprinting(&value); - if emphasized { - write!( - f, - "{}", - fmt_styled(line_style.apply_to(&value), self.stylesheet.underline) - )?; - } else { - write!(f, "{}", line_style.apply_to(&value))?; + + for (idx, group) in diff.grouped_ops(3).iter().enumerate() { + if idx > 0 { + writeln!(f, "{:-^1$}", "-", 80)?; + } + for op in group { + for change in diff.iter_inline_changes(op) { + let sign = match change.tag() { + ChangeTag::Delete => "-", + ChangeTag::Insert => "+", + ChangeTag::Equal => " ", + }; + + let line_style = LineStyle::from(change.tag(), self.stylesheet); + + let old_index = change.old_index().map(OneIndexed::from_zero_indexed); + let new_index = change.new_index().map(OneIndexed::from_zero_indexed); + + write!( + f, + "{} {} |{}", + Line { + index: old_index, + width: digit_with, + }, + Line { + index: new_index, + width: digit_with, + }, + fmt_styled(line_style.apply_to(sign), self.stylesheet.emphasis), + )?; + + for (emphasized, value) in change.iter_strings_lossy() { + let value = show_nonprinting(&value); + if emphasized { + write!( + f, + "{}", + fmt_styled( + line_style.apply_to(&value), + self.stylesheet.underline + ) + )?; + } else { + write!(f, "{}", line_style.apply_to(&value))?; + } + } + if change.missing_newline() { + writeln!(f)?; } - } - if change.missing_newline() { - writeln!(f)?; } } } @@ -253,7 +297,7 @@ fn show_nonprinting(s: &str) -> Cow<'_, str> { #[cfg(test)] mod tests { - use ruff_diagnostics::Applicability; + use ruff_diagnostics::{Applicability, Fix}; use ruff_text_size::{TextLen, TextRange, TextSize}; use crate::diagnostic::{ @@ -654,6 +698,107 @@ print() "); } + /// Test that we remap notebook cell line numbers in the diff as well as the main diagnostic. + #[test] + fn notebook_output_with_diff() { + let (mut env, diagnostics) = create_notebook_diagnostics(DiagnosticFormat::Full); + env.show_fix_diff(true); + insta::assert_snapshot!(env.render_diagnostics(&diagnostics), @r" + error[unused-import][*]: `os` imported but unused + --> notebook.ipynb:cell 1:2:8 + | + 1 | # cell 1 + 2 | import os + | ^^ + | + help: Remove unused import: `os` + + ℹ Safe fix + ::: cell 1 + 1 1 | # cell 1 + 2 |-import os + + error[unused-import][*]: `math` imported but unused + --> notebook.ipynb:cell 2:2:8 + | + 1 | # cell 2 + 2 | import math + | ^^^^ + 3 | + 4 | print('hello world') + | + help: Remove unused import: `math` + + ℹ Safe fix + ::: cell 2 + 1 1 | # cell 2 + 2 |-import math + 3 2 | + 4 3 | print('hello world') + + error[unused-variable]: Local variable `x` is assigned to but never used + --> notebook.ipynb:cell 3:4:5 + | + 2 | def foo(): + 3 | print() + 4 | x = 1 + | ^ + | + help: Remove assignment to unused variable `x` + + ℹ Unsafe fix + ::: cell 3 + 1 1 | # cell 3 + 2 2 | def foo(): + 3 3 | print() + 4 |- x = 1 + 5 4 | + "); + } + + #[test] + fn notebook_output_with_diff_spanning_cells() { + let (mut env, mut diagnostics) = create_notebook_diagnostics(DiagnosticFormat::Full); + env.show_fix_diff(true); + + // Move all of the edits from the later diagnostics to the first diagnostic to simulate a + // single diagnostic with edits in different cells. + let mut diagnostic = diagnostics.swap_remove(0); + let fix = diagnostic.fix_mut().unwrap(); + let mut edits = fix.edits().to_vec(); + for diag in diagnostics { + edits.extend_from_slice(diag.fix().unwrap().edits()); + } + *fix = Fix::unsafe_edits(edits.remove(0), edits); + + insta::assert_snapshot!(env.render(&diagnostic), @r" + error[unused-import]: `os` imported but unused + --> notebook.ipynb:cell 1:2:8 + | + 1 | # cell 1 + 2 | import os + | ^^ + | + help: Remove unused import: `os` + + ℹ Unsafe fix + ::: cell 1 + 1 1 | # cell 1 + 2 |-import os + ::: cell 2 + 1 1 | # cell 2 + 2 |-import math + 3 2 | + 4 3 | print('hello world') + ::: cell 3 + 1 1 | # cell 3 + 2 2 | def foo(): + 3 3 | print() + 4 |- x = 1 + 5 4 | + "); + } + /// Carriage return (`\r`) is a valid line-ending in Python, so we should normalize this to a /// line feed (`\n`) for rendering. Otherwise we report a single long line for this case. #[test] diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap index d4cb049469cf7..71e562fd013fa 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__import_sorting.snap @@ -12,14 +12,12 @@ I001 [*] Import block is un-sorted or un-formatted help: Organize imports ℹ Safe fix + ::: cell 1 1 |+import math 2 |+import random 1 3 | from pathlib import Path 2 |-import random 3 |-import math -4 4 | from typing import Any -5 5 | import collections -6 6 | # Newline should be added here I001 [*] Import block is un-sorted or un-formatted --> isort.ipynb:cell 2:1:1 @@ -33,17 +31,15 @@ I001 [*] Import block is un-sorted or un-formatted help: Organize imports ℹ Safe fix -1 1 | from pathlib import Path -2 2 | import random -3 3 | import math - 4 |+import collections -4 5 | from typing import Any -5 |-import collections - 6 |+ - 7 |+ -6 8 | # Newline should be added here -7 9 | def foo(): -8 10 | pass + ::: cell 2 + 1 |+import collections +1 2 | from typing import Any +2 |-import collections + 3 |+ + 4 |+ +3 5 | # Newline should be added here +4 6 | def foo(): +5 7 | pass I001 [*] Import block is un-sorted or un-formatted --> isort.ipynb:cell 3:1:1 @@ -57,15 +53,13 @@ I001 [*] Import block is un-sorted or un-formatted help: Organize imports ℹ Safe fix -6 6 | # Newline should be added here -7 7 | def foo(): -8 8 | pass - 9 |+import sys -9 10 | from pathlib import Path -10 |-import sys -11 11 | -12 12 | %matplotlib \ -13 13 | --inline + ::: cell 3 + 1 |+import sys +1 2 | from pathlib import Path +2 |-import sys +3 3 | +4 4 | %matplotlib \ +5 5 | --inline I001 [*] Import block is un-sorted or un-formatted --> isort.ipynb:cell 3:7:1 @@ -79,9 +73,10 @@ I001 [*] Import block is un-sorted or un-formatted help: Organize imports ℹ Safe fix -12 12 | %matplotlib \ -13 13 | --inline -14 14 | - 15 |+import abc -15 16 | import math -16 |-import abc + ::: cell 3 +4 4 | %matplotlib \ +5 5 | --inline +6 6 | + 7 |+import abc +7 8 | import math +8 |-import abc diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__ipy_escape_command.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__ipy_escape_command.snap index d373e3d036f19..95e166dfc5db8 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__ipy_escape_command.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__ipy_escape_command.snap @@ -14,13 +14,13 @@ F401 [*] `os` imported but unused help: Remove unused import: `os` ℹ Safe fix + ::: cell 1 2 2 | 3 3 | %matplotlib inline 4 4 | 5 |-import os 6 5 | 7 6 | _ = math.pi -8 7 | %%timeit F401 [*] `sys` imported but unused --> ipy_escape_command.ipynb:cell 2:2:8 @@ -32,7 +32,6 @@ F401 [*] `sys` imported but unused help: Remove unused import: `sys` ℹ Safe fix -6 6 | -7 7 | _ = math.pi -8 8 | %%timeit -9 |-import sys + ::: cell 2 +1 1 | %%timeit +2 |-import sys diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__unused_variable.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__unused_variable.snap index 3e51ee839d53e..e79da46867879 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__unused_variable.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__unused_variable.snap @@ -12,12 +12,11 @@ F841 [*] Local variable `foo1` is assigned to but never used help: Remove assignment to unused variable `foo1` ℹ Unsafe fix + ::: cell 1 1 1 | def f(): 2 |- foo1 = %matplotlib --list 2 |+ %matplotlib --list 3 3 | foo2: list[str] = %matplotlib --list -4 4 | def f(): -5 5 | bar1 = !pwd F841 [*] Local variable `foo2` is assigned to but never used --> unused_variable.ipynb:cell 1:3:5 @@ -30,13 +29,11 @@ F841 [*] Local variable `foo2` is assigned to but never used help: Remove assignment to unused variable `foo2` ℹ Unsafe fix + ::: cell 1 1 1 | def f(): 2 2 | foo1 = %matplotlib --list 3 |- foo2: list[str] = %matplotlib --list 3 |+ %matplotlib --list -4 4 | def f(): -5 5 | bar1 = !pwd -6 6 | bar2: str = !pwd F841 [*] Local variable `bar1` is assigned to but never used --> unused_variable.ipynb:cell 2:2:5 @@ -49,12 +46,11 @@ F841 [*] Local variable `bar1` is assigned to but never used help: Remove assignment to unused variable `bar1` ℹ Unsafe fix -2 2 | foo1 = %matplotlib --list -3 3 | foo2: list[str] = %matplotlib --list -4 4 | def f(): -5 |- bar1 = !pwd - 5 |+ !pwd -6 6 | bar2: str = !pwd + ::: cell 2 +1 1 | def f(): +2 |- bar1 = !pwd + 2 |+ !pwd +3 3 | bar2: str = !pwd F841 [*] Local variable `bar2` is assigned to but never used --> unused_variable.ipynb:cell 2:3:5 @@ -67,8 +63,8 @@ F841 [*] Local variable `bar2` is assigned to but never used help: Remove assignment to unused variable `bar2` ℹ Unsafe fix -3 3 | foo2: list[str] = %matplotlib --list -4 4 | def f(): -5 5 | bar1 = !pwd -6 |- bar2: str = !pwd - 6 |+ !pwd + ::: cell 2 +1 1 | def f(): +2 2 | bar1 = !pwd +3 |- bar2: str = !pwd + 3 |+ !pwd diff --git a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__vscode_language_id.snap b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__vscode_language_id.snap index 8bdc926bd5ce1..72e92de07d867 100644 --- a/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__vscode_language_id.snap +++ b/crates/ruff_linter/src/snapshots/ruff_linter__linter__tests__vscode_language_id.snap @@ -12,6 +12,7 @@ F401 [*] `os` imported but unused help: Remove unused import: `os` ℹ Safe fix + ::: cell 3 1 |-import os 2 1 | 3 2 | print("hello world") diff --git a/crates/ruff_notebook/src/index.rs b/crates/ruff_notebook/src/index.rs index 35e4e07fcbe52..eff605aa6df1f 100644 --- a/crates/ruff_notebook/src/index.rs +++ b/crates/ruff_notebook/src/index.rs @@ -33,6 +33,14 @@ impl NotebookIndex { self.row_to_row_in_cell.get(row.to_zero_indexed()).copied() } + /// Returns an iterator over the row:cell-number pairs (both 1-based). + pub fn iter(&self) -> impl Iterator { + self.row_to_cell + .iter() + .enumerate() + .map(|(row, cell)| (OneIndexed::from_zero_indexed(row), *cell)) + } + /// Translates the given [`LineColumn`] based on the indexing table. /// /// This will translate the row/column in the concatenated source code From a04823cfadbf8cb6dbf64b1432c8568db4a8e020 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 25 Aug 2025 15:27:55 +0100 Subject: [PATCH 131/160] [ty] Completely ignore typeshed's stub for `Any` (#20079) --- .../resources/mdtest/annotations/any.md | 43 +++++++++++++- .../type_properties/is_assignable_to.md | 10 ++-- crates/ty_python_semantic/src/types.rs | 2 +- crates/ty_python_semantic/src/types/class.rs | 25 ++------ .../src/types/class_base.rs | 9 +-- .../ty_python_semantic/src/types/display.rs | 3 - .../ty_python_semantic/src/types/function.rs | 59 +++++++++++++------ crates/ty_python_semantic/src/types/infer.rs | 33 +++++------ .../ty_python_semantic/src/types/instance.rs | 20 +++---- crates/ty_python_semantic/src/types/narrow.rs | 10 +--- .../src/types/special_form.rs | 6 +- .../src/types/subclass_of.rs | 19 ++---- 12 files changed, 134 insertions(+), 105 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/any.md b/crates/ty_python_semantic/resources/mdtest/annotations/any.md index d4b1e6f502224..e5244051f06fc 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/any.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/any.md @@ -137,6 +137,22 @@ from unittest.mock import MagicMock x: int = MagicMock() ``` +## Runtime properties + +`typing.Any` is a class at runtime on Python 3.11+, and `typing_extensions.Any` is always a class. +On earlier versions of Python, `typing.Any` was an instance of `typing._SpecialForm`, but this is +not currently modeled by ty. We currently infer `Any` has having all attributes a class would have +on all versions of Python: + +```py +from typing import Any +from ty_extensions import TypeOf, static_assert, is_assignable_to + +reveal_type(Any.__base__) # revealed: type | None +reveal_type(Any.__bases__) # revealed: tuple[type, ...] +static_assert(is_assignable_to(TypeOf[Any], type)) +``` + ## Invalid `Any` cannot be parameterized: @@ -144,7 +160,32 @@ x: int = MagicMock() ```py from typing import Any -# error: [invalid-type-form] "Type `typing.Any` expected no type parameter" +# error: [invalid-type-form] "Special form `typing.Any` expected no type parameter" def f(x: Any[int]): reveal_type(x) # revealed: Unknown ``` + +`Any` cannot be called (this leads to a `TypeError` at runtime): + +```py +Any() # error: [call-non-callable] "Object of type `typing.Any` is not callable" +``` + +`Any` also cannot be used as a metaclass (under the hood, this leads to an implicit call to `Any`): + +```py +class F(metaclass=Any): ... # error: [invalid-metaclass] "Metaclass type `typing.Any` is not callable" +``` + +And `Any` cannot be used in `isinstance()` checks: + +```py +# error: [invalid-argument-type] "`typing.Any` cannot be used with `isinstance()`: This call will raise `TypeError` at runtime" +isinstance("", Any) +``` + +But `issubclass()` checks are fine: + +```py +issubclass(object, Any) # no error! +``` diff --git a/crates/ty_python_semantic/resources/mdtest/type_properties/is_assignable_to.md b/crates/ty_python_semantic/resources/mdtest/type_properties/is_assignable_to.md index 5338b25ce805f..869625c678164 100644 --- a/crates/ty_python_semantic/resources/mdtest/type_properties/is_assignable_to.md +++ b/crates/ty_python_semantic/resources/mdtest/type_properties/is_assignable_to.md @@ -221,11 +221,11 @@ static_assert(is_assignable_to(type[Unknown], Meta)) static_assert(is_assignable_to(Meta, type[Any])) static_assert(is_assignable_to(Meta, type[Unknown])) -class AnyMeta(metaclass=Any): ... - -static_assert(is_assignable_to(type[AnyMeta], type)) -static_assert(is_assignable_to(type[AnyMeta], type[object])) -static_assert(is_assignable_to(type[AnyMeta], type[Any])) +def _(x: Any): + class AnyMeta(metaclass=x): ... + static_assert(is_assignable_to(type[AnyMeta], type)) + static_assert(is_assignable_to(type[AnyMeta], type[object])) + static_assert(is_assignable_to(type[AnyMeta], type[Any])) from typing import TypeVar, Generic, Any diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index f8fbda0850e61..d29130ebadd11 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -5528,7 +5528,6 @@ impl<'db> Type<'db> { // https://typing.python.org/en/latest/spec/special-types.html#special-cases-for-float-and-complex Type::ClassLiteral(class) => { let ty = match class.known(db) { - Some(KnownClass::Any) => Type::any(), Some(KnownClass::Complex) => UnionType::from_elements( db, [ @@ -5622,6 +5621,7 @@ impl<'db> Type<'db> { Type::SpecialForm(special_form) => match special_form { SpecialFormType::Never | SpecialFormType::NoReturn => Ok(Type::Never), SpecialFormType::LiteralString => Ok(Type::LiteralString), + SpecialFormType::Any => Ok(Type::any()), SpecialFormType::Unknown => Ok(Type::unknown()), SpecialFormType::AlwaysTruthy => Ok(Type::AlwaysTruthy), SpecialFormType::AlwaysFalsy => Ok(Type::AlwaysFalsy), diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 58fe067963a9d..2baeffd80e9ee 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -3485,7 +3485,6 @@ pub enum KnownClass { // Typeshed NoneType, // Part of `types` for Python >= 3.10 // Typing - Any, Awaitable, Generator, Deprecated, @@ -3568,8 +3567,7 @@ impl KnownClass { Self::NoneType => Some(Truthiness::AlwaysFalse), - Self::Any - | Self::BaseException + Self::BaseException | Self::Exception | Self::ExceptionGroup | Self::Object @@ -3689,7 +3687,6 @@ impl KnownClass { // Anything with a *runtime* MRO (N.B. sometimes different from the MRO that typeshed gives!) // with length >2, or anything that is implemented in pure Python, is not a solid base. Self::ABCMeta - | Self::Any | Self::Awaitable | Self::Generator | Self::Enum @@ -3762,7 +3759,6 @@ impl KnownClass { | KnownClass::AsyncGeneratorType | KnownClass::CoroutineType | KnownClass::NoneType - | KnownClass::Any | KnownClass::StdlibAlias | KnownClass::SpecialForm | KnownClass::TypeVar @@ -3839,7 +3835,6 @@ impl KnownClass { | KnownClass::AsyncGeneratorType | KnownClass::CoroutineType | KnownClass::NoneType - | KnownClass::Any | KnownClass::StdlibAlias | KnownClass::SpecialForm | KnownClass::TypeVar @@ -3916,7 +3911,6 @@ impl KnownClass { | KnownClass::AsyncGeneratorType | KnownClass::CoroutineType | KnownClass::NoneType - | KnownClass::Any | KnownClass::StdlibAlias | KnownClass::SpecialForm | KnownClass::TypeVar @@ -3967,8 +3961,7 @@ impl KnownClass { | Self::NamedTupleLike | Self::Generator => true, - Self::Any - | Self::Bool + Self::Bool | Self::Object | Self::Bytes | Self::Bytearray @@ -4037,7 +4030,6 @@ impl KnownClass { pub(crate) fn name(self, db: &dyn Db) -> &'static str { match self { - Self::Any => "Any", Self::Bool => "bool", Self::Object => "object", Self::Bytes => "bytes", @@ -4347,8 +4339,7 @@ impl KnownClass { | Self::UnionType | Self::WrapperDescriptorType => KnownModule::Types, Self::NoneType => KnownModule::Typeshed, - Self::Any - | Self::Awaitable + Self::Awaitable | Self::Generator | Self::SpecialForm | Self::TypeVar @@ -4409,8 +4400,7 @@ impl KnownClass { | Self::UnionType | Self::NotImplementedType => Some(true), - Self::Any - | Self::Bool + Self::Bool | Self::Object | Self::Bytes | Self::Bytearray @@ -4489,8 +4479,7 @@ impl KnownClass { | Self::TypeAliasType | Self::NotImplementedType => true, - Self::Any - | Self::Bool + Self::Bool | Self::Object | Self::Bytes | Self::Bytearray @@ -4565,7 +4554,6 @@ impl KnownClass { // We assert that this match is exhaustive over the right-hand side in the unit test // `known_class_roundtrip_from_str()` let candidate = match class_name { - "Any" => Self::Any, "bool" => Self::Bool, "object" => Self::Object, "bytes" => Self::Bytes, @@ -4655,8 +4643,7 @@ impl KnownClass { /// Return `true` if the module of `self` matches `module` fn check_module(self, db: &dyn Db, module: KnownModule) -> bool { match self { - Self::Any - | Self::Bool + Self::Bool | Self::Object | Self::Bytes | Self::Bytearray diff --git a/crates/ty_python_semantic/src/types/class_base.rs b/crates/ty_python_semantic/src/types/class_base.rs index 08eda64f0934c..85cadc0b5de63 100644 --- a/crates/ty_python_semantic/src/types/class_base.rs +++ b/crates/ty_python_semantic/src/types/class_base.rs @@ -77,13 +77,7 @@ impl<'db> ClassBase<'db> { ) -> Option { match ty { Type::Dynamic(dynamic) => Some(Self::Dynamic(dynamic)), - Type::ClassLiteral(literal) => { - if literal.is_known(db, KnownClass::Any) { - Some(Self::Dynamic(DynamicType::Any)) - } else { - Some(Self::Class(literal.default_specialization(db))) - } - } + Type::ClassLiteral(literal) => Some(Self::Class(literal.default_specialization(db))), Type::GenericAlias(generic) => Some(Self::Class(ClassType::Generic(generic))), Type::NominalInstance(instance) if instance.class(db).is_known(db, KnownClass::GenericAlias) => @@ -201,6 +195,7 @@ impl<'db> ClassBase<'db> { | SpecialFormType::AlwaysTruthy | SpecialFormType::AlwaysFalsy => None, + SpecialFormType::Any => Some(Self::Dynamic(DynamicType::Any)), SpecialFormType::Unknown => Some(Self::unknown()), SpecialFormType::Protocol => Some(Self::Protocol), diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index b8ec4bd61aaaa..534cdf8e82808 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -76,9 +76,6 @@ impl Display for DisplayType<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { let representation = self.ty.representation(self.db, self.settings); match self.ty { - Type::ClassLiteral(literal) if literal.is_known(self.db, KnownClass::Any) => { - write!(f, "typing.Any") - } Type::IntLiteral(_) | Type::BooleanLiteral(_) | Type::StringLiteral(_) diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 8f71854fd8974..691068f896ea2 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -68,7 +68,7 @@ use crate::types::call::{Binding, CallArguments}; use crate::types::constraints::Constraints; use crate::types::context::InferContext; use crate::types::diagnostic::{ - REDUNDANT_CAST, STATIC_ASSERT_ERROR, TYPE_ASSERTION_FAILURE, + INVALID_ARGUMENT_TYPE, REDUNDANT_CAST, STATIC_ASSERT_ERROR, TYPE_ASSERTION_FAILURE, report_bad_argument_to_get_protocol_members, report_bad_argument_to_protocol_interface, report_runtime_check_against_non_runtime_checkable_protocol, }; @@ -79,8 +79,8 @@ use crate::types::visitor::any_over_type; use crate::types::{ BoundMethodType, BoundTypeVarInstance, CallableType, ClassBase, ClassLiteral, ClassType, DeprecatedInstance, DynamicType, HasRelationToVisitor, IsEquivalentVisitor, KnownClass, - NormalizedVisitor, Truthiness, Type, TypeMapping, TypeRelation, UnionBuilder, all_members, - walk_type_mapping, + NormalizedVisitor, SpecialFormType, Truthiness, Type, TypeMapping, TypeRelation, UnionBuilder, + all_members, walk_type_mapping, }; use crate::{Db, FxOrderSet, ModuleName, resolve_module}; @@ -1454,25 +1454,48 @@ impl KnownFunction { } KnownFunction::IsInstance | KnownFunction::IsSubclass => { - let [Some(first_arg), Some(Type::ClassLiteral(class))] = parameter_types else { + let [Some(first_arg), Some(second_argument)] = parameter_types else { return; }; - if let Some(protocol_class) = class.into_protocol_class(db) { - if !protocol_class.is_runtime_checkable(db) { - report_runtime_check_against_non_runtime_checkable_protocol( - context, - call_expression, - protocol_class, - self, - ); + match second_argument { + Type::ClassLiteral(class) => { + if let Some(protocol_class) = class.into_protocol_class(db) { + if !protocol_class.is_runtime_checkable(db) { + report_runtime_check_against_non_runtime_checkable_protocol( + context, + call_expression, + protocol_class, + self, + ); + } + } + + if self == KnownFunction::IsInstance { + overload.set_return_type( + is_instance_truthiness(db, *first_arg, *class).into_type(db), + ); + } } - } - - if self == KnownFunction::IsInstance { - overload.set_return_type( - is_instance_truthiness(db, *first_arg, *class).into_type(db), - ); + // The special-casing here is necessary because we recognise the symbol `typing.Any` as an + // instance of `type` at runtime. Even once we understand typeshed's annotation for + // `isinstance()`, we'd continue to accept calls such as `isinstance(x, typing.Any)` without + // emitting a diagnostic if we didn't have this branch. + Type::SpecialForm(SpecialFormType::Any) + if self == KnownFunction::IsInstance => + { + let Some(builder) = + context.report_lint(&INVALID_ARGUMENT_TYPE, call_expression) + else { + return; + }; + let mut diagnostic = builder.into_diagnostic(format_args!( + "`typing.Any` cannot be used with `isinstance()`" + )); + diagnostic + .set_primary_message("This call will raise `TypeError` at runtime"); + } + _ => {} } } diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 43c1abed21527..b7fe22465f913 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -3080,15 +3080,19 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let maybe_known_class = KnownClass::try_from_file_and_name(self.db(), self.file(), name); - let ty = if maybe_known_class.is_none() - && &name.id == "NamedTuple" - && matches!( + let in_typing_module = || { + matches!( file_to_module(self.db(), self.file()).and_then(|module| module.known(self.db())), Some(KnownModule::Typing | KnownModule::TypingExtensions) - ) { - Type::SpecialForm(SpecialFormType::NamedTuple) - } else { - Type::from(ClassLiteral::new( + ) + }; + + let ty = match (maybe_known_class, &*name.id) { + (None, "NamedTuple") if in_typing_module() => { + Type::SpecialForm(SpecialFormType::NamedTuple) + } + (None, "Any") if in_typing_module() => Type::SpecialForm(SpecialFormType::Any), + _ => Type::from(ClassLiteral::new( self.db(), name.id.clone(), body_scope, @@ -3096,7 +3100,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { deprecated, dataclass_params, dataclass_transformer_params, - )) + )), }; self.add_declaration_with_binding( @@ -10242,9 +10246,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let name_ty = self.infer_expression(slice); match name_ty { Type::ClassLiteral(class_literal) => { - if class_literal.is_known(self.db(), KnownClass::Any) { - SubclassOfType::subclass_of_any() - } else if class_literal.is_protocol(self.db()) { + if class_literal.is_protocol(self.db()) { SubclassOfType::from( self.db(), todo_type!("type[T] for protocols").expect_dynamic(), @@ -10256,6 +10258,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { ) } } + Type::SpecialForm(SpecialFormType::Any) => SubclassOfType::subclass_of_any(), Type::SpecialForm(SpecialFormType::Unknown) => { SubclassOfType::subclass_of_unknown() } @@ -10339,13 +10342,6 @@ impl<'db> TypeInferenceBuilder<'db, '_> { self.infer_expression(&subscript.slice); Type::unknown() } - Type::ClassLiteral(literal) if literal.is_known(self.db(), KnownClass::Any) => { - self.infer_expression(slice); - if let Some(builder) = self.context.report_lint(&INVALID_TYPE_FORM, subscript) { - builder.into_diagnostic("Type `typing.Any` expected no type parameter"); - } - Type::unknown() - } Type::SpecialForm(special_form) => { self.infer_parameterized_special_form_type_expression(subscript, special_form) } @@ -10919,6 +10915,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { | SpecialFormType::TypeAlias | SpecialFormType::TypedDict | SpecialFormType::Unknown + | SpecialFormType::Any | SpecialFormType::NamedTuple => { self.infer_type_expression(arguments_slice); diff --git a/crates/ty_python_semantic/src/types/instance.rs b/crates/ty_python_semantic/src/types/instance.rs index 8c3cdbb786468..1a403e11ea17b 100644 --- a/crates/ty_python_semantic/src/types/instance.rs +++ b/crates/ty_python_semantic/src/types/instance.rs @@ -12,7 +12,7 @@ use crate::types::enums::is_single_member_enum; use crate::types::protocol_class::walk_protocol_interface; use crate::types::tuple::{TupleSpec, TupleType}; use crate::types::{ - ApplyTypeMappingVisitor, ClassBase, DynamicType, HasRelationToVisitor, IsDisjointVisitor, + ApplyTypeMappingVisitor, ClassBase, HasRelationToVisitor, IsDisjointVisitor, IsEquivalentVisitor, NormalizedVisitor, TypeMapping, TypeRelation, VarianceInferable, }; use crate::{Db, FxOrderSet}; @@ -23,20 +23,20 @@ impl<'db> Type<'db> { pub(crate) fn instance(db: &'db dyn Db, class: ClassType<'db>) -> Self { let (class_literal, specialization) = class.class_literal(db); - match class_literal.known(db) { - Some(KnownClass::Any) => Type::Dynamic(DynamicType::Any), - Some(KnownClass::Tuple) => Type::tuple(TupleType::new( + if class_literal.is_known(db, KnownClass::Tuple) { + Type::tuple(TupleType::new( db, specialization .and_then(|spec| Some(Cow::Borrowed(spec.tuple(db)?))) .unwrap_or_else(|| Cow::Owned(TupleSpec::homogeneous(Type::unknown()))) .as_ref(), - )), - _ if class_literal.is_protocol(db) => { - Self::ProtocolInstance(ProtocolInstanceType::from_class(class)) - } - _ if class_literal.is_typed_dict(db) => Type::typed_dict(class), - _ => Type::non_tuple_instance(class), + )) + } else if class_literal.is_protocol(db) { + Self::ProtocolInstance(ProtocolInstanceType::from_class(class)) + } else if class_literal.is_typed_dict(db) { + Type::typed_dict(class) + } else { + Type::non_tuple_instance(class) } } diff --git a/crates/ty_python_semantic/src/types/narrow.rs b/crates/ty_python_semantic/src/types/narrow.rs index d1df76dee6fa2..46a0b5a8f5b1e 100644 --- a/crates/ty_python_semantic/src/types/narrow.rs +++ b/crates/ty_python_semantic/src/types/narrow.rs @@ -183,15 +183,7 @@ impl ClassInfoConstraintFunction { match classinfo { Type::TypeAlias(alias) => self.generate_constraint(db, alias.value_type(db)), - Type::ClassLiteral(class_literal) => { - // At runtime (on Python 3.11+), this will return `True` for classes that actually - // do inherit `typing.Any` and `False` otherwise. We could accurately model that? - if class_literal.is_known(db, KnownClass::Any) { - None - } else { - Some(constraint_fn(class_literal)) - } - } + Type::ClassLiteral(class_literal) => Some(constraint_fn(class_literal)), Type::SubclassOf(subclass_of_ty) => match subclass_of_ty.subclass_of() { SubclassOfInner::Class(ClassType::NonGeneric(class)) => Some(constraint_fn(class)), // It's not valid to use a generic alias as the second argument to `isinstance()` or `issubclass()`, diff --git a/crates/ty_python_semantic/src/types/special_form.rs b/crates/ty_python_semantic/src/types/special_form.rs index 494e7331ce22e..de4dc4d3f1771 100644 --- a/crates/ty_python_semantic/src/types/special_form.rs +++ b/crates/ty_python_semantic/src/types/special_form.rs @@ -27,6 +27,7 @@ use std::str::FromStr; get_size2::GetSize, )] pub enum SpecialFormType { + Any, /// The symbol `typing.Annotated` (which can also be found as `typing_extensions.Annotated`) Annotated, /// The symbol `typing.Literal` (which can also be found as `typing_extensions.Literal`) @@ -162,7 +163,7 @@ impl SpecialFormType { | Self::Protocol // actually `_ProtocolMeta` at runtime but this is what typeshed says | Self::ReadOnly => KnownClass::SpecialForm, - Self::Generic => KnownClass::Type, + Self::Generic | Self::Any => KnownClass::Type, Self::List | Self::Dict @@ -245,6 +246,7 @@ impl SpecialFormType { | Self::TypingSelf | Self::Protocol | Self::NamedTuple + | Self::Any | Self::ReadOnly => { matches!(module, KnownModule::Typing | KnownModule::TypingExtensions) } @@ -317,6 +319,7 @@ impl SpecialFormType { | Self::TypeIs | Self::ReadOnly | Self::Protocol + | Self::Any | Self::Generic => false, } } @@ -324,6 +327,7 @@ impl SpecialFormType { /// Return the repr of the symbol at runtime pub(super) const fn repr(self) -> &'static str { match self { + SpecialFormType::Any => "typing.Any", SpecialFormType::Annotated => "typing.Annotated", SpecialFormType::Literal => "typing.Literal", SpecialFormType::LiteralString => "typing.LiteralString", diff --git a/crates/ty_python_semantic/src/types/subclass_of.rs b/crates/ty_python_semantic/src/types/subclass_of.rs index 38f399ae5613a..63c7c13d51979 100644 --- a/crates/ty_python_semantic/src/types/subclass_of.rs +++ b/crates/ty_python_semantic/src/types/subclass_of.rs @@ -7,7 +7,7 @@ use crate::types::variance::VarianceInferable; use crate::types::{ ApplyTypeMappingVisitor, BindingContext, BoundTypeVarInstance, ClassType, DynamicType, HasRelationToVisitor, IsDisjointVisitor, KnownClass, MemberLookupPolicy, NormalizedVisitor, - Type, TypeMapping, TypeRelation, TypeVarInstance, + SpecialFormType, Type, TypeMapping, TypeRelation, TypeVarInstance, }; use crate::{Db, FxOrderSet}; @@ -47,14 +47,10 @@ impl<'db> SubclassOfType<'db> { SubclassOfInner::Class(class) => { if class.is_final(db) { Type::from(class) + } else if class.is_object(db) { + KnownClass::Type.to_instance(db) } else { - match class.known(db) { - Some(KnownClass::Object) => KnownClass::Type.to_instance(db), - Some(KnownClass::Any) => Type::SubclassOf(Self { - subclass_of: SubclassOfInner::Dynamic(DynamicType::Any), - }), - _ => Type::SubclassOf(Self { subclass_of }), - } + Type::SubclassOf(Self { subclass_of }) } } } @@ -288,12 +284,9 @@ impl<'db> SubclassOfInner<'db> { pub(crate) fn try_from_type(db: &'db dyn Db, ty: Type<'db>) -> Option { match ty { Type::Dynamic(dynamic) => Some(Self::Dynamic(dynamic)), - Type::ClassLiteral(literal) => Some(if literal.is_known(db, KnownClass::Any) { - Self::Dynamic(DynamicType::Any) - } else { - Self::Class(literal.default_specialization(db)) - }), + Type::ClassLiteral(literal) => Some(Self::Class(literal.default_specialization(db))), Type::GenericAlias(generic) => Some(Self::Class(ClassType::Generic(generic))), + Type::SpecialForm(SpecialFormType::Any) => Some(Self::Dynamic(DynamicType::Any)), _ => None, } } From db423ee9789b3a045266665198c4b25f31a23b6f Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Mon, 25 Aug 2025 23:15:34 +0800 Subject: [PATCH 132/160] [`airflow`] replace wrong path `airflow.io.stroage` as `airflow.io.store` (`AIR311`) (#20081) ## Summary `airflow.io.storage` is not the correct path. it should be `airflow.io.store` instead --- .../resources/test/fixtures/airflow/AIR311_names.py | 2 +- .../src/rules/airflow/rules/suggested_to_update_3_0.rs | 2 +- ..._rules__airflow__tests__AIR311_AIR311_names.py.snap | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py b/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py index 47c7b4270d8ff..712957f3b1b93 100644 --- a/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py +++ b/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py @@ -34,7 +34,7 @@ setup() from airflow.decorators import teardown from airflow.io.path import ObjectStoragePath -from airflow.io.storage import attach +from airflow.io.store import attach from airflow.models import DAG as DAGFromModel from airflow.models import ( Connection, diff --git a/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs b/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs index b5e26ea2aba1b..c2c7a64fa3bb6 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs @@ -233,7 +233,7 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) { module: "airflow.sdk", name: "ObjectStoragePath".to_string(), }, - ["airflow", "io", "storage", "attach"] => Replacement::SourceModuleMoved { + ["airflow", "io", "store", "attach"] => Replacement::SourceModuleMoved { module: "airflow.sdk.io", name: "attach".to_string(), }, diff --git a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap index 1477d7e53542f..fa121a1dce043 100644 --- a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap +++ b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap @@ -312,7 +312,7 @@ help: Use `teardown` from `airflow.sdk` instead. 34 34 | setup() 35 |-from airflow.decorators import teardown 36 35 | from airflow.io.path import ObjectStoragePath -37 36 | from airflow.io.storage import attach +37 36 | from airflow.io.store import attach 38 37 | from airflow.models import DAG as DAGFromModel -------------------------------------------------------------------------------- 43 42 | from airflow.models.baseoperator import chain, chain_linear, cross_downstream @@ -338,7 +338,7 @@ help: Use `ObjectStoragePath` from `airflow.sdk` instead. 34 34 | setup() 35 35 | from airflow.decorators import teardown 36 |-from airflow.io.path import ObjectStoragePath -37 36 | from airflow.io.storage import attach +37 36 | from airflow.io.store import attach 38 37 | from airflow.models import DAG as DAGFromModel 39 38 | from airflow.models import ( -------------------------------------------------------------------------------- @@ -350,7 +350,7 @@ help: Use `ObjectStoragePath` from `airflow.sdk` instead. 47 47 | # airflow.decorators 48 48 | teardown() -AIR311 [*] `airflow.io.storage.attach` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. +AIR311 [*] `airflow.io.store.attach` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. --> AIR311_names.py:52:1 | 50 | # # airflow.io @@ -366,7 +366,7 @@ help: Use `attach` from `airflow.sdk.io` instead. 34 34 | setup() 35 35 | from airflow.decorators import teardown 36 36 | from airflow.io.path import ObjectStoragePath -37 |-from airflow.io.storage import attach +37 |-from airflow.io.store import attach 38 37 | from airflow.models import DAG as DAGFromModel 39 38 | from airflow.models import ( 40 39 | Connection, @@ -391,7 +391,7 @@ AIR311 [*] `airflow.models.Connection` is removed in Airflow 3.0; It still works help: Use `Connection` from `airflow.sdk` instead. ℹ Unsafe fix -37 37 | from airflow.io.storage import attach +37 37 | from airflow.io.store import attach 38 38 | from airflow.models import DAG as DAGFromModel 39 39 | from airflow.models import ( 40 |- Connection, From ba47010150ff24b30c7779fbd38351007ce17aff Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 25 Aug 2025 17:01:51 +0000 Subject: [PATCH 133/160] [ty] Sync vendored typeshed stubs (#20083) Co-authored-by: typeshedbot <> Co-authored-by: Alex Waygood --- crates/ty_ide/src/goto_type_definition.rs | 102 +++-- ...\200\246_-_Syntax_(142fa2948c3c6cf1).snap" | 18 +- ...2\200\246_-_Basic_(f15db7dc447d0795).snap" | 11 +- crates/ty_python_semantic/src/place.rs | 19 +- crates/ty_python_semantic/src/types/infer.rs | 8 + .../vendor/typeshed/source_commit.txt | 2 +- .../vendor/typeshed/stdlib/_asyncio.pyi | 12 +- .../vendor/typeshed/stdlib/_blake2.pyi | 115 +++-- .../vendor/typeshed/stdlib/_csv.pyi | 7 +- .../vendor/typeshed/stdlib/_curses.pyi | 12 +- .../vendor/typeshed/stdlib/_dbm.pyi | 2 +- .../vendor/typeshed/stdlib/_decimal.pyi | 16 +- .../vendor/typeshed/stdlib/_hashlib.pyi | 3 +- .../vendor/typeshed/stdlib/_interpreters.pyi | 3 +- .../vendor/typeshed/stdlib/_io.pyi | 396 +++++++++++++----- .../vendor/typeshed/stdlib/_lsprof.pyi | 2 + .../vendor/typeshed/stdlib/_lzma.pyi | 8 +- .../typeshed/stdlib/_multibytecodec.pyi | 5 + .../vendor/typeshed/stdlib/_pickle.pyi | 4 +- .../vendor/typeshed/stdlib/_queue.pyi | 2 + .../vendor/typeshed/stdlib/_random.pyi | 10 +- .../vendor/typeshed/stdlib/_socket.pyi | 3 +- .../vendor/typeshed/stdlib/_ssl.pyi | 3 +- .../vendor/typeshed/stdlib/_struct.pyi | 2 + .../vendor/typeshed/stdlib/_thread.pyi | 3 +- .../typeshed/stdlib/_typeshed/__init__.pyi | 3 +- .../vendor/typeshed/stdlib/_warnings.pyi | 14 +- .../vendor/typeshed/stdlib/_zstd.pyi | 10 +- .../vendor/typeshed/stdlib/annotationlib.pyi | 14 + .../vendor/typeshed/stdlib/argparse.pyi | 2 +- .../vendor/typeshed/stdlib/array.pyi | 3 +- .../vendor/typeshed/stdlib/ast.pyi | 28 +- .../typeshed/stdlib/asyncio/base_events.pyi | 26 +- .../vendor/typeshed/stdlib/asyncio/events.pyi | 28 +- .../vendor/typeshed/stdlib/asyncio/graph.pyi | 94 +++-- .../typeshed/stdlib/asyncio/streams.pyi | 8 +- .../typeshed/stdlib/asyncio/subprocess.pyi | 12 +- .../vendor/typeshed/stdlib/asyncio/trsock.pyi | 29 +- .../stdlib/asyncio/windows_events.pyi | 2 +- .../typeshed/stdlib/asyncio/windows_utils.pyi | 6 +- .../vendor/typeshed/stdlib/binascii.pyi | 4 +- .../vendor/typeshed/stdlib/builtins.pyi | 57 ++- .../vendor/typeshed/stdlib/cgi.pyi | 9 +- .../vendor/typeshed/stdlib/codecs.pyi | 94 +++-- .../typeshed/stdlib/collections/__init__.pyi | 23 +- .../stdlib/compression/zstd/__init__.pyi | 1 + .../concurrent/interpreters/_crossinterp.pyi | 1 + .../concurrent/interpreters/_queues.pyi | 4 +- .../vendor/typeshed/stdlib/configparser.pyi | 7 +- .../vendor/typeshed/stdlib/crypt.pyi | 17 +- .../vendor/typeshed/stdlib/datetime.pyi | 6 +- .../vendor/typeshed/stdlib/decimal.pyi | 4 +- .../vendor/typeshed/stdlib/dis.pyi | 175 ++++---- .../typeshed/stdlib/distutils/file_util.pyi | 4 +- .../vendor/typeshed/stdlib/enum.pyi | 61 ++- .../vendor/typeshed/stdlib/functools.pyi | 18 +- .../vendor/typeshed/stdlib/gettext.pyi | 18 +- .../stdlib/importlib/metadata/__init__.pyi | 141 +++++-- .../vendor/typeshed/stdlib/inspect.pyi | 85 ++-- .../ty_vendored/vendor/typeshed/stdlib/io.pyi | 2 + .../vendor/typeshed/stdlib/itertools.pyi | 21 +- .../stdlib/lib2to3/fixes/fix_tuple_params.pyi | 3 +- .../vendor/typeshed/stdlib/logging/config.pyi | 25 +- .../vendor/typeshed/stdlib/mmap.pyi | 5 +- .../vendor/typeshed/stdlib/os/__init__.pyi | 2 +- .../typeshed/stdlib/pathlib/__init__.pyi | 1 + .../vendor/typeshed/stdlib/pdb.pyi | 43 +- .../vendor/typeshed/stdlib/platform.pyi | 45 +- .../vendor/typeshed/stdlib/random.pyi | 5 + .../vendor/typeshed/stdlib/select.pyi | 2 +- .../typeshed/stdlib/sqlite3/__init__.pyi | 5 +- .../vendor/typeshed/stdlib/sre_constants.pyi | 15 +- .../vendor/typeshed/stdlib/subprocess.pyi | 126 +++--- .../vendor/typeshed/stdlib/tarfile.pyi | 22 + .../typeshed/stdlib/tkinter/__init__.pyi | 10 +- .../vendor/typeshed/stdlib/tokenize.pyi | 15 +- .../vendor/typeshed/stdlib/turtle.pyi | 87 ++-- .../vendor/typeshed/stdlib/types.pyi | 51 ++- .../vendor/typeshed/stdlib/typing.pyi | 1 + .../typeshed/stdlib/typing_extensions.pyi | 38 +- .../vendor/typeshed/stdlib/unittest/mock.pyi | 258 ++++++++---- .../vendor/typeshed/stdlib/weakref.pyi | 3 +- .../typeshed/stdlib/xml/etree/ElementTree.pyi | 5 +- .../typeshed/stdlib/zoneinfo/__init__.pyi | 3 +- 84 files changed, 1728 insertions(+), 841 deletions(-) diff --git a/crates/ty_ide/src/goto_type_definition.rs b/crates/ty_ide/src/goto_type_definition.rs index 4e9a3af4d7313..9d01e159f6e43 100644 --- a/crates/ty_ide/src/goto_type_definition.rs +++ b/crates/ty_ide/src/goto_type_definition.rs @@ -199,14 +199,13 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:901:7 + --> stdlib/builtins.pyi:911:7 | - 899 | def __getitem__(self, key: int, /) -> str | int | None: ... - 900 | - 901 | class str(Sequence[str]): + 910 | @disjoint_base + 911 | class str(Sequence[str]): | ^^^ - 902 | """str(object='') -> str - 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 912 | """str(object='') -> str + 913 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:4:1 @@ -228,14 +227,13 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:901:7 + --> stdlib/builtins.pyi:911:7 | - 899 | def __getitem__(self, key: int, /) -> str | int | None: ... - 900 | - 901 | class str(Sequence[str]): + 910 | @disjoint_base + 911 | class str(Sequence[str]): | ^^^ - 902 | """str(object='') -> str - 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 912 | """str(object='') -> str + 913 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:2:10 @@ -344,14 +342,13 @@ mod tests { assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:901:7 + --> stdlib/builtins.pyi:911:7 | - 899 | def __getitem__(self, key: int, /) -> str | int | None: ... - 900 | - 901 | class str(Sequence[str]): + 910 | @disjoint_base + 911 | class str(Sequence[str]): | ^^^ - 902 | """str(object='') -> str - 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 912 | """str(object='') -> str + 913 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:4:6 @@ -379,14 +376,13 @@ mod tests { // is an int. Navigating to `str` would match pyright's behavior. assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:337:7 + --> stdlib/builtins.pyi:344:7 | - 335 | _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed - 336 | - 337 | class int: + 343 | @disjoint_base + 344 | class int: | ^^^ - 338 | """int([x]) -> integer - 339 | int(x, base=10) -> integer + 345 | """int([x]) -> integer + 346 | int(x, base=10) -> integer | info: Source --> main.py:4:6 @@ -411,16 +407,15 @@ f(**kwargs) "#, ); - assert_snapshot!(test.goto_type_definition(), @r###" + assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:2901:7 + --> stdlib/builtins.pyi:2917:7 | - 2899 | """See PEP 585""" - 2900 | - 2901 | class dict(MutableMapping[_KT, _VT]): + 2916 | @disjoint_base + 2917 | class dict(MutableMapping[_KT, _VT]): | ^^^^ - 2902 | """dict() -> new empty dictionary - 2903 | dict(mapping) -> new dictionary initialized from a mapping object's + 2918 | """dict() -> new empty dictionary + 2919 | dict(mapping) -> new dictionary initialized from a mapping object's | info: Source --> main.py:6:5 @@ -430,7 +425,7 @@ f(**kwargs) 6 | f(**kwargs) | ^^^^^^ | - "###); + "#); } #[test] @@ -444,14 +439,13 @@ f(**kwargs) assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:901:7 + --> stdlib/builtins.pyi:911:7 | - 899 | def __getitem__(self, key: int, /) -> str | int | None: ... - 900 | - 901 | class str(Sequence[str]): + 910 | @disjoint_base + 911 | class str(Sequence[str]): | ^^^ - 902 | """str(object='') -> str - 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 912 | """str(object='') -> str + 913 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:3:5 @@ -537,14 +531,13 @@ f(**kwargs) assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:901:7 + --> stdlib/builtins.pyi:911:7 | - 899 | def __getitem__(self, key: int, /) -> str | int | None: ... - 900 | - 901 | class str(Sequence[str]): + 910 | @disjoint_base + 911 | class str(Sequence[str]): | ^^^ - 902 | """str(object='') -> str - 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 912 | """str(object='') -> str + 913 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:4:15 @@ -568,13 +561,13 @@ f(**kwargs) assert_snapshot!(test.goto_type_definition(), @r#" info[goto-type-definition]: Type definition - --> stdlib/types.pyi:922:11 + --> stdlib/types.pyi:941:11 | - 920 | if sys.version_info >= (3, 10): - 921 | @final - 922 | class NoneType: + 939 | if sys.version_info >= (3, 10): + 940 | @final + 941 | class NoneType: | ^^^^^^^^ - 923 | """The type of the None singleton.""" + 942 | """The type of the None singleton.""" | info: Source --> main.py:3:5 @@ -585,14 +578,13 @@ f(**kwargs) | info[goto-type-definition]: Type definition - --> stdlib/builtins.pyi:901:7 + --> stdlib/builtins.pyi:911:7 | - 899 | def __getitem__(self, key: int, /) -> str | int | None: ... - 900 | - 901 | class str(Sequence[str]): + 910 | @disjoint_base + 911 | class str(Sequence[str]): | ^^^ - 902 | """str(object='') -> str - 903 | str(bytes_or_buffer[, encoding[, errors]]) -> str + 912 | """str(object='') -> str + 913 | str(bytes_or_buffer[, encoding[, errors]]) -> str | info: Source --> main.py:3:5 diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" index 8d387415ba731..78cbed24b6c66 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/deprecated.md_-_Tests_for_the_`@depr\342\200\246_-_Syntax_(142fa2948c3c6cf1).snap" @@ -91,15 +91,15 @@ error[missing-argument]: No argument provided for required parameter `arg` of bo 7 | from typing_extensions import deprecated | info: Parameter declared here - --> stdlib/typing_extensions.pyi:973:28 - | -971 | stacklevel: int -972 | def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... -973 | def __call__(self, arg: _T, /) -> _T: ... - | ^^^^^^^ -974 | -975 | @final - | + --> stdlib/typing_extensions.pyi:1000:28 + | + 998 | stacklevel: int + 999 | def __init__(self, message: LiteralString, /, *, category: type[Warning] | None = ..., stacklevel: int = 1) -> None: ... +1000 | def __call__(self, arg: _T, /) -> _T: ... + | ^^^^^^^ +1001 | +1002 | @final + | info: rule `missing-argument` is enabled by default ``` diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" index c4304a77ee004..52bde42ce5a11 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/invalid_await.md_-_Invalid_await_diagno\342\200\246_-_Basic_(f15db7dc447d0795).snap" @@ -26,14 +26,13 @@ error[invalid-await]: `Literal[1]` is not awaitable 2 | await 1 # error: [invalid-await] | ^ | - ::: stdlib/builtins.pyi:337:7 + ::: stdlib/builtins.pyi:344:7 | -335 | _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed -336 | -337 | class int: +343 | @disjoint_base +344 | class int: | --- type defined here -338 | """int([x]) -> integer -339 | int(x, base=10) -> integer +345 | """int([x]) -> integer +346 | int(x, base=10) -> integer | info: `__await__` is missing info: rule `invalid-await` is enabled by default diff --git a/crates/ty_python_semantic/src/place.rs b/crates/ty_python_semantic/src/place.rs index 56e5637e32372..b55129513ab54 100644 --- a/crates/ty_python_semantic/src/place.rs +++ b/crates/ty_python_semantic/src/place.rs @@ -1409,7 +1409,12 @@ mod implicit_globals { /// Conceptually this function could be a `Set` rather than a list, /// but the number of symbols declared in this scope is likely to be very small, /// so the cost of hashing the names is likely to be more expensive than it's worth. - #[salsa::tracked(returns(deref), heap_size=ruff_memory_usage::heap_size)] + #[salsa::tracked( + returns(deref), + cycle_initial=module_type_symbols_initial, + cycle_fn=module_type_symbols_cycle_recover, + heap_size=ruff_memory_usage::heap_size + )] fn module_type_symbols<'db>(db: &'db dyn Db) -> smallvec::SmallVec<[ast::name::Name; 8]> { let Some(module_type) = KnownClass::ModuleType .to_class_literal(db) @@ -1437,6 +1442,18 @@ mod implicit_globals { .collect() } + fn module_type_symbols_initial(_db: &dyn Db) -> smallvec::SmallVec<[ast::name::Name; 8]> { + smallvec::SmallVec::default() + } + + fn module_type_symbols_cycle_recover( + _db: &dyn Db, + _value: &smallvec::SmallVec<[ast::name::Name; 8]>, + _count: u32, + ) -> salsa::CycleRecoveryAction> { + salsa::CycleRecoveryAction::Iterate + } + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index b7fe22465f913..c9fc52c6f875e 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -11726,6 +11726,14 @@ mod tests { fn unbound_symbol_no_reachability_constraint_check() { let mut db = setup_db(); + // First, type-check a random other file so that we cache a result for the `module_type_symbols` + // query (which often encounters cycles due to `types.pyi` importing `typing_extensions` and + // `typing_extensions.pyi` importing `types`). Clear the events afterwards so that unrelated + // cycles from that query don't interfere with our test. + db.write_dedented("src/wherever.py", "print(x)").unwrap(); + assert_file_diagnostics(&db, "src/wherever.py", &["Name `x` used when not defined"]); + db.clear_salsa_events(); + // If the bug we are testing for is not fixed, what happens is that when inferring the // `flag: bool = True` definitions, we look up `bool` as a deferred name (thus from end of // scope), and because of the early return its "unbound" binding has a reachability diff --git a/crates/ty_vendored/vendor/typeshed/source_commit.txt b/crates/ty_vendored/vendor/typeshed/source_commit.txt index 9d77d588f91cb..294b9bdffc1c4 100644 --- a/crates/ty_vendored/vendor/typeshed/source_commit.txt +++ b/crates/ty_vendored/vendor/typeshed/source_commit.txt @@ -1 +1 @@ -f32d9f08bde8e42a3a35c050839d0275979eb3af +91e2ed0953592795fd8c29e3005a1315bf652ffc diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_asyncio.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_asyncio.pyi index efb8ef77ff178..5b11b3445aab1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_asyncio.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_asyncio.pyi @@ -6,12 +6,13 @@ from collections.abc import Awaitable, Callable, Coroutine, Generator from contextvars import Context from types import FrameType, GenericAlias from typing import Any, Literal, TextIO, TypeVar -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _TaskYieldType: TypeAlias = Future[object] | None +@disjoint_base class Future(Awaitable[_T]): """This class is *almost* compatible with concurrent.futures.Future. @@ -36,7 +37,7 @@ class Future(Awaitable[_T]): @_log_traceback.setter def _log_traceback(self, val: Literal[False]) -> None: ... _asyncio_future_blocking: bool # is a part of duck-typing contract for `Future` - def __init__(self, *, loop: AbstractEventLoop | None = ...) -> None: ... + def __init__(self, *, loop: AbstractEventLoop | None = None) -> None: ... def __del__(self) -> None: """Called when the instance is about to be destroyed.""" @@ -128,6 +129,7 @@ else: # While this is true in general, here it's sort-of okay to have a covariant subclass, # since the only reason why `asyncio.Future` is invariant is the `set_result()` method, # and `asyncio.Task.set_result()` always raises. +@disjoint_base class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments] """A coroutine wrapped in a Future.""" @@ -137,7 +139,7 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, - name: str | None = ..., + name: str | None = None, context: Context | None = None, eager_start: bool = False, ) -> None: ... @@ -147,12 +149,12 @@ class Task(Future[_T_co]): # type: ignore[type-var] # pyright: ignore[reportIn coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, - name: str | None = ..., + name: str | None = None, context: Context | None = None, ) -> None: ... else: def __init__( - self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, name: str | None = ... + self, coro: _TaskCompatibleCoro[_T_co], *, loop: AbstractEventLoop | None = None, name: str | None = None ) -> None: ... if sys.version_info >= (3, 12): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi index cf2872da70623..b806cd201c7fe 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_blake2.pyi @@ -1,5 +1,6 @@ """_blake2b provides BLAKE2b for hashlib""" +import sys from _typeshed import ReadableBuffer from typing import ClassVar, Final, final from typing_extensions import Self @@ -24,24 +25,45 @@ class blake2b: block_size: int digest_size: int name: str - def __new__( - cls, - data: ReadableBuffer = b"", - /, - *, - digest_size: int = 64, - key: ReadableBuffer = b"", - salt: ReadableBuffer = b"", - person: ReadableBuffer = b"", - fanout: int = 1, - depth: int = 1, - leaf_size: int = 0, - node_offset: int = 0, - node_depth: int = 0, - inner_size: int = 0, - last_node: bool = False, - usedforsecurity: bool = True, - ) -> Self: ... + if sys.version_info >= (3, 13): + def __new__( + cls, + data: ReadableBuffer = b"", + *, + digest_size: int = 64, + key: ReadableBuffer = b"", + salt: ReadableBuffer = b"", + person: ReadableBuffer = b"", + fanout: int = 1, + depth: int = 1, + leaf_size: int = 0, + node_offset: int = 0, + node_depth: int = 0, + inner_size: int = 0, + last_node: bool = False, + usedforsecurity: bool = True, + string: ReadableBuffer | None = None, + ) -> Self: ... + else: + def __new__( + cls, + data: ReadableBuffer = b"", + /, + *, + digest_size: int = 64, + key: ReadableBuffer = b"", + salt: ReadableBuffer = b"", + person: ReadableBuffer = b"", + fanout: int = 1, + depth: int = 1, + leaf_size: int = 0, + node_offset: int = 0, + node_depth: int = 0, + inner_size: int = 0, + last_node: bool = False, + usedforsecurity: bool = True, + ) -> Self: ... + def copy(self) -> Self: """Return a copy of the hash object.""" @@ -65,24 +87,45 @@ class blake2s: block_size: int digest_size: int name: str - def __new__( - cls, - data: ReadableBuffer = b"", - /, - *, - digest_size: int = 32, - key: ReadableBuffer = b"", - salt: ReadableBuffer = b"", - person: ReadableBuffer = b"", - fanout: int = 1, - depth: int = 1, - leaf_size: int = 0, - node_offset: int = 0, - node_depth: int = 0, - inner_size: int = 0, - last_node: bool = False, - usedforsecurity: bool = True, - ) -> Self: ... + if sys.version_info >= (3, 13): + def __new__( + cls, + data: ReadableBuffer = b"", + *, + digest_size: int = 32, + key: ReadableBuffer = b"", + salt: ReadableBuffer = b"", + person: ReadableBuffer = b"", + fanout: int = 1, + depth: int = 1, + leaf_size: int = 0, + node_offset: int = 0, + node_depth: int = 0, + inner_size: int = 0, + last_node: bool = False, + usedforsecurity: bool = True, + string: ReadableBuffer | None = None, + ) -> Self: ... + else: + def __new__( + cls, + data: ReadableBuffer = b"", + /, + *, + digest_size: int = 32, + key: ReadableBuffer = b"", + salt: ReadableBuffer = b"", + person: ReadableBuffer = b"", + fanout: int = 1, + depth: int = 1, + leaf_size: int = 0, + node_offset: int = 0, + node_depth: int = 0, + inner_size: int = 0, + last_node: bool = False, + usedforsecurity: bool = True, + ) -> Self: ... + def copy(self) -> Self: """Return a copy of the hash object.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_csv.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_csv.pyi index 67e1927f8e46c..93322e781d4f6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_csv.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_csv.pyi @@ -5,7 +5,7 @@ import sys from _typeshed import SupportsWrite from collections.abc import Iterable from typing import Any, Final, Literal, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base __version__: Final[str] @@ -26,6 +26,7 @@ class Error(Exception): ... _DialectLike: TypeAlias = str | Dialect | csv.Dialect | type[Dialect | csv.Dialect] +@disjoint_base class Dialect: """CSV dialect @@ -42,7 +43,7 @@ class Dialect: strict: bool def __new__( cls, - dialect: _DialectLike | None = ..., + dialect: _DialectLike | None = None, delimiter: str = ",", doublequote: bool = True, escapechar: str | None = None, @@ -55,6 +56,7 @@ class Dialect: if sys.version_info >= (3, 10): # This class calls itself _csv.reader. + @disjoint_base class Reader: """CSV reader @@ -72,6 +74,7 @@ if sys.version_info >= (3, 10): """Implement next(self).""" # This class calls itself _csv.writer. + @disjoint_base class Writer: """CSV writer diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi index c5bf3a717a2ef..b53a33e16e46f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_curses.pyi @@ -573,7 +573,7 @@ def newpad(nlines: int, ncols: int, /) -> window: Width. """ -def newwin(nlines: int, ncols: int, begin_y: int = ..., begin_x: int = ..., /) -> window: +def newwin(nlines: int, ncols: int, begin_y: int = 0, begin_x: int = 0, /) -> window: """newwin(nlines, ncols, [begin_y=0, begin_x=0]) Return a new window. @@ -1016,7 +1016,7 @@ class window: # undocumented """ @overload - def box(self, vertch: _ChType = ..., horch: _ChType = ...) -> None: ... + def box(self, vertch: _ChType = 0, horch: _ChType = 0) -> None: ... @overload def chgat(self, attr: int) -> None: """chgat([y, x,] [n=-1,] attr) @@ -1289,7 +1289,7 @@ class window: # undocumented @overload def insstr(self, y: int, x: int, str: str, attr: int = ...) -> None: ... @overload - def instr(self, n: int = ...) -> bytes: + def instr(self, n: int = 2047) -> bytes: """instr([y, x,] n=2047) Return a string of characters, extracted from the window. @@ -1307,7 +1307,7 @@ class window: # undocumented """ @overload - def instr(self, y: int, x: int, n: int = ...) -> bytes: ... + def instr(self, y: int, x: int, n: int = 2047) -> bytes: ... def is_linetouched(self, line: int, /) -> bool: """Return True if the specified line was modified, otherwise return False. @@ -1415,7 +1415,7 @@ class window: # undocumented @overload def refresh(self, pminrow: int, pmincol: int, sminrow: int, smincol: int, smaxrow: int, smaxcol: int) -> None: ... def resize(self, nlines: int, ncols: int) -> None: ... - def scroll(self, lines: int = ...) -> None: + def scroll(self, lines: int = 1) -> None: """scroll([lines=1]) Scroll the screen or scrolling region. @@ -1483,7 +1483,7 @@ class window: # undocumented def syncok(self, flag: bool) -> None: ... def syncup(self) -> None: ... def timeout(self, delay: int) -> None: ... - def touchline(self, start: int, count: int, changed: bool = ...) -> None: + def touchline(self, start: int, count: int, changed: bool = True) -> None: """touchline(start, count, [changed=True]) Pretend count lines have been changed, starting with line start. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi index b9165094ffe3a..7d6157c503011 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_dbm.pyi @@ -33,7 +33,7 @@ if sys.platform != "win32": @overload def get(self, k: _KeyType, default: _T, /) -> bytes | _T: ... def keys(self) -> list[bytes]: ... - def setdefault(self, k: _KeyType, default: _ValueType = ..., /) -> bytes: ... + def setdefault(self, k: _KeyType, default: _ValueType = b"", /) -> bytes: ... # This isn't true, but the class can't be instantiated. See #13024 __new__: None # type: ignore[assignment] __init__: None # type: ignore[assignment] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_decimal.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_decimal.pyi index 549d808659c19..bda849f6988e1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_decimal.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_decimal.pyi @@ -56,14 +56,14 @@ if sys.version_info >= (3, 11): def localcontext( ctx: Context | None = None, *, - prec: int | None = ..., - rounding: str | None = ..., - Emin: int | None = ..., - Emax: int | None = ..., - capitals: int | None = ..., - clamp: int | None = ..., - traps: dict[_TrapType, bool] | None = ..., - flags: dict[_TrapType, bool] | None = ..., + prec: int | None = None, + rounding: str | None = None, + Emin: int | None = None, + Emax: int | None = None, + capitals: int | None = None, + clamp: int | None = None, + traps: dict[_TrapType, bool] | None = None, + flags: dict[_TrapType, bool] | None = None, ) -> _ContextManager: """Return a context manager that will set the default context to a copy of ctx on entry to the with-statement and restore the previous default context when diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_hashlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_hashlib.pyi index a7153d44cfdd1..1dda9af2cbf3e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_hashlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_hashlib.pyi @@ -5,7 +5,7 @@ from _typeshed import ReadableBuffer from collections.abc import Callable from types import ModuleType from typing import AnyStr, Protocol, final, overload, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base _DigestMod: TypeAlias = str | Callable[[], _HashObject] | ModuleType | None @@ -24,6 +24,7 @@ class _HashObject(Protocol): def hexdigest(self) -> str: ... def update(self, obj: ReadableBuffer, /) -> None: ... +@disjoint_base class HASH: """A hash is an object used to calculate a checksum of a string of information. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi index 7bbf2a42d4fe0..958ae497f1ac8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_interpreters.pyi @@ -5,7 +5,7 @@ The 'interpreters' module provides a more convenient interface. import types from collections.abc import Callable from typing import Any, Final, Literal, SupportsIndex, TypeVar, overload -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, disjoint_base _R = TypeVar("_R") @@ -20,6 +20,7 @@ class InterpreterNotFoundError(InterpreterError): class NotShareableError(ValueError): ... +@disjoint_base class CrossInterpreterBufferView: def __buffer__(self, flags: int, /) -> memoryview: """Return a buffer object that exposes the underlying memory of the object.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi index ef07b92aaf339..e63f1d485689e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_io.pyi @@ -41,11 +41,14 @@ from io import BufferedIOBase, RawIOBase, TextIOBase, UnsupportedOperation as Un from os import _Opener from types import TracebackType from typing import IO, Any, BinaryIO, Final, Generic, Literal, Protocol, TextIO, TypeVar, overload, type_check_only -from typing_extensions import Self +from typing_extensions import Self, disjoint_base _T = TypeVar("_T") -DEFAULT_BUFFER_SIZE: Final = 8192 +if sys.version_info >= (3, 14): + DEFAULT_BUFFER_SIZE: Final = 131072 +else: + DEFAULT_BUFFER_SIZE: Final = 8192 open = builtins.open @@ -58,150 +61,296 @@ def open_code(path: str) -> IO[bytes]: BlockingIOError = builtins.BlockingIOError -class _IOBase: - """The abstract base class for all I/O classes. +if sys.version_info >= (3, 12): + @disjoint_base + class _IOBase: + """The abstract base class for all I/O classes. - This class provides dummy implementations for many methods that - derived classes can override selectively; the default implementations - represent a file that cannot be read, written or seeked. + This class provides dummy implementations for many methods that + derived classes can override selectively; the default implementations + represent a file that cannot be read, written or seeked. - Even though IOBase does not declare read, readinto, or write because - their signatures will vary, implementations and clients should - consider those methods part of the interface. Also, implementations - may raise UnsupportedOperation when operations they do not support are - called. + Even though IOBase does not declare read, readinto, or write because + their signatures will vary, implementations and clients should + consider those methods part of the interface. Also, implementations + may raise UnsupportedOperation when operations they do not support are + called. - The basic type used for binary data read from or written to a file is - bytes. Other bytes-like objects are accepted as method arguments too. - In some cases (such as readinto), a writable object is required. Text - I/O classes work with str data. + The basic type used for binary data read from or written to a file is + bytes. Other bytes-like objects are accepted as method arguments too. + In some cases (such as readinto), a writable object is required. Text + I/O classes work with str data. - Note that calling any method (except additional calls to close(), - which are ignored) on a closed stream should raise a ValueError. + Note that calling any method (except additional calls to close(), + which are ignored) on a closed stream should raise a ValueError. - IOBase (and its subclasses) support the iterator protocol, meaning - that an IOBase object can be iterated over yielding the lines in a - stream. + IOBase (and its subclasses) support the iterator protocol, meaning + that an IOBase object can be iterated over yielding the lines in a + stream. - IOBase also supports the :keyword:`with` statement. In this example, - fp is closed after the suite of the with statement is complete: + IOBase also supports the :keyword:`with` statement. In this example, + fp is closed after the suite of the with statement is complete: - with open('spam.txt', 'r') as fp: - fp.write('Spam and eggs!') - """ + with open('spam.txt', 'r') as fp: + fp.write('Spam and eggs!') + """ - def __iter__(self) -> Iterator[bytes]: - """Implement iter(self).""" + def __iter__(self) -> Iterator[bytes]: + """Implement iter(self).""" - def __next__(self) -> bytes: - """Implement next(self).""" + def __next__(self) -> bytes: + """Implement next(self).""" - def __enter__(self) -> Self: ... - def __exit__( - self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None - ) -> None: ... - def close(self) -> None: - """Flush and close the IO object. + def __enter__(self) -> Self: ... + def __exit__( + self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None + ) -> None: ... + def close(self) -> None: + """Flush and close the IO object. - This method has no effect if the file is already closed. - """ + This method has no effect if the file is already closed. + """ - def fileno(self) -> int: - """Return underlying file descriptor if one exists. + def fileno(self) -> int: + """Return underlying file descriptor if one exists. - Raise OSError if the IO object does not use a file descriptor. - """ + Raise OSError if the IO object does not use a file descriptor. + """ - def flush(self) -> None: - """Flush write buffers, if applicable. + def flush(self) -> None: + """Flush write buffers, if applicable. - This is not implemented for read-only and non-blocking streams. - """ + This is not implemented for read-only and non-blocking streams. + """ - def isatty(self) -> bool: - """Return whether this is an 'interactive' stream. + def isatty(self) -> bool: + """Return whether this is an 'interactive' stream. - Return False if it can't be determined. - """ + Return False if it can't be determined. + """ - def readable(self) -> bool: - """Return whether object was opened for reading. + def readable(self) -> bool: + """Return whether object was opened for reading. - If False, read() will raise OSError. - """ - read: Callable[..., Any] - def readlines(self, hint: int = -1, /) -> list[bytes]: - """Return a list of lines from the stream. + If False, read() will raise OSError. + """ + read: Callable[..., Any] + def readlines(self, hint: int = -1, /) -> list[bytes]: + """Return a list of lines from the stream. - hint can be specified to control the number of lines read: no more - lines will be read if the total size (in bytes/characters) of all - lines so far exceeds hint. - """ + hint can be specified to control the number of lines read: no more + lines will be read if the total size (in bytes/characters) of all + lines so far exceeds hint. + """ - def seek(self, offset: int, whence: int = 0, /) -> int: - """Change the stream position to the given byte offset. + def seek(self, offset: int, whence: int = 0, /) -> int: + """Change the stream position to the given byte offset. - offset - The stream position, relative to 'whence'. - whence - The relative position to seek from. + offset + The stream position, relative to 'whence'. + whence + The relative position to seek from. - The offset is interpreted relative to the position indicated by whence. - Values for whence are: + The offset is interpreted relative to the position indicated by whence. + Values for whence are: - * os.SEEK_SET or 0 -- start of stream (the default); offset should be zero or positive - * os.SEEK_CUR or 1 -- current stream position; offset may be negative - * os.SEEK_END or 2 -- end of stream; offset is usually negative + * os.SEEK_SET or 0 -- start of stream (the default); offset should be zero or positive + * os.SEEK_CUR or 1 -- current stream position; offset may be negative + * os.SEEK_END or 2 -- end of stream; offset is usually negative - Return the new absolute position. - """ + Return the new absolute position. + """ - def seekable(self) -> bool: - """Return whether object supports random access. + def seekable(self) -> bool: + """Return whether object supports random access. - If False, seek(), tell() and truncate() will raise OSError. - This method may need to do a test seek(). - """ + If False, seek(), tell() and truncate() will raise OSError. + This method may need to do a test seek(). + """ - def tell(self) -> int: - """Return current stream position.""" + def tell(self) -> int: + """Return current stream position.""" - def truncate(self, size: int | None = None, /) -> int: - """Truncate file to size bytes. + def truncate(self, size: int | None = None, /) -> int: + """Truncate file to size bytes. - File pointer is left unchanged. Size defaults to the current IO position - as reported by tell(). Return the new size. - """ + File pointer is left unchanged. Size defaults to the current IO position + as reported by tell(). Return the new size. + """ - def writable(self) -> bool: - """Return whether object was opened for writing. + def writable(self) -> bool: + """Return whether object was opened for writing. - If False, write() will raise OSError. - """ - write: Callable[..., Any] - def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: - """Write a list of lines to stream. + If False, write() will raise OSError. + """ + write: Callable[..., Any] + def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: + """Write a list of lines to stream. - Line separators are not added, so it is usual for each of the - lines provided to have a line separator at the end. - """ + Line separators are not added, so it is usual for each of the + lines provided to have a line separator at the end. + """ + + def readline(self, size: int | None = -1, /) -> bytes: + """Read and return a line from the stream. + + If size is specified, at most size bytes will be read. + + The line terminator is always b'\\n' for binary files; for text + files, the newlines argument to open can be used to select the line + terminator(s) recognized. + """ + + def __del__(self) -> None: + """Called when the instance is about to be destroyed.""" + + @property + def closed(self) -> bool: ... + def _checkClosed(self) -> None: ... # undocumented + +else: + class _IOBase: + """The abstract base class for all I/O classes. + + This class provides dummy implementations for many methods that + derived classes can override selectively; the default implementations + represent a file that cannot be read, written or seeked. + + Even though IOBase does not declare read, readinto, or write because + their signatures will vary, implementations and clients should + consider those methods part of the interface. Also, implementations + may raise UnsupportedOperation when operations they do not support are + called. + + The basic type used for binary data read from or written to a file is + bytes. Other bytes-like objects are accepted as method arguments too. + In some cases (such as readinto), a writable object is required. Text + I/O classes work with str data. + + Note that calling any method (except additional calls to close(), + which are ignored) on a closed stream should raise a ValueError. - def readline(self, size: int | None = -1, /) -> bytes: - """Read and return a line from the stream. + IOBase (and its subclasses) support the iterator protocol, meaning + that an IOBase object can be iterated over yielding the lines in a + stream. - If size is specified, at most size bytes will be read. + IOBase also supports the :keyword:`with` statement. In this example, + fp is closed after the suite of the with statement is complete: - The line terminator is always b'\\n' for binary files; for text - files, the newlines argument to open can be used to select the line - terminator(s) recognized. + with open('spam.txt', 'r') as fp: + fp.write('Spam and eggs!') """ - def __del__(self) -> None: - """Called when the instance is about to be destroyed.""" + def __iter__(self) -> Iterator[bytes]: + """Implement iter(self).""" - @property - def closed(self) -> bool: ... - def _checkClosed(self) -> None: ... # undocumented + def __next__(self) -> bytes: + """Implement next(self).""" + + def __enter__(self) -> Self: ... + def __exit__( + self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None + ) -> None: ... + def close(self) -> None: + """Flush and close the IO object. + + This method has no effect if the file is already closed. + """ + + def fileno(self) -> int: + """Returns underlying file descriptor if one exists. + + OSError is raised if the IO object does not use a file descriptor. + """ + + def flush(self) -> None: + """Flush write buffers, if applicable. + + This is not implemented for read-only and non-blocking streams. + """ + + def isatty(self) -> bool: + """Return whether this is an 'interactive' stream. + + Return False if it can't be determined. + """ + + def readable(self) -> bool: + """Return whether object was opened for reading. + + If False, read() will raise OSError. + """ + read: Callable[..., Any] + def readlines(self, hint: int = -1, /) -> list[bytes]: + """Return a list of lines from the stream. + + hint can be specified to control the number of lines read: no more + lines will be read if the total size (in bytes/characters) of all + lines so far exceeds hint. + """ + + def seek(self, offset: int, whence: int = 0, /) -> int: + """Change the stream position to the given byte offset. + + offset + The stream position, relative to 'whence'. + whence + The relative position to seek from. + + The offset is interpreted relative to the position indicated by whence. + Values for whence are: + + * os.SEEK_SET or 0 -- start of stream (the default); offset should be zero or positive + * os.SEEK_CUR or 1 -- current stream position; offset may be negative + * os.SEEK_END or 2 -- end of stream; offset is usually negative + + Return the new absolute position. + """ + + def seekable(self) -> bool: + """Return whether object supports random access. + + If False, seek(), tell() and truncate() will raise OSError. + This method may need to do a test seek(). + """ + + def tell(self) -> int: + """Return current stream position.""" + + def truncate(self, size: int | None = None, /) -> int: + """Truncate file to size bytes. + + File pointer is left unchanged. Size defaults to the current IO + position as reported by tell(). Returns the new size. + """ + + def writable(self) -> bool: + """Return whether object was opened for writing. + + If False, write() will raise OSError. + """ + write: Callable[..., Any] + def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: + """Write a list of lines to stream. + + Line separators are not added, so it is usual for each of the + lines provided to have a line separator at the end. + """ + + def readline(self, size: int | None = -1, /) -> bytes: + """Read and return a line from the stream. + + If size is specified, at most size bytes will be read. + + The line terminator is always b'\\n' for binary files; for text + files, the newlines argument to open can be used to select the line + terminator(s) recognized. + """ + + def __del__(self) -> None: ... + @property + def closed(self) -> bool: ... + def _checkClosed(self) -> None: ... # undocumented class _RawIOBase(_IOBase): """Base class for raw binary I/O.""" @@ -275,6 +424,7 @@ class _BufferedIOBase(_IOBase): A short result does not imply that EOF is imminent. """ +@disjoint_base class FileIO(RawIOBase, _RawIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes """Open a file. @@ -328,6 +478,7 @@ class FileIO(RawIOBase, _RawIOBase, BinaryIO): # type: ignore[misc] # incompat bytes object at EOF. """ +@disjoint_base class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes """Buffered I/O implementation using an in-memory bytes buffer.""" @@ -395,15 +546,21 @@ class _BufferedReaderStream(Protocol): _BufferedReaderStreamT = TypeVar("_BufferedReaderStreamT", bound=_BufferedReaderStream, default=_BufferedReaderStream) +@disjoint_base class BufferedReader(BufferedIOBase, _BufferedIOBase, BinaryIO, Generic[_BufferedReaderStreamT]): # type: ignore[misc] # incompatible definitions of methods in the base classes """Create a new buffered reader using the given readable raw IO object.""" raw: _BufferedReaderStreamT - def __init__(self, raw: _BufferedReaderStreamT, buffer_size: int = 8192) -> None: ... + if sys.version_info >= (3, 14): + def __init__(self, raw: _BufferedReaderStreamT, buffer_size: int = 131072) -> None: ... + else: + def __init__(self, raw: _BufferedReaderStreamT, buffer_size: int = 8192) -> None: ... + def peek(self, size: int = 0, /) -> bytes: ... def seek(self, target: int, whence: int = 0, /) -> int: ... def truncate(self, pos: int | None = None, /) -> int: ... +@disjoint_base class BufferedWriter(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes """A buffer for a writeable sequential RawIO object. @@ -413,11 +570,16 @@ class BufferedWriter(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore """ raw: RawIOBase - def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ... + if sys.version_info >= (3, 14): + def __init__(self, raw: RawIOBase, buffer_size: int = 131072) -> None: ... + else: + def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ... + def write(self, buffer: ReadableBuffer, /) -> int: ... def seek(self, target: int, whence: int = 0, /) -> int: ... def truncate(self, pos: int | None = None, /) -> int: ... +@disjoint_base class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes """A buffered interface to random access streams. @@ -429,11 +591,16 @@ class BufferedRandom(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore mode: str name: Any raw: RawIOBase - def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ... + if sys.version_info >= (3, 14): + def __init__(self, raw: RawIOBase, buffer_size: int = 131072) -> None: ... + else: + def __init__(self, raw: RawIOBase, buffer_size: int = 8192) -> None: ... + def seek(self, target: int, whence: int = 0, /) -> int: ... # stubtest needs this def peek(self, size: int = 0, /) -> bytes: ... def truncate(self, pos: int | None = None, /) -> int: ... +@disjoint_base class BufferedRWPair(BufferedIOBase, _BufferedIOBase, Generic[_BufferedReaderStreamT]): """A buffered reader and writer object together. @@ -446,7 +613,11 @@ class BufferedRWPair(BufferedIOBase, _BufferedIOBase, Generic[_BufferedReaderStr DEFAULT_BUFFER_SIZE. """ - def __init__(self, reader: _BufferedReaderStreamT, writer: RawIOBase, buffer_size: int = 8192, /) -> None: ... + if sys.version_info >= (3, 14): + def __init__(self, reader: _BufferedReaderStreamT, writer: RawIOBase, buffer_size: int = 131072, /) -> None: ... + else: + def __init__(self, reader: _BufferedReaderStreamT, writer: RawIOBase, buffer_size: int = 8192, /) -> None: ... + def peek(self, size: int = 0, /) -> bytes: ... class _TextIOBase(_IOBase): @@ -533,6 +704,7 @@ class _WrappedBuffer(Protocol): _BufferT_co = TypeVar("_BufferT_co", bound=_WrappedBuffer, default=_WrappedBuffer, covariant=True) +@disjoint_base class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # type: ignore[misc] # incompatible definitions of write in the base classes """Character and line based layer over a BufferedIOBase object, buffer. @@ -622,6 +794,7 @@ class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # t def truncate(self, pos: int | None = None, /) -> int: ... +@disjoint_base class StringIO(TextIOBase, _TextIOBase, TextIO): # type: ignore[misc] # incompatible definitions of write in the base classes """Text I/O implementation using an in-memory buffer. @@ -657,6 +830,7 @@ class StringIO(TextIOBase, _TextIOBase, TextIO): # type: ignore[misc] # incomp Returns the new absolute position. """ +@disjoint_base class IncrementalNewlineDecoder: """Codec used when reading a file in universal newlines mode. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_lsprof.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_lsprof.pyi index 87281edf2f9ec..ed6d52517bb11 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_lsprof.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_lsprof.pyi @@ -5,7 +5,9 @@ from _typeshed import structseq from collections.abc import Callable from types import CodeType from typing import Any, Final, final +from typing_extensions import disjoint_base +@disjoint_base class Profiler: """Build a profiler object using the specified timer function. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi index a91a3608710ec..dc41fd420f147 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_lzma.pyi @@ -58,9 +58,9 @@ class LZMADecompressor: """ if sys.version_info >= (3, 12): - def __new__(cls, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> Self: ... + def __new__(cls, format: int = 0, memlimit: int | None = None, filters: _FilterChain | None = None) -> Self: ... else: - def __init__(self, format: int | None = ..., memlimit: int | None = ..., filters: _FilterChain | None = ...) -> None: ... + def __init__(self, format: int = 0, memlimit: int | None = None, filters: _FilterChain | None = None) -> None: ... def decompress(self, data: ReadableBuffer, max_length: int = -1) -> bytes: """Decompress *data*, returning uncompressed data as bytes. @@ -127,11 +127,11 @@ class LZMACompressor: if sys.version_info >= (3, 12): def __new__( - cls, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ... + cls, format: int = 1, check: int = -1, preset: int | None = None, filters: _FilterChain | None = None ) -> Self: ... else: def __init__( - self, format: int | None = ..., check: int = ..., preset: int | None = ..., filters: _FilterChain | None = ... + self, format: int = 1, check: int = -1, preset: int | None = None, filters: _FilterChain | None = None ) -> None: ... def compress(self, data: ReadableBuffer, /) -> bytes: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_multibytecodec.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_multibytecodec.pyi index 7e408f2aa30e1..abe58cb64f319 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_multibytecodec.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_multibytecodec.pyi @@ -2,6 +2,7 @@ from _typeshed import ReadableBuffer from codecs import _ReadableStream, _WritableStream from collections.abc import Iterable from typing import final, type_check_only +from typing_extensions import disjoint_base # This class is not exposed. It calls itself _multibytecodec.MultibyteCodec. @final @@ -10,6 +11,7 @@ class _MultibyteCodec: def decode(self, input: ReadableBuffer, errors: str | None = None) -> str: ... def encode(self, input: str, errors: str | None = None) -> bytes: ... +@disjoint_base class MultibyteIncrementalDecoder: errors: str def __init__(self, errors: str = "strict") -> None: ... @@ -18,6 +20,7 @@ class MultibyteIncrementalDecoder: def reset(self) -> None: ... def setstate(self, state: tuple[bytes, int], /) -> None: ... +@disjoint_base class MultibyteIncrementalEncoder: errors: str def __init__(self, errors: str = "strict") -> None: ... @@ -26,6 +29,7 @@ class MultibyteIncrementalEncoder: def reset(self) -> None: ... def setstate(self, state: int, /) -> None: ... +@disjoint_base class MultibyteStreamReader: errors: str stream: _ReadableStream @@ -35,6 +39,7 @@ class MultibyteStreamReader: def readlines(self, sizehintobj: int | None = None, /) -> list[str]: ... def reset(self) -> None: ... +@disjoint_base class MultibyteStreamWriter: errors: str stream: _WritableStream diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi index de25ab866c53f..9867a477a7f80 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_pickle.pyi @@ -4,7 +4,7 @@ from _typeshed import ReadableBuffer, SupportsWrite from collections.abc import Callable, Iterable, Iterator, Mapping from pickle import PickleBuffer as PickleBuffer from typing import Any, Protocol, type_check_only -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, disjoint_base @type_check_only class _ReadableFileobj(Protocol): @@ -145,6 +145,7 @@ class PicklerMemoProxy: def clear(self, /) -> None: ... def copy(self, /) -> dict[int, tuple[int, Any]]: ... +@disjoint_base class Pickler: """This takes a binary file for writing a pickle data stream. @@ -212,6 +213,7 @@ class UnpicklerMemoProxy: def clear(self, /) -> None: ... def copy(self, /) -> dict[int, tuple[int, Any]]: ... +@disjoint_base class Unpickler: """This takes a binary file for reading a pickle data stream. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_queue.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_queue.pyi index 7c2d4c7400089..2e78fd1d78391 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_queue.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_queue.pyi @@ -4,12 +4,14 @@ This module is an implementation detail, please do not use it directly. from types import GenericAlias from typing import Any, Generic, TypeVar +from typing_extensions import disjoint_base _T = TypeVar("_T") class Empty(Exception): """Exception raised by Queue.get(block=0)/get_nowait().""" +@disjoint_base class SimpleQueue(Generic[_T]): """Simple, unbounded, reentrant FIFO queue.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_random.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_random.pyi index 3baf234edd2b3..243de87f5aa5f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_random.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_random.pyi @@ -1,14 +1,20 @@ """Module implements the Mersenne Twister random number generator.""" -from typing_extensions import TypeAlias +import sys +from typing_extensions import Self, TypeAlias, disjoint_base # Actually Tuple[(int,) * 625] _State: TypeAlias = tuple[int, ...] +@disjoint_base class Random: """Random() -> create a random number generator with its own internal state.""" - def __init__(self, seed: object = ...) -> None: ... + if sys.version_info >= (3, 10): + def __init__(self, seed: object = ..., /) -> None: ... + else: + def __new__(self, seed: object = ..., /) -> Self: ... + def seed(self, n: object = None, /) -> None: """seed([n]) -> None. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi index f5abc17748389..fd99c122d0100 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_socket.pyi @@ -8,7 +8,7 @@ from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterable from socket import error as error, gaierror as gaierror, herror as herror, timeout as timeout from typing import Any, Final, SupportsIndex, overload -from typing_extensions import CapsuleType, TypeAlias +from typing_extensions import CapsuleType, TypeAlias, disjoint_base _CMSG: TypeAlias = tuple[int, int, bytes] _CMSGArg: TypeAlias = tuple[int, int, ReadableBuffer] @@ -736,6 +736,7 @@ if sys.platform != "win32" and sys.platform != "darwin": # ===== Classes ===== +@disjoint_base class socket: """socket(family=AF_INET, type=SOCK_STREAM, proto=0) -> socket object socket(family=-1, type=-1, proto=-1, fileno=None) -> socket object diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi index d700e8f8c55b3..ca8fe20333eae 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_ssl.pyi @@ -17,7 +17,7 @@ from ssl import ( SSLZeroReturnError as SSLZeroReturnError, ) from typing import Any, ClassVar, Final, Literal, TypedDict, final, overload, type_check_only -from typing_extensions import NotRequired, Self, TypeAlias, deprecated +from typing_extensions import NotRequired, Self, TypeAlias, deprecated, disjoint_base _PasswordType: TypeAlias = Callable[[], str | bytes | bytearray] | str | bytes | bytearray _PCTRTT: TypeAlias = tuple[tuple[str, str], ...] @@ -117,6 +117,7 @@ def txt2obj(txt: str, name: bool = False) -> tuple[int, str, str, str]: def nid2obj(nid: int, /) -> tuple[int, str, str, str]: """Lookup NID, short name, long name and OID of an ASN1_OBJECT by NID.""" +@disjoint_base class _SSLContext: check_hostname: bool keylog_filename: str | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_struct.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_struct.pyi index 5bc790ef45351..801e999a08089 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_struct.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_struct.pyi @@ -31,6 +31,7 @@ The variable struct.error is an exception raised on errors. from _typeshed import ReadableBuffer, WriteableBuffer from collections.abc import Iterator from typing import Any +from typing_extensions import disjoint_base def pack(fmt: str | bytes, /, *v: Any) -> bytes: """pack(format, v1, v2, ...) -> bytes @@ -76,6 +77,7 @@ def iter_unpack(format: str | bytes, buffer: ReadableBuffer, /) -> Iterator[tupl def calcsize(format: str | bytes, /) -> int: """Return size in bytes of the struct described by the format string.""" +@disjoint_base class Struct: """Struct(fmt) --> compiled struct object""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi index 86cd3ae0a87e2..8b63cc7ca8bc1 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_thread.pyi @@ -9,7 +9,7 @@ from collections.abc import Callable from threading import Thread from types import TracebackType from typing import Any, Final, NoReturn, final, overload -from typing_extensions import TypeVarTuple, Unpack +from typing_extensions import TypeVarTuple, Unpack, disjoint_base _Ts = TypeVarTuple("_Ts") @@ -361,6 +361,7 @@ if sys.version_info >= (3, 14): def set_name(name: str) -> None: """Set the name of the current thread.""" +@disjoint_base class _local: """Thread-local data""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi index 2cfd8173afd1b..25054b601a4f6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_typeshed/__init__.pyi @@ -54,7 +54,8 @@ Unused: TypeAlias = object # stable # Marker for return types that include None, but where forcing the user to # check for None can be detrimental. Sometimes called "the Any trick". See -# CONTRIBUTING.md for more information. +# https://typing.python.org/en/latest/guides/writing_stubs.html#the-any-trick +# for more information. MaybeNone: TypeAlias = Any # stable # Used to mark arguments that default to a sentinel value. This prevents diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_warnings.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_warnings.pyi index 10bb176ca9f00..10ab8833673ba 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_warnings.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_warnings.pyi @@ -60,9 +60,9 @@ def warn_explicit( filename: str, lineno: int, module: str | None = ..., - registry: dict[str | tuple[str, type[Warning], int], int] | None = ..., - module_globals: dict[str, Any] | None = ..., - source: Any | None = ..., + registry: dict[str | tuple[str, type[Warning], int], int] | None = None, + module_globals: dict[str, Any] | None = None, + source: Any | None = None, ) -> None: """Issue a warning, or maybe ignore it or raise an exception.""" @@ -72,8 +72,8 @@ def warn_explicit( category: Any, filename: str, lineno: int, - module: str | None = ..., - registry: dict[str | tuple[str, type[Warning], int], int] | None = ..., - module_globals: dict[str, Any] | None = ..., - source: Any | None = ..., + module: str | None = None, + registry: dict[str | tuple[str, type[Warning], int], int] | None = None, + module_globals: dict[str, Any] | None = None, + source: Any | None = None, ) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi index 2bfc6b6337bcf..3d4413ed11377 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/_zstd.pyi @@ -60,9 +60,9 @@ class ZstdCompressor: CONTINUE: Final = 0 FLUSH_BLOCK: Final = 1 FLUSH_FRAME: Final = 2 - def __init__( - self, level: int | None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None - ) -> None: ... + def __new__( + cls, level: int | None = None, options: Mapping[int, int] | None = None, zstd_dict: ZstdDict | None = None + ) -> Self: ... def compress( self, /, data: ReadableBuffer, mode: _ZstdCompressorContinue | _ZstdCompressorFlushBlock | _ZstdCompressorFlushFrame = 0 ) -> bytes: @@ -126,7 +126,7 @@ class ZstdDecompressor: function instead. """ - def __init__(self, zstd_dict: ZstdDict | None = None, options: Mapping[int, int] | None = None) -> None: ... + def __new__(cls, zstd_dict: ZstdDict | None = None, options: Mapping[int, int] | None = None) -> Self: ... def decompress(self, /, data: ReadableBuffer, max_length: int = -1) -> bytes: """Decompress *data*, returning uncompressed bytes if possible, or b'' otherwise. @@ -188,7 +188,7 @@ class ZstdDict: by multiple ZstdCompressor or ZstdDecompressor objects. """ - def __init__(self, dict_content: bytes, /, *, is_raw: bool = False) -> None: ... + def __new__(cls, dict_content: bytes, /, *, is_raw: bool = False) -> Self: ... def __len__(self, /) -> int: """Return len(self).""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi index 2c02c4c8a44c8..685bd2ea8687e 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/annotationlib.pyi @@ -42,6 +42,20 @@ if sys.version_info >= (3, 14): """ + __slots__ = ( + "__forward_is_argument__", + "__forward_is_class__", + "__forward_module__", + "__weakref__", + "__arg__", + "__globals__", + "__extra_names__", + "__code__", + "__ast_node__", + "__cell__", + "__owner__", + "__stringifier_dict__", + ) __forward_is_argument__: bool __forward_is_class__: bool __forward_module__: str | None diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi index c2fff6022532a..52ab6bbf013b6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/argparse.pyi @@ -260,7 +260,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer): exit_on_error: bool = True, *, suggest_on_error: bool = False, - color: bool = False, + color: bool = True, ) -> None: ... else: def __init__( diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi index 947cc6a1ccb12..a7b41229c92d3 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/array.pyi @@ -9,7 +9,7 @@ from _typeshed import ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Iterable, MutableSequence from types import GenericAlias from typing import Any, ClassVar, Literal, SupportsIndex, TypeVar, overload -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Self, TypeAlias, deprecated, disjoint_base _IntTypeCode: TypeAlias = Literal["b", "B", "h", "H", "i", "I", "l", "L", "q", "Q"] _FloatTypeCode: TypeAlias = Literal["f", "d"] @@ -23,6 +23,7 @@ _T = TypeVar("_T", int, float, str) typecodes: str +@disjoint_base class array(MutableSequence[_T]): """array(typecode [, initializer]) -> array diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi index 1771edd5a251a..772f165a98f00 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/ast.pyi @@ -34,7 +34,7 @@ from _ast import ( from _typeshed import ReadableBuffer, Unused from collections.abc import Iterable, Iterator, Sequence from typing import Any, ClassVar, Generic, Literal, TypedDict, TypeVar as _TypeVar, overload, type_check_only -from typing_extensions import Self, Unpack, deprecated +from typing_extensions import Self, Unpack, deprecated, disjoint_base if sys.version_info >= (3, 13): from _ast import PyCF_OPTIMIZED_AST as PyCF_OPTIMIZED_AST @@ -53,17 +53,25 @@ class _Attributes(TypedDict, Generic[_EndPositionT], total=False): # The various AST classes are implemented in C, and imported from _ast at runtime, # but they consider themselves to live in the ast module, # so we'll define the stubs in this file. -class AST: - if sys.version_info >= (3, 10): +if sys.version_info >= (3, 12): + @disjoint_base + class AST: __match_args__ = () - _attributes: ClassVar[tuple[str, ...]] - _fields: ClassVar[tuple[str, ...]] - if sys.version_info >= (3, 13): - _field_types: ClassVar[dict[str, Any]] + _attributes: ClassVar[tuple[str, ...]] + _fields: ClassVar[tuple[str, ...]] + if sys.version_info >= (3, 13): + _field_types: ClassVar[dict[str, Any]] - if sys.version_info >= (3, 14): - def __replace__(self) -> Self: - """Return a copy of the AST node with new values for the specified fields.""" + if sys.version_info >= (3, 14): + def __replace__(self) -> Self: + """Return a copy of the AST node with new values for the specified fields.""" + +else: + class AST: + if sys.version_info >= (3, 10): + __match_args__ = () + _attributes: ClassVar[tuple[str, ...]] + _fields: ClassVar[tuple[str, ...]] class mod(AST): """mod = Module(stmt* body, type_ignore* type_ignores) diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/base_events.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/base_events.pyi index 8d9543fcca6b5..82ab82d7c5940 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/base_events.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/base_events.pyi @@ -25,7 +25,7 @@ from asyncio.transports import BaseTransport, DatagramTransport, ReadTransport, from collections.abc import Callable, Iterable, Sequence from concurrent.futures import Executor, ThreadPoolExecutor from contextvars import Context -from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket +from socket import AddressFamily, AddressInfo, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Literal, TypeVar, overload from typing_extensions import TypeAlias, TypeVarTuple, Unpack @@ -392,8 +392,8 @@ class BaseEventLoop(AbstractEventLoop): host: str | Sequence[str] | None = None, port: int = ..., *, - family: int = ..., - flags: int = ..., + family: int = 0, + flags: int = 1, sock: None = None, backlog: int = 100, ssl: _SSLContext = None, @@ -427,8 +427,8 @@ class BaseEventLoop(AbstractEventLoop): host: None = None, port: None = None, *, - family: int = ..., - flags: int = ..., + family: int = 0, + flags: int = 1, sock: socket = ..., backlog: int = 100, ssl: _SSLContext = None, @@ -447,8 +447,8 @@ class BaseEventLoop(AbstractEventLoop): host: str | Sequence[str] | None = None, port: int = ..., *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: None = None, backlog: int = 100, ssl: _SSLContext = None, @@ -481,8 +481,8 @@ class BaseEventLoop(AbstractEventLoop): host: None = None, port: None = None, *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: socket = ..., backlog: int = 100, ssl: _SSLContext = None, @@ -500,8 +500,8 @@ class BaseEventLoop(AbstractEventLoop): host: str | Sequence[str] | None = None, port: int = ..., *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: None = None, backlog: int = 100, ssl: _SSLContext = None, @@ -533,8 +533,8 @@ class BaseEventLoop(AbstractEventLoop): host: None = None, port: None = None, *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: socket = ..., backlog: int = 100, ssl: _SSLContext = None, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi index 1ce38b5f07419..0a48124eaf1a6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/events.pyi @@ -13,7 +13,7 @@ from abc import ABCMeta, abstractmethod from collections.abc import Callable, Sequence from concurrent.futures import Executor from contextvars import Context -from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket +from socket import AddressFamily, AddressInfo, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Literal, Protocol, TypeVar, overload, type_check_only from typing_extensions import Self, TypeAlias, TypeVarTuple, Unpack, deprecated @@ -352,8 +352,8 @@ class AbstractEventLoop: host: str | Sequence[str] | None = None, port: int = ..., *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: None = None, backlog: int = 100, ssl: _SSLContext = None, @@ -424,8 +424,8 @@ class AbstractEventLoop: host: None = None, port: None = None, *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: socket = ..., backlog: int = 100, ssl: _SSLContext = None, @@ -445,8 +445,8 @@ class AbstractEventLoop: host: str | Sequence[str] | None = None, port: int = ..., *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: None = None, backlog: int = 100, ssl: _SSLContext = None, @@ -513,8 +513,8 @@ class AbstractEventLoop: host: None = None, port: None = None, *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: socket = ..., backlog: int = 100, ssl: _SSLContext = None, @@ -533,8 +533,8 @@ class AbstractEventLoop: host: str | Sequence[str] | None = None, port: int = ..., *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: None = None, backlog: int = 100, ssl: _SSLContext = None, @@ -596,8 +596,8 @@ class AbstractEventLoop: host: None = None, port: None = None, *, - family: int = ..., - flags: int = ..., + family: int = AddressFamily.AF_UNSPEC, + flags: int = AddressInfo.AI_PASSIVE, sock: socket = ..., backlog: int = 100, ssl: _SSLContext = None, @@ -872,7 +872,7 @@ class AbstractEventLoop: bufsize: Literal[0] = 0, encoding: None = None, errors: None = None, - text: Literal[False] | None = ..., + text: Literal[False] | None = None, **kwargs: Any, ) -> tuple[SubprocessTransport, _ProtocolT]: ... @abstractmethod diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/graph.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/graph.pyi index 7266d6a7a71d4..2b9fb15f4fc63 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/graph.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/graph.pyi @@ -1,72 +1,74 @@ """Introspection utils for tasks call graphs.""" +import sys from _typeshed import SupportsWrite from asyncio import Future from dataclasses import dataclass from types import FrameType from typing import Any, overload -__all__ = ("capture_call_graph", "format_call_graph", "print_call_graph", "FrameCallGraphEntry", "FutureCallGraph") +if sys.version_info >= (3, 14): + __all__ = ("capture_call_graph", "format_call_graph", "print_call_graph", "FrameCallGraphEntry", "FutureCallGraph") -@dataclass(frozen=True) -class FrameCallGraphEntry: - """FrameCallGraphEntry(frame: frame)""" + @dataclass(frozen=True, slots=True) + class FrameCallGraphEntry: + """FrameCallGraphEntry(frame: frame)""" - frame: FrameType + frame: FrameType -@dataclass(frozen=True) -class FutureCallGraph: - """FutureCallGraph(future: _asyncio.Future, call_stack: tuple['FrameCallGraphEntry', ...], awaited_by: tuple['FutureCallGraph', ...])""" + @dataclass(frozen=True, slots=True) + class FutureCallGraph: + """FutureCallGraph(future: _asyncio.Future, call_stack: tuple['FrameCallGraphEntry', ...], awaited_by: tuple['FutureCallGraph', ...])""" - future: Future[Any] - call_stack: tuple[FrameCallGraphEntry, ...] - awaited_by: tuple[FutureCallGraph, ...] + future: Future[Any] + call_stack: tuple[FrameCallGraphEntry, ...] + awaited_by: tuple[FutureCallGraph, ...] -@overload -def capture_call_graph(future: None = None, /, *, depth: int = 1, limit: int | None = None) -> FutureCallGraph | None: - """Capture the async call graph for the current task or the provided Future. + @overload + def capture_call_graph(future: None = None, /, *, depth: int = 1, limit: int | None = None) -> FutureCallGraph | None: + """Capture the async call graph for the current task or the provided Future. - The graph is represented with three data structures: + The graph is represented with three data structures: - * FutureCallGraph(future, call_stack, awaited_by) + * FutureCallGraph(future, call_stack, awaited_by) - Where 'future' is an instance of asyncio.Future or asyncio.Task. + Where 'future' is an instance of asyncio.Future or asyncio.Task. - 'call_stack' is a tuple of FrameGraphEntry objects. + 'call_stack' is a tuple of FrameGraphEntry objects. - 'awaited_by' is a tuple of FutureCallGraph objects. + 'awaited_by' is a tuple of FutureCallGraph objects. - * FrameCallGraphEntry(frame) + * FrameCallGraphEntry(frame) - Where 'frame' is a frame object of a regular Python function - in the call stack. + Where 'frame' is a frame object of a regular Python function + in the call stack. - Receives an optional 'future' argument. If not passed, - the current task will be used. If there's no current task, the function - returns None. + Receives an optional 'future' argument. If not passed, + the current task will be used. If there's no current task, the function + returns None. - If "capture_call_graph()" is introspecting *the current task*, the - optional keyword-only 'depth' argument can be used to skip the specified - number of frames from top of the stack. + If "capture_call_graph()" is introspecting *the current task*, the + optional keyword-only 'depth' argument can be used to skip the specified + number of frames from top of the stack. - If the optional keyword-only 'limit' argument is provided, each call stack - in the resulting graph is truncated to include at most ``abs(limit)`` - entries. If 'limit' is positive, the entries left are the closest to - the invocation point. If 'limit' is negative, the topmost entries are - left. If 'limit' is omitted or None, all entries are present. - If 'limit' is 0, the call stack is not captured at all, only - "awaited by" information is present. - """ + If the optional keyword-only 'limit' argument is provided, each call stack + in the resulting graph is truncated to include at most ``abs(limit)`` + entries. If 'limit' is positive, the entries left are the closest to + the invocation point. If 'limit' is negative, the topmost entries are + left. If 'limit' is omitted or None, all entries are present. + If 'limit' is 0, the call stack is not captured at all, only + "awaited by" information is present. + """ -@overload -def capture_call_graph(future: Future[Any], /, *, depth: int = 1, limit: int | None = None) -> FutureCallGraph | None: ... -def format_call_graph(future: Future[Any] | None = None, /, *, depth: int = 1, limit: int | None = None) -> str: - """Return the async call graph as a string for `future`. + @overload + def capture_call_graph(future: Future[Any], /, *, depth: int = 1, limit: int | None = None) -> FutureCallGraph | None: ... + def format_call_graph(future: Future[Any] | None = None, /, *, depth: int = 1, limit: int | None = None) -> str: + """Return the async call graph as a string for `future`. - If `future` is not provided, format the call graph for the current task. - """ + If `future` is not provided, format the call graph for the current task. + """ -def print_call_graph( - future: Future[Any] | None = None, /, *, file: SupportsWrite[str] | None = None, depth: int = 1, limit: int | None = None -) -> None: - """Print the async call graph for the current task or the provided Future.""" + def print_call_graph( + future: Future[Any] | None = None, /, *, file: SupportsWrite[str] | None = None, depth: int = 1, limit: int | None = None + ) -> None: + """Print the async call graph for the current task or the provided Future.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi index 7c145f01cbb7a..968a5d08ee14d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/streams.pyi @@ -34,7 +34,7 @@ if sys.version_info >= (3, 10): port: int | str | None = None, *, limit: int = 65536, - ssl_handshake_timeout: float | None = ..., + ssl_handshake_timeout: float | None = None, **kwds: Any, ) -> tuple[StreamReader, StreamWriter]: """A wrapper for create_connection() returning a (reader, writer) pair. @@ -61,7 +61,7 @@ if sys.version_info >= (3, 10): port: int | str | None = None, *, limit: int = 65536, - ssl_handshake_timeout: float | None = ..., + ssl_handshake_timeout: float | None = None, **kwds: Any, ) -> Server: """Start a socket server, call back for each client connected. @@ -92,7 +92,7 @@ else: *, loop: events.AbstractEventLoop | None = None, limit: int = 65536, - ssl_handshake_timeout: float | None = ..., + ssl_handshake_timeout: float | None = None, **kwds: Any, ) -> tuple[StreamReader, StreamWriter]: """A wrapper for create_connection() returning a (reader, writer) pair. @@ -120,7 +120,7 @@ else: *, loop: events.AbstractEventLoop | None = None, limit: int = 65536, - ssl_handshake_timeout: float | None = ..., + ssl_handshake_timeout: float | None = None, **kwds: Any, ) -> Server: """Start a socket server, call back for each client connected. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/subprocess.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/subprocess.pyi index c870fc1ef0a83..b82f0ba4ea3a0 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/subprocess.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/subprocess.pyi @@ -64,7 +64,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), group: None | str | int = None, extra_groups: None | Collection[str | int] = None, user: None | str | int = None, @@ -96,7 +96,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), group: None | str | int = None, extra_groups: None | Collection[str | int] = None, user: None | str | int = None, @@ -130,7 +130,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), group: None | str | int = None, extra_groups: None | Collection[str | int] = None, user: None | str | int = None, @@ -161,7 +161,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), group: None | str | int = None, extra_groups: None | Collection[str | int] = None, user: None | str | int = None, @@ -195,7 +195,7 @@ else: # >= 3.9 creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), group: None | str | int = None, extra_groups: None | Collection[str | int] = None, user: None | str | int = None, @@ -226,7 +226,7 @@ else: # >= 3.9 creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), group: None | str | int = None, extra_groups: None | Collection[str | int] = None, user: None | str | int = None, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi index a1f5b209cfc2f..4d08d240165be 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/trsock.pyi @@ -70,7 +70,7 @@ class TransportSocket: @deprecated("Removed in Python 3.11") def makefile(self) -> BinaryIO: ... @deprecated("Rmoved in Python 3.11") - def sendfile(self, file: BinaryIO, offset: int = ..., count: int | None = ...) -> int: ... + def sendfile(self, file: BinaryIO, offset: int = 0, count: int | None = None) -> int: ... @deprecated("Removed in Python 3.11") def close(self) -> None: ... @deprecated("Removed in Python 3.11") @@ -78,17 +78,22 @@ class TransportSocket: if sys.platform == "linux": @deprecated("Removed in Python 3.11") def sendmsg_afalg( - self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ... + self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = 0 ) -> int: ... else: @deprecated("Removed in Python 3.11.") def sendmsg_afalg( - self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = ... + self, msg: Iterable[ReadableBuffer] = ..., *, op: int, iv: Any = ..., assoclen: int = ..., flags: int = 0 ) -> NoReturn: ... @deprecated("Removed in Python 3.11.") def sendmsg( - self, buffers: Iterable[ReadableBuffer], ancdata: Iterable[_CMSG] = ..., flags: int = ..., address: _Address = ..., / + self, + buffers: Iterable[ReadableBuffer], + ancdata: Iterable[_CMSG] = ..., + flags: int = 0, + address: _Address | None = None, + /, ) -> int: ... @overload @deprecated("Removed in Python 3.11.") @@ -97,9 +102,9 @@ class TransportSocket: @deprecated("Removed in Python 3.11.") def sendto(self, data: ReadableBuffer, flags: int, address: _Address) -> int: ... @deprecated("Removed in Python 3.11.") - def send(self, data: ReadableBuffer, flags: int = ...) -> int: ... + def send(self, data: ReadableBuffer, flags: int = 0) -> int: ... @deprecated("Removed in Python 3.11.") - def sendall(self, data: ReadableBuffer, flags: int = ...) -> None: ... + def sendall(self, data: ReadableBuffer, flags: int = 0) -> None: ... @deprecated("Removed in Python 3.11.") def set_inheritable(self, inheritable: bool) -> None: ... if sys.platform == "win32": @@ -110,19 +115,19 @@ class TransportSocket: def share(self, process_id: int) -> NoReturn: ... @deprecated("Removed in Python 3.11.") - def recv_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> int: ... + def recv_into(self, buffer: _WriteBuffer, nbytes: int = 0, flags: int = 0) -> int: ... @deprecated("Removed in Python 3.11.") - def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = ..., flags: int = ...) -> tuple[int, _RetAddress]: ... + def recvfrom_into(self, buffer: _WriteBuffer, nbytes: int = 0, flags: int = 0) -> tuple[int, _RetAddress]: ... @deprecated("Removed in Python 3.11.") def recvmsg_into( - self, buffers: Iterable[_WriteBuffer], ancbufsize: int = ..., flags: int = ..., / + self, buffers: Iterable[_WriteBuffer], ancbufsize: int = 0, flags: int = 0, / ) -> tuple[int, list[_CMSG], int, Any]: ... @deprecated("Removed in Python 3.11.") - def recvmsg(self, bufsize: int, ancbufsize: int = ..., flags: int = ..., /) -> tuple[bytes, list[_CMSG], int, Any]: ... + def recvmsg(self, bufsize: int, ancbufsize: int = 0, flags: int = 0, /) -> tuple[bytes, list[_CMSG], int, Any]: ... @deprecated("Removed in Python 3.11.") - def recvfrom(self, bufsize: int, flags: int = ...) -> tuple[bytes, _RetAddress]: ... + def recvfrom(self, bufsize: int, flags: int = 0) -> tuple[bytes, _RetAddress]: ... @deprecated("Removed in Python 3.11.") - def recv(self, bufsize: int, flags: int = ...) -> bytes: ... + def recv(self, bufsize: int, flags: int = 0) -> bytes: ... @deprecated("Removed in Python 3.11.") def __enter__(self) -> socket.socket: ... @deprecated("Removed in Python 3.11.") diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_events.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_events.pyi index 5136d1c09f41e..99b9ec9565aed 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_events.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_events.pyi @@ -140,6 +140,6 @@ if sys.platform == "win32": if sys.version_info >= (3, 14): _DefaultEventLoopPolicy = _WindowsProactorEventLoopPolicy else: - DefaultEventLoopPolicy = WindowsSelectorEventLoopPolicy + DefaultEventLoopPolicy = WindowsProactorEventLoopPolicy if sys.version_info >= (3, 13): EventLoop = ProactorEventLoop diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi index 41bd0da716310..1b1d0bcf62c27 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/asyncio/windows_utils.pyi @@ -47,9 +47,9 @@ if sys.platform == "win32": def __new__( cls, args: subprocess._CMD, - stdin: subprocess._FILE | None = ..., - stdout: subprocess._FILE | None = ..., - stderr: subprocess._FILE | None = ..., + stdin: subprocess._FILE | None = None, + stdout: subprocess._FILE | None = None, + stderr: subprocess._FILE | None = None, **kwds: Any, ) -> Self: ... def __init__( diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi index 136c245253a89..394c9ed001c0d 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/binascii.pyi @@ -64,7 +64,7 @@ def crc_hqx(data: ReadableBuffer, crc: int, /) -> int: def crc32(data: ReadableBuffer, crc: int = 0, /) -> int: """Compute CRC-32 incrementally.""" -def b2a_hex(data: ReadableBuffer, sep: str | bytes = ..., bytes_per_sep: int = ...) -> bytes: +def b2a_hex(data: ReadableBuffer, sep: str | bytes = ..., bytes_per_sep: int = 1) -> bytes: """Hexadecimal representation of binary data. sep @@ -85,7 +85,7 @@ def b2a_hex(data: ReadableBuffer, sep: str | bytes = ..., bytes_per_sep: int = . b'b9_01ef' """ -def hexlify(data: ReadableBuffer, sep: str | bytes = ..., bytes_per_sep: int = ...) -> bytes: +def hexlify(data: ReadableBuffer, sep: str | bytes = ..., bytes_per_sep: int = 1) -> bytes: """Hexadecimal representation of binary data. sep diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi index 5226fadaf6b93..0b67e23a32156 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/builtins.pyi @@ -83,6 +83,7 @@ from typing_extensions import ( # noqa: Y023 TypeIs, TypeVarTuple, deprecated, + disjoint_base, ) if sys.version_info >= (3, 14): @@ -115,6 +116,7 @@ _StopT_co = TypeVar("_StopT_co", covariant=True, default=_StartT_co) # slice[A # FIXME: https://github.com/python/typing/issues/213 (replace step=start|stop with step=start&stop) _StepT_co = TypeVar("_StepT_co", covariant=True, default=_StartT_co | _StopT_co) # slice[A,B] -> slice[A, B, A|B] +@disjoint_base class object: """The base class of the class hierarchy. @@ -156,6 +158,7 @@ class object: @classmethod def __subclasshook__(cls, subclass: type, /) -> bool: ... +@disjoint_base class staticmethod(Generic[_P, _R_co]): """Convert a function to be a static method. @@ -197,6 +200,7 @@ class staticmethod(Generic[_P, _R_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... __annotate__: AnnotateFunc | None +@disjoint_base class classmethod(Generic[_T, _P, _R_co]): """Convert a function to be a class method. @@ -238,6 +242,7 @@ class classmethod(Generic[_T, _P, _R_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... __annotate__: AnnotateFunc | None +@disjoint_base class type: """type(object) -> the object's type type(name, bases, dict, **kwds) -> a new type @@ -307,6 +312,7 @@ class type: if sys.version_info >= (3, 14): __annotate__: AnnotateFunc | None +@disjoint_base class super: """super() -> same as super(__class__, ) super(type) -> unbound super object @@ -334,6 +340,7 @@ _PositiveInteger: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, _NegativeInteger: TypeAlias = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20] _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed +@disjoint_base class int: """int([x]) -> integer int(x, base=10) -> integer @@ -646,6 +653,7 @@ class int: def __format__(self, format_spec: str, /) -> str: """Convert to a string according to format_spec.""" +@disjoint_base class float: """Convert a string or number to a floating-point number, if possible.""" @@ -806,6 +814,7 @@ class float: def from_number(cls, number: float | SupportsIndex | SupportsFloat, /) -> Self: """Convert real number to a floating-point number.""" +@disjoint_base class complex: """Create a complex number from a string or numbers. @@ -898,6 +907,7 @@ class _FormatMapMapping(Protocol): class _TranslateTable(Protocol): def __getitem__(self, key: int, /) -> str | int | None: ... +@disjoint_base class str(Sequence[str]): """str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str @@ -1430,6 +1440,7 @@ class str(Sequence[str]): def __format__(self, format_spec: str, /) -> str: """Return a formatted version of the string as described by format_spec.""" +@disjoint_base class bytes(Sequence[int]): """bytes(iterable_of_ints) -> bytes bytes(string, encoding[, errors]) -> bytes @@ -1881,6 +1892,7 @@ class bytes(Sequence[int]): def __buffer__(self, flags: int, /) -> memoryview: """Return a buffer object that exposes the underlying memory of the object.""" +@disjoint_base class bytearray(MutableSequence[int]): """bytearray(iterable_of_ints) -> bytearray bytearray(string, encoding[, errors]) -> bytearray @@ -2675,6 +2687,8 @@ class slice(Generic[_StartT_co, _StopT_co, _StepT_co]): handling of normal slices. """ +# Making this a disjoint_base upsets pyright +# @disjoint_base class tuple(Sequence[_T_co]): """Built-in immutable sequence. @@ -2781,6 +2795,7 @@ class function: # mypy uses `builtins.function.__get__` to represent methods, properties, and getset_descriptors so we type the return as Any. def __get__(self, instance: object, owner: type | None = None, /) -> Any: ... +@disjoint_base class list(MutableSequence[_T]): """Built-in mutable sequence. @@ -2898,6 +2913,7 @@ class list(MutableSequence[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: """See PEP 585""" +@disjoint_base class dict(MutableMapping[_KT, _VT]): """dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's @@ -3027,6 +3043,7 @@ class dict(MutableMapping[_KT, _VT]): @overload def __ior__(self, value: Iterable[tuple[_KT, _VT]], /) -> Self: ... +@disjoint_base class set(MutableSet[_T]): """Build an unordered collection of unique elements.""" @@ -3131,6 +3148,7 @@ class set(MutableSet[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: """See PEP 585""" +@disjoint_base class frozenset(AbstractSet[_T_co]): """Build an immutable unordered collection of unique elements.""" @@ -3192,6 +3210,7 @@ class frozenset(AbstractSet[_T_co]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: """See PEP 585""" +@disjoint_base class enumerate(Generic[_T]): """Return an enumerate object. @@ -3265,6 +3284,7 @@ class range(Sequence[int]): def __reversed__(self) -> Iterator[int]: """Return a reverse iterator.""" +@disjoint_base class property: """Property attribute. @@ -3599,6 +3619,7 @@ else: exit: _sitebuiltins.Quitter +@disjoint_base class filter(Generic[_T]): """Return an iterator yielding those items of iterable for which function(item) is true. If function is None, return the items that are true. @@ -3752,6 +3773,7 @@ def locals() -> dict[str, Any]: covered by any backwards compatibility guarantees. """ +@disjoint_base class map(Generic[_S]): """Make an iterator that computes the function using arguments from each of the iterables. Stops when the shortest iterable is exhausted. @@ -4231,6 +4253,7 @@ def pow(base: _SupportsSomeKindOfPow, exp: complex, mod: None = None) -> complex quit: _sitebuiltins.Quitter +@disjoint_base class reversed(Generic[_T]): """Return a reverse iterator over the values of the given sequence.""" @@ -4335,7 +4358,7 @@ def vars(object: type, /) -> types.MappingProxyType[str, Any]: @overload def vars(object: Any = ..., /) -> dict[str, Any]: ... - +@disjoint_base class zip(Generic[_T_co]): """The zip object yields n-length tuples, where n is the number of iterables passed as positional arguments to zip(). The i-th element in every tuple @@ -4475,6 +4498,7 @@ else: Ellipsis: ellipsis +@disjoint_base class BaseException: """Common base class for all exceptions""" @@ -4500,6 +4524,7 @@ class GeneratorExit(BaseException): class KeyboardInterrupt(BaseException): """Program interrupted by user.""" +@disjoint_base class SystemExit(BaseException): """Request to exit from the interpreter.""" @@ -4508,11 +4533,13 @@ class SystemExit(BaseException): class Exception(BaseException): """Common base class for all non-exit exceptions.""" +@disjoint_base class StopIteration(Exception): """Signal the end from iterator.__next__().""" value: Any +@disjoint_base class OSError(Exception): """Base class for I/O related errors.""" @@ -4535,20 +4562,26 @@ class ArithmeticError(Exception): class AssertionError(Exception): """Assertion failed.""" -class AttributeError(Exception): - """Attribute not found.""" +if sys.version_info >= (3, 10): + @disjoint_base + class AttributeError(Exception): + """Attribute not found.""" - if sys.version_info >= (3, 10): def __init__(self, *args: object, name: str | None = ..., obj: object = ...) -> None: ... name: str obj: object +else: + class AttributeError(Exception): + """Attribute not found.""" + class BufferError(Exception): """Buffer error.""" class EOFError(Exception): """Read beyond end of file.""" +@disjoint_base class ImportError(Exception): """Import can't find module, or can't find name in module.""" @@ -4565,13 +4598,18 @@ class LookupError(Exception): class MemoryError(Exception): """Out of memory.""" -class NameError(Exception): - """Name not found globally.""" +if sys.version_info >= (3, 10): + @disjoint_base + class NameError(Exception): + """Name not found globally.""" - if sys.version_info >= (3, 10): def __init__(self, *args: object, name: str | None = ...) -> None: ... name: str +else: + class NameError(Exception): + """Name not found globally.""" + class ReferenceError(Exception): """Weak ref proxy used after referent went away.""" @@ -4581,6 +4619,7 @@ class RuntimeError(Exception): class StopAsyncIteration(Exception): """Signal the end from iterator.__anext__().""" +@disjoint_base class SyntaxError(Exception): """Invalid syntax.""" @@ -4708,6 +4747,7 @@ class TabError(IndentationError): class UnicodeError(ValueError): """Unicode related error.""" +@disjoint_base class UnicodeDecodeError(UnicodeError): """Unicode decoding error.""" @@ -4718,6 +4758,7 @@ class UnicodeDecodeError(UnicodeError): reason: str def __init__(self, encoding: str, object: ReadableBuffer, start: int, end: int, reason: str, /) -> None: ... +@disjoint_base class UnicodeEncodeError(UnicodeError): """Unicode encoding error.""" @@ -4728,6 +4769,7 @@ class UnicodeEncodeError(UnicodeError): reason: str def __init__(self, encoding: str, object: str, start: int, end: int, reason: str, /) -> None: ... +@disjoint_base class UnicodeTranslateError(UnicodeError): """Unicode translation error.""" @@ -4790,6 +4832,7 @@ if sys.version_info >= (3, 11): _ExceptionT = TypeVar("_ExceptionT", bound=Exception) # See `check_exception_group.py` for use-cases and comments. + @disjoint_base class BaseExceptionGroup(BaseException, Generic[_BaseExceptionT_co]): """A combination of multiple unrelated exceptions.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/cgi.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/cgi.pyi index b3ed05365dd71..1154503deb7b5 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/cgi.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/cgi.pyi @@ -9,6 +9,7 @@ ValueError being raised during parsing. The default value of this variable is 0, meaning the request size is unlimited. """ +import os from _typeshed import SupportsContainsAndGetItem, SupportsGetItem, SupportsItemAccess, Unused from builtins import list as _list, type as _type from collections.abc import Iterable, Iterator, Mapping @@ -34,7 +35,7 @@ __all__ = [ def parse( fp: IO[Any] | None = None, - environ: SupportsItemAccess[str, str] = ..., + environ: SupportsItemAccess[str, str] = os.environ, keep_blank_values: bool = ..., strict_parsing: bool = ..., separator: str = "&", @@ -90,7 +91,7 @@ def parse_header(line: str) -> tuple[str, dict[str, str]]: """ -def test(environ: _Environ = ...) -> None: +def test(environ: _Environ = os.environ) -> None: """Robust test CGI script, usable as main program. Write minimal HTTP headers and dump all information provided to @@ -98,7 +99,7 @@ def test(environ: _Environ = ...) -> None: """ -def print_environ(environ: _Environ = ...) -> None: +def print_environ(environ: _Environ = os.environ) -> None: """Dump the shell environment as HTML.""" def print_form(form: dict[str, Any]) -> None: @@ -197,7 +198,7 @@ class FieldStorage: fp: IO[Any] | None = None, headers: Mapping[str, str] | Message | None = None, outerboundary: bytes = b"", - environ: SupportsContainsAndGetItem[str, str] = ..., + environ: SupportsContainsAndGetItem[str, str] = os.environ, keep_blank_values: int = 0, strict_parsing: int = 0, limit: int | None = None, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi index e6ae5d53ac326..5754989a3f37c 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/codecs.pyi @@ -7,13 +7,14 @@ Written by Marc-Andre Lemburg (mal@lemburg.com). """ +import sys import types from _codecs import * from _typeshed import ReadableBuffer from abc import abstractmethod from collections.abc import Callable, Generator, Iterable from typing import Any, BinaryIO, ClassVar, Final, Literal, Protocol, TextIO, overload, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base __all__ = [ "register", @@ -131,35 +132,68 @@ class _IncrementalDecoder(Protocol): class _BufferedIncrementalDecoder(Protocol): def __call__(self, errors: str = ...) -> BufferedIncrementalDecoder: ... -class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): - """Codec details when looking up the codec registry""" - - _is_text_encoding: bool - @property - def encode(self) -> _Encoder: ... - @property - def decode(self) -> _Decoder: ... - @property - def streamreader(self) -> _StreamReader: ... - @property - def streamwriter(self) -> _StreamWriter: ... - @property - def incrementalencoder(self) -> _IncrementalEncoder: ... - @property - def incrementaldecoder(self) -> _IncrementalDecoder: ... - name: str - def __new__( - cls, - encode: _Encoder, - decode: _Decoder, - streamreader: _StreamReader | None = None, - streamwriter: _StreamWriter | None = None, - incrementalencoder: _IncrementalEncoder | None = None, - incrementaldecoder: _IncrementalDecoder | None = None, - name: str | None = None, - *, - _is_text_encoding: bool | None = None, - ) -> Self: ... +if sys.version_info >= (3, 12): + class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): + """Codec details when looking up the codec registry""" + + _is_text_encoding: bool + @property + def encode(self) -> _Encoder: ... + @property + def decode(self) -> _Decoder: ... + @property + def streamreader(self) -> _StreamReader: ... + @property + def streamwriter(self) -> _StreamWriter: ... + @property + def incrementalencoder(self) -> _IncrementalEncoder: ... + @property + def incrementaldecoder(self) -> _IncrementalDecoder: ... + name: str + def __new__( + cls, + encode: _Encoder, + decode: _Decoder, + streamreader: _StreamReader | None = None, + streamwriter: _StreamWriter | None = None, + incrementalencoder: _IncrementalEncoder | None = None, + incrementaldecoder: _IncrementalDecoder | None = None, + name: str | None = None, + *, + _is_text_encoding: bool | None = None, + ) -> Self: ... + +else: + @disjoint_base + class CodecInfo(tuple[_Encoder, _Decoder, _StreamReader, _StreamWriter]): + """Codec details when looking up the codec registry""" + + _is_text_encoding: bool + @property + def encode(self) -> _Encoder: ... + @property + def decode(self) -> _Decoder: ... + @property + def streamreader(self) -> _StreamReader: ... + @property + def streamwriter(self) -> _StreamWriter: ... + @property + def incrementalencoder(self) -> _IncrementalEncoder: ... + @property + def incrementaldecoder(self) -> _IncrementalDecoder: ... + name: str + def __new__( + cls, + encode: _Encoder, + decode: _Decoder, + streamreader: _StreamReader | None = None, + streamwriter: _StreamWriter | None = None, + incrementalencoder: _IncrementalEncoder | None = None, + incrementaldecoder: _IncrementalDecoder | None = None, + name: str | None = None, + *, + _is_text_encoding: bool | None = None, + ) -> Self: ... def getencoder(encoding: str) -> _Encoder: """Lookup up the codec for the given encoding and return diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi index c6b3b2a15c699..adb79e5ff4104 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/collections/__init__.pyi @@ -19,7 +19,7 @@ from _collections_abc import dict_items, dict_keys, dict_values from _typeshed import SupportsItems, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT from types import GenericAlias from typing import Any, ClassVar, Generic, NoReturn, SupportsIndex, TypeVar, final, overload, type_check_only -from typing_extensions import Self +from typing_extensions import Self, disjoint_base if sys.version_info >= (3, 10): from collections.abc import ( @@ -271,6 +271,7 @@ class UserString(Sequence[UserString]): def upper(self) -> Self: ... def zfill(self, width: int) -> Self: ... +@disjoint_base class deque(MutableSequence[_T]): """A list-like sequence optimized for data accesses near its endpoints.""" @@ -645,6 +646,7 @@ class _odict_items(dict_items[_KT_co, _VT_co]): # type: ignore[misc] # pyright class _odict_values(dict_values[_KT_co, _VT_co]): # type: ignore[misc] # pyright: ignore[reportGeneralTypeIssues] def __reversed__(self) -> Iterator[_VT_co]: ... +@disjoint_base class OrderedDict(dict[_KT, _VT]): """Dictionary that remembers insertion order""" @@ -717,6 +719,7 @@ class OrderedDict(dict[_KT, _VT]): @overload def __ror__(self, value: dict[_T1, _T2], /) -> OrderedDict[_KT | _T1, _VT | _T2]: ... # type: ignore[misc] +@disjoint_base class defaultdict(dict[_KT, _VT]): """defaultdict(default_factory=None, /, [...]) --> dict with default factory @@ -852,15 +855,23 @@ class ChainMap(MutableMapping[_KT, _VT]): __copy__ = copy # All arguments to `fromkeys` are passed to `dict.fromkeys` at runtime, # so the signature should be kept in line with `dict.fromkeys`. - @classmethod - @overload - def fromkeys(cls, iterable: Iterable[_T]) -> ChainMap[_T, Any | None]: - """Create a new ChainMap with keys from iterable and values set to value.""" + if sys.version_info >= (3, 13): + @classmethod + @overload + def fromkeys(cls, iterable: Iterable[_T], /) -> ChainMap[_T, Any | None]: + """Create a new ChainMap with keys from iterable and values set to value.""" + else: + @classmethod + @overload + def fromkeys(cls, iterable: Iterable[_T]) -> ChainMap[_T, Any | None]: + """Create a ChainMap with a single dict created from the iterable.""" @classmethod @overload # Special-case None: the user probably wants to add non-None values later. - def fromkeys(cls, iterable: Iterable[_T], value: None, /) -> ChainMap[_T, Any | None]: ... + def fromkeys(cls, iterable: Iterable[_T], value: None, /) -> ChainMap[_T, Any | None]: + """Create a new ChainMap with keys from iterable and values set to value.""" + @classmethod @overload def fromkeys(cls, iterable: Iterable[_T], value: _S, /) -> ChainMap[_T, _S]: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/compression/zstd/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/compression/zstd/__init__.pyi index d6481b8b8103a..d47f8eab3b051 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/compression/zstd/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/compression/zstd/__init__.pyi @@ -39,6 +39,7 @@ COMPRESSION_LEVEL_DEFAULT: Final = _zstd.ZSTD_CLEVEL_DEFAULT class FrameInfo: """Information about a Zstandard frame.""" + __slots__ = ("decompressed_size", "dictionary_id") decompressed_size: int dictionary_id: int def __init__(self, decompressed_size: int, dictionary_id: int) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_crossinterp.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_crossinterp.pyi index b2a01173ff64d..372ac39270544 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_crossinterp.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_crossinterp.pyi @@ -22,6 +22,7 @@ if sys.version_info >= (3, 13): # needed to satisfy pyright checks for Python < cross-interpreter container is destroyed. """ + __slots__ = () def __new__(cls) -> Never: ... @classonly def singleton(cls, kind: str, module: str, name: str = "UNBOUND") -> Self: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_queues.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_queues.pyi index 4eb08bfc81474..a8f49297671f4 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_queues.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/concurrent/interpreters/_queues.pyi @@ -77,7 +77,7 @@ if sys.version_info >= (3, 13): # needed to satisfy pyright checks for Python < timeout: SupportsIndex | None = None, *, unbounditems: _AnyUnbound | None = None, - _delay: float = ..., + _delay: float = 0.01, ) -> None: """Add the object to the queue. @@ -116,7 +116,7 @@ if sys.version_info >= (3, 13): # needed to satisfy pyright checks for Python < """ def put_nowait(self, obj: object, *, unbounditems: _AnyUnbound | None = None) -> None: ... - def get(self, timeout: SupportsIndex | None = None, *, _delay: float = ...) -> object: + def get(self, timeout: SupportsIndex | None = None, *, _delay: float = 0.01) -> object: """Return the next object from the queue. This blocks while the queue is empty. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi index 979c97359ecad..ee1ffa5a83afa 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/configparser.pyi @@ -784,10 +784,13 @@ class ParsingError(Error): def __init__(self, source: str) -> None: ... else: @overload - def __init__(self, source: str, filename: None = None) -> None: ... + def __init__(self, source: str) -> None: ... + @overload + @deprecated("The `filename` parameter removed in Python 3.12. Use `source` instead.") + def __init__(self, source: None, filename: str | None) -> None: ... @overload @deprecated("The `filename` parameter removed in Python 3.12. Use `source` instead.") - def __init__(self, source: None = None, filename: str = ...) -> None: ... + def __init__(self, source: None = None, *, filename: str | None) -> None: ... def append(self, lineno: int, line: str) -> None: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/crypt.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/crypt.pyi index 0830524b75057..df7d315f06982 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/crypt.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/crypt.pyi @@ -2,6 +2,7 @@ import sys from typing import Final, NamedTuple, type_check_only +from typing_extensions import disjoint_base if sys.platform != "win32": @type_check_only @@ -11,10 +12,18 @@ if sys.platform != "win32": salt_chars: int total_size: int - class _Method(_MethodBase): - """Class representing a salt method per the Modular Crypt Format or the - legacy 2-character crypt method. - """ + if sys.version_info >= (3, 12): + class _Method(_MethodBase): + """Class representing a salt method per the Modular Crypt Format or the + legacy 2-character crypt method. + """ + + else: + @disjoint_base + class _Method(_MethodBase): + """Class representing a salt method per the Modular Crypt Format or the + legacy 2-character crypt method. + """ METHOD_CRYPT: Final[_Method] METHOD_MD5: Final[_Method] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/datetime.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/datetime.pyi index 4729c819c0504..4571f2dcf6e65 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/datetime.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/datetime.pyi @@ -8,7 +8,7 @@ import sys from abc import abstractmethod from time import struct_time from typing import ClassVar, Final, NoReturn, SupportsIndex, final, overload, type_check_only -from typing_extensions import CapsuleType, Self, TypeAlias, deprecated +from typing_extensions import CapsuleType, Self, TypeAlias, deprecated, disjoint_base if sys.version_info >= (3, 11): __all__ = ("date", "datetime", "time", "timedelta", "timezone", "tzinfo", "MINYEAR", "MAXYEAR", "UTC") @@ -74,6 +74,7 @@ class _IsoCalendarDate(tuple[int, int, int]): @property def weekday(self) -> int: ... +@disjoint_base class date: """date(year, month, day) --> date object""" @@ -181,6 +182,7 @@ class date: def isocalendar(self) -> _IsoCalendarDate: """Return a named tuple containing ISO year, week number, and weekday.""" +@disjoint_base class time: """time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object @@ -284,6 +286,7 @@ class time: _Date: TypeAlias = date _Time: TypeAlias = time +@disjoint_base class timedelta: """Difference between two datetime values. @@ -376,6 +379,7 @@ class timedelta: def __hash__(self) -> int: ... +@disjoint_base class datetime(date): """datetime(year, month, day[, hour[, minute[, second[, microsecond[,tzinfo]]]]]) diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/decimal.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/decimal.pyi index a4e56372dc0bb..1f6ba755df7a2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/decimal.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/decimal.pyi @@ -127,7 +127,7 @@ from _decimal import ( from collections.abc import Container, Sequence from types import TracebackType from typing import Any, ClassVar, Literal, NamedTuple, final, overload, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base if sys.version_info >= (3, 14): from _decimal import IEEE_CONTEXT_MAX_BITS as IEEE_CONTEXT_MAX_BITS, IEEEContext as IEEEContext @@ -170,6 +170,7 @@ class Overflow(Inexact, Rounded): ... class Underflow(Inexact, Rounded, Subnormal): ... class FloatOperation(DecimalException, TypeError): ... +@disjoint_base class Decimal: """Construct a new Decimal object. 'value' can be an integer, string, tuple, or another Decimal object. If no value is given, return Decimal('0'). The @@ -693,6 +694,7 @@ class Decimal: def __deepcopy__(self, memo: Any, /) -> Self: ... def __format__(self, specifier: str, context: Context | None = None, /) -> str: ... +@disjoint_base class Context: """The context affects almost all operations and controls rounding, Over/Underflow, raising of exceptions and much more. A new context diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi index 1718f0d1cb8f3..6da3dc252cf51 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/dis.pyi @@ -5,7 +5,7 @@ import types from collections.abc import Callable, Iterator from opcode import * # `dis` re-exports it as a part of public API from typing import IO, Any, Final, NamedTuple -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base __all__ = [ "code_info", @@ -98,28 +98,107 @@ else: starts_line: int | None is_jump_target: bool -class Instruction(_Instruction): - """Details for a bytecode operation. - - Defined fields: - opname - human readable name for operation - opcode - numeric code for operation - arg - numeric argument to operation (if any), otherwise None - argval - resolved arg value (if known), otherwise same as arg - argrepr - human readable description of operation argument - offset - start index of operation within bytecode sequence - start_offset - start index of operation within bytecode sequence including extended args if present; - otherwise equal to Instruction.offset - starts_line - True if this opcode starts a source line, otherwise False - line_number - source line number associated with this opcode (if any), otherwise None - label - A label if this instruction is a jump target, otherwise None - positions - Optional dis.Positions object holding the span of source code - covered by this instruction - cache_info - information about the format and content of the instruction's cache - entries (if any) - """ +if sys.version_info >= (3, 12): + class Instruction(_Instruction): + """Details for a bytecode operation. + + Defined fields: + opname - human readable name for operation + opcode - numeric code for operation + arg - numeric argument to operation (if any), otherwise None + argval - resolved arg value (if known), otherwise same as arg + argrepr - human readable description of operation argument + offset - start index of operation within bytecode sequence + start_offset - start index of operation within bytecode sequence including extended args if present; + otherwise equal to Instruction.offset + starts_line - True if this opcode starts a source line, otherwise False + line_number - source line number associated with this opcode (if any), otherwise None + label - A label if this instruction is a jump target, otherwise None + positions - Optional dis.Positions object holding the span of source code + covered by this instruction + cache_info - information about the format and content of the instruction's cache + entries (if any) + """ + + if sys.version_info < (3, 13): + def _disassemble(self, lineno_width: int = 3, mark_as_current: bool = False, offset_width: int = 4) -> str: + """Format instruction details for inclusion in disassembly output + + *lineno_width* sets the width of the line number field (0 omits it) + *mark_as_current* inserts a '-->' marker arrow as part of the line + *offset_width* sets the width of the instruction offset field + """ + if sys.version_info >= (3, 13): + @property + def oparg(self) -> int: + """Alias for Instruction.arg.""" + + @property + def baseopcode(self) -> int: + """Numeric code for the base operation if operation is specialized. + + Otherwise equal to Instruction.opcode. + """ + + @property + def baseopname(self) -> str: + """Human readable name for the base operation if operation is specialized. + + Otherwise equal to Instruction.opname. + """ + + @property + def cache_offset(self) -> int: + """Start index of the cache entries following the operation.""" + + @property + def end_offset(self) -> int: + """End index of the cache entries following the operation.""" + + @property + def jump_target(self) -> int: + """Bytecode index of the jump target if this is a jump operation. + + Otherwise return None. + """ + + @property + def is_jump_target(self) -> bool: + """True if other code jumps to here, otherwise False""" + if sys.version_info >= (3, 14): + @staticmethod + def make( + opname: str, + arg: int | None, + argval: Any, + argrepr: str, + offset: int, + start_offset: int, + starts_line: bool, + line_number: int | None, + label: int | None = None, + positions: Positions | None = None, + cache_info: list[tuple[str, int, Any]] | None = None, + ) -> Instruction: ... + +else: + @disjoint_base + class Instruction(_Instruction): + """Details for a bytecode operation + + Defined fields: + opname - human readable name for operation + opcode - numeric code for operation + arg - numeric argument to operation (if any), otherwise None + argval - resolved arg value (if known), otherwise same as arg + argrepr - human readable description of operation argument + offset - start index of operation within bytecode sequence + starts_line - line started by this opcode (if any), otherwise None + is_jump_target - True if other code jumps to here, otherwise False + positions - Optional dis.Positions object holding the span of source code + covered by this instruction + """ - if sys.version_info < (3, 13): def _disassemble(self, lineno_width: int = 3, mark_as_current: bool = False, offset_width: int = 4) -> str: """Format instruction details for inclusion in disassembly output @@ -127,58 +206,6 @@ class Instruction(_Instruction): *mark_as_current* inserts a '-->' marker arrow as part of the line *offset_width* sets the width of the instruction offset field """ - if sys.version_info >= (3, 13): - @property - def oparg(self) -> int: - """Alias for Instruction.arg.""" - - @property - def baseopcode(self) -> int: - """Numeric code for the base operation if operation is specialized. - - Otherwise equal to Instruction.opcode. - """ - - @property - def baseopname(self) -> str: - """Human readable name for the base operation if operation is specialized. - - Otherwise equal to Instruction.opname. - """ - - @property - def cache_offset(self) -> int: - """Start index of the cache entries following the operation.""" - - @property - def end_offset(self) -> int: - """End index of the cache entries following the operation.""" - - @property - def jump_target(self) -> int: - """Bytecode index of the jump target if this is a jump operation. - - Otherwise return None. - """ - - @property - def is_jump_target(self) -> bool: - """True if other code jumps to here, otherwise False""" - if sys.version_info >= (3, 14): - @staticmethod - def make( - opname: str, - arg: int | None, - argval: Any, - argrepr: str, - offset: int, - start_offset: int, - starts_line: bool, - line_number: int | None, - label: int | None = None, - positions: Positions | None = None, - cache_info: list[tuple[str, int, Any]] | None = None, - ) -> Instruction: ... class Bytecode: """The bytecode operations of a piece of code diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/distutils/file_util.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/distutils/file_util.pyi index cc7b10bfb51da..ba4ded2abf9f2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/distutils/file_util.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/distutils/file_util.pyi @@ -59,7 +59,7 @@ def copy_file( ) -> tuple[_BytesPathT | bytes, bool]: ... @overload def move_file( - src: StrPath, dst: _StrPathT, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0 + src: StrPath, dst: _StrPathT, verbose: bool | Literal[0, 1] = 1, dry_run: bool | Literal[0, 1] = 0 ) -> _StrPathT | str: """Move a file 'src' to 'dst'. If 'dst' is a directory, the file will be moved into it with the same name; otherwise, 'src' is just renamed @@ -71,7 +71,7 @@ def move_file( @overload def move_file( - src: BytesPath, dst: _BytesPathT, verbose: bool | Literal[0, 1] = 0, dry_run: bool | Literal[0, 1] = 0 + src: BytesPath, dst: _BytesPathT, verbose: bool | Literal[0, 1] = 1, dry_run: bool | Literal[0, 1] = 0 ) -> _BytesPathT | bytes: ... def write_file(filename: StrOrBytesPath, contents: Iterable[str]) -> None: """Create a file with the specified name and write 'contents' (a diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi index 79b49491482d7..b9933de380be8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/enum.pyi @@ -5,7 +5,7 @@ from _typeshed import SupportsKeysAndGetItem, Unused from builtins import property as _builtins_property from collections.abc import Callable, Iterable, Iterator, Mapping from typing import Any, Final, Generic, Literal, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base __all__ = ["EnumMeta", "Enum", "IntEnum", "Flag", "IntFlag", "auto", "unique"] @@ -464,22 +464,37 @@ if sys.version_info >= (3, 11): Only changes the repr(), leaving str() and format() to the mixed-in type. """ -if sys.version_info >= (3, 11): - _IntEnumBase = ReprEnum +if sys.version_info >= (3, 12): + class IntEnum(int, ReprEnum): + """ + Enum where members are also (and must be) ints + """ + + _value_: int + @_magic_enum_attr + def value(self) -> int: + """The value of the Enum member.""" + + def __new__(cls, value: int) -> Self: ... + else: - _IntEnumBase = Enum + if sys.version_info >= (3, 11): + _IntEnumBase = ReprEnum + else: + _IntEnumBase = Enum -class IntEnum(int, _IntEnumBase): - """ - Enum where members are also (and must be) ints - """ + @disjoint_base + class IntEnum(int, _IntEnumBase): + """ + Enum where members are also (and must be) ints + """ - _value_: int - @_magic_enum_attr - def value(self) -> int: - """The value of the Enum member.""" + _value_: int + @_magic_enum_attr + def value(self) -> int: + """The value of the Enum member.""" - def __new__(cls, value: int) -> Self: ... + def __new__(cls, value: int) -> Self: ... def unique(enumeration: _EnumerationT) -> _EnumerationT: """ @@ -608,8 +623,25 @@ if sys.version_info >= (3, 11): the module is the last module in case of a multi-module name """ -if sys.version_info >= (3, 11): +if sys.version_info >= (3, 12): + # The body of the class is the same, but the base classes are different. + class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases + """ + Support for integer-based Flags + """ + + def __new__(cls, value: int) -> Self: ... + def __or__(self, other: int) -> Self: ... + def __and__(self, other: int) -> Self: ... + def __xor__(self, other: int) -> Self: ... + def __invert__(self) -> Self: ... + __ror__ = __or__ + __rand__ = __and__ + __rxor__ = __xor__ + +elif sys.version_info >= (3, 11): # The body of the class is the same, but the base classes are different. + @disjoint_base class IntFlag(int, ReprEnum, Flag, boundary=KEEP): # type: ignore[misc] # complaints about incompatible bases """ Support for integer-based Flags @@ -625,6 +657,7 @@ if sys.version_info >= (3, 11): __rxor__ = __xor__ else: + @disjoint_base class IntFlag(int, Flag): # type: ignore[misc] # complaints about incompatible bases """ Support for integer-based Flags diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi index 26c2166122a25..cd65e31ae8d8f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/functools.pyi @@ -6,7 +6,7 @@ from _typeshed import SupportsAllComparisons, SupportsItems from collections.abc import Callable, Hashable, Iterable, Sized from types import GenericAlias from typing import Any, Final, Generic, Literal, NamedTuple, TypedDict, TypeVar, final, overload, type_check_only -from typing_extensions import ParamSpec, Self, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias, disjoint_base __all__ = [ "update_wrapper", @@ -292,6 +292,7 @@ def cmp_to_key(mycmp: Callable[[_T, _T], int]) -> Callable[[_T], SupportsAllComp Function that compares two objects. """ +@disjoint_base class partial(Generic[_T]): """Create a new function with partial application of the given arguments and keywords. @@ -330,10 +331,17 @@ class partialmethod(Generic[_T]): func: Callable[..., _T] | _Descriptor args: tuple[Any, ...] keywords: dict[str, Any] - @overload - def __init__(self, func: Callable[..., _T], /, *args: Any, **keywords: Any) -> None: ... - @overload - def __init__(self, func: _Descriptor, /, *args: Any, **keywords: Any) -> None: ... + if sys.version_info >= (3, 14): + @overload + def __new__(self, func: Callable[..., _T], /, *args: Any, **keywords: Any) -> Self: ... + @overload + def __new__(self, func: _Descriptor, /, *args: Any, **keywords: Any) -> Self: ... + else: + @overload + def __init__(self, func: Callable[..., _T], /, *args: Any, **keywords: Any) -> None: ... + @overload + def __init__(self, func: _Descriptor, /, *args: Any, **keywords: Any) -> None: ... + def __get__(self, obj: Any, cls: type[Any] | None = None) -> Callable[..., _T]: ... @property def __isabstractmethod__(self) -> bool: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi index c5db318457879..9b61fdad980ab 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/gettext.pyi @@ -132,7 +132,7 @@ else: languages: Iterable[str] | None = None, class_: None = None, fallback: Literal[False] = False, - codeset: str | None = None, + codeset: str | None = ..., ) -> GNUTranslations: ... @overload def translation( @@ -142,7 +142,7 @@ else: *, class_: Callable[[io.BufferedReader], _NullTranslationsT], fallback: Literal[False] = False, - codeset: str | None = None, + codeset: str | None = ..., ) -> _NullTranslationsT: ... @overload def translation( @@ -151,7 +151,7 @@ else: languages: Iterable[str] | None, class_: Callable[[io.BufferedReader], _NullTranslationsT], fallback: Literal[False] = False, - codeset: str | None = None, + codeset: str | None = ..., ) -> _NullTranslationsT: ... @overload def translation( @@ -160,18 +160,18 @@ else: languages: Iterable[str] | None = None, class_: Callable[[io.BufferedReader], NullTranslations] | None = None, fallback: bool = False, - codeset: str | None = None, + codeset: str | None = ..., ) -> NullTranslations: ... @overload - def install( - domain: str, localedir: StrPath | None = None, codeset: None = None, names: Container[str] | None = None - ) -> None: ... + def install(domain: str, localedir: StrPath | None = None, names: Container[str] | None = None) -> None: ... @overload @deprecated("The `codeset` parameter is deprecated since Python 3.8; removed in Python 3.11.") - def install(domain: str, localedir: StrPath | None, codeset: str, /, names: Container[str] | None = None) -> None: ... + def install(domain: str, localedir: StrPath | None, codeset: str | None, /, names: Container[str] | None = None) -> None: ... @overload @deprecated("The `codeset` parameter is deprecated since Python 3.8; removed in Python 3.11.") - def install(domain: str, localedir: StrPath | None = None, *, codeset: str, names: Container[str] | None = None) -> None: ... + def install( + domain: str, localedir: StrPath | None = None, *, codeset: str | None, names: Container[str] | None = None + ) -> None: ... def textdomain(domain: str | None = None) -> str: ... def bindtextdomain(domain: str, localedir: StrPath | None = None) -> str: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi index c6094da324cf8..561bfc1a533b0 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/importlib/metadata/__init__.pyi @@ -11,7 +11,7 @@ from os import PathLike from pathlib import Path from re import Pattern from typing import Any, ClassVar, Generic, NamedTuple, TypeVar, overload -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Self, TypeAlias, deprecated, disjoint_base _T = TypeVar("_T") _KT = TypeVar("_KT") @@ -83,44 +83,42 @@ else: value: str group: str -class EntryPoint(_EntryPointBase): - """An entry point as defined by Python packaging conventions. - - See `the packaging docs on entry points - `_ - for more information. - - >>> ep = EntryPoint( - ... name=None, group=None, value='package.module:attr [extra1, extra2]') - >>> ep.module - 'package.module' - >>> ep.attr - 'attr' - >>> ep.extras - ['extra1', 'extra2'] - """ +if sys.version_info >= (3, 11): + class EntryPoint(_EntryPointBase): + """An entry point as defined by Python packaging conventions. - pattern: ClassVar[Pattern[str]] - if sys.version_info >= (3, 11): + See `the packaging docs on entry points + `_ + for more information. + + >>> ep = EntryPoint( + ... name=None, group=None, value='package.module:attr [extra1, extra2]') + >>> ep.module + 'package.module' + >>> ep.attr + 'attr' + >>> ep.extras + ['extra1', 'extra2'] + """ + + pattern: ClassVar[Pattern[str]] name: str value: str group: str def __init__(self, name: str, value: str, group: str) -> None: ... + def load(self) -> Any: # Callable[[], Any] or an importable module + """Load the entry point from its definition. If only a module + is indicated by the value, return that module. Otherwise, + return the named object. + """ - def load(self) -> Any: # Callable[[], Any] or an importable module - """Load the entry point from its definition. If only a module - is indicated by the value, return that module. Otherwise, - return the named object. - """ - - @property - def extras(self) -> list[str]: ... - @property - def module(self) -> str: ... - @property - def attr(self) -> str: ... - if sys.version_info >= (3, 10): + @property + def extras(self) -> list[str]: ... + @property + def module(self) -> str: ... + @property + def attr(self) -> str: ... dist: ClassVar[Distribution | None] def matches( self, @@ -152,11 +150,81 @@ class EntryPoint(_EntryPointBase): True """ - def __hash__(self) -> int: ... - if sys.version_info >= (3, 11): + def __hash__(self) -> int: ... def __eq__(self, other: object) -> bool: ... def __lt__(self, other: object) -> bool: ... - if sys.version_info < (3, 12): + if sys.version_info < (3, 12): + def __iter__(self) -> Iterator[Any]: # result of iter((str, Self)), really + """ + Supply iter so one may construct dicts of EntryPoints by name. + """ + +else: + @disjoint_base + class EntryPoint(_EntryPointBase): + """An entry point as defined by Python packaging conventions. + + See `the packaging docs on entry points + `_ + for more information. + + >>> ep = EntryPoint( + ... name=None, group=None, value='package.module:attr [extra1, extra2]') + >>> ep.module + 'package.module' + >>> ep.attr + 'attr' + >>> ep.extras + ['extra1', 'extra2'] + """ + + pattern: ClassVar[Pattern[str]] + + def load(self) -> Any: # Callable[[], Any] or an importable module + """Load the entry point from its definition. If only a module + is indicated by the value, return that module. Otherwise, + return the named object. + """ + + @property + def extras(self) -> list[str]: ... + @property + def module(self) -> str: ... + @property + def attr(self) -> str: ... + if sys.version_info >= (3, 10): + dist: ClassVar[Distribution | None] + def matches( + self, + *, + name: str = ..., + value: str = ..., + group: str = ..., + module: str = ..., + attr: str = ..., + extras: list[str] = ..., + ) -> bool: # undocumented + """ + EntryPoint matches the given parameters. + + >>> ep = EntryPoint(group='foo', name='bar', value='bing:bong [extra1, extra2]') + >>> ep.matches(group='foo') + True + >>> ep.matches(name='bar', value='bing:bong [extra1, extra2]') + True + >>> ep.matches(group='foo', name='other') + False + >>> ep.matches() + True + >>> ep.matches(extras=['extra1', 'extra2']) + True + >>> ep.matches(module='bing') + True + >>> ep.matches(attr='bong') + True + """ + + def __hash__(self) -> int: ... def __iter__(self) -> Iterator[Any]: # result of iter((str, Self)), really """ Supply iter so one may construct dicts of EntryPoints by name. @@ -234,12 +302,15 @@ elif sys.version_info >= (3, 10): 1 """ + __slots__ = () + class EntryPoints(DeprecatedList[EntryPoint]): # use as list is deprecated since 3.10 """ An immutable collection of selectable EntryPoint objects. """ # int argument is deprecated since 3.10 + __slots__ = () def __getitem__(self, name: int | str) -> EntryPoint: # type: ignore[override] """ Get the EntryPoint in self matching name. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi index 584fe96403459..08d3d9d299832 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/inspect.pyi @@ -54,7 +54,7 @@ from types import ( WrapperDescriptorType, ) from typing import Any, ClassVar, Final, Literal, NamedTuple, Protocol, TypeVar, overload, type_check_only -from typing_extensions import ParamSpec, Self, TypeAlias, TypeGuard, TypeIs, deprecated +from typing_extensions import ParamSpec, Self, TypeAlias, TypeGuard, TypeIs, deprecated, disjoint_base if sys.version_info >= (3, 14): from annotationlib import Format @@ -1143,19 +1143,6 @@ if sys.version_info >= (3, 11): code_context: list[str] | None index: int | None # type: ignore[assignment] - class Traceback(_Traceback): - positions: dis.Positions | None - def __new__( - cls, - filename: str, - lineno: int, - function: str, - code_context: list[str] | None, - index: int | None, - *, - positions: dis.Positions | None = None, - ) -> Self: ... - class _FrameInfo(NamedTuple): """_FrameInfo(frame, filename, lineno, function, code_context, index)""" @@ -1166,19 +1153,63 @@ if sys.version_info >= (3, 11): code_context: list[str] | None index: int | None # type: ignore[assignment] - class FrameInfo(_FrameInfo): - positions: dis.Positions | None - def __new__( - cls, - frame: FrameType, - filename: str, - lineno: int, - function: str, - code_context: list[str] | None, - index: int | None, - *, - positions: dis.Positions | None = None, - ) -> Self: ... + if sys.version_info >= (3, 12): + class Traceback(_Traceback): + positions: dis.Positions | None + def __new__( + cls, + filename: str, + lineno: int, + function: str, + code_context: list[str] | None, + index: int | None, + *, + positions: dis.Positions | None = None, + ) -> Self: ... + + class FrameInfo(_FrameInfo): + positions: dis.Positions | None + def __new__( + cls, + frame: FrameType, + filename: str, + lineno: int, + function: str, + code_context: list[str] | None, + index: int | None, + *, + positions: dis.Positions | None = None, + ) -> Self: ... + + else: + @disjoint_base + class Traceback(_Traceback): + positions: dis.Positions | None + def __new__( + cls, + filename: str, + lineno: int, + function: str, + code_context: list[str] | None, + index: int | None, + *, + positions: dis.Positions | None = None, + ) -> Self: ... + + @disjoint_base + class FrameInfo(_FrameInfo): + positions: dis.Positions | None + def __new__( + cls, + frame: FrameType, + filename: str, + lineno: int, + function: str, + code_context: list[str] | None, + index: int | None, + *, + positions: dis.Positions | None = None, + ) -> Self: ... else: class Traceback(NamedTuple): diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/io.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/io.pyi index 34366c036f474..94d8ed0257f05 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/io.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/io.pyi @@ -162,6 +162,7 @@ if sys.version_info >= (3, 14): This protocol only supports blocking I/O. """ + __slots__ = () def read(self, size: int = ..., /) -> _T_co: """Read data from the input stream and return it. @@ -175,5 +176,6 @@ if sys.version_info >= (3, 14): This protocol only supports blocking I/O. """ + __slots__ = () def write(self, data: _T_contra, /) -> int: """Write *data* to the output stream and return the number of items written.""" diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/itertools.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/itertools.pyi index 453ec01c94652..4c1eaf164d8b2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/itertools.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/itertools.pyi @@ -34,7 +34,7 @@ from _typeshed import MaybeNone from collections.abc import Callable, Iterable, Iterator from types import GenericAlias from typing import Any, Generic, Literal, SupportsComplex, SupportsFloat, SupportsIndex, SupportsInt, TypeVar, overload -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base _T = TypeVar("_T") _S = TypeVar("_S") @@ -58,6 +58,7 @@ _Predicate: TypeAlias = Callable[[_T], object] # Technically count can take anything that implements a number protocol and has an add method # but we can't enforce the add method +@disjoint_base class count(Generic[_N]): """Return a count object whose .__next__() method returns consecutive values. @@ -81,6 +82,7 @@ class count(Generic[_N]): def __iter__(self) -> Self: """Implement iter(self).""" +@disjoint_base class cycle(Generic[_T]): """Return elements from the iterable until it is exhausted. Then repeat the sequence indefinitely.""" @@ -91,6 +93,7 @@ class cycle(Generic[_T]): def __iter__(self) -> Self: """Implement iter(self).""" +@disjoint_base class repeat(Generic[_T]): """repeat(object [,times]) -> create an iterator which returns the object for the specified number of times. If not specified, returns the object @@ -110,6 +113,7 @@ class repeat(Generic[_T]): def __length_hint__(self) -> int: """Private method returning an estimate of len(list(it)).""" +@disjoint_base class accumulate(Generic[_T]): """Return series of accumulated sums (or other binary function results).""" @@ -123,6 +127,7 @@ class accumulate(Generic[_T]): def __next__(self) -> _T: """Implement next(self).""" +@disjoint_base class chain(Generic[_T]): """Return a chain object whose .__next__() method returns elements from the first iterable until it is exhausted, then elements from the next @@ -144,6 +149,7 @@ class chain(Generic[_T]): def __class_getitem__(cls, item: Any, /) -> GenericAlias: """See PEP 585""" +@disjoint_base class compress(Generic[_T]): """Return data elements corresponding to true selector elements. @@ -158,6 +164,7 @@ class compress(Generic[_T]): def __next__(self) -> _T: """Implement next(self).""" +@disjoint_base class dropwhile(Generic[_T]): """Drop items from the iterable while predicate(item) is true. @@ -171,6 +178,7 @@ class dropwhile(Generic[_T]): def __next__(self) -> _T: """Implement next(self).""" +@disjoint_base class filterfalse(Generic[_T]): """Return those items of iterable for which function(item) is false. @@ -184,6 +192,7 @@ class filterfalse(Generic[_T]): def __next__(self) -> _T: """Implement next(self).""" +@disjoint_base class groupby(Generic[_T_co, _S_co]): """make an iterator that returns consecutive keys and groups from the iterable @@ -205,6 +214,7 @@ class groupby(Generic[_T_co, _S_co]): def __next__(self) -> tuple[_T_co, Iterator[_S_co]]: """Implement next(self).""" +@disjoint_base class islice(Generic[_T]): """islice(iterable, stop) --> islice object islice(iterable, start, stop[, step]) --> islice object @@ -227,6 +237,7 @@ class islice(Generic[_T]): def __next__(self) -> _T: """Implement next(self).""" +@disjoint_base class starmap(Generic[_T_co]): """Return an iterator whose values are returned from the function evaluated with an argument tuple taken from the given sequence.""" @@ -237,6 +248,7 @@ class starmap(Generic[_T_co]): def __next__(self) -> _T_co: """Implement next(self).""" +@disjoint_base class takewhile(Generic[_T]): """Return successive entries from an iterable as long as the predicate evaluates to true for each entry.""" @@ -250,6 +262,7 @@ class takewhile(Generic[_T]): def tee(iterable: Iterable[_T], n: int = 2, /) -> tuple[Iterator[_T], ...]: """Returns a tuple of n independent iterators.""" +@disjoint_base class zip_longest(Generic[_T_co]): """Return a zip_longest object whose .__next__() method returns a tuple where the i-th element comes from the i-th iterable argument. The .__next__() @@ -339,6 +352,7 @@ class zip_longest(Generic[_T_co]): def __next__(self) -> _T_co: """Implement next(self).""" +@disjoint_base class product(Generic[_T_co]): """Cartesian product of input iterables. Equivalent to nested for-loops. @@ -442,6 +456,7 @@ class product(Generic[_T_co]): def __next__(self) -> _T_co: """Implement next(self).""" +@disjoint_base class permutations(Generic[_T_co]): """Return successive r-length permutations of elements in the iterable. @@ -464,6 +479,7 @@ class permutations(Generic[_T_co]): def __next__(self) -> _T_co: """Implement next(self).""" +@disjoint_base class combinations(Generic[_T_co]): """Return successive r-length combinations of elements in the iterable. @@ -486,6 +502,7 @@ class combinations(Generic[_T_co]): def __next__(self) -> _T_co: """Implement next(self).""" +@disjoint_base class combinations_with_replacement(Generic[_T_co]): """Return successive r-length combinations of elements in the iterable allowing individual elements to have successive repeats. @@ -509,6 +526,7 @@ class combinations_with_replacement(Generic[_T_co]): """Implement next(self).""" if sys.version_info >= (3, 10): + @disjoint_base class pairwise(Generic[_T_co]): """Return an iterator of overlapping pairs taken from the input iterator. @@ -523,6 +541,7 @@ if sys.version_info >= (3, 10): """Implement next(self).""" if sys.version_info >= (3, 12): + @disjoint_base class batched(Generic[_T_co]): """Batch data into tuples of length n. The last batch may be shorter than n. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/lib2to3/fixes/fix_tuple_params.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/lib2to3/fixes/fix_tuple_params.pyi index f61837d19d0c7..263a340f477fd 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/lib2to3/fixes/fix_tuple_params.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/lib2to3/fixes/fix_tuple_params.pyi @@ -17,7 +17,6 @@ It will also support lambdas: lambda (x): x + y -> lambda x: x + y """ -from _typeshed import Incomplete from typing import ClassVar, Literal from .. import fixer_base @@ -32,5 +31,5 @@ class FixTupleParams(fixer_base.BaseFix): def simplify_args(node): ... def find_params(node): ... -def map_to_index(param_list, prefix=..., d: Incomplete | None = ...): ... +def map_to_index(param_list, prefix=[], d=None): ... def tuple_name(param_list): ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi index 77c713032b1d2..7c083b255cce2 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/logging/config.pyi @@ -15,7 +15,7 @@ from configparser import RawConfigParser from re import Pattern from threading import Thread from typing import IO, Any, Final, Literal, SupportsIndex, TypedDict, overload, type_check_only -from typing_extensions import Required, TypeAlias +from typing_extensions import Required, TypeAlias, disjoint_base from . import Filter, Filterer, Formatter, Handler, Logger, _FilterType, _FormatStyle, _Level @@ -155,13 +155,24 @@ class ConvertingList(list[Any], ConvertingMixin): # undocumented def __getitem__(self, key: slice) -> Any: ... def pop(self, idx: SupportsIndex = -1) -> Any: ... -class ConvertingTuple(tuple[Any, ...], ConvertingMixin): # undocumented - """A converting tuple wrapper.""" +if sys.version_info >= (3, 12): + class ConvertingTuple(tuple[Any, ...], ConvertingMixin): # undocumented + """A converting tuple wrapper.""" - @overload - def __getitem__(self, key: SupportsIndex) -> Any: ... - @overload - def __getitem__(self, key: slice) -> Any: ... + @overload + def __getitem__(self, key: SupportsIndex) -> Any: ... + @overload + def __getitem__(self, key: slice) -> Any: ... + +else: + @disjoint_base + class ConvertingTuple(tuple[Any, ...], ConvertingMixin): # undocumented + """A converting tuple wrapper.""" + + @overload + def __getitem__(self, key: SupportsIndex) -> Any: ... + @overload + def __getitem__(self, key: slice) -> Any: ... class BaseConfigurator: """ diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/mmap.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/mmap.pyi index cffd27128ea10..42214fb31ac63 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/mmap.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/mmap.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import ReadableBuffer, Unused from collections.abc import Iterator from typing import Final, Literal, NoReturn, overload -from typing_extensions import Self +from typing_extensions import Self, disjoint_base ACCESS_DEFAULT: Final = 0 ACCESS_READ: Final = 1 @@ -31,6 +31,7 @@ if sys.platform != "win32": PAGESIZE: Final[int] +@disjoint_base class mmap: """Windows: mmap(fileno, length[, tagname[, access[, offset]]]) @@ -56,7 +57,7 @@ class mmap: """ if sys.platform == "win32": - def __init__(self, fileno: int, length: int, tagname: str | None = None, access: int = 0, offset: int = 0) -> None: ... + def __new__(self, fileno: int, length: int, tagname: str | None = None, access: int = 0, offset: int = 0) -> Self: ... else: if sys.version_info >= (3, 13): def __new__( diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi index 650246955c738..88f6a919a15fc 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/os/__init__.pyi @@ -1746,7 +1746,7 @@ def getcwd() -> str: def getcwdb() -> bytes: """Return a bytes string representing the current working directory.""" -def chmod(path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = None, follow_symlinks: bool = ...) -> None: +def chmod(path: FileDescriptorOrPath, mode: int, *, dir_fd: int | None = None, follow_symlinks: bool = True) -> None: """Change the access permissions of a file. path diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi index b552301ba5e9f..bfd6d681e68cf 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pathlib/__init__.pyi @@ -292,6 +292,7 @@ class Path(PurePath): __slots__ = () else: __slots__ = ("_accessor",) + if sys.version_info >= (3, 12): def __new__(cls, *args: StrPath, **kwargs: Unused) -> Self: ... # pyright: ignore[reportInconsistentConstructor] else: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi index b56ca9eab8f0c..60436b2c81a55 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/pdb.pyi @@ -606,23 +606,40 @@ class Pdb(Bdb, Cmd): print anything, you will see no sign that the breakpoint was reached. """ + if sys.version_info >= (3, 14): + def do_break(self, arg: str, temporary: bool = False) -> bool | None: + """b(reak) [ ([filename:]lineno | function) [, condition] ] - def do_break(self, arg: str, temporary: bool = ...) -> bool | None: - """b(reak) [ ([filename:]lineno | function) [, condition] ] + Without argument, list all breaks. - Without argument, list all breaks. + With a line number argument, set a break at this line in the + current file. With a function name, set a break at the first + executable line of that function. If a second argument is + present, it is a string specifying an expression which must + evaluate to true before the breakpoint is honored. - With a line number argument, set a break at this line in the - current file. With a function name, set a break at the first - executable line of that function. If a second argument is - present, it is a string specifying an expression which must - evaluate to true before the breakpoint is honored. + The line number may be prefixed with a filename and a colon, + to specify a breakpoint in another file (probably one that + hasn't been loaded yet). The file is searched for on + sys.path; the .py suffix may be omitted. + """ + else: + def do_break(self, arg: str, temporary: bool | Literal[0, 1] = 0) -> bool | None: + """b(reak) [ ([filename:]lineno | function) [, condition] ] - The line number may be prefixed with a filename and a colon, - to specify a breakpoint in another file (probably one that - hasn't been loaded yet). The file is searched for on - sys.path; the .py suffix may be omitted. - """ + Without argument, list all breaks. + + With a line number argument, set a break at this line in the + current file. With a function name, set a break at the first + executable line of that function. If a second argument is + present, it is a string specifying an expression which must + evaluate to true before the breakpoint is honored. + + The line number may be prefixed with a filename and a colon, + to specify a breakpoint in another file (probably one that + hasn't been loaded yet). The file is searched for on + sys.path; the .py suffix may be omitted. + """ def do_tbreak(self, arg: str) -> bool | None: """tbreak [ ([filename:]lineno | function) [, condition] ] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi index e6d49bd3ff2b1..cc2e1aa5694ec 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/platform.pyi @@ -9,7 +9,7 @@ format is usable as part of a filename. import sys from typing import NamedTuple, type_check_only -from typing_extensions import Self, deprecated +from typing_extensions import Self, deprecated, disjoint_base def libc_ver(executable: str | None = None, lib: str = "", version: str = "", chunksize: int = 16384) -> tuple[str, str]: """Tries to determine the libc version that the file executable @@ -123,22 +123,41 @@ class _uname_result_base(NamedTuple): # uname_result emulates a 6-field named tuple, but the processor field # is lazily evaluated rather than being passed in to the constructor. -class uname_result(_uname_result_base): - """ - A uname_result that's largely compatible with a - simple namedtuple except that 'processor' is - resolved late and cached to avoid calling "uname" - except when needed. - """ +if sys.version_info >= (3, 12): + class uname_result(_uname_result_base): + """ + A uname_result that's largely compatible with a + simple namedtuple except that 'processor' is + resolved late and cached to avoid calling "uname" + except when needed. + """ - if sys.version_info >= (3, 10): __match_args__ = ("system", "node", "release", "version", "machine") # pyright: ignore[reportAssignmentType] - def __new__(_cls, system: str, node: str, release: str, version: str, machine: str) -> Self: - """Create new instance of uname_result_base(system, node, release, version, machine)""" + def __new__(_cls, system: str, node: str, release: str, version: str, machine: str) -> Self: + """Create new instance of uname_result_base(system, node, release, version, machine)""" + + @property + def processor(self) -> str: ... + +else: + @disjoint_base + class uname_result(_uname_result_base): + """ + A uname_result that's largely compatible with a + simple namedtuple except that 'processor' is + resolved late and cached to avoid calling "uname" + except when needed. + """ + + if sys.version_info >= (3, 10): + __match_args__ = ("system", "node", "release", "version", "machine") # pyright: ignore[reportAssignmentType] + + def __new__(_cls, system: str, node: str, release: str, version: str, machine: str) -> Self: + """Create new instance of uname_result_base(system, node, release, version, machine)""" - @property - def processor(self) -> str: ... + @property + def processor(self) -> str: ... def uname() -> uname_result: """Fairly portable uname interface. Returns a tuple diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/random.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/random.pyi index b46488f02e31a..1ba0e2106407a 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/random.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/random.pyi @@ -52,6 +52,7 @@ from _typeshed import SupportsLenAndGetItem from collections.abc import Callable, Iterable, MutableSequence, Sequence, Set as AbstractSet from fractions import Fraction from typing import Any, ClassVar, NoReturn, TypeVar +from typing_extensions import Self __all__ = [ "Random", @@ -109,6 +110,10 @@ class Random(_random.Random): # Using other `seed` types is deprecated since 3.9 and removed in 3.11 # Ignore Y041, since random.seed doesn't treat int like a float subtype. Having an explicit # int better documents conventional usage of random.seed. + if sys.version_info < (3, 10): + # this is a workaround for pyright correctly flagging an inconsistent inherited constructor, see #14624 + def __new__(cls, x: int | float | str | bytes | bytearray | None = None) -> Self: ... # noqa: Y041 + def seed(self, a: int | float | str | bytes | bytearray | None = None, version: int = 2) -> None: # type: ignore[override] # noqa: Y041 """Initialize internal state from a seed. diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi index 59937607821ee..93d3b5a72f05f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/select.pyi @@ -207,7 +207,7 @@ if sys.platform == "linux": the maximum number of monitored events. """ - def __init__(self, sizehint: int = ..., flags: int = ...) -> None: ... + def __new__(self, sizehint: int = ..., flags: int = ...) -> Self: ... def __enter__(self) -> Self: ... def __exit__( self, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi index ae46b544a5dec..e378b4d434026 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sqlite3/__init__.pyi @@ -97,7 +97,7 @@ from sqlite3.dbapi2 import ( ) from types import TracebackType from typing import Any, Literal, Protocol, SupportsIndex, TypeVar, final, overload, type_check_only -from typing_extensions import Self, TypeAlias +from typing_extensions import Self, TypeAlias, disjoint_base if sys.version_info < (3, 14): from sqlite3.dbapi2 import version_info as version_info @@ -302,6 +302,7 @@ class OperationalError(DatabaseError): ... class ProgrammingError(DatabaseError): ... class Warning(Exception): ... +@disjoint_base class Connection: """SQLite database connection object.""" @@ -610,6 +611,7 @@ class Connection: If there was any exception, a rollback takes place; otherwise we commit. """ +@disjoint_base class Cursor: """SQLite database cursor class.""" @@ -669,6 +671,7 @@ class PrepareProtocol: def __init__(self, *args: object, **kwargs: object) -> None: ... +@disjoint_base class Row(Sequence[Any]): def __new__(cls, cursor: Cursor, data: tuple[Any, ...], /) -> Self: ... def keys(self) -> list[str]: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/sre_constants.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/sre_constants.pyi index 0d22f3af5a2ea..d1c52ccfb1025 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/sre_constants.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/sre_constants.pyi @@ -3,15 +3,22 @@ import sys from re import error as error from typing import Final -from typing_extensions import Self +from typing_extensions import Self, disjoint_base MAXGROUPS: Final[int] MAGIC: Final[int] -class _NamedIntConstant(int): - name: str - def __new__(cls, value: int, name: str) -> Self: ... +if sys.version_info >= (3, 12): + class _NamedIntConstant(int): + name: str + def __new__(cls, value: int, name: str) -> Self: ... + +else: + @disjoint_base + class _NamedIntConstant(int): + name: str + def __new__(cls, value: int, name: str) -> Self: ... MAXREPEAT: Final[_NamedIntConstant] OPCODES: list[_NamedIntConstant] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/subprocess.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/subprocess.pyi index a199b8714b473..60e4906577077 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/subprocess.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/subprocess.pyi @@ -157,7 +157,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -220,7 +220,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -254,7 +254,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -289,7 +289,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), # where the *real* keyword only args start capture_output: bool = False, check: bool = False, @@ -323,7 +323,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -357,7 +357,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -394,7 +394,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -456,7 +456,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -489,7 +489,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -523,7 +523,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), # where the *real* keyword only args start capture_output: bool = False, check: bool = False, @@ -556,7 +556,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -589,7 +589,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -625,7 +625,7 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -685,7 +685,7 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -717,7 +717,7 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -750,7 +750,7 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), # where the *real* keyword only args start capture_output: bool = False, check: bool = False, @@ -782,7 +782,7 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -814,7 +814,7 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, capture_output: bool = False, check: bool = False, @@ -849,7 +849,7 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, encoding: str | None = None, timeout: float | None = None, @@ -888,7 +888,7 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, encoding: str | None = None, timeout: float | None = None, @@ -925,7 +925,7 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, encoding: str | None = None, timeout: float | None = None, @@ -963,8 +963,8 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., - timeout: float | None = ..., + pass_fds: Collection[int] = (), + timeout: float | None = None, *, encoding: str | None = None, text: bool | None = None, @@ -1004,8 +1004,8 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., - timeout: float | None = ..., + pass_fds: Collection[int] = (), + timeout: float | None = None, *, encoding: str | None = None, text: bool | None = None, @@ -1043,8 +1043,8 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., - timeout: float | None = ..., + pass_fds: Collection[int] = (), + timeout: float | None = None, *, encoding: str | None = None, text: bool | None = None, @@ -1082,10 +1082,10 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: Literal[True], @@ -1148,10 +1148,10 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str, errors: str | None = None, text: bool | None = None, @@ -1179,10 +1179,10 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str, text: bool | None = None, @@ -1211,10 +1211,10 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), # where the real keyword only ones start timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: bool | None = None, @@ -1242,10 +1242,10 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: None = None, errors: None = None, text: Literal[False] | None = None, @@ -1273,10 +1273,10 @@ if sys.version_info >= (3, 11): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: bool | None = None, @@ -1307,10 +1307,10 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: Literal[True], @@ -1372,10 +1372,10 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str, errors: str | None = None, text: bool | None = None, @@ -1402,10 +1402,10 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str, text: bool | None = None, @@ -1433,10 +1433,10 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), # where the real keyword only ones start timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: bool | None = None, @@ -1463,10 +1463,10 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: None = None, errors: None = None, text: Literal[False] | None = None, @@ -1493,10 +1493,10 @@ elif sys.version_info >= (3, 10): creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: bool | None = None, @@ -1525,10 +1525,10 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: Literal[True], @@ -1589,10 +1589,10 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str, errors: str | None = None, text: bool | None = None, @@ -1618,10 +1618,10 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str, text: bool | None = None, @@ -1648,10 +1648,10 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), # where the real keyword only ones start timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: bool | None = None, @@ -1677,10 +1677,10 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: None = None, errors: None = None, text: Literal[False] | None = None, @@ -1706,10 +1706,10 @@ else: creationflags: int = 0, restore_signals: bool = True, start_new_session: bool = False, - pass_fds: Collection[int] = ..., + pass_fds: Collection[int] = (), *, timeout: float | None = None, - input: _InputString | None = ..., + input: _InputString | None = None, encoding: str | None = None, errors: str | None = None, text: bool | None = None, diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi index b73e3966da692..389e24eb4c1d6 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tarfile.pyi @@ -1053,6 +1053,28 @@ class TarInfo: usually created internally. """ + __slots__ = ( + "name", + "mode", + "uid", + "gid", + "size", + "mtime", + "chksum", + "type", + "linkname", + "uname", + "gname", + "devmajor", + "devminor", + "offset", + "offset_data", + "pax_headers", + "sparse", + "_tarfile", + "_sparse_structs", + "_link_target", + ) name: str path: str size: int diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi index febd62c5c0920..df8dd37ab1bf8 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tkinter/__init__.pyi @@ -38,7 +38,7 @@ from tkinter.constants import * from tkinter.font import _FontDescription from types import GenericAlias, TracebackType from typing import Any, ClassVar, Final, Generic, Literal, NamedTuple, Protocol, TypedDict, TypeVar, overload, type_check_only -from typing_extensions import TypeAlias, TypeVarTuple, Unpack, deprecated +from typing_extensions import TypeAlias, TypeVarTuple, Unpack, deprecated, disjoint_base if sys.version_info >= (3, 11): from enum import StrEnum @@ -230,7 +230,11 @@ if sys.version_info >= (3, 11): releaselevel: str serial: int - class _VersionInfoType(_VersionInfoTypeBase): ... + if sys.version_info >= (3, 12): + class _VersionInfoType(_VersionInfoTypeBase): ... + else: + @disjoint_base + class _VersionInfoType(_VersionInfoTypeBase): ... if sys.version_info >= (3, 11): class EventType(StrEnum): @@ -5683,7 +5687,7 @@ class Text(Widget, XView, YView): def image_configure( self, index: _TextIndex, - cnf: dict[str, Any] | None = {}, + cnf: dict[str, Any] | None = None, *, align: Literal["baseline", "bottom", "center", "top"] = ..., image: _ImageSpec = ..., diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi index f9f7f6984919f..9dad927315954 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/tokenize.pyi @@ -26,7 +26,7 @@ from collections.abc import Callable, Generator, Iterable, Sequence from re import Pattern from token import * from typing import Any, Final, NamedTuple, TextIO, type_check_only -from typing_extensions import TypeAlias +from typing_extensions import TypeAlias, disjoint_base if sys.version_info < (3, 12): # Avoid double assignment to Final name by imports, which pyright objects to. @@ -137,9 +137,16 @@ class _TokenInfo(NamedTuple): end: _Position line: str -class TokenInfo(_TokenInfo): - @property - def exact_type(self) -> int: ... +if sys.version_info >= (3, 12): + class TokenInfo(_TokenInfo): + @property + def exact_type(self) -> int: ... + +else: + @disjoint_base + class TokenInfo(_TokenInfo): + @property + def exact_type(self) -> int: ... # Backwards compatible tokens can be sequences of a shorter length too _Token: TypeAlias = TokenInfo | Sequence[int | str | _Position] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi index 8fbdfbc3bef03..d6fcbe1d551c9 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/turtle.pyi @@ -81,7 +81,7 @@ from collections.abc import Callable, Generator, Sequence from contextlib import contextmanager from tkinter import Canvas, Frame, Misc, PhotoImage, Scrollbar from typing import Any, ClassVar, Literal, TypedDict, overload, type_check_only -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Self, TypeAlias, deprecated, disjoint_base __all__ = [ "ScrolledCanvas", @@ -240,33 +240,64 @@ class _PenState(TypedDict): _Speed: TypeAlias = str | float _PolygonCoords: TypeAlias = Sequence[tuple[float, float]] -class Vec2D(tuple[float, float]): - """A 2 dimensional vector class, used as a helper class - for implementing turtle graphics. - May be useful for turtle graphics programs also. - Derived from tuple, so a vector is a tuple! - - Provides (for a, b vectors, k number): - a+b vector addition - a-b vector subtraction - a*b inner product - k*a and a*k multiplication with scalar - |a| absolute value of a - a.rotate(angle) rotation - """ - - def __new__(cls, x: float, y: float) -> Self: ... - def __add__(self, other: tuple[float, float]) -> Vec2D: ... # type: ignore[override] - @overload # type: ignore[override] - def __mul__(self, other: Vec2D) -> float: ... - @overload - def __mul__(self, other: float) -> Vec2D: ... - def __rmul__(self, other: float) -> Vec2D: ... # type: ignore[override] - def __sub__(self, other: tuple[float, float]) -> Vec2D: ... - def __neg__(self) -> Vec2D: ... - def __abs__(self) -> float: ... - def rotate(self, angle: float) -> Vec2D: - """rotate self counterclockwise by angle""" +if sys.version_info >= (3, 12): + class Vec2D(tuple[float, float]): + """A 2 dimensional vector class, used as a helper class + for implementing turtle graphics. + May be useful for turtle graphics programs also. + Derived from tuple, so a vector is a tuple! + + Provides (for a, b vectors, k number): + a+b vector addition + a-b vector subtraction + a*b inner product + k*a and a*k multiplication with scalar + |a| absolute value of a + a.rotate(angle) rotation + """ + + def __new__(cls, x: float, y: float) -> Self: ... + def __add__(self, other: tuple[float, float]) -> Vec2D: ... # type: ignore[override] + @overload # type: ignore[override] + def __mul__(self, other: Vec2D) -> float: ... + @overload + def __mul__(self, other: float) -> Vec2D: ... + def __rmul__(self, other: float) -> Vec2D: ... # type: ignore[override] + def __sub__(self, other: tuple[float, float]) -> Vec2D: ... + def __neg__(self) -> Vec2D: ... + def __abs__(self) -> float: ... + def rotate(self, angle: float) -> Vec2D: + """rotate self counterclockwise by angle""" + +else: + @disjoint_base + class Vec2D(tuple[float, float]): + """A 2 dimensional vector class, used as a helper class + for implementing turtle graphics. + May be useful for turtle graphics programs also. + Derived from tuple, so a vector is a tuple! + + Provides (for a, b vectors, k number): + a+b vector addition + a-b vector subtraction + a*b inner product + k*a and a*k multiplication with scalar + |a| absolute value of a + a.rotate(angle) rotation + """ + + def __new__(cls, x: float, y: float) -> Self: ... + def __add__(self, other: tuple[float, float]) -> Vec2D: ... # type: ignore[override] + @overload # type: ignore[override] + def __mul__(self, other: Vec2D) -> float: ... + @overload + def __mul__(self, other: float) -> Vec2D: ... + def __rmul__(self, other: float) -> Vec2D: ... # type: ignore[override] + def __sub__(self, other: tuple[float, float]) -> Vec2D: ... + def __neg__(self) -> Vec2D: ... + def __abs__(self) -> float: ... + def rotate(self, angle: float) -> Vec2D: + """rotate self counterclockwise by angle""" # Does not actually inherit from Canvas, but dynamically gets all methods of Canvas class ScrolledCanvas(Canvas, Frame): # type: ignore[misc] diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi index 06f11b8b71f32..81a158266b915 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/types.pyi @@ -21,7 +21,7 @@ from collections.abc import ( ) from importlib.machinery import ModuleSpec from typing import Any, ClassVar, Literal, TypeVar, final, overload -from typing_extensions import ParamSpec, Self, TypeAliasType, TypeVarTuple, deprecated +from typing_extensions import ParamSpec, Self, TypeAliasType, TypeVarTuple, deprecated, disjoint_base if sys.version_info >= (3, 14): from _typeshed import AnnotateFunc @@ -384,23 +384,42 @@ class MappingProxyType(Mapping[_KT, _VT_co]): def __ror__(self, value: Mapping[_T1, _T2], /) -> dict[_KT | _T1, _VT_co | _T2]: """Return value|self.""" -class SimpleNamespace: - """A simple attribute-based namespace.""" +if sys.version_info >= (3, 12): + @disjoint_base + class SimpleNamespace: + """A simple attribute-based namespace.""" + + __hash__: ClassVar[None] # type: ignore[assignment] + if sys.version_info >= (3, 13): + def __init__( + self, mapping_or_iterable: Mapping[str, Any] | Iterable[tuple[str, Any]] = (), /, **kwargs: Any + ) -> None: ... + else: + def __init__(self, **kwargs: Any) -> None: ... - __hash__: ClassVar[None] # type: ignore[assignment] - if sys.version_info >= (3, 13): - def __init__(self, mapping_or_iterable: Mapping[str, Any] | Iterable[tuple[str, Any]] = (), /, **kwargs: Any) -> None: ... - else: - def __init__(self, **kwargs: Any) -> None: ... + def __eq__(self, value: object, /) -> bool: ... + def __getattribute__(self, name: str, /) -> Any: ... + def __setattr__(self, name: str, value: Any, /) -> None: ... + def __delattr__(self, name: str, /) -> None: ... + if sys.version_info >= (3, 13): + def __replace__(self, **kwargs: Any) -> Self: + """Return a copy of the namespace object with new values for the specified attributes.""" + +else: + class SimpleNamespace: + """A simple attribute-based namespace. + + SimpleNamespace(**kwargs) + """ - def __eq__(self, value: object, /) -> bool: ... - def __getattribute__(self, name: str, /) -> Any: ... - def __setattr__(self, name: str, value: Any, /) -> None: ... - def __delattr__(self, name: str, /) -> None: ... - if sys.version_info >= (3, 13): - def __replace__(self, **kwargs: Any) -> Self: - """Return a copy of the namespace object with new values for the specified attributes.""" + __hash__: ClassVar[None] # type: ignore[assignment] + def __init__(self, **kwargs: Any) -> None: ... + def __eq__(self, value: object, /) -> bool: ... + def __getattribute__(self, name: str, /) -> Any: ... + def __setattr__(self, name: str, value: Any, /) -> None: ... + def __delattr__(self, name: str, /) -> None: ... +@disjoint_base class ModuleType: """Create a module object. @@ -881,7 +900,7 @@ def coroutine(func: Callable[_P, Generator[Any, Any, _R]]) -> Callable[_P, Await @overload def coroutine(func: _Fn) -> _Fn: ... - +@disjoint_base class GenericAlias: """Represent a PEP 585 generic type diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi index 4167d2a2a305d..76b8a63a62298 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/typing.pyi @@ -1204,6 +1204,7 @@ class MutableSet(AbstractSet[_T]): def __isub__(self, it: AbstractSet[Any]) -> typing_extensions.Self: ... class MappingView(Sized): + __slots__ = ("_mapping",) def __init__(self, mapping: Sized) -> None: ... # undocumented def __len__(self) -> int: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi index fe1d83951aced..bc5347a4b397f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/typing_extensions.pyi @@ -265,7 +265,27 @@ def final(f: _F) -> _F: object to allow runtime introspection. """ -def disjoint_base(cls: _TC) -> _TC: ... +def disjoint_base(cls: _TC) -> _TC: + """This decorator marks a class as a disjoint base. + + Child classes of a disjoint base cannot inherit from other disjoint bases that are + not parent classes of the disjoint base. + + For example: + + @disjoint_base + class Disjoint1: pass + + @disjoint_base + class Disjoint2: pass + + class Disjoint3(Disjoint1, Disjoint2): pass # Type checker error + + Type checkers can use knowledge of disjoint bases to detect unreachable code + and determine when two types can overlap. + + See PEP 800. + """ Literal: _SpecialForm @@ -780,6 +800,7 @@ else: class SupportsInt(Protocol, metaclass=abc.ABCMeta): """An ABC with one abstract method __int__.""" + __slots__ = () @abc.abstractmethod def __int__(self) -> int: ... @@ -787,6 +808,7 @@ else: class SupportsFloat(Protocol, metaclass=abc.ABCMeta): """An ABC with one abstract method __float__.""" + __slots__ = () @abc.abstractmethod def __float__(self) -> float: ... @@ -794,6 +816,7 @@ else: class SupportsComplex(Protocol, metaclass=abc.ABCMeta): """An ABC with one abstract method __complex__.""" + __slots__ = () @abc.abstractmethod def __complex__(self) -> complex: ... @@ -801,11 +824,13 @@ else: class SupportsBytes(Protocol, metaclass=abc.ABCMeta): """An ABC with one abstract method __bytes__.""" + __slots__ = () @abc.abstractmethod def __bytes__(self) -> bytes: ... @runtime_checkable class SupportsIndex(Protocol, metaclass=abc.ABCMeta): + __slots__ = () @abc.abstractmethod def __index__(self) -> int: ... @@ -815,6 +840,7 @@ else: An ABC with one abstract method __abs__ that is covariant in its return type. """ + __slots__ = () @abc.abstractmethod def __abs__(self) -> _T_co: ... @@ -824,6 +850,7 @@ else: An ABC with one abstract method __round__ that is covariant in its return type. """ + __slots__ = () @overload @abc.abstractmethod def __round__(self) -> int: ... @@ -1298,7 +1325,14 @@ else: format: Format | None = None, _recursive_guard: Container[str] = ..., ) -> AnnotationForm: ... - def type_repr(value: object) -> str: ... + def type_repr(value: object) -> str: + """Convert a Python value to a format suitable for use with the STRING format. + + This is intended as a helper for tools that support the STRING format but do + not have access to the code that originally produced the annotations. It uses + repr() for most objects. + + """ # PEP 661 class Sentinel: diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi index 50e722e206ee7..680e181102f3b 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/unittest/mock.pyi @@ -4,7 +4,7 @@ from collections.abc import Awaitable, Callable, Coroutine, Iterable, Mapping, S from contextlib import _GeneratorContextManager from types import TracebackType from typing import Any, ClassVar, Final, Generic, Literal, TypeVar, overload, type_check_only -from typing_extensions import ParamSpec, Self, TypeAlias +from typing_extensions import ParamSpec, Self, TypeAlias, disjoint_base _T = TypeVar("_T") _TT = TypeVar("_TT", bound=type[Any]) @@ -72,53 +72,113 @@ _ArgsKwargs: TypeAlias = tuple[tuple[Any, ...], Mapping[str, Any]] _NameArgsKwargs: TypeAlias = tuple[str, tuple[Any, ...], Mapping[str, Any]] _CallValue: TypeAlias = str | tuple[Any, ...] | Mapping[str, Any] | _ArgsKwargs | _NameArgsKwargs -class _Call(tuple[Any, ...]): - """ - A tuple for holding the results of a call to a mock, either in the form - `(args, kwargs)` or `(name, args, kwargs)`. +if sys.version_info >= (3, 12): + class _Call(tuple[Any, ...]): + """ + A tuple for holding the results of a call to a mock, either in the form + `(args, kwargs)` or `(name, args, kwargs)`. - If args or kwargs are empty then a call tuple will compare equal to - a tuple without those values. This makes comparisons less verbose:: + If args or kwargs are empty then a call tuple will compare equal to + a tuple without those values. This makes comparisons less verbose:: - _Call(('name', (), {})) == ('name',) - _Call(('name', (1,), {})) == ('name', (1,)) - _Call(((), {'a': 'b'})) == ({'a': 'b'},) + _Call(('name', (), {})) == ('name',) + _Call(('name', (1,), {})) == ('name', (1,)) + _Call(((), {'a': 'b'})) == ({'a': 'b'},) - The `_Call` object provides a useful shortcut for comparing with call:: + The `_Call` object provides a useful shortcut for comparing with call:: - _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) - _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) + _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) + _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) - If the _Call has no name then it will match any name. - """ + If the _Call has no name then it will match any name. + """ - def __new__( - cls, value: _CallValue = (), name: str | None = "", parent: _Call | None = None, two: bool = False, from_kall: bool = True - ) -> Self: ... - def __init__( - self, - value: _CallValue = (), - name: str | None = None, - parent: _Call | None = None, - two: bool = False, - from_kall: bool = True, - ) -> None: ... - __hash__: ClassVar[None] # type: ignore[assignment] - def __eq__(self, other: object) -> bool: ... - def __ne__(self, value: object, /) -> bool: ... - def __call__(self, *args: Any, **kwargs: Any) -> _Call: ... - def __getattr__(self, attr: str) -> Any: ... - def __getattribute__(self, attr: str) -> Any: ... - @property - def args(self) -> tuple[Any, ...]: ... - @property - def kwargs(self) -> Mapping[str, Any]: ... - def call_list(self) -> Any: - """For a call object that represents multiple calls, `call_list` - returns a list of all the intermediate calls as well as the - final call. + def __new__( + cls, + value: _CallValue = (), + name: str | None = "", + parent: _Call | None = None, + two: bool = False, + from_kall: bool = True, + ) -> Self: ... + def __init__( + self, + value: _CallValue = (), + name: str | None = None, + parent: _Call | None = None, + two: bool = False, + from_kall: bool = True, + ) -> None: ... + __hash__: ClassVar[None] # type: ignore[assignment] + def __eq__(self, other: object) -> bool: ... + def __ne__(self, value: object, /) -> bool: ... + def __call__(self, *args: Any, **kwargs: Any) -> _Call: ... + def __getattr__(self, attr: str) -> Any: ... + def __getattribute__(self, attr: str) -> Any: ... + @property + def args(self) -> tuple[Any, ...]: ... + @property + def kwargs(self) -> Mapping[str, Any]: ... + def call_list(self) -> Any: + """For a call object that represents multiple calls, `call_list` + returns a list of all the intermediate calls as well as the + final call. + """ + +else: + @disjoint_base + class _Call(tuple[Any, ...]): + """ + A tuple for holding the results of a call to a mock, either in the form + `(args, kwargs)` or `(name, args, kwargs)`. + + If args or kwargs are empty then a call tuple will compare equal to + a tuple without those values. This makes comparisons less verbose:: + + _Call(('name', (), {})) == ('name',) + _Call(('name', (1,), {})) == ('name', (1,)) + _Call(((), {'a': 'b'})) == ({'a': 'b'},) + + The `_Call` object provides a useful shortcut for comparing with call:: + + _Call(((1, 2), {'a': 3})) == call(1, 2, a=3) + _Call(('foo', (1, 2), {'a': 3})) == call.foo(1, 2, a=3) + + If the _Call has no name then it will match any name. """ + def __new__( + cls, + value: _CallValue = (), + name: str | None = "", + parent: _Call | None = None, + two: bool = False, + from_kall: bool = True, + ) -> Self: ... + def __init__( + self, + value: _CallValue = (), + name: str | None = None, + parent: _Call | None = None, + two: bool = False, + from_kall: bool = True, + ) -> None: ... + __hash__: ClassVar[None] # type: ignore[assignment] + def __eq__(self, other: object) -> bool: ... + def __ne__(self, value: object, /) -> bool: ... + def __call__(self, *args: Any, **kwargs: Any) -> _Call: ... + def __getattr__(self, attr: str) -> Any: ... + def __getattribute__(self, attr: str) -> Any: ... + @property + def args(self) -> tuple[Any, ...]: ... + @property + def kwargs(self) -> Mapping[str, Any]: ... + def call_list(self) -> Any: + """For a call object that represents multiple calls, `call_list` + returns a list of all the intermediate calls as well as the + final call. + """ + call: _Call class _CallList(list[_Call]): @@ -523,27 +583,32 @@ class _patcher: # Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock], # but that's impossible with the current type system. @overload - def __call__( + def __call__( # type: ignore[overload-overlap] self, target: str, new: _T, - spec: Any | None = ..., - create: bool = ..., - spec_set: Any | None = ..., - autospec: Any | None = ..., - new_callable: Callable[..., Any] | None = ..., - **kwargs: Any, + spec: Literal[False] | None = None, + create: bool = False, + spec_set: Literal[False] | None = None, + autospec: Literal[False] | None = None, + new_callable: None = None, + *, + unsafe: bool = False, ) -> _patch[_T]: ... @overload def __call__( self, target: str, *, - spec: Any | None = ..., - create: bool = ..., - spec_set: Any | None = ..., - autospec: Any | None = ..., + # If not False or None, this is passed to new_callable + spec: Any | Literal[False] | None = None, + create: bool = False, + # If not False or None, this is passed to new_callable + spec_set: Any | Literal[False] | None = None, + autospec: Literal[False] | None = None, new_callable: Callable[..., _T], + unsafe: bool = False, + # kwargs are passed to new_callable **kwargs: Any, ) -> _patch_pass_arg[_T]: ... @overload @@ -551,25 +616,31 @@ class _patcher: self, target: str, *, - spec: Any | None = ..., - create: bool = ..., - spec_set: Any | None = ..., - autospec: Any | None = ..., + spec: Any | bool | None = None, + create: bool = False, + spec_set: Any | bool | None = None, + autospec: Any | bool | None = None, new_callable: None = None, + unsafe: bool = False, + # kwargs are passed to the MagicMock/AsyncMock constructor **kwargs: Any, ) -> _patch_pass_arg[MagicMock | AsyncMock]: ... + # This overload also covers the case, where new==DEFAULT. In this case, the return type is _patch[Any]. + # Ideally we'd be able to add an overload for it so that the return type is _patch[MagicMock], + # but that's impossible with the current type system. @overload @staticmethod def object( target: Any, attribute: str, new: _T, - spec: Any | None = ..., - create: bool = ..., - spec_set: Any | None = ..., - autospec: Any | None = ..., - new_callable: Callable[..., Any] | None = ..., - **kwargs: Any, + spec: Literal[False] | None = None, + create: bool = False, + spec_set: Literal[False] | None = None, + autospec: Literal[False] | None = None, + new_callable: None = None, + *, + unsafe: bool = False, ) -> _patch[_T]: ... @overload @staticmethod @@ -577,11 +648,15 @@ class _patcher: target: Any, attribute: str, *, - spec: Any | None = ..., - create: bool = ..., - spec_set: Any | None = ..., - autospec: Any | None = ..., + # If not False or None, this is passed to new_callable + spec: Any | Literal[False] | None = None, + create: bool = False, + # If not False or None, this is passed to new_callable + spec_set: Any | Literal[False] | None = None, + autospec: Literal[False] | None = None, new_callable: Callable[..., _T], + unsafe: bool = False, + # kwargs are passed to new_callable **kwargs: Any, ) -> _patch_pass_arg[_T]: ... @overload @@ -590,21 +665,54 @@ class _patcher: target: Any, attribute: str, *, - spec: Any | None = ..., - create: bool = ..., - spec_set: Any | None = ..., - autospec: Any | None = ..., + spec: Any | bool | None = None, + create: bool = False, + spec_set: Any | bool | None = None, + autospec: Any | bool | None = None, new_callable: None = None, + unsafe: bool = False, + # kwargs are passed to the MagicMock/AsyncMock constructor **kwargs: Any, ) -> _patch_pass_arg[MagicMock | AsyncMock]: ... + @overload @staticmethod def multiple( - target: Any, - spec: Any | None = ..., - create: bool = ..., - spec_set: Any | None = ..., - autospec: Any | None = ..., - new_callable: Any | None = ..., + target: Any | str, + # If not False or None, this is passed to new_callable + spec: Any | Literal[False] | None = None, + create: bool = False, + # If not False or None, this is passed to new_callable + spec_set: Any | Literal[False] | None = None, + autospec: Literal[False] | None = None, + *, + new_callable: Callable[..., _T], + # The kwargs must be DEFAULT + **kwargs: Any, + ) -> _patch_pass_arg[_T]: ... + @overload + @staticmethod + def multiple( + target: Any | str, + # If not False or None, this is passed to new_callable + spec: Any | Literal[False] | None, + create: bool, + # If not False or None, this is passed to new_callable + spec_set: Any | Literal[False] | None, + autospec: Literal[False] | None, + new_callable: Callable[..., _T], + # The kwargs must be DEFAULT + **kwargs: Any, + ) -> _patch_pass_arg[_T]: ... + @overload + @staticmethod + def multiple( + target: Any | str, + spec: Any | bool | None = None, + create: bool = False, + spec_set: Any | bool | None = None, + autospec: Any | bool | None = None, + new_callable: None = None, + # The kwargs are the mock objects or DEFAULT **kwargs: Any, ) -> _patch[Any]: ... @staticmethod diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi index 11b2f3f5ccb89..4dbec668b1679 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/weakref.pyi @@ -11,7 +11,7 @@ from _weakrefset import WeakSet as WeakSet from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping from types import GenericAlias from typing import Any, ClassVar, Generic, TypeVar, final, overload -from typing_extensions import ParamSpec, Self +from typing_extensions import ParamSpec, Self, disjoint_base __all__ = [ "ref", @@ -59,6 +59,7 @@ class ProxyType(Generic[_T]): # "weakproxy" def __getattr__(self, attr: str) -> Any: ... __hash__: ClassVar[None] # type: ignore[assignment] +@disjoint_base class ReferenceType(Generic[_T]): # "weakref" __callback__: Callable[[Self], Any] def __new__(cls, o: _T, callback: Callable[[Self], Any] | None = ..., /) -> Self: ... diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi index 2af9feea5d835..b56f88621468f 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/xml/etree/ElementTree.pyi @@ -38,7 +38,7 @@ from _collections_abc import dict_keys from _typeshed import FileDescriptorOrPath, ReadableBuffer, SupportsRead, SupportsWrite from collections.abc import Callable, Generator, ItemsView, Iterable, Iterator, Mapping, Sequence from typing import Any, Final, Generic, Literal, Protocol, SupportsIndex, TypeVar, overload, type_check_only -from typing_extensions import TypeAlias, TypeGuard, deprecated +from typing_extensions import TypeAlias, TypeGuard, deprecated, disjoint_base from xml.parsers.expat import XMLParserType __all__ = [ @@ -134,6 +134,7 @@ _ElementCallable: TypeAlias = Callable[..., Element[_ElementCallable]] _Tag = TypeVar("_Tag", default=str, bound=str | _ElementCallable) _OtherTag = TypeVar("_OtherTag", default=str, bound=str | _ElementCallable) +@disjoint_base class Element(Generic[_Tag]): tag: _Tag attrib: dict[str, str] @@ -592,6 +593,7 @@ def fromstringlist(sequence: Sequence[str | ReadableBuffer], parser: XMLParser | # elementfactories. _ElementFactory: TypeAlias = Callable[[Any, dict[Any, Any]], Element] +@disjoint_base class TreeBuilder: # comment_factory can take None because passing None to Comment is not an error def __init__( @@ -679,6 +681,7 @@ _E = TypeVar("_E", default=Element) # The default target is TreeBuilder, which returns Element. # C14NWriterTarget does not implement a close method, so using it results # in a type of XMLParser[None]. +@disjoint_base class XMLParser(Generic[_E]): parser: XMLParserType target: _Target diff --git a/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/__init__.pyi b/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/__init__.pyi index 8a04019d399f2..9cae9b7de8f88 100644 --- a/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/__init__.pyi +++ b/crates/ty_vendored/vendor/typeshed/stdlib/zoneinfo/__init__.pyi @@ -1,7 +1,7 @@ import sys from collections.abc import Iterable from datetime import datetime, timedelta, tzinfo -from typing_extensions import Self +from typing_extensions import Self, disjoint_base from zoneinfo._common import ZoneInfoNotFoundError as ZoneInfoNotFoundError, _IOBytes from zoneinfo._tzpath import ( TZPATH as TZPATH, @@ -12,6 +12,7 @@ from zoneinfo._tzpath import ( __all__ = ["ZoneInfo", "reset_tzpath", "available_timezones", "TZPATH", "ZoneInfoNotFoundError", "InvalidTZPathWarning"] +@disjoint_base class ZoneInfo(tzinfo): @property def key(self) -> str: ... From 33c5f6f4f8a47e050ba421131262a534c2fb7fc5 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Mon, 25 Aug 2025 11:32:18 -0700 Subject: [PATCH 134/160] [ty] don't mark entire type-alias scopes as Deferred (#20086) ## Summary This has been here for awhile (since our initial PEP 695 type alias support) but isn't really correct. The right-hand-side of a PEP 695 type alias is a distinct scope, and we don't mark it as an "eager" nested scope, so it automatically gets "deferred" resolution of names from outer scopes (just like a nested function). Thus it's redundant/unnecessary for us to use `DeferredExpressionState::Deferred` for resolving that RHS expression -- that's for deferring resolution of individual names within a scope. Using it here causes us to wrongly ignore applicable outer-scope narrowing. ## Test Plan Added mdtest that failed before this PR (the second snippet -- the first snippet always passed.) --- .../resources/mdtest/pep695_type_aliases.md | 26 +++++++++++++++++++ crates/ty_python_semantic/src/types/infer.rs | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md b/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md index 904f08099a76a..32f64a246a1f5 100644 --- a/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md +++ b/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md @@ -75,6 +75,32 @@ def f(x: T): reveal_type(b) # revealed: str ``` +## Scoping + +PEP 695 type aliases delay runtime evaluation of their right-hand side, so they are a lazy (not +eager) nested scope. + +```py +type Alias = Foo | str + +def f(x: Alias): + reveal_type(x) # revealed: Foo | str + +class Foo: + pass +``` + +But narrowing of names used in the type alias is still respected: + +```py +def _(flag: bool): + t = int if flag else None + if t is not None: + type Alias = t | str + def f(x: Alias): + reveal_type(x) # revealed: int | str +``` + ## Generic type aliases ```py diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index c9fc52c6f875e..27c23dcf978e1 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -2344,7 +2344,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } fn infer_type_alias(&mut self, type_alias: &ast::StmtTypeAlias) { - self.infer_annotation_expression(&type_alias.value, DeferredExpressionState::Deferred); + self.infer_annotation_expression(&type_alias.value, DeferredExpressionState::None); } /// If the current scope is a method inside an enclosing class, From ecf3c4ca1134bcb3885a0d02b7ed9cd804374d45 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 25 Aug 2025 19:39:05 +0100 Subject: [PATCH 135/160] [ty] Add support for PEP 800 (#20084) --- crates/ty/docs/rules.md | 2 +- .../mdtest/instance_layout_conflict.md | 30 ++- ...impli\342\200\246_(f5857d64ce69ca1d).snap" | 210 +++++++++++------- .../type_properties/is_disjoint_from.md | 26 ++- crates/ty_python_semantic/src/types/class.rs | 181 +++++---------- .../src/types/diagnostic.rs | 78 +++---- .../ty_python_semantic/src/types/function.rs | 5 +- crates/ty_python_semantic/src/types/infer.rs | 12 +- ty.schema.json | 2 +- 9 files changed, 275 insertions(+), 271 deletions(-) diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index 3043c84eaa500..25290865c8e58 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -422,7 +422,7 @@ class D(A, B, C): ... **Known problems** Classes that have "dynamic" definitions of `__slots__` (definitions do not consist -of string literals, or tuples of string literals) are not currently considered solid +of string literals, or tuples of string literals) are not currently considered disjoint bases by ty. Additionally, this check is not exhaustive: many C extensions (including several in diff --git a/crates/ty_python_semantic/resources/mdtest/instance_layout_conflict.md b/crates/ty_python_semantic/resources/mdtest/instance_layout_conflict.md index 45f5c5d53ca96..f64412f4f3e0d 100644 --- a/crates/ty_python_semantic/resources/mdtest/instance_layout_conflict.md +++ b/crates/ty_python_semantic/resources/mdtest/instance_layout_conflict.md @@ -103,7 +103,7 @@ class E( # error: [instance-layout-conflict] ): ... ``` -## A single "solid base" +## A single "disjoint base" ```py class A: @@ -152,14 +152,15 @@ class Baz(Foo, Bar): ... # fine Certain classes implemented in C extensions also have an extended instance memory layout, in the -same way as classes that define non-empty `__slots__`. (CPython internally calls all such classes -with a unique instance memory layout "solid bases", and we also borrow this term.) There is -currently no generalized way for ty to detect such a C-extension class, as there is currently no way -of expressing the fact that a class is a solid base in a stub file. However, ty special-cases -certain builtin classes in order to detect that attempting to combine them in a single MRO would -fail: +same way as classes that define non-empty `__slots__`. CPython internally calls all such classes +with a unique instance memory layout "solid bases", but [PEP 800](https://peps.python.org/pep-0800/) +calls these classes "disjoint bases", and this is the term we generally use. The `@disjoint_base` +decorator introduced by this PEP provides a generalised way for type checkers to identify such +classes. ```py +from typing_extensions import disjoint_base + # fmt: off class A( # error: [instance-layout-conflict] @@ -183,6 +184,17 @@ class E( # error: [instance-layout-conflict] class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] +@disjoint_base +class G: ... + +@disjoint_base +class H: ... + +class I( # error: [instance-layout-conflict] + G, + H +): ... + # fmt: on ``` @@ -193,9 +205,9 @@ We avoid emitting an `instance-layout-conflict` diagnostic for this class defini class Foo(range, str): ... # error: [subclass-of-final-class] ``` -## Multiple "solid bases" where one is a subclass of the other +## Multiple "disjoint bases" where one is a subclass of the other -A class is permitted to multiple-inherit from multiple solid bases if one is a subclass of the +A class is permitted to multiple-inherit from multiple disjoint bases if one is a subclass of the other: ```py diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/instance_layout_conf\342\200\246_-_Tests_for_ty's_`inst\342\200\246_-_Built-ins_with_impli\342\200\246_(f5857d64ce69ca1d).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/instance_layout_conf\342\200\246_-_Tests_for_ty's_`inst\342\200\246_-_Built-ins_with_impli\342\200\246_(f5857d64ce69ca1d).snap" index 8c9a693f17e22..ddeee94396035 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/instance_layout_conf\342\200\246_-_Tests_for_ty's_`inst\342\200\246_-_Built-ins_with_impli\342\200\246_(f5857d64ce69ca1d).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/instance_layout_conf\342\200\246_-_Tests_for_ty's_`inst\342\200\246_-_Built-ins_with_impli\342\200\246_(f5857d64ce69ca1d).snap" @@ -12,59 +12,72 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/instance_layout_conflict ## mdtest_snippet.py ``` - 1 | # fmt: off + 1 | from typing_extensions import disjoint_base 2 | - 3 | class A( # error: [instance-layout-conflict] - 4 | int, - 5 | str - 6 | ): ... - 7 | - 8 | class B: - 9 | __slots__ = ("b",) -10 | -11 | class C( # error: [instance-layout-conflict] -12 | int, -13 | B, -14 | ): ... -15 | class D(int): ... -16 | -17 | class E( # error: [instance-layout-conflict] -18 | D, -19 | str -20 | ): ... -21 | -22 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] + 3 | # fmt: off + 4 | + 5 | class A( # error: [instance-layout-conflict] + 6 | int, + 7 | str + 8 | ): ... + 9 | +10 | class B: +11 | __slots__ = ("b",) +12 | +13 | class C( # error: [instance-layout-conflict] +14 | int, +15 | B, +16 | ): ... +17 | class D(int): ... +18 | +19 | class E( # error: [instance-layout-conflict] +20 | D, +21 | str +22 | ): ... 23 | -24 | # fmt: on -25 | class Foo(range, str): ... # error: [subclass-of-final-class] +24 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] +25 | +26 | @disjoint_base +27 | class G: ... +28 | +29 | @disjoint_base +30 | class H: ... +31 | +32 | class I( # error: [instance-layout-conflict] +33 | G, +34 | H +35 | ): ... +36 | +37 | # fmt: on +38 | class Foo(range, str): ... # error: [subclass-of-final-class] ``` # Diagnostics ``` error[instance-layout-conflict]: Class will raise `TypeError` at runtime due to incompatible bases - --> src/mdtest_snippet.py:3:7 - | -1 | # fmt: off -2 | -3 | class A( # error: [instance-layout-conflict] - | _______^ -4 | | int, -5 | | str -6 | | ): ... - | |_^ Bases `int` and `str` cannot be combined in multiple inheritance -7 | -8 | class B: - | + --> src/mdtest_snippet.py:5:7 + | + 3 | # fmt: off + 4 | + 5 | class A( # error: [instance-layout-conflict] + | _______^ + 6 | | int, + 7 | | str + 8 | | ): ... + | |_^ Bases `int` and `str` cannot be combined in multiple inheritance + 9 | +10 | class B: + | info: Two classes cannot coexist in a class's MRO if their instances have incompatible memory layouts - --> src/mdtest_snippet.py:4:5 + --> src/mdtest_snippet.py:6:5 | -3 | class A( # error: [instance-layout-conflict] -4 | int, +5 | class A( # error: [instance-layout-conflict] +6 | int, | --- `int` instances have a distinct memory layout because of the way `int` is implemented in a C extension -5 | str +7 | str | --- `str` instances have a distinct memory layout because of the way `str` is implemented in a C extension -6 | ): ... +8 | ): ... | info: rule `instance-layout-conflict` is enabled by default @@ -72,28 +85,28 @@ info: rule `instance-layout-conflict` is enabled by default ``` error[instance-layout-conflict]: Class will raise `TypeError` at runtime due to incompatible bases - --> src/mdtest_snippet.py:11:7 + --> src/mdtest_snippet.py:13:7 | - 9 | __slots__ = ("b",) -10 | -11 | class C( # error: [instance-layout-conflict] +11 | __slots__ = ("b",) +12 | +13 | class C( # error: [instance-layout-conflict] | _______^ -12 | | int, -13 | | B, -14 | | ): ... +14 | | int, +15 | | B, +16 | | ): ... | |_^ Bases `int` and `B` cannot be combined in multiple inheritance -15 | class D(int): ... +17 | class D(int): ... | info: Two classes cannot coexist in a class's MRO if their instances have incompatible memory layouts - --> src/mdtest_snippet.py:12:5 + --> src/mdtest_snippet.py:14:5 | -11 | class C( # error: [instance-layout-conflict] -12 | int, +13 | class C( # error: [instance-layout-conflict] +14 | int, | --- `int` instances have a distinct memory layout because of the way `int` is implemented in a C extension -13 | B, +15 | B, | - `B` instances have a distinct memory layout because `B` defines non-empty `__slots__` -14 | ): ... -15 | class D(int): ... +16 | ): ... +17 | class D(int): ... | info: rule `instance-layout-conflict` is enabled by default @@ -101,31 +114,31 @@ info: rule `instance-layout-conflict` is enabled by default ``` error[instance-layout-conflict]: Class will raise `TypeError` at runtime due to incompatible bases - --> src/mdtest_snippet.py:17:7 + --> src/mdtest_snippet.py:19:7 | -15 | class D(int): ... -16 | -17 | class E( # error: [instance-layout-conflict] +17 | class D(int): ... +18 | +19 | class E( # error: [instance-layout-conflict] | _______^ -18 | | D, -19 | | str -20 | | ): ... +20 | | D, +21 | | str +22 | | ): ... | |_^ Bases `D` and `str` cannot be combined in multiple inheritance -21 | -22 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] +23 | +24 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] | info: Two classes cannot coexist in a class's MRO if their instances have incompatible memory layouts - --> src/mdtest_snippet.py:18:5 + --> src/mdtest_snippet.py:20:5 | -17 | class E( # error: [instance-layout-conflict] -18 | D, +19 | class E( # error: [instance-layout-conflict] +20 | D, | - | | | `D` instances have a distinct memory layout because `D` inherits from `int` | `int` instances have a distinct memory layout because of the way `int` is implemented in a C extension -19 | str +21 | str | --- `str` instances have a distinct memory layout because of the way `str` is implemented in a C extension -20 | ): ... +22 | ): ... | info: rule `instance-layout-conflict` is enabled by default @@ -133,28 +146,57 @@ info: rule `instance-layout-conflict` is enabled by default ``` error[instance-layout-conflict]: Class will raise `TypeError` at runtime due to incompatible bases - --> src/mdtest_snippet.py:22:7 + --> src/mdtest_snippet.py:24:7 | -20 | ): ... -21 | -22 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Bases `int`, `str`, `bytes` and `bytearray` cannot be combined in multiple inheritance +22 | ): ... 23 | -24 | # fmt: on +24 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Bases `int`, `str`, `bytes` and `bytearray` cannot be combined in multiple inheritance +25 | +26 | @disjoint_base | info: Two classes cannot coexist in a class's MRO if their instances have incompatible memory layouts - --> src/mdtest_snippet.py:22:9 + --> src/mdtest_snippet.py:24:9 | -20 | ): ... -21 | -22 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] +22 | ): ... +23 | +24 | class F(int, str, bytes, bytearray): ... # error: [instance-layout-conflict] | --- --- ----- --------- `bytearray` instances have a distinct memory layout because of the way `bytearray` is implemented in a C extension | | | | | | | `bytes` instances have a distinct memory layout because of the way `bytes` is implemented in a C extension | | `str` instances have a distinct memory layout because of the way `str` is implemented in a C extension | `int` instances have a distinct memory layout because of the way `int` is implemented in a C extension -23 | -24 | # fmt: on +25 | +26 | @disjoint_base + | +info: rule `instance-layout-conflict` is enabled by default + +``` + +``` +error[instance-layout-conflict]: Class will raise `TypeError` at runtime due to incompatible bases + --> src/mdtest_snippet.py:32:7 + | +30 | class H: ... +31 | +32 | class I( # error: [instance-layout-conflict] + | _______^ +33 | | G, +34 | | H +35 | | ): ... + | |_^ Bases `G` and `H` cannot be combined in multiple inheritance +36 | +37 | # fmt: on + | +info: Two classes cannot coexist in a class's MRO if their instances have incompatible memory layouts + --> src/mdtest_snippet.py:33:5 + | +32 | class I( # error: [instance-layout-conflict] +33 | G, + | - `G` instances have a distinct memory layout because of the way `G` is implemented in a C extension +34 | H + | - `H` instances have a distinct memory layout because of the way `H` is implemented in a C extension +35 | ): ... | info: rule `instance-layout-conflict` is enabled by default @@ -162,10 +204,10 @@ info: rule `instance-layout-conflict` is enabled by default ``` error[subclass-of-final-class]: Class `Foo` cannot inherit from final class `range` - --> src/mdtest_snippet.py:25:11 + --> src/mdtest_snippet.py:38:11 | -24 | # fmt: on -25 | class Foo(range, str): ... # error: [subclass-of-final-class] +37 | # fmt: on +38 | class Foo(range, str): ... # error: [subclass-of-final-class] | ^^^^^ | info: rule `subclass-of-final-class` is enabled by default diff --git a/crates/ty_python_semantic/resources/mdtest/type_properties/is_disjoint_from.md b/crates/ty_python_semantic/resources/mdtest/type_properties/is_disjoint_from.md index 6ec192fb8c326..aa5c3eaee24ea 100644 --- a/crates/ty_python_semantic/resources/mdtest/type_properties/is_disjoint_from.md +++ b/crates/ty_python_semantic/resources/mdtest/type_properties/is_disjoint_from.md @@ -87,7 +87,7 @@ static_assert(is_disjoint_from(memoryview, Foo)) static_assert(is_disjoint_from(type[memoryview], type[Foo])) ``` -## "Solid base" builtin types +## "Disjoint base" builtin types Most other builtins can be subclassed and can even be used in multiple inheritance. However, builtin classes *cannot* generally be used in multiple inheritance with other builtin types. This is because @@ -95,11 +95,14 @@ the CPython interpreter considers these classes "solid bases": due to the way th in C, they have atypical instance memory layouts. No class can ever have more than one "solid base" in its MRO. -It's not currently possible for ty to detect in a generalized way whether a class is a "solid base" -or not, but we special-case some commonly used builtin types: +[PEP 800](https://peps.python.org/pep-0800/) provides a generalised way for type checkers to know +whether a class has an atypical instance memory layout via the `@disjoint_base` decorator; we +generally use the term "disjoint base" for these classes. ```py +import asyncio from typing import Any +from typing_extensions import disjoint_base from ty_extensions import static_assert, is_disjoint_from class Foo: ... @@ -114,12 +117,23 @@ static_assert(is_disjoint_from(list, dict[Any, Any])) static_assert(is_disjoint_from(list[Foo], dict[Any, Any])) static_assert(is_disjoint_from(list[Any], dict[Any, Any])) static_assert(is_disjoint_from(type[list], type[dict])) + +static_assert(is_disjoint_from(asyncio.Task, dict)) + +@disjoint_base +class A: ... + +@disjoint_base +class B: ... + +static_assert(is_disjoint_from(A, B)) ``` -## Other solid bases +## Other disjoint bases As well as certain classes that are implemented in C extensions, any class that declares non-empty -`__slots__` is also considered a "solid base"; these types are also considered to be disjoint by ty: +`__slots__` is also considered a "disjoint base"; these types are also considered to be disjoint by +ty: ```py from ty_extensions import static_assert, is_disjoint_from @@ -141,7 +155,7 @@ static_assert(not is_disjoint_from(B, C)) static_assert(not is_disjoint_from(type[B], type[C])) ``` -Two solid bases are not disjoint if one inherits from the other, however: +Two disjoint bases are not disjoint if one inherits from the other, however: ```py class D(A): diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 2baeffd80e9ee..ef706b18f9fb5 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -465,9 +465,9 @@ impl<'db> ClassType<'db> { class_literal.definition(db) } - /// Return `Some` if this class is known to be a [`SolidBase`], or `None` if it is not. - pub(super) fn as_solid_base(self, db: &'db dyn Db) -> Option> { - self.class_literal(db).0.as_solid_base(db) + /// Return `Some` if this class is known to be a [`DisjointBase`], or `None` if it is not. + pub(super) fn as_disjoint_base(self, db: &'db dyn Db) -> Option> { + self.class_literal(db).0.as_disjoint_base(db) } /// Return `true` if this class represents `known_class` @@ -633,13 +633,13 @@ impl<'db> ClassType<'db> { .apply_optional_specialization(db, specialization) } - /// Return the [`SolidBase`] that appears first in the MRO of this class. + /// Return the [`DisjointBase`] that appears first in the MRO of this class. /// - /// Returns `None` if this class does not have any solid bases in its MRO. - pub(super) fn nearest_solid_base(self, db: &'db dyn Db) -> Option> { + /// Returns `None` if this class does not have any disjoint bases in its MRO. + pub(super) fn nearest_disjoint_base(self, db: &'db dyn Db) -> Option> { self.iter_mro(db) .filter_map(ClassBase::into_class) - .find_map(|base| base.as_solid_base(db)) + .find_map(|base| base.as_disjoint_base(db)) } /// Return `true` if this class could coexist in an MRO with `other`. @@ -660,12 +660,17 @@ impl<'db> ClassType<'db> { return other.is_subclass_of(db, self); } - // Two solid bases can only coexist in an MRO if one is a subclass of the other. - if self.nearest_solid_base(db).is_some_and(|solid_base_1| { - other.nearest_solid_base(db).is_some_and(|solid_base_2| { - !solid_base_1.could_coexist_in_mro_with(db, &solid_base_2) + // Two disjoint bases can only coexist in an MRO if one is a subclass of the other. + if self + .nearest_disjoint_base(db) + .is_some_and(|disjoint_base_1| { + other + .nearest_disjoint_base(db) + .is_some_and(|disjoint_base_2| { + !disjoint_base_1.could_coexist_in_mro_with(db, &disjoint_base_2) + }) }) - }) { + { return false; } @@ -1519,14 +1524,19 @@ impl<'db> ClassLiteral<'db> { } } - /// Return `Some()` if this class is known to be a [`SolidBase`], or `None` if it is not. - pub(super) fn as_solid_base(self, db: &'db dyn Db) -> Option> { - if let Some(known_class) = self.known(db) { - known_class - .is_solid_base() - .then_some(SolidBase::hard_coded(self)) + /// Return `Some()` if this class is known to be a [`DisjointBase`], or `None` if it is not. + pub(super) fn as_disjoint_base(self, db: &'db dyn Db) -> Option> { + // TODO: Typeshed cannot add `@disjoint_base` to its `tuple` definition without breaking pyright. + // See . + // This should be fixed soon; we can remove this workaround then. + if self.is_known(db, KnownClass::Tuple) + || self + .known_function_decorators(db) + .contains(&KnownFunction::DisjointBase) + { + Some(DisjointBase::due_to_decorator(self)) } else if SlotsKind::from(db, self) == SlotsKind::NotEmpty { - Some(SolidBase::due_to_dunder_slots(self)) + Some(DisjointBase::due_to_dunder_slots(self)) } else { None } @@ -3375,39 +3385,47 @@ impl InheritanceCycle { /// CPython internally considers a class a "solid base" if it has an atypical instance memory layout, /// with additional memory "slots" for each instance, besides the default object metadata and an -/// attribute dictionary. A "solid base" can be a class defined in a C extension which defines C-level -/// instance slots, or a Python class that defines non-empty `__slots__`. +/// attribute dictionary. Per [PEP 800], however, we use the term "disjoint base" for this concept. +/// +/// A "disjoint base" can be a class defined in a C extension which defines C-level instance slots, +/// or a Python class that defines non-empty `__slots__`. C-level instance slots are not generally +/// visible to Python code, but PEP 800 specifies that any class decorated with +/// `@typing_extensions.disjoint_base` should be treated by type checkers as a disjoint base; it is +/// assumed that classes with C-level instance slots will be decorated as such when they appear in +/// stub files. /// -/// Two solid bases can only coexist in a class's MRO if one is a subclass of the other. Knowing if -/// a class is "solid base" or not is therefore valuable for inferring whether two instance types or +/// Two disjoint bases can only coexist in a class's MRO if one is a subclass of the other. Knowing if +/// a class is "disjoint base" or not is therefore valuable for inferring whether two instance types or /// two subclass-of types are disjoint from each other. It also allows us to detect possible /// `TypeError`s resulting from class definitions. +/// +/// [PEP 800]: https://peps.python.org/pep-0800/ #[derive(Debug, PartialEq, Eq, Hash, Copy, Clone)] -pub(super) struct SolidBase<'db> { +pub(super) struct DisjointBase<'db> { pub(super) class: ClassLiteral<'db>, - pub(super) kind: SolidBaseKind, + pub(super) kind: DisjointBaseKind, } -impl<'db> SolidBase<'db> { - /// Creates a [`SolidBase`] instance where we know the class is a solid base - /// because it is special-cased by ty. - fn hard_coded(class: ClassLiteral<'db>) -> Self { +impl<'db> DisjointBase<'db> { + /// Creates a [`DisjointBase`] instance where we know the class is a disjoint base + /// because it has the `@disjoint_base` decorator on its definition + fn due_to_decorator(class: ClassLiteral<'db>) -> Self { Self { class, - kind: SolidBaseKind::HardCoded, + kind: DisjointBaseKind::DisjointBaseDecorator, } } - /// Creates a [`SolidBase`] instance where we know the class is a solid base + /// Creates a [`DisjointBase`] instance where we know the class is a disjoint base /// because of its `__slots__` definition. fn due_to_dunder_slots(class: ClassLiteral<'db>) -> Self { Self { class, - kind: SolidBaseKind::DefinesSlots, + kind: DisjointBaseKind::DefinesSlots, } } - /// Two solid bases can only coexist in a class's MRO if one is a subclass of the other + /// Two disjoint bases can only coexist in a class's MRO if one is a subclass of the other fn could_coexist_in_mro_with(&self, db: &'db dyn Db, other: &Self) -> bool { self == other || self @@ -3420,10 +3438,11 @@ impl<'db> SolidBase<'db> { } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub(super) enum SolidBaseKind { - /// We know the class is a solid base because of some hardcoded knowledge in ty. - HardCoded, - /// We know the class is a solid base because it has a non-empty `__slots__` definition. +pub(super) enum DisjointBaseKind { + /// We know the class is a disjoint base because it's either hardcoded in ty + /// or has the `@disjoint_base` decorator. + DisjointBaseDecorator, + /// We know the class is a disjoint base because it has a non-empty `__slots__` definition. DefinesSlots, } @@ -3624,94 +3643,6 @@ impl KnownClass { } } - /// Return `true` if this class is a [`SolidBase`] - const fn is_solid_base(self) -> bool { - match self { - Self::Object => false, - - // Most non-`@final` builtins (other than `object`) are solid bases. - Self::Set - | Self::FrozenSet - | Self::BaseException - | Self::Bytearray - | Self::Int - | Self::Float - | Self::Complex - | Self::Str - | Self::List - | Self::Tuple - | Self::Dict - | Self::Slice - | Self::Property - | Self::Staticmethod - | Self::Classmethod - | Self::Deprecated - | Self::Type - | Self::ModuleType - | Self::Super - | Self::GenericAlias - | Self::Deque - | Self::Bytes => true, - - // It doesn't really make sense to ask the question for `@final` types, - // since these are "more than solid bases". But we'll anyway infer a `@final` - // class as being disjoint from a class that doesn't appear in its MRO, - // and we'll anyway complain if we see a class definition that includes a - // `@final` class in its bases. We therefore return `false` here to avoid - // unnecessary duplicate diagnostics elsewhere. - Self::TypeVarTuple - | Self::TypeAliasType - | Self::UnionType - | Self::NoDefaultType - | Self::MethodType - | Self::MethodWrapperType - | Self::FunctionType - | Self::GeneratorType - | Self::AsyncGeneratorType - | Self::StdlibAlias - | Self::SpecialForm - | Self::TypeVar - | Self::ParamSpec - | Self::ParamSpecArgs - | Self::ParamSpecKwargs - | Self::WrapperDescriptorType - | Self::EllipsisType - | Self::NotImplementedType - | Self::KwOnly - | Self::InitVar - | Self::VersionInfo - | Self::Bool - | Self::NoneType - | Self::CoroutineType => false, - - // Anything with a *runtime* MRO (N.B. sometimes different from the MRO that typeshed gives!) - // with length >2, or anything that is implemented in pure Python, is not a solid base. - Self::ABCMeta - | Self::Awaitable - | Self::Generator - | Self::Enum - | Self::EnumType - | Self::Auto - | Self::Member - | Self::Nonmember - | Self::ChainMap - | Self::Exception - | Self::ExceptionGroup - | Self::Field - | Self::SupportsIndex - | Self::NamedTupleFallback - | Self::NamedTupleLike - | Self::TypedDictFallback - | Self::Counter - | Self::DefaultDict - | Self::OrderedDict - | Self::NewType - | Self::Iterable - | Self::Iterator - | Self::BaseExceptionGroup => false, - } - } - /// Return `true` if this class is a subclass of `enum.Enum` *and* has enum members, i.e. /// if it is an "actual" enum, not `enum.Enum` itself or a similar custom enum class. pub(crate) const fn is_enum_subclass_with_members(self) -> bool { diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index bc2fcfb2e3b2c..5377614e5a111 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -10,7 +10,7 @@ use crate::semantic_index::SemanticIndex; use crate::semantic_index::definition::Definition; use crate::semantic_index::place::{PlaceTable, ScopedPlaceId}; use crate::suppression::FileSuppressionId; -use crate::types::class::{Field, SolidBase, SolidBaseKind}; +use crate::types::class::{DisjointBase, DisjointBaseKind, Field}; use crate::types::function::KnownFunction; use crate::types::string_annotation::{ BYTE_STRING_TYPE_ANNOTATION, ESCAPE_CHARACTER_IN_FORWARD_ANNOTATION, FSTRING_TYPE_ANNOTATION, @@ -405,7 +405,7 @@ declare_lint! { /// /// ## Known problems /// Classes that have "dynamic" definitions of `__slots__` (definitions do not consist - /// of string literals, or tuples of string literals) are not currently considered solid + /// of string literals, or tuples of string literals) are not currently considered disjoint /// bases by ty. /// /// Additionally, this check is not exhaustive: many C extensions (including several in @@ -2170,9 +2170,9 @@ pub(crate) fn report_instance_layout_conflict( context: &InferContext, class: ClassLiteral, node: &ast::StmtClassDef, - solid_bases: &IncompatibleBases, + disjoint_bases: &IncompatibleBases, ) { - debug_assert!(solid_bases.len() > 1); + debug_assert!(disjoint_bases.len() > 1); let db = context.db(); @@ -2186,7 +2186,7 @@ pub(crate) fn report_instance_layout_conflict( diagnostic.set_primary_message(format_args!( "Bases {} cannot be combined in multiple inheritance", - solid_bases.describe_problematic_class_bases(db) + disjoint_bases.describe_problematic_class_bases(db) )); let mut subdiagnostic = SubDiagnostic::new( @@ -2195,23 +2195,23 @@ pub(crate) fn report_instance_layout_conflict( have incompatible memory layouts", ); - for (solid_base, solid_base_info) in solid_bases { + for (disjoint_base, disjoint_base_info) in disjoint_bases { let IncompatibleBaseInfo { node_index, originating_base, - } = solid_base_info; + } = disjoint_base_info; let span = context.span(&node.bases()[*node_index]); let mut annotation = Annotation::secondary(span.clone()); - if solid_base.class == *originating_base { - match solid_base.kind { - SolidBaseKind::DefinesSlots => { + if disjoint_base.class == *originating_base { + match disjoint_base.kind { + DisjointBaseKind::DefinesSlots => { annotation = annotation.message(format_args!( "`{base}` instances have a distinct memory layout because `{base}` defines non-empty `__slots__`", base = originating_base.name(db) )); } - SolidBaseKind::HardCoded => { + DisjointBaseKind::DisjointBaseDecorator => { annotation = annotation.message(format_args!( "`{base}` instances have a distinct memory layout because of the way `{base}` \ is implemented in a C extension", @@ -2223,26 +2223,28 @@ pub(crate) fn report_instance_layout_conflict( } else { annotation = annotation.message(format_args!( "`{base}` instances have a distinct memory layout \ - because `{base}` inherits from `{solid_base}`", + because `{base}` inherits from `{disjoint_base}`", base = originating_base.name(db), - solid_base = solid_base.class.name(db) + disjoint_base = disjoint_base.class.name(db) )); subdiagnostic.annotate(annotation); let mut additional_annotation = Annotation::secondary(span); - additional_annotation = match solid_base.kind { - SolidBaseKind::DefinesSlots => additional_annotation.message(format_args!( - "`{solid_base}` instances have a distinct memory layout because `{solid_base}` \ + additional_annotation = match disjoint_base.kind { + DisjointBaseKind::DefinesSlots => additional_annotation.message(format_args!( + "`{disjoint_base}` instances have a distinct memory layout because `{disjoint_base}` \ defines non-empty `__slots__`", - solid_base = solid_base.class.name(db), + disjoint_base = disjoint_base.class.name(db), )), - SolidBaseKind::HardCoded => additional_annotation.message(format_args!( - "`{solid_base}` instances have a distinct memory layout \ - because of the way `{solid_base}` is implemented in a C extension", - solid_base = solid_base.class.name(db), - )), + DisjointBaseKind::DisjointBaseDecorator => { + additional_annotation.message(format_args!( + "`{disjoint_base}` instances have a distinct memory layout \ + because of the way `{disjoint_base}` is implemented in a C extension", + disjoint_base = disjoint_base.class.name(db), + )) + } }; subdiagnostic.annotate(additional_annotation); @@ -2252,20 +2254,20 @@ pub(crate) fn report_instance_layout_conflict( diagnostic.sub(subdiagnostic); } -/// Information regarding the conflicting solid bases a class is inferred to have in its MRO. +/// Information regarding the conflicting disjoint bases a class is inferred to have in its MRO. /// -/// For each solid base, we record information about which element in the class's bases list -/// caused the solid base to be included in the class's MRO. +/// For each disjoint base, we record information about which element in the class's bases list +/// caused the disjoint base to be included in the class's MRO. /// -/// The inner data is an `IndexMap` to ensure that diagnostics regarding conflicting solid bases +/// The inner data is an `IndexMap` to ensure that diagnostics regarding conflicting disjoint bases /// are reported in a stable order. #[derive(Debug, Default)] -pub(super) struct IncompatibleBases<'db>(FxIndexMap, IncompatibleBaseInfo<'db>>); +pub(super) struct IncompatibleBases<'db>(FxIndexMap, IncompatibleBaseInfo<'db>>); impl<'db> IncompatibleBases<'db> { pub(super) fn insert( &mut self, - base: SolidBase<'db>, + base: DisjointBase<'db>, node_index: usize, class: ClassLiteral<'db>, ) { @@ -2287,19 +2289,19 @@ impl<'db> IncompatibleBases<'db> { self.0.len() } - /// Two solid bases are allowed to coexist in an MRO if one is a subclass of the other. + /// Two disjoint bases are allowed to coexist in an MRO if one is a subclass of the other. /// This method therefore removes any entry in `self` that is a subclass of one or more /// other entries also contained in `self`. pub(super) fn remove_redundant_entries(&mut self, db: &'db dyn Db) { self.0 = self .0 .iter() - .filter(|(solid_base, _)| { + .filter(|(disjoint_base, _)| { self.0 .keys() - .filter(|other_base| other_base != solid_base) + .filter(|other_base| other_base != disjoint_base) .all(|other_base| { - !solid_base.class.is_subclass_of( + !disjoint_base.class.is_subclass_of( db, None, other_base.class.default_specialization(db), @@ -2312,25 +2314,25 @@ impl<'db> IncompatibleBases<'db> { } impl<'a, 'db> IntoIterator for &'a IncompatibleBases<'db> { - type Item = (&'a SolidBase<'db>, &'a IncompatibleBaseInfo<'db>); - type IntoIter = indexmap::map::Iter<'a, SolidBase<'db>, IncompatibleBaseInfo<'db>>; + type Item = (&'a DisjointBase<'db>, &'a IncompatibleBaseInfo<'db>); + type IntoIter = indexmap::map::Iter<'a, DisjointBase<'db>, IncompatibleBaseInfo<'db>>; fn into_iter(self) -> Self::IntoIter { self.0.iter() } } -/// Information about which class base the "solid base" stems from +/// Information about which class base the "disjoint base" stems from #[derive(Debug, Copy, Clone)] pub(super) struct IncompatibleBaseInfo<'db> { /// The index of the problematic base in the [`ast::StmtClassDef`]'s bases list. node_index: usize, /// The base class in the [`ast::StmtClassDef`]'s bases list that caused - /// the solid base to be included in the class's MRO. + /// the disjoint base to be included in the class's MRO. /// - /// This won't necessarily be the same class as the `SolidBase`'s class, - /// as the `SolidBase` may have found its way into the class's MRO by dint of it being a + /// This won't necessarily be the same class as the `DisjointBase`'s class, + /// as the `DisjointBase` may have found its way into the class's MRO by dint of it being a /// superclass of one of the classes in the class definition's bases list. originating_base: ClassLiteral<'db>, } diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 691068f896ea2..5fc02fc0c372b 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -1109,7 +1109,8 @@ pub enum KnownFunction { /// `typing(_extensions).final` Final, - + /// `typing(_extensions).disjoint_base` + DisjointBase, /// [`typing(_extensions).no_type_check`](https://typing.python.org/en/latest/spec/directives.html#no-type-check) NoTypeCheck, @@ -1212,6 +1213,7 @@ impl KnownFunction { | Self::GetProtocolMembers | Self::RuntimeCheckable | Self::DataclassTransform + | Self::DisjointBase | Self::NoTypeCheck => { matches!(module, KnownModule::Typing | KnownModule::TypingExtensions) } @@ -1574,6 +1576,7 @@ pub(crate) mod tests { | KnownFunction::GetProtocolMembers | KnownFunction::RuntimeCheckable | KnownFunction::DataclassTransform + | KnownFunction::DisjointBase | KnownFunction::NoTypeCheck => KnownModule::TypingExtensions, KnownFunction::IsSingleton diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 27c23dcf978e1..97392af811f98 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -1147,7 +1147,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let is_protocol = class.is_protocol(self.db()); - let mut solid_bases = IncompatibleBases::default(); + let mut disjoint_bases = IncompatibleBases::default(); // (3) Iterate through the class's explicit bases to check for various possible errors: // - Check for inheritance from plain `Generic`, @@ -1209,8 +1209,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { _ => continue, }; - if let Some(solid_base) = base_class.nearest_solid_base(self.db()) { - solid_bases.insert(solid_base, i, base_class.class_literal(self.db()).0); + if let Some(disjoint_base) = base_class.nearest_disjoint_base(self.db()) { + disjoint_bases.insert(disjoint_base, i, base_class.class_literal(self.db()).0); } if is_protocol @@ -1301,14 +1301,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } }, Ok(_) => { - solid_bases.remove_redundant_entries(self.db()); + disjoint_bases.remove_redundant_entries(self.db()); - if solid_bases.len() > 1 { + if disjoint_bases.len() > 1 { report_instance_layout_conflict( &self.context, class, class_node, - &solid_bases, + &disjoint_bases, ); } } diff --git a/ty.schema.json b/ty.schema.json index 6b5540697714b..a9261dfefbd70 100644 --- a/ty.schema.json +++ b/ty.schema.json @@ -433,7 +433,7 @@ }, "instance-layout-conflict": { "title": "detects class definitions that raise `TypeError` due to instance layout conflict", - "description": "## What it does\nChecks for classes definitions which will fail at runtime due to\n\"instance memory layout conflicts\".\n\nThis error is usually caused by attempting to combine multiple classes\nthat define non-empty `__slots__` in a class's [Method Resolution Order]\n(MRO), or by attempting to combine multiple builtin classes in a class's\nMRO.\n\n## Why is this bad?\nInheriting from bases with conflicting instance memory layouts\nwill lead to a `TypeError` at runtime.\n\nAn instance memory layout conflict occurs when CPython cannot determine\nthe memory layout instances of a class should have, because the instance\nmemory layout of one of its bases conflicts with the instance memory layout\nof one or more of its other bases.\n\nFor example, if a Python class defines non-empty `__slots__`, this will\nimpact the memory layout of instances of that class. Multiple inheritance\nfrom more than one different class defining non-empty `__slots__` is not\nallowed:\n\n```python\nclass A:\n __slots__ = (\"a\", \"b\")\n\nclass B:\n __slots__ = (\"a\", \"b\") # Even if the values are the same\n\n# TypeError: multiple bases have instance lay-out conflict\nclass C(A, B): ...\n```\n\nAn instance layout conflict can also be caused by attempting to use\nmultiple inheritance with two builtin classes, due to the way that these\nclasses are implemented in a CPython C extension:\n\n```python\nclass A(int, float): ... # TypeError: multiple bases have instance lay-out conflict\n```\n\nNote that pure-Python classes with no `__slots__`, or pure-Python classes\nwith empty `__slots__`, are always compatible:\n\n```python\nclass A: ...\nclass B:\n __slots__ = ()\nclass C:\n __slots__ = (\"a\", \"b\")\n\n# fine\nclass D(A, B, C): ...\n```\n\n## Known problems\nClasses that have \"dynamic\" definitions of `__slots__` (definitions do not consist\nof string literals, or tuples of string literals) are not currently considered solid\nbases by ty.\n\nAdditionally, this check is not exhaustive: many C extensions (including several in\nthe standard library) define classes that use extended memory layouts and thus cannot\ncoexist in a single MRO. Since it is currently not possible to represent this fact in\nstub files, having a full knowledge of these classes is also impossible. When it comes\nto classes that do not define `__slots__` at the Python level, therefore, ty, currently\nonly hard-codes a number of cases where it knows that a class will produce instances with\nan atypical memory layout.\n\n## Further reading\n- [CPython documentation: `__slots__`](https://docs.python.org/3/reference/datamodel.html#slots)\n- [CPython documentation: Method Resolution Order](https://docs.python.org/3/glossary.html#term-method-resolution-order)\n\n[Method Resolution Order]: https://docs.python.org/3/glossary.html#term-method-resolution-order", + "description": "## What it does\nChecks for classes definitions which will fail at runtime due to\n\"instance memory layout conflicts\".\n\nThis error is usually caused by attempting to combine multiple classes\nthat define non-empty `__slots__` in a class's [Method Resolution Order]\n(MRO), or by attempting to combine multiple builtin classes in a class's\nMRO.\n\n## Why is this bad?\nInheriting from bases with conflicting instance memory layouts\nwill lead to a `TypeError` at runtime.\n\nAn instance memory layout conflict occurs when CPython cannot determine\nthe memory layout instances of a class should have, because the instance\nmemory layout of one of its bases conflicts with the instance memory layout\nof one or more of its other bases.\n\nFor example, if a Python class defines non-empty `__slots__`, this will\nimpact the memory layout of instances of that class. Multiple inheritance\nfrom more than one different class defining non-empty `__slots__` is not\nallowed:\n\n```python\nclass A:\n __slots__ = (\"a\", \"b\")\n\nclass B:\n __slots__ = (\"a\", \"b\") # Even if the values are the same\n\n# TypeError: multiple bases have instance lay-out conflict\nclass C(A, B): ...\n```\n\nAn instance layout conflict can also be caused by attempting to use\nmultiple inheritance with two builtin classes, due to the way that these\nclasses are implemented in a CPython C extension:\n\n```python\nclass A(int, float): ... # TypeError: multiple bases have instance lay-out conflict\n```\n\nNote that pure-Python classes with no `__slots__`, or pure-Python classes\nwith empty `__slots__`, are always compatible:\n\n```python\nclass A: ...\nclass B:\n __slots__ = ()\nclass C:\n __slots__ = (\"a\", \"b\")\n\n# fine\nclass D(A, B, C): ...\n```\n\n## Known problems\nClasses that have \"dynamic\" definitions of `__slots__` (definitions do not consist\nof string literals, or tuples of string literals) are not currently considered disjoint\nbases by ty.\n\nAdditionally, this check is not exhaustive: many C extensions (including several in\nthe standard library) define classes that use extended memory layouts and thus cannot\ncoexist in a single MRO. Since it is currently not possible to represent this fact in\nstub files, having a full knowledge of these classes is also impossible. When it comes\nto classes that do not define `__slots__` at the Python level, therefore, ty, currently\nonly hard-codes a number of cases where it knows that a class will produce instances with\nan atypical memory layout.\n\n## Further reading\n- [CPython documentation: `__slots__`](https://docs.python.org/3/reference/datamodel.html#slots)\n- [CPython documentation: Method Resolution Order](https://docs.python.org/3/glossary.html#term-method-resolution-order)\n\n[Method Resolution Order]: https://docs.python.org/3/glossary.html#term-method-resolution-order", "default": "error", "oneOf": [ { From ef4897f9f38440d04716580b9655f5c18d5398d5 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 25 Aug 2025 13:49:49 -0500 Subject: [PATCH 136/160] [ty] Add support for PEP 750 t-strings (#20085) This PR attempts to adds support for inferring`string.templatelib.Template` for t-string literals. --- .../resources/mdtest/t_strings.md | 20 ++++++++ .../src/module_resolver/module.rs | 3 ++ crates/ty_python_semantic/src/types/class.rs | 46 +++++++++++++++---- crates/ty_python_semantic/src/types/infer.rs | 2 +- 4 files changed, 61 insertions(+), 10 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/t_strings.md diff --git a/crates/ty_python_semantic/resources/mdtest/t_strings.md b/crates/ty_python_semantic/resources/mdtest/t_strings.md new file mode 100644 index 0000000000000..97ebeed51a257 --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/t_strings.md @@ -0,0 +1,20 @@ +# Template strings + +(NB: `black` does not support Python 3.14 at the time of this writing) + + + +```toml +[environment] +python-version = "3.14" +``` + +Template strings, or t-strings, were added in Python 3.14. + +They may be specified as literals and are objects of type `string.templatelib.Template`. + +## Empty template string + +```py +reveal_type(t"") # revealed: Template +``` diff --git a/crates/ty_python_semantic/src/module_resolver/module.rs b/crates/ty_python_semantic/src/module_resolver/module.rs index a7d50829b06fc..3586f52933ca0 100644 --- a/crates/ty_python_semantic/src/module_resolver/module.rs +++ b/crates/ty_python_semantic/src/module_resolver/module.rs @@ -270,6 +270,8 @@ pub enum KnownModule { Dataclasses, Collections, Inspect, + #[strum(serialize = "string.templatelib")] + Templatelib, #[strum(serialize = "_typeshed._type_checker_internals")] TypeCheckerInternals, TyExtensions, @@ -305,6 +307,7 @@ impl KnownModule { Self::UnittestMock => "unittest.mock", #[cfg(test)] Self::Uuid => "uuid", + Self::Templatelib => "string.templatelib", } } diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index ef706b18f9fb5..d29a0afdee62a 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -3540,6 +3540,8 @@ pub enum KnownClass { NamedTupleFallback, NamedTupleLike, TypedDictFallback, + // string.templatelib + Template, } impl KnownClass { @@ -3582,7 +3584,8 @@ impl KnownClass { | Self::GeneratorType | Self::AsyncGeneratorType | Self::MethodWrapperType - | Self::CoroutineType => Some(Truthiness::AlwaysTrue), + | Self::CoroutineType + | Self::Template => Some(Truthiness::AlwaysTrue), Self::NoneType => Some(Truthiness::AlwaysFalse), @@ -3716,7 +3719,8 @@ impl KnownClass { | KnownClass::InitVar | KnownClass::NamedTupleFallback | KnownClass::NamedTupleLike - | KnownClass::TypedDictFallback => false, + | KnownClass::TypedDictFallback + | KnownClass::Template => false, } } @@ -3792,7 +3796,8 @@ impl KnownClass { | KnownClass::InitVar | KnownClass::NamedTupleFallback | KnownClass::NamedTupleLike - | KnownClass::TypedDictFallback => false, + | KnownClass::TypedDictFallback + | KnownClass::Template => false, } } @@ -3867,7 +3872,8 @@ impl KnownClass { | KnownClass::InitVar | KnownClass::TypedDictFallback | KnownClass::NamedTupleLike - | KnownClass::NamedTupleFallback => false, + | KnownClass::NamedTupleFallback + | KnownClass::Template => false, } } @@ -3955,7 +3961,8 @@ impl KnownClass { | Self::KwOnly | Self::InitVar | Self::NamedTupleFallback - | Self::TypedDictFallback => false, + | Self::TypedDictFallback + | Self::Template => false, } } @@ -4051,6 +4058,7 @@ impl KnownClass { Self::NamedTupleFallback => "NamedTupleFallback", Self::NamedTupleLike => "NamedTupleLike", Self::TypedDictFallback => "TypedDictFallback", + Self::Template => "Template", } } @@ -4315,6 +4323,7 @@ impl KnownClass { Self::Field | Self::KwOnly | Self::InitVar => KnownModule::Dataclasses, Self::NamedTupleFallback | Self::TypedDictFallback => KnownModule::TypeCheckerInternals, Self::NamedTupleLike => KnownModule::TyExtensions, + Self::Template => KnownModule::Templatelib, } } @@ -4392,7 +4401,8 @@ impl KnownClass { | Self::Iterator | Self::NamedTupleFallback | Self::NamedTupleLike - | Self::TypedDictFallback => Some(false), + | Self::TypedDictFallback + | Self::Template => Some(false), Self::Tuple => None, } @@ -4473,7 +4483,8 @@ impl KnownClass { | Self::Iterator | Self::NamedTupleFallback | Self::NamedTupleLike - | Self::TypedDictFallback => false, + | Self::TypedDictFallback + | Self::Template => false, } } @@ -4563,6 +4574,7 @@ impl KnownClass { "NamedTupleFallback" => Self::NamedTupleFallback, "NamedTupleLike" => Self::NamedTupleLike, "TypedDictFallback" => Self::TypedDictFallback, + "Template" => Self::Template, _ => return None, }; @@ -4629,7 +4641,8 @@ impl KnownClass { | Self::TypedDictFallback | Self::NamedTupleLike | Self::Awaitable - | Self::Generator => module == self.canonical_module(db), + | Self::Generator + | Self::Template => module == self.canonical_module(db), Self::NoneType => matches!(module, KnownModule::Typeshed | KnownModule::Types), Self::SpecialForm | Self::TypeVar @@ -5095,7 +5108,13 @@ mod tests { #[test] fn known_class_roundtrip_from_str() { - let db = setup_db(); + let mut db = setup_db(); + Program::get(&db) + .set_python_version_with_source(&mut db) + .to(PythonVersionWithSource { + version: PythonVersion::latest_preview(), + source: PythonVersionSource::default(), + }); for class in KnownClass::iter() { let class_name = class.name(&db); let class_module = resolve_module(&db, &class.canonical_module(&db).name()).unwrap(); @@ -5124,6 +5143,14 @@ mod tests { }); for class in KnownClass::iter() { + // Until the latest supported version is bumped to Python 3.14 + // we need to skip template strings here. + // The assertion below should remind the developer to + // remove this exception once we _do_ bump `latest_ty` + assert_ne!(PythonVersion::latest_ty(), PythonVersion::PY314); + if matches!(class, KnownClass::Template) { + continue; + } assert_ne!( class.to_instance(&db), Type::unknown(), @@ -5143,6 +5170,7 @@ mod tests { let mut classes: Vec<(KnownClass, PythonVersion)> = KnownClass::iter() .map(|class| { let version_added = match class { + KnownClass::Template => PythonVersion::PY314, KnownClass::UnionType => PythonVersion::PY310, KnownClass::BaseExceptionGroup | KnownClass::ExceptionGroup => { PythonVersion::PY311 diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 97392af811f98..abb032644e778 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -5744,7 +5744,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } } - todo_type!("Template") + KnownClass::Template.to_instance(self.db()) } fn infer_ellipsis_literal_expression( From 8d6dc7d3a3efcf0d88d5588332e6e8f7ee698e94 Mon Sep 17 00:00:00 2001 From: Matthew Mckee Date: Tue, 26 Aug 2025 05:51:31 +0100 Subject: [PATCH 137/160] [ty] Refactor inlay hints structure to use separate parts (#20052) ## Summary Our internal inlay hints structure (`ty_ide::InlayHint`) now more closely resembles `lsp_types::InlayHint`. This mainly allows us to convert to `lsp_types::InlayHint` with less hassle, but it also allows us to manage the different parts of the inlay hint better, which in the future will allow us to implement features like goto on the type part of the type inlay hint. It also really isn't important to store a specific `Type` instance in the `InlayHintContent`. So we remove this and use `InlayHintLabel` instead which just shows the representation of the type (along with other information). We see a similar structure used in rust-analyzer too. --- crates/ty_ide/src/inlay_hints.rs | 149 ++++++++++++------ crates/ty_ide/src/lib.rs | 2 +- .../src/server/api/requests/inlay_hints.rs | 27 +++- crates/ty_server/tests/e2e/inlay_hints.rs | 18 ++- crates/ty_wasm/src/lib.rs | 12 +- 5 files changed, 147 insertions(+), 61 deletions(-) diff --git a/crates/ty_ide/src/inlay_hints.rs b/crates/ty_ide/src/inlay_hints.rs index 1004f5b4d58aa..2ab77f2f1f4b0 100644 --- a/crates/ty_ide/src/inlay_hints.rs +++ b/crates/ty_ide/src/inlay_hints.rs @@ -1,62 +1,128 @@ +use std::{fmt, vec}; + use crate::Db; use ruff_db::files::File; use ruff_db::parsed::parsed_module; use ruff_python_ast::visitor::source_order::{self, SourceOrderVisitor, TraversalSignal}; use ruff_python_ast::{AnyNodeRef, Expr, Stmt}; use ruff_text_size::{Ranged, TextRange, TextSize}; -use std::fmt; -use std::fmt::Formatter; use ty_python_semantic::types::{Type, inlay_hint_function_argument_details}; use ty_python_semantic::{HasType, SemanticModel}; -#[derive(Debug, Clone, Eq, PartialEq)] -pub struct InlayHint<'db> { +#[derive(Debug, Clone)] +pub struct InlayHint { pub position: TextSize, - pub content: InlayHintContent<'db>, + pub kind: InlayHintKind, + pub label: InlayHintLabel, } -impl<'db> InlayHint<'db> { - pub const fn display(&self, db: &'db dyn Db) -> DisplayInlayHint<'_, 'db> { - self.content.display(db) +impl InlayHint { + fn variable_type(position: TextSize, ty: Type, db: &dyn Db) -> Self { + let label_parts = vec![ + ": ".into(), + InlayHintLabelPart::new(ty.display(db).to_string()), + ]; + + Self { + position, + kind: InlayHintKind::Type, + label: InlayHintLabel { parts: label_parts }, + } + } + + fn call_argument_name(position: TextSize, name: &str) -> Self { + let label_parts = vec![InlayHintLabelPart::new(name), "=".into()]; + + Self { + position, + kind: InlayHintKind::CallArgumentName, + label: InlayHintLabel { parts: label_parts }, + } + } + + pub fn display(&self) -> InlayHintDisplay<'_> { + InlayHintDisplay { inlay_hint: self } } } -#[derive(Debug, Clone, Eq, PartialEq)] -pub enum InlayHintContent<'db> { - Type(Type<'db>), - CallArgumentName(String), +#[derive(Debug, Clone)] +pub enum InlayHintKind { + Type, + CallArgumentName, +} + +#[derive(Debug, Clone)] +pub struct InlayHintLabel { + parts: Vec, } -impl<'db> InlayHintContent<'db> { - pub const fn display(&self, db: &'db dyn Db) -> DisplayInlayHint<'_, 'db> { - DisplayInlayHint { db, hint: self } +impl InlayHintLabel { + pub fn parts(&self) -> &[InlayHintLabelPart] { + &self.parts } } -pub struct DisplayInlayHint<'a, 'db> { - db: &'db dyn Db, - hint: &'a InlayHintContent<'db>, +pub struct InlayHintDisplay<'a> { + inlay_hint: &'a InlayHint, } -impl fmt::Display for DisplayInlayHint<'_, '_> { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self.hint { - InlayHintContent::Type(ty) => { - write!(f, ": {}", ty.display(self.db)) - } - InlayHintContent::CallArgumentName(name) => { - write!(f, "{name}=") - } +impl fmt::Display for InlayHintDisplay<'_> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result { + for part in &self.inlay_hint.label.parts { + write!(f, "{}", part.text)?; } + Ok(()) } } -pub fn inlay_hints<'db>( - db: &'db dyn Db, +#[derive(Default, Debug, Clone)] +pub struct InlayHintLabelPart { + text: String, + + target: Option, +} + +impl InlayHintLabelPart { + pub fn new(text: impl Into) -> Self { + Self { + text: text.into(), + target: None, + } + } + + pub fn text(&self) -> &str { + &self.text + } + + pub fn target(&self) -> Option<&crate::NavigationTarget> { + self.target.as_ref() + } +} + +impl From for InlayHintLabelPart { + fn from(s: String) -> Self { + Self { + text: s, + target: None, + } + } +} + +impl From<&str> for InlayHintLabelPart { + fn from(s: &str) -> Self { + Self { + text: s.to_string(), + target: None, + } + } +} + +pub fn inlay_hints( + db: &dyn Db, file: File, range: TextRange, settings: &InlayHintSettings, -) -> Vec> { +) -> Vec { let mut visitor = InlayHintVisitor::new(db, file, range, settings); let ast = parsed_module(db, file).load(db); @@ -106,7 +172,7 @@ impl Default for InlayHintSettings { struct InlayHintVisitor<'a, 'db> { db: &'db dyn Db, model: SemanticModel<'db>, - hints: Vec>, + hints: Vec, in_assignment: bool, range: TextRange, settings: &'a InlayHintSettings, @@ -128,13 +194,11 @@ impl<'a, 'db> InlayHintVisitor<'a, 'db> { if !self.settings.variable_types { return; } - self.hints.push(InlayHint { - position, - content: InlayHintContent::Type(ty), - }); + self.hints + .push(InlayHint::variable_type(position, ty, self.db)); } - fn add_call_argument_name(&mut self, position: TextSize, name: String) { + fn add_call_argument_name(&mut self, position: TextSize, name: &str) { if !self.settings.call_argument_names { return; } @@ -143,10 +207,8 @@ impl<'a, 'db> InlayHintVisitor<'a, 'db> { return; } - self.hints.push(InlayHint { - position, - content: InlayHintContent::CallArgumentName(name), - }); + self.hints + .push(InlayHint::call_argument_name(position, name)); } } @@ -212,10 +274,7 @@ impl SourceOrderVisitor<'_> for InlayHintVisitor<'_, '_> { for (index, arg_or_keyword) in call.arguments.arguments_source_order().enumerate() { if let Some(name) = argument_names.get(&index) { - self.add_call_argument_name( - arg_or_keyword.range().start(), - name.to_string(), - ); + self.add_call_argument_name(arg_or_keyword.range().start(), name); } self.visit_expr(arg_or_keyword.value()); } @@ -322,7 +381,7 @@ mod tests { for hint in hints { let end_position = (hint.position.to_u32() as usize) + offset; - let hint_str = format!("[{}]", hint.display(&self.db)); + let hint_str = format!("[{}]", hint.display()); buf.insert_str(end_position, &hint_str); offset += hint_str.len(); } diff --git a/crates/ty_ide/src/lib.rs b/crates/ty_ide/src/lib.rs index c2567ece0da23..6baea75a8f938 100644 --- a/crates/ty_ide/src/lib.rs +++ b/crates/ty_ide/src/lib.rs @@ -30,7 +30,7 @@ pub use document_symbols::document_symbols; pub use goto::{goto_declaration, goto_definition, goto_type_definition}; pub use goto_references::goto_references; pub use hover::hover; -pub use inlay_hints::{InlayHintContent, InlayHintSettings, inlay_hints}; +pub use inlay_hints::{InlayHintKind, InlayHintLabel, InlayHintSettings, inlay_hints}; pub use markup::MarkupKind; pub use references::ReferencesMode; pub use rename::{can_rename, rename}; diff --git a/crates/ty_server/src/server/api/requests/inlay_hints.rs b/crates/ty_server/src/server/api/requests/inlay_hints.rs index 52a82cd3a2e20..ec8464fc6b187 100644 --- a/crates/ty_server/src/server/api/requests/inlay_hints.rs +++ b/crates/ty_server/src/server/api/requests/inlay_hints.rs @@ -9,7 +9,7 @@ use crate::session::client::Client; use lsp_types::request::InlayHintRequest; use lsp_types::{InlayHintParams, Url}; use ruff_db::source::{line_index, source_text}; -use ty_ide::{InlayHintContent, inlay_hints}; +use ty_ide::{InlayHintKind, InlayHintLabel, inlay_hints}; use ty_project::ProjectDatabase; pub(crate) struct InlayHintRequestHandler; @@ -55,8 +55,8 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler { position: hint .position .to_position(&source, &index, snapshot.encoding()), - label: lsp_types::InlayHintLabel::String(hint.display(db).to_string()), - kind: Some(inlay_hint_kind(&hint.content)), + label: inlay_hint_label(&hint.label), + kind: Some(inlay_hint_kind(&hint.kind)), tooltip: None, padding_left: None, padding_right: None, @@ -71,9 +71,22 @@ impl BackgroundDocumentRequestHandler for InlayHintRequestHandler { impl RetriableRequestHandler for InlayHintRequestHandler {} -fn inlay_hint_kind(inlay_hint_content: &InlayHintContent) -> lsp_types::InlayHintKind { - match inlay_hint_content { - InlayHintContent::Type(_) => lsp_types::InlayHintKind::TYPE, - InlayHintContent::CallArgumentName(_) => lsp_types::InlayHintKind::PARAMETER, +fn inlay_hint_kind(inlay_hint_kind: &InlayHintKind) -> lsp_types::InlayHintKind { + match inlay_hint_kind { + InlayHintKind::Type => lsp_types::InlayHintKind::TYPE, + InlayHintKind::CallArgumentName => lsp_types::InlayHintKind::PARAMETER, } } + +fn inlay_hint_label(inlay_hint_label: &InlayHintLabel) -> lsp_types::InlayHintLabel { + let mut label_parts = Vec::new(); + for part in inlay_hint_label.parts() { + label_parts.push(lsp_types::InlayHintLabelPart { + value: part.text().into(), + location: None, + tooltip: None, + command: None, + }); + } + lsp_types::InlayHintLabel::LabelParts(label_parts) +} diff --git a/crates/ty_server/tests/e2e/inlay_hints.rs b/crates/ty_server/tests/e2e/inlay_hints.rs index 324c4f1fc62e8..3dbbbee994e23 100644 --- a/crates/ty_server/tests/e2e/inlay_hints.rs +++ b/crates/ty_server/tests/e2e/inlay_hints.rs @@ -42,7 +42,14 @@ foo(1) "line": 0, "character": 1 }, - "label": ": Literal[1]", + "label": [ + { + "value": ": " + }, + { + "value": "Literal[1]" + } + ], "kind": 1 }, { @@ -50,7 +57,14 @@ foo(1) "line": 5, "character": 4 }, - "label": "a=", + "label": [ + { + "value": "a" + }, + { + "value": "=" + } + ], "kind": 2 } ] diff --git a/crates/ty_wasm/src/lib.rs b/crates/ty_wasm/src/lib.rs index 7b2c970ea359d..8722afcbe797c 100644 --- a/crates/ty_wasm/src/lib.rs +++ b/crates/ty_wasm/src/lib.rs @@ -449,14 +449,14 @@ impl Workspace { Ok(result .into_iter() .map(|hint| InlayHint { - markdown: hint.display(&self.db).to_string(), + markdown: hint.display().to_string(), position: Position::from_text_size( hint.position, &index, &source, self.position_encoding, ), - kind: hint.content.into(), + kind: hint.kind.into(), }) .collect()) } @@ -988,11 +988,11 @@ pub enum InlayHintKind { Parameter, } -impl From> for InlayHintKind { - fn from(kind: ty_ide::InlayHintContent) -> Self { +impl From for InlayHintKind { + fn from(kind: ty_ide::InlayHintKind) -> Self { match kind { - ty_ide::InlayHintContent::Type(_) => Self::Type, - ty_ide::InlayHintContent::CallArgumentName(_) => Self::Parameter, + ty_ide::InlayHintKind::Type => Self::Type, + ty_ide::InlayHintKind::CallArgumentName => Self::Parameter, } } } From 911d5cc973b67677c100215e16f16cd806ad3eb2 Mon Sep 17 00:00:00 2001 From: Avasam Date: Tue, 26 Aug 2025 00:54:58 -0400 Subject: [PATCH 138/160] Fix incorrect D413 links in docstrings convention FAQ (#20089) ## Summary D413 in this section was incorrectly linking to D410. I haven't checked if this issue happens anywhere else in the docs. ## Test Plan Look at docs --- docs/faq.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/faq.md b/docs/faq.md index 6ed942e1f3b84..c4b358b092492 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -560,7 +560,7 @@ The PEP 257 convention includes all `D` errors apart from: [`D409`](rules/mismatched-section-underline-length.md), [`D410`](rules/no-blank-line-after-section.md), [`D411`](rules/no-blank-line-before-section.md), -[`D413`](rules/no-blank-line-after-section.md), +[`D413`](rules/missing-blank-line-after-last-section.md), [`D415`](rules/missing-terminal-punctuation.md), [`D416`](rules/missing-section-name-colon.md), and [`D417`](rules/undocumented-param.md). @@ -571,7 +571,7 @@ The NumPy convention includes all `D` errors apart from: [`D212`](rules/multi-line-summary-first-line.md), [`D213`](rules/multi-line-summary-second-line.md), [`D402`](rules/signature-in-docstring.md), -[`D413`](rules/no-blank-line-after-section.md), +[`D413`](rules/missing-blank-line-after-last-section.md), [`D415`](rules/missing-terminal-punctuation.md), [`D416`](rules/missing-section-name-colon.md), and [`D417`](rules/undocumented-param.md). @@ -588,7 +588,7 @@ The Google convention includes all `D` errors apart from: [`D407`](rules/missing-dashed-underline-after-section.md), [`D408`](rules/missing-section-underline-after-name.md), [`D409`](rules/mismatched-section-underline-length.md), and -[`D413`](rules/no-blank-line-after-section.md). +[`D413`](rules/missing-blank-line-after-last-section.md). By default, no [`convention`](settings.md#lint_pydocstyle_convention) is set, and so the enabled rules are determined by the [`select`](settings.md#lint_select) setting alone. From bc7274d1481c0d223a1cf8dc297740b4b3467315 Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Tue, 26 Aug 2025 09:49:08 -0400 Subject: [PATCH 139/160] Add a `ScopeKind` for the `__class__` cell (#20048) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary -- This PR aims to resolve (or help to resolve) #18442 and #19357 by encoding the CPython semantics around the `__class__` cell in our semantic model. Namely, > `__class__` is an implicit closure reference created by the compiler if any methods in a class body refer to either `__class__` or super. from the Python [docs](https://docs.python.org/3/reference/datamodel.html#creating-the-class-object). As noted in the variant docs by @AlexWaygood, we don't fully model this behavior, opting always to create the `__class__` cell binding in a new `ScopeKind::DunderClassCell` around each method definition, without checking if any method in the class body actually refers to `__class__` or `super`. As such, this PR fixes #18442 but not #19357. Test Plan -- Existing tests, plus the tests from #19783, which now pass without any rule-specific code. Note that we opted not to alter the behavior of F841 here because flagging `__class__` in these cases still seems helpful. See the discussion in https://github.com/astral-sh/ruff/pull/20048#discussion_r2296252395 and in the test comments for more information. --------- Co-authored-by: Alex Waygood Co-authored-by: Mikko Leppänen --- .../test/fixtures/pyflakes/F841_0.py | 36 +++++++++++ .../pylint/nonlocal_without_binding.py | 5 ++ crates/ruff_linter/src/checkers/ast/mod.rs | 33 +++++++++- crates/ruff_linter/src/renamer.rs | 5 +- crates/ruff_linter/src/rules/pyflakes/mod.rs | 1 + ...ules__pyflakes__tests__F841_F841_0.py.snap | 60 ++++++++++++++++++ ...lakes__tests__f841_dummy_variable_rgx.snap | 62 +++++++++++++++++++ .../src/rules/pylint/rules/non_ascii_name.rs | 3 +- crates/ruff_python_semantic/src/binding.rs | 20 +++++- crates/ruff_python_semantic/src/model.rs | 57 ++++++++--------- crates/ruff_python_semantic/src/scope.rs | 42 ++++++++++++- 11 files changed, 287 insertions(+), 37 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_0.py b/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_0.py index bde71536966f4..52dd297a0e078 100644 --- a/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_0.py +++ b/crates/ruff_linter/resources/test/fixtures/pyflakes/F841_0.py @@ -151,3 +151,39 @@ def f(): pass except Exception as _: pass + + +# OK, `__class__` in this case is not the special `__class__` cell, so we don't +# emit a diagnostic. (It has its own special semantics -- see +# https://github.com/astral-sh/ruff/pull/20048#discussion_r2298338048 -- but +# those aren't relevant here.) +class A: + __class__ = 1 + + +# The following three cases are flagged because they declare local `__class__` +# variables that don't refer to the special `__class__` cell. +class A: + def set_class(self, cls): + __class__ = cls # F841 + + +class A: + class B: + def set_class(self, cls): + __class__ = cls # F841 + + +class A: + def foo(): + class B: + print(__class__) + def set_class(self, cls): + __class__ = cls # F841 + + +# OK, the `__class__` cell is nonlocal and declared as such. +class NonlocalDunderClass: + def foo(): + nonlocal __class__ + __class__ = 1 diff --git a/crates/ruff_linter/resources/test/fixtures/pylint/nonlocal_without_binding.py b/crates/ruff_linter/resources/test/fixtures/pylint/nonlocal_without_binding.py index 154ee23bec74a..4a45556a778d8 100644 --- a/crates/ruff_linter/resources/test/fixtures/pylint/nonlocal_without_binding.py +++ b/crates/ruff_linter/resources/test/fixtures/pylint/nonlocal_without_binding.py @@ -44,3 +44,8 @@ def f(): def g(): nonlocal x x = 2 + +# OK +class A: + def method(self): + nonlocal __class__ diff --git a/crates/ruff_linter/src/checkers/ast/mod.rs b/crates/ruff_linter/src/checkers/ast/mod.rs index 1437b1655dd0c..906fe2491b3a6 100644 --- a/crates/ruff_linter/src/checkers/ast/mod.rs +++ b/crates/ruff_linter/src/checkers/ast/mod.rs @@ -703,7 +703,10 @@ impl SemanticSyntaxContext for Checker<'_> { match scope.kind { ScopeKind::Class(_) | ScopeKind::Lambda(_) => return false, ScopeKind::Function(ast::StmtFunctionDef { is_async, .. }) => return *is_async, - ScopeKind::Generator { .. } | ScopeKind::Module | ScopeKind::Type => {} + ScopeKind::Generator { .. } + | ScopeKind::Module + | ScopeKind::Type + | ScopeKind::DunderClassCell => {} } } false @@ -714,7 +717,10 @@ impl SemanticSyntaxContext for Checker<'_> { match scope.kind { ScopeKind::Class(_) => return false, ScopeKind::Function(_) | ScopeKind::Lambda(_) => return true, - ScopeKind::Generator { .. } | ScopeKind::Module | ScopeKind::Type => {} + ScopeKind::Generator { .. } + | ScopeKind::Module + | ScopeKind::Type + | ScopeKind::DunderClassCell => {} } } false @@ -725,7 +731,7 @@ impl SemanticSyntaxContext for Checker<'_> { match scope.kind { ScopeKind::Class(_) | ScopeKind::Generator { .. } => return false, ScopeKind::Function(_) | ScopeKind::Lambda(_) => return true, - ScopeKind::Module | ScopeKind::Type => {} + ScopeKind::Module | ScopeKind::Type | ScopeKind::DunderClassCell => {} } } false @@ -1092,6 +1098,24 @@ impl<'a> Visitor<'a> for Checker<'a> { } } + // Here we add the implicit scope surrounding a method which allows code in the + // method to access `__class__` at runtime. See the `ScopeKind::DunderClassCell` + // docs for more information. + let added_dunder_class_scope = if self.semantic.current_scope().kind.is_class() { + self.semantic.push_scope(ScopeKind::DunderClassCell); + let binding_id = self.semantic.push_binding( + TextRange::default(), + BindingKind::DunderClassCell, + BindingFlags::empty(), + ); + self.semantic + .current_scope_mut() + .add("__class__", binding_id); + true + } else { + false + }; + self.semantic.push_scope(ScopeKind::Type); if let Some(type_params) = type_params { @@ -1155,6 +1179,9 @@ impl<'a> Visitor<'a> for Checker<'a> { self.semantic.pop_scope(); // Function scope self.semantic.pop_definition(); self.semantic.pop_scope(); // Type parameter scope + if added_dunder_class_scope { + self.semantic.pop_scope(); // `__class__` cell closure scope + } self.add_binding( name, stmt.identifier(), diff --git a/crates/ruff_linter/src/renamer.rs b/crates/ruff_linter/src/renamer.rs index d31793dc746e5..d4c587142dbeb 100644 --- a/crates/ruff_linter/src/renamer.rs +++ b/crates/ruff_linter/src/renamer.rs @@ -354,7 +354,10 @@ impl Renamer { )) } // Avoid renaming builtins and other "special" bindings. - BindingKind::FutureImport | BindingKind::Builtin | BindingKind::Export(_) => None, + BindingKind::FutureImport + | BindingKind::Builtin + | BindingKind::Export(_) + | BindingKind::DunderClassCell => None, // By default, replace the binding's name with the target name. BindingKind::Annotation | BindingKind::Argument diff --git a/crates/ruff_linter/src/rules/pyflakes/mod.rs b/crates/ruff_linter/src/rules/pyflakes/mod.rs index 2aa8104d6b4f6..12b7d5ce86424 100644 --- a/crates/ruff_linter/src/rules/pyflakes/mod.rs +++ b/crates/ruff_linter/src/rules/pyflakes/mod.rs @@ -737,6 +737,7 @@ mod tests { /// A re-implementation of the Pyflakes test runner. /// Note that all tests marked with `#[ignore]` should be considered TODOs. + #[track_caller] fn flakes(contents: &str, expected: &[Rule]) { let contents = dedent(contents); let source_type = PySourceType::default(); diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F841_F841_0.py.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F841_F841_0.py.snap index 2361f61f36c78..b03ac3b0dd576 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F841_F841_0.py.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__F841_F841_0.py.snap @@ -251,3 +251,63 @@ F841 Local variable `value` is assigned to but never used 128 | print(key) | help: Remove assignment to unused variable `value` + +F841 [*] Local variable `__class__` is assigned to but never used + --> F841_0.py:168:9 + | +166 | class A: +167 | def set_class(self, cls): +168 | __class__ = cls # F841 + | ^^^^^^^^^ + | +help: Remove assignment to unused variable `__class__` + +ℹ Unsafe fix +165 165 | # variables that don't refer to the special `__class__` cell. +166 166 | class A: +167 167 | def set_class(self, cls): +168 |- __class__ = cls # F841 + 168 |+ pass # F841 +169 169 | +170 170 | +171 171 | class A: + +F841 [*] Local variable `__class__` is assigned to but never used + --> F841_0.py:174:13 + | +172 | class B: +173 | def set_class(self, cls): +174 | __class__ = cls # F841 + | ^^^^^^^^^ + | +help: Remove assignment to unused variable `__class__` + +ℹ Unsafe fix +171 171 | class A: +172 172 | class B: +173 173 | def set_class(self, cls): +174 |- __class__ = cls # F841 + 174 |+ pass # F841 +175 175 | +176 176 | +177 177 | class A: + +F841 [*] Local variable `__class__` is assigned to but never used + --> F841_0.py:182:17 + | +180 | print(__class__) +181 | def set_class(self, cls): +182 | __class__ = cls # F841 + | ^^^^^^^^^ + | +help: Remove assignment to unused variable `__class__` + +ℹ Unsafe fix +179 179 | class B: +180 180 | print(__class__) +181 181 | def set_class(self, cls): +182 |- __class__ = cls # F841 + 182 |+ pass # F841 +183 183 | +184 184 | +185 185 | # OK, the `__class__` cell is nonlocal and declared as such. diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f841_dummy_variable_rgx.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f841_dummy_variable_rgx.snap index 747f7ba421756..7caaa6ef15184 100644 --- a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f841_dummy_variable_rgx.snap +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f841_dummy_variable_rgx.snap @@ -289,3 +289,65 @@ help: Remove assignment to unused variable `_` 152 |- except Exception as _: 152 |+ except Exception: 153 153 | pass +154 154 | +155 155 | + +F841 [*] Local variable `__class__` is assigned to but never used + --> F841_0.py:168:9 + | +166 | class A: +167 | def set_class(self, cls): +168 | __class__ = cls # F841 + | ^^^^^^^^^ + | +help: Remove assignment to unused variable `__class__` + +ℹ Unsafe fix +165 165 | # variables that don't refer to the special `__class__` cell. +166 166 | class A: +167 167 | def set_class(self, cls): +168 |- __class__ = cls # F841 + 168 |+ pass # F841 +169 169 | +170 170 | +171 171 | class A: + +F841 [*] Local variable `__class__` is assigned to but never used + --> F841_0.py:174:13 + | +172 | class B: +173 | def set_class(self, cls): +174 | __class__ = cls # F841 + | ^^^^^^^^^ + | +help: Remove assignment to unused variable `__class__` + +ℹ Unsafe fix +171 171 | class A: +172 172 | class B: +173 173 | def set_class(self, cls): +174 |- __class__ = cls # F841 + 174 |+ pass # F841 +175 175 | +176 176 | +177 177 | class A: + +F841 [*] Local variable `__class__` is assigned to but never used + --> F841_0.py:182:17 + | +180 | print(__class__) +181 | def set_class(self, cls): +182 | __class__ = cls # F841 + | ^^^^^^^^^ + | +help: Remove assignment to unused variable `__class__` + +ℹ Unsafe fix +179 179 | class B: +180 180 | print(__class__) +181 181 | def set_class(self, cls): +182 |- __class__ = cls # F841 + 182 |+ pass # F841 +183 183 | +184 184 | +185 185 | # OK, the `__class__` cell is nonlocal and declared as such. diff --git a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs index 2458f418a4b16..6d66ac2345094 100644 --- a/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs +++ b/crates/ruff_linter/src/rules/pylint/rules/non_ascii_name.rs @@ -73,7 +73,8 @@ pub(crate) fn non_ascii_name(checker: &Checker, binding: &Binding) { | BindingKind::SubmoduleImport(_) | BindingKind::Deletion | BindingKind::ConditionalDeletion(_) - | BindingKind::UnboundException(_) => { + | BindingKind::UnboundException(_) + | BindingKind::DunderClassCell => { return; } }; diff --git a/crates/ruff_python_semantic/src/binding.rs b/crates/ruff_python_semantic/src/binding.rs index e762d5d95cd16..9254a5b528560 100644 --- a/crates/ruff_python_semantic/src/binding.rs +++ b/crates/ruff_python_semantic/src/binding.rs @@ -446,7 +446,7 @@ impl Ranged for Binding<'_> { /// ID uniquely identifying a [Binding] in a program. /// /// Using a `u32` to identify [Binding]s should be sufficient because Ruff only supports documents with a -/// size smaller than or equal to `u32::max`. A document with the size of `u32::max` must have fewer than `u32::max` +/// size smaller than or equal to `u32::MAX`. A document with the size of `u32::MAX` must have fewer than `u32::MAX` /// bindings because bindings must be separated by whitespace (and have an assignment). #[newtype_index] pub struct BindingId; @@ -672,6 +672,24 @@ pub enum BindingKind<'a> { /// Stores the ID of the binding that was shadowed in the enclosing /// scope, if any. UnboundException(Option), + + /// A binding to `__class__` in the implicit closure created around every method in a class + /// body, if any method refers to either `__class__` or `super`. + /// + /// ```python + /// class C: + /// __class__ # NameError: name '__class__' is not defined + /// + /// def f(): + /// print(__class__) # allowed + /// + /// def g(): + /// nonlocal __class__ # also allowed because the scope is *not* the function scope + /// ``` + /// + /// See for more + /// details. + DunderClassCell, } bitflags! { diff --git a/crates/ruff_python_semantic/src/model.rs b/crates/ruff_python_semantic/src/model.rs index 3d8d39febe938..16d57622cc8bd 100644 --- a/crates/ruff_python_semantic/src/model.rs +++ b/crates/ruff_python_semantic/src/model.rs @@ -404,22 +404,11 @@ impl<'a> SemanticModel<'a> { } } - let mut seen_function = false; let mut import_starred = false; let mut class_variables_visible = true; for (index, scope_id) in self.scopes.ancestor_ids(self.scope_id).enumerate() { let scope = &self.scopes[scope_id]; if scope.kind.is_class() { - // Allow usages of `__class__` within methods, e.g.: - // - // ```python - // class Foo: - // def __init__(self): - // print(__class__) - // ``` - if seen_function && matches!(name.id.as_str(), "__class__") { - return ReadResult::ImplicitGlobal; - } // Do not allow usages of class symbols unless it is the immediate parent // (excluding type scopes), e.g.: // @@ -442,7 +431,13 @@ impl<'a> SemanticModel<'a> { // Allow class variables to be visible for an additional scope level // when a type scope is seen — this covers the type scope present between // function and class definitions and their parent class scope. - class_variables_visible = scope.kind.is_type() && index == 0; + // + // Also allow an additional level beyond that to cover the implicit + // `__class__` closure created around methods and enclosing the type scope. + class_variables_visible = matches!( + (scope.kind, index), + (ScopeKind::Type, 0) | (ScopeKind::DunderClassCell, 1) + ); if let Some(binding_id) = scope.get(name.id.as_str()) { // Mark the binding as used. @@ -614,7 +609,6 @@ impl<'a> SemanticModel<'a> { } } - seen_function |= scope.kind.is_function(); import_starred = import_starred || scope.uses_star_imports(); } @@ -658,21 +652,19 @@ impl<'a> SemanticModel<'a> { } } - let mut seen_function = false; let mut class_variables_visible = true; for (index, scope_id) in self.scopes.ancestor_ids(scope_id).enumerate() { let scope = &self.scopes[scope_id]; if scope.kind.is_class() { - if seen_function && matches!(symbol, "__class__") { - return None; - } if !class_variables_visible { continue; } } - class_variables_visible = scope.kind.is_type() && index == 0; - seen_function |= scope.kind.is_function(); + class_variables_visible = matches!( + (scope.kind, index), + (ScopeKind::Type, 0) | (ScopeKind::DunderClassCell, 1) + ); if let Some(binding_id) = scope.get(symbol) { match self.bindings[binding_id].kind { @@ -786,15 +778,15 @@ impl<'a> SemanticModel<'a> { } if scope.kind.is_class() { - if seen_function && matches!(symbol, "__class__") { - return None; - } if !class_variables_visible { continue; } } - class_variables_visible = scope.kind.is_type() && index == 0; + class_variables_visible = matches!( + (scope.kind, index), + (ScopeKind::Type, 0) | (ScopeKind::DunderClassCell, 1) + ); seen_function |= scope.kind.is_function(); if let Some(binding_id) = scope.get(symbol) { @@ -1353,11 +1345,12 @@ impl<'a> SemanticModel<'a> { self.scopes[scope_id].parent } - /// Returns the first parent of the given [`Scope`] that is not of [`ScopeKind::Type`], if any. + /// Returns the first parent of the given [`Scope`] that is not of [`ScopeKind::Type`] or + /// [`ScopeKind::DunderClassCell`], if any. pub fn first_non_type_parent_scope(&self, scope: &Scope) -> Option<&Scope<'a>> { let mut current_scope = scope; while let Some(parent) = self.parent_scope(current_scope) { - if parent.kind.is_type() { + if matches!(parent.kind, ScopeKind::Type | ScopeKind::DunderClassCell) { current_scope = parent; } else { return Some(parent); @@ -1366,11 +1359,15 @@ impl<'a> SemanticModel<'a> { None } - /// Returns the first parent of the given [`ScopeId`] that is not of [`ScopeKind::Type`], if any. + /// Returns the first parent of the given [`ScopeId`] that is not of [`ScopeKind::Type`] or + /// [`ScopeKind::DunderClassCell`], if any. pub fn first_non_type_parent_scope_id(&self, scope_id: ScopeId) -> Option { let mut current_scope_id = scope_id; while let Some(parent_id) = self.parent_scope_id(current_scope_id) { - if self.scopes[parent_id].kind.is_type() { + if matches!( + self.scopes[parent_id].kind, + ScopeKind::Type | ScopeKind::DunderClassCell + ) { current_scope_id = parent_id; } else { return Some(parent_id); @@ -2649,16 +2646,16 @@ pub enum ReadResult { /// The `x` in `print(x)` is resolved to the binding of `x` in `x = 1`. Resolved(BindingId), - /// The read reference is resolved to a context-specific, implicit global (e.g., `__class__` + /// The read reference is resolved to a context-specific, implicit global (e.g., `__qualname__` /// within a class scope). /// /// For example, given: /// ```python /// class C: - /// print(__class__) + /// print(__qualname__) /// ``` /// - /// The `__class__` in `print(__class__)` is resolved to the implicit global `__class__`. + /// The `__qualname__` in `print(__qualname__)` is resolved to the implicit global `__qualname__`. ImplicitGlobal, /// The read reference is unresolved, but at least one of the containing scopes contains a diff --git a/crates/ruff_python_semantic/src/scope.rs b/crates/ruff_python_semantic/src/scope.rs index 0ac31f26cc5e8..f44ac019a53c4 100644 --- a/crates/ruff_python_semantic/src/scope.rs +++ b/crates/ruff_python_semantic/src/scope.rs @@ -166,9 +166,49 @@ bitflags! { } } -#[derive(Debug, is_macro::Is)] +#[derive(Clone, Copy, Debug, is_macro::Is)] pub enum ScopeKind<'a> { Class(&'a ast::StmtClassDef), + /// The implicit `__class__` scope surrounding a method which allows code in the + /// method to access `__class__` at runtime. The closure sits in between the class + /// scope and the function scope. + /// + /// Parameter defaults in methods cannot access `__class__`: + /// + /// ```pycon + /// >>> class Bar: + /// ... def method(self, x=__class__): ... + /// ... + /// Traceback (most recent call last): + /// File "", line 1, in + /// class Bar: + /// def method(self, x=__class__): ... + /// File "", line 2, in Bar + /// def method(self, x=__class__): ... + /// ^^^^^^^^^ + /// NameError: name '__class__' is not defined + /// ``` + /// + /// However, type parameters in methods *can* access `__class__`: + /// + /// ```pycon + /// >>> class Foo: + /// ... def bar[T: __class__](): ... + /// ... + /// >>> Foo.bar.__type_params__[0].__bound__ + /// + /// ``` + /// + /// Note that this is still not 100% accurate! At runtime, the implicit `__class__` + /// closure is only added if the name `super` (has to be a name -- `builtins.super` + /// and similar don't count!) or the name `__class__` is used in any method of the + /// class. However, accurately emulating that would be both complex and probably + /// quite expensive unless we moved to a double-traversal of each scope similar to + /// ty. It would also only matter in extreme and unlikely edge cases. So we ignore + /// that subtlety for now. + /// + /// See . + DunderClassCell, Function(&'a ast::StmtFunctionDef), Generator { kind: GeneratorKind, From 136abace9241ebf42afb70e60ee760361b13e2d0 Mon Sep 17 00:00:00 2001 From: Hamir Mahal Date: Tue, 26 Aug 2025 07:51:24 -0700 Subject: [PATCH 140/160] [`flake8-logging-format`] Add auto-fix for f-string logging calls (`G004`) (#19303) Closes #19302 ## Summary This adds an auto-fix for `Logging statement uses f-string` Ruff G004, so users don't have to resolve it manually. ## Test Plan I ran the auto-fixes on a Python file locally and and it worked as expected. --------- Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com> --- .../fixtures/flake8_logging_format/G004.py | 47 +++ .../flake8_logging_format/G004_arg_order.py | 10 + crates/ruff_linter/src/preview.rs | 5 + .../src/rules/flake8_logging_format/mod.rs | 21 ++ .../rules/logging_call.rs | 95 +++++- ...flake8_logging_format__tests__G004.py.snap | 158 ++++++++++ ...ging_format__tests__G004_arg_order.py.snap | 23 ++ ..._format__tests__preview__G004_G004.py.snap | 291 ++++++++++++++++++ ...ests__preview__G004_G004_arg_order.py.snap | 23 ++ .../rules/flake8_logging_format/violations.rs | 6 + 10 files changed, 674 insertions(+), 5 deletions(-) create mode 100644 crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004_arg_order.py create mode 100644 crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004_arg_order.py.snap create mode 100644 crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004.py.snap create mode 100644 crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004_arg_order.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004.py b/crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004.py index da05aba630efd..fcfa953a329f9 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004.py @@ -17,3 +17,50 @@ # Don't trigger for t-strings info(t"{name}") info(t"{__name__}") + +count = 5 +total = 9 +directory_path = "/home/hamir/ruff/crates/ruff_linter/resources/test/" +logging.info(f"{count} out of {total} files in {directory_path} checked") + + + +x = 99 +fmt = "08d" +logger.info(f"{x:{'08d'}}") +logger.info(f"{x:>10} {x:{fmt}}") + +logging.info(f"") +logging.info(f"This message doesn't have any variables.") + +obj = {"key": "value"} +logging.info(f"Object: {obj!r}") + +items_count = 3 +logging.warning(f"Items: {items_count:d}") + +data = {"status": "active"} +logging.info(f"Processing {len(data)} items") +logging.info(f"Status: {data.get('status', 'unknown').upper()}") + + +result = 123 +logging.info(f"Calculated result: {result + 100}") + +temperature = 123 +logging.info(f"Temperature: {temperature:.1f}°C") + +class FilePath: + def __init__(self, name: str): + self.name = name + +logging.info(f"No changes made to {file_path.name}.") + +user = "tron" +balance = 123.45 +logging.error(f"Error {404}: User {user} has insufficient balance ${balance:.2f}") + +import logging + +x = 1 +logging.error(f"{x} -> %s", x) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004_arg_order.py b/crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004_arg_order.py new file mode 100644 index 0000000000000..44c370bd3d3b8 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/flake8_logging_format/G004_arg_order.py @@ -0,0 +1,10 @@ +"""Test f-string argument order.""" + +import logging + +logger = logging.getLogger(__name__) + +X = 1 +Y = 2 +logger.error(f"{X} -> %s", Y) +logger.error(f"{Y} -> %s", X) diff --git a/crates/ruff_linter/src/preview.rs b/crates/ruff_linter/src/preview.rs index b7d3b5df7abce..6b6a4d15e5e7f 100644 --- a/crates/ruff_linter/src/preview.rs +++ b/crates/ruff_linter/src/preview.rs @@ -40,6 +40,11 @@ pub(crate) const fn is_bad_version_info_in_non_stub_enabled(settings: &LinterSet settings.preview.is_enabled() } +/// +pub(crate) const fn is_fix_f_string_logging_enabled(settings: &LinterSettings) -> bool { + settings.preview.is_enabled() +} + // https://github.com/astral-sh/ruff/pull/16719 pub(crate) const fn is_fix_manual_dict_comprehension_enabled(settings: &LinterSettings) -> bool { settings.preview.is_enabled() diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs b/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs index 1dc2b536a629f..cea8ce78e803a 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/mod.rs @@ -22,6 +22,7 @@ mod tests { #[test_case(Path::new("G002.py"))] #[test_case(Path::new("G003.py"))] #[test_case(Path::new("G004.py"))] + #[test_case(Path::new("G004_arg_order.py"))] #[test_case(Path::new("G010.py"))] #[test_case(Path::new("G101_1.py"))] #[test_case(Path::new("G101_2.py"))] @@ -48,4 +49,24 @@ mod tests { assert_diagnostics!(snapshot, diagnostics); Ok(()) } + + #[test_case(Rule::LoggingFString, Path::new("G004.py"))] + #[test_case(Rule::LoggingFString, Path::new("G004_arg_order.py"))] + fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { + let snapshot = format!( + "preview__{}_{}", + rule_code.noqa_code(), + path.to_string_lossy() + ); + let diagnostics = test_path( + Path::new("flake8_logging_format").join(path).as_path(), + &settings::LinterSettings { + logger_objects: vec!["logging_setup.logger".to_string()], + preview: settings::types::PreviewMode::Enabled, + ..settings::LinterSettings::for_rule(rule_code) + }, + )?; + assert_diagnostics!(snapshot, diagnostics); + Ok(()) + } } diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs index 33727411543c2..e87cf3a38db3d 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/rules/logging_call.rs @@ -1,9 +1,11 @@ -use ruff_python_ast::{self as ast, Arguments, Expr, Keyword, Operator}; +use ruff_python_ast::InterpolatedStringElement; +use ruff_python_ast::{self as ast, Arguments, Expr, Keyword, Operator, StringFlags}; use ruff_python_semantic::analyze::logging; use ruff_python_stdlib::logging::LoggingLevel; use ruff_text_size::Ranged; use crate::checkers::ast::Checker; +use crate::preview::is_fix_f_string_logging_enabled; use crate::registry::Rule; use crate::rules::flake8_logging_format::violations::{ LoggingExcInfo, LoggingExtraAttrClash, LoggingFString, LoggingPercentFormat, @@ -11,6 +13,87 @@ use crate::rules::flake8_logging_format::violations::{ }; use crate::{Edit, Fix}; +fn logging_f_string( + checker: &Checker, + msg: &Expr, + f_string: &ast::ExprFString, + arguments: &Arguments, + msg_pos: usize, +) { + // Report the diagnostic up-front so we can attach a fix later only when preview is enabled. + let mut diagnostic = checker.report_diagnostic(LoggingFString, msg.range()); + + // Preview gate for the automatic fix. + if !is_fix_f_string_logging_enabled(checker.settings()) { + return; + } + + // If there are existing positional arguments after the message, bail out. + // This could indicate a mistake or complex usage we shouldn't try to fix. + if arguments.args.len() > msg_pos + 1 { + return; + } + + let mut format_string = String::new(); + let mut args: Vec<&str> = Vec::new(); + + // Try to reuse the first part's quote style when building the replacement. + // Default to double quotes if we can't determine it. + let quote_str = f_string + .value + .f_strings() + .next() + .map(|f| f.flags.quote_str()) + .unwrap_or("\""); + + for f in f_string.value.f_strings() { + for element in &f.elements { + match element { + InterpolatedStringElement::Literal(lit) => { + // If the literal text contains a '%' placeholder, bail out: mixing + // f-string interpolation with '%' placeholders is ambiguous for our + // automatic conversion, so don't offer a fix for this case. + if lit.value.as_ref().contains('%') { + return; + } + format_string.push_str(lit.value.as_ref()); + } + InterpolatedStringElement::Interpolation(interpolated) => { + if interpolated.format_spec.is_some() + || !matches!( + interpolated.conversion, + ruff_python_ast::ConversionFlag::None + ) + { + return; + } + match interpolated.expression.as_ref() { + Expr::Name(name) => { + format_string.push_str("%s"); + args.push(name.id.as_str()); + } + _ => return, + } + } + } + } + } + + if args.is_empty() { + return; + } + + let replacement = format!( + "{q}{format_string}{q}, {args}", + q = quote_str, + format_string = format_string, + args = args.join(", ") + ); + + let fix = Fix::safe_edit(Edit::range_replacement(replacement, msg.range())); + diagnostic.set_fix(fix); +} + /// Returns `true` if the attribute is a reserved attribute on the `logging` module's `LogRecord` /// class. fn is_reserved_attr(attr: &str) -> bool { @@ -42,7 +125,7 @@ fn is_reserved_attr(attr: &str) -> bool { } /// Check logging messages for violations. -fn check_msg(checker: &Checker, msg: &Expr) { +fn check_msg(checker: &Checker, msg: &Expr, arguments: &Arguments, msg_pos: usize) { match msg { // Check for string concatenation and percent format. Expr::BinOp(ast::ExprBinOp { op, .. }) => match op { @@ -55,8 +138,10 @@ fn check_msg(checker: &Checker, msg: &Expr) { _ => {} }, // Check for f-strings. - Expr::FString(_) => { - checker.report_diagnostic_if_enabled(LoggingFString, msg.range()); + Expr::FString(f_string) => { + if checker.is_rule_enabled(Rule::LoggingFString) { + logging_f_string(checker, msg, f_string, arguments, msg_pos); + } } // Check for .format() calls. Expr::Call(ast::ExprCall { func, .. }) => { @@ -168,7 +253,7 @@ pub(crate) fn logging_call(checker: &Checker, call: &ast::ExprCall) { // G001, G002, G003, G004 let msg_pos = usize::from(matches!(logging_call_type, LoggingCallType::LogCall)); if let Some(format_arg) = call.arguments.find_argument_value("msg", msg_pos) { - check_msg(checker, format_arg); + check_msg(checker, format_arg, &call.arguments, msg_pos); } // G010 diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004.py.snap b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004.py.snap index 10a31007b8a1a..f02d019ad5a50 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004.py.snap +++ b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004.py.snap @@ -9,6 +9,7 @@ G004 Logging statement uses f-string | ^^^^^^^^^^^^^^^ 5 | logging.log(logging.INFO, f"Hello {name}") | +help: Convert to lazy `%` formatting G004 Logging statement uses f-string --> G004.py:5:27 @@ -20,6 +21,7 @@ G004 Logging statement uses f-string 6 | 7 | _LOGGER = logging.getLogger() | +help: Convert to lazy `%` formatting G004 Logging statement uses f-string --> G004.py:8:14 @@ -30,6 +32,7 @@ G004 Logging statement uses f-string 9 | 10 | logging.getLogger().info(f"{name}") | +help: Convert to lazy `%` formatting G004 Logging statement uses f-string --> G004.py:10:26 @@ -41,6 +44,7 @@ G004 Logging statement uses f-string 11 | 12 | from logging import info | +help: Convert to lazy `%` formatting G004 Logging statement uses f-string --> G004.py:14:6 @@ -51,6 +55,7 @@ G004 Logging statement uses f-string | ^^^^^^^^^ 15 | info(f"{__name__}") | +help: Convert to lazy `%` formatting G004 Logging statement uses f-string --> G004.py:15:6 @@ -61,3 +66,156 @@ G004 Logging statement uses f-string 16 | 17 | # Don't trigger for t-strings | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:24:14 + | +22 | total = 9 +23 | directory_path = "/home/hamir/ruff/crates/ruff_linter/resources/test/" +24 | logging.info(f"{count} out of {total} files in {directory_path} checked") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:30:13 + | +28 | x = 99 +29 | fmt = "08d" +30 | logger.info(f"{x:{'08d'}}") + | ^^^^^^^^^^^^^^ +31 | logger.info(f"{x:>10} {x:{fmt}}") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:31:13 + | +29 | fmt = "08d" +30 | logger.info(f"{x:{'08d'}}") +31 | logger.info(f"{x:>10} {x:{fmt}}") + | ^^^^^^^^^^^^^^^^^^^^ +32 | +33 | logging.info(f"") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:33:14 + | +31 | logger.info(f"{x:>10} {x:{fmt}}") +32 | +33 | logging.info(f"") + | ^^^ +34 | logging.info(f"This message doesn't have any variables.") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:34:14 + | +33 | logging.info(f"") +34 | logging.info(f"This message doesn't have any variables.") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +35 | +36 | obj = {"key": "value"} + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:37:14 + | +36 | obj = {"key": "value"} +37 | logging.info(f"Object: {obj!r}") + | ^^^^^^^^^^^^^^^^^^ +38 | +39 | items_count = 3 + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:40:17 + | +39 | items_count = 3 +40 | logging.warning(f"Items: {items_count:d}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +41 | +42 | data = {"status": "active"} + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:43:14 + | +42 | data = {"status": "active"} +43 | logging.info(f"Processing {len(data)} items") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +44 | logging.info(f"Status: {data.get('status', 'unknown').upper()}") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:44:14 + | +42 | data = {"status": "active"} +43 | logging.info(f"Processing {len(data)} items") +44 | logging.info(f"Status: {data.get('status', 'unknown').upper()}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:48:14 + | +47 | result = 123 +48 | logging.info(f"Calculated result: {result + 100}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +49 | +50 | temperature = 123 + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:51:14 + | +50 | temperature = 123 +51 | logging.info(f"Temperature: {temperature:.1f}°C") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +52 | +53 | class FilePath: + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:57:14 + | +55 | self.name = name +56 | +57 | logging.info(f"No changes made to {file_path.name}.") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +58 | +59 | user = "tron" + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:61:15 + | +59 | user = "tron" +60 | balance = 123.45 +61 | logging.error(f"Error {404}: User {user} has insufficient balance ${balance:.2f}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +62 | +63 | import logging + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:66:15 + | +65 | x = 1 +66 | logging.error(f"{x} -> %s", x) + | ^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004_arg_order.py.snap b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004_arg_order.py.snap new file mode 100644 index 0000000000000..cb976e768a6b7 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__G004_arg_order.py.snap @@ -0,0 +1,23 @@ +--- +source: crates/ruff_linter/src/rules/flake8_logging_format/mod.rs +--- +G004 Logging statement uses f-string + --> G004_arg_order.py:9:14 + | + 7 | X = 1 + 8 | Y = 2 + 9 | logger.error(f"{X} -> %s", Y) + | ^^^^^^^^^^^^ +10 | logger.error(f"{Y} -> %s", X) + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004_arg_order.py:10:14 + | + 8 | Y = 2 + 9 | logger.error(f"{X} -> %s", Y) +10 | logger.error(f"{Y} -> %s", X) + | ^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004.py.snap b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004.py.snap new file mode 100644 index 0000000000000..b74a9e2306b74 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004.py.snap @@ -0,0 +1,291 @@ +--- +source: crates/ruff_linter/src/rules/flake8_logging_format/mod.rs +--- +G004 [*] Logging statement uses f-string + --> G004.py:4:14 + | +3 | name = "world" +4 | logging.info(f"Hello {name}") + | ^^^^^^^^^^^^^^^ +5 | logging.log(logging.INFO, f"Hello {name}") + | +help: Convert to lazy `%` formatting + +ℹ Safe fix +1 1 | import logging +2 2 | +3 3 | name = "world" +4 |-logging.info(f"Hello {name}") + 4 |+logging.info("Hello %s", name) +5 5 | logging.log(logging.INFO, f"Hello {name}") +6 6 | +7 7 | _LOGGER = logging.getLogger() + +G004 [*] Logging statement uses f-string + --> G004.py:5:27 + | +3 | name = "world" +4 | logging.info(f"Hello {name}") +5 | logging.log(logging.INFO, f"Hello {name}") + | ^^^^^^^^^^^^^^^ +6 | +7 | _LOGGER = logging.getLogger() + | +help: Convert to lazy `%` formatting + +ℹ Safe fix +2 2 | +3 3 | name = "world" +4 4 | logging.info(f"Hello {name}") +5 |-logging.log(logging.INFO, f"Hello {name}") + 5 |+logging.log(logging.INFO, "Hello %s", name) +6 6 | +7 7 | _LOGGER = logging.getLogger() +8 8 | _LOGGER.info(f"{__name__}") + +G004 [*] Logging statement uses f-string + --> G004.py:8:14 + | + 7 | _LOGGER = logging.getLogger() + 8 | _LOGGER.info(f"{__name__}") + | ^^^^^^^^^^^^^ + 9 | +10 | logging.getLogger().info(f"{name}") + | +help: Convert to lazy `%` formatting + +ℹ Safe fix +5 5 | logging.log(logging.INFO, f"Hello {name}") +6 6 | +7 7 | _LOGGER = logging.getLogger() +8 |-_LOGGER.info(f"{__name__}") + 8 |+_LOGGER.info("%s", __name__) +9 9 | +10 10 | logging.getLogger().info(f"{name}") +11 11 | + +G004 [*] Logging statement uses f-string + --> G004.py:10:26 + | + 8 | _LOGGER.info(f"{__name__}") + 9 | +10 | logging.getLogger().info(f"{name}") + | ^^^^^^^^^ +11 | +12 | from logging import info + | +help: Convert to lazy `%` formatting + +ℹ Safe fix +7 7 | _LOGGER = logging.getLogger() +8 8 | _LOGGER.info(f"{__name__}") +9 9 | +10 |-logging.getLogger().info(f"{name}") + 10 |+logging.getLogger().info("%s", name) +11 11 | +12 12 | from logging import info +13 13 | + +G004 [*] Logging statement uses f-string + --> G004.py:14:6 + | +12 | from logging import info +13 | +14 | info(f"{name}") + | ^^^^^^^^^ +15 | info(f"{__name__}") + | +help: Convert to lazy `%` formatting + +ℹ Safe fix +11 11 | +12 12 | from logging import info +13 13 | +14 |-info(f"{name}") + 14 |+info("%s", name) +15 15 | info(f"{__name__}") +16 16 | +17 17 | # Don't trigger for t-strings + +G004 [*] Logging statement uses f-string + --> G004.py:15:6 + | +14 | info(f"{name}") +15 | info(f"{__name__}") + | ^^^^^^^^^^^^^ +16 | +17 | # Don't trigger for t-strings + | +help: Convert to lazy `%` formatting + +ℹ Safe fix +12 12 | from logging import info +13 13 | +14 14 | info(f"{name}") +15 |-info(f"{__name__}") + 15 |+info("%s", __name__) +16 16 | +17 17 | # Don't trigger for t-strings +18 18 | info(t"{name}") + +G004 [*] Logging statement uses f-string + --> G004.py:24:14 + | +22 | total = 9 +23 | directory_path = "/home/hamir/ruff/crates/ruff_linter/resources/test/" +24 | logging.info(f"{count} out of {total} files in {directory_path} checked") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting + +ℹ Safe fix +21 21 | count = 5 +22 22 | total = 9 +23 23 | directory_path = "/home/hamir/ruff/crates/ruff_linter/resources/test/" +24 |-logging.info(f"{count} out of {total} files in {directory_path} checked") + 24 |+logging.info("%s out of %s files in %s checked", count, total, directory_path) +25 25 | +26 26 | +27 27 | + +G004 Logging statement uses f-string + --> G004.py:30:13 + | +28 | x = 99 +29 | fmt = "08d" +30 | logger.info(f"{x:{'08d'}}") + | ^^^^^^^^^^^^^^ +31 | logger.info(f"{x:>10} {x:{fmt}}") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:31:13 + | +29 | fmt = "08d" +30 | logger.info(f"{x:{'08d'}}") +31 | logger.info(f"{x:>10} {x:{fmt}}") + | ^^^^^^^^^^^^^^^^^^^^ +32 | +33 | logging.info(f"") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:33:14 + | +31 | logger.info(f"{x:>10} {x:{fmt}}") +32 | +33 | logging.info(f"") + | ^^^ +34 | logging.info(f"This message doesn't have any variables.") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:34:14 + | +33 | logging.info(f"") +34 | logging.info(f"This message doesn't have any variables.") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +35 | +36 | obj = {"key": "value"} + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:37:14 + | +36 | obj = {"key": "value"} +37 | logging.info(f"Object: {obj!r}") + | ^^^^^^^^^^^^^^^^^^ +38 | +39 | items_count = 3 + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:40:17 + | +39 | items_count = 3 +40 | logging.warning(f"Items: {items_count:d}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +41 | +42 | data = {"status": "active"} + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:43:14 + | +42 | data = {"status": "active"} +43 | logging.info(f"Processing {len(data)} items") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +44 | logging.info(f"Status: {data.get('status', 'unknown').upper()}") + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:44:14 + | +42 | data = {"status": "active"} +43 | logging.info(f"Processing {len(data)} items") +44 | logging.info(f"Status: {data.get('status', 'unknown').upper()}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:48:14 + | +47 | result = 123 +48 | logging.info(f"Calculated result: {result + 100}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +49 | +50 | temperature = 123 + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:51:14 + | +50 | temperature = 123 +51 | logging.info(f"Temperature: {temperature:.1f}°C") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +52 | +53 | class FilePath: + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:57:14 + | +55 | self.name = name +56 | +57 | logging.info(f"No changes made to {file_path.name}.") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +58 | +59 | user = "tron" + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:61:15 + | +59 | user = "tron" +60 | balance = 123.45 +61 | logging.error(f"Error {404}: User {user} has insufficient balance ${balance:.2f}") + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +62 | +63 | import logging + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004.py:66:15 + | +65 | x = 1 +66 | logging.error(f"{x} -> %s", x) + | ^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004_arg_order.py.snap b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004_arg_order.py.snap new file mode 100644 index 0000000000000..cb976e768a6b7 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_logging_format/snapshots/ruff_linter__rules__flake8_logging_format__tests__preview__G004_G004_arg_order.py.snap @@ -0,0 +1,23 @@ +--- +source: crates/ruff_linter/src/rules/flake8_logging_format/mod.rs +--- +G004 Logging statement uses f-string + --> G004_arg_order.py:9:14 + | + 7 | X = 1 + 8 | Y = 2 + 9 | logger.error(f"{X} -> %s", Y) + | ^^^^^^^^^^^^ +10 | logger.error(f"{Y} -> %s", X) + | +help: Convert to lazy `%` formatting + +G004 Logging statement uses f-string + --> G004_arg_order.py:10:14 + | + 8 | Y = 2 + 9 | logger.error(f"{X} -> %s", Y) +10 | logger.error(f"{Y} -> %s", X) + | ^^^^^^^^^^^^ + | +help: Convert to lazy `%` formatting diff --git a/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs b/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs index 51cc9f436ff6e..21e22bf2f71c0 100644 --- a/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs +++ b/crates/ruff_linter/src/rules/flake8_logging_format/violations.rs @@ -327,10 +327,16 @@ impl Violation for LoggingStringConcat { pub(crate) struct LoggingFString; impl Violation for LoggingFString { + const FIX_AVAILABILITY: crate::FixAvailability = crate::FixAvailability::Sometimes; + #[derive_message_formats] fn message(&self) -> String { "Logging statement uses f-string".to_string() } + + fn fix_title(&self) -> Option { + Some("Convert to lazy `%` formatting".to_string()) + } } /// ## What it does From 73720c73be981df6f71ce837a67ca1167da0265e Mon Sep 17 00:00:00 2001 From: Renkai Ge Date: Tue, 26 Aug 2025 23:01:16 +0800 Subject: [PATCH 141/160] [ty] Add search paths info to unresolved import diagnostics (#20040) Fixes https://github.com/astral-sh/ty/issues/457 --------- Co-authored-by: Alex Waygood --- crates/ty/tests/cli/main.rs | 19 ++++++++++++-- crates/ty/tests/cli/python_environment.rs | 25 +++++++++++++++++++ crates/ty/tests/cli/rule_selection.rs | 10 ++++++-- ...s_imp\342\200\246_(cbfbf5ff94e6e104).snap" | 3 +++ ...dule_\342\200\246_(846453deaca1071c).snap" | 3 +++ ...bmodu\342\200\246_(4fad4be9778578b7).snap" | 6 +++++ ..._impo\342\200\246_(72d090df51ea97b8).snap" | 3 +++ ...th_an\342\200\246_(9fa713dfa17cc404).snap" | 3 +++ .../src/module_resolver/mod.rs | 3 +-- .../src/module_resolver/path.rs | 19 ++++++++++++++ crates/ty_python_semantic/src/types/infer.rs | 24 +++++++++++++++++- 11 files changed, 111 insertions(+), 7 deletions(-) diff --git a/crates/ty/tests/cli/main.rs b/crates/ty/tests/cli/main.rs index 82edcda8c7ef5..f85f294842f7e 100644 --- a/crates/ty/tests/cli/main.rs +++ b/crates/ty/tests/cli/main.rs @@ -263,6 +263,9 @@ fn cli_arguments_are_relative_to_the_current_directory() -> anyhow::Result<()> { 3 | 4 | stat = add(10, 15) | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -477,7 +480,7 @@ fn check_specific_paths() -> anyhow::Result<()> { assert_cmd_snapshot!( case.command(), - @r###" + @r" success: false exit_code: 1 ----- stdout ----- @@ -489,6 +492,9 @@ fn check_specific_paths() -> anyhow::Result<()> { 3 | 4 | print(z) | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -498,6 +504,9 @@ fn check_specific_paths() -> anyhow::Result<()> { 2 | import does_not_exist # error: unresolved-import | ^^^^^^^^^^^^^^ | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -505,7 +514,7 @@ fn check_specific_paths() -> anyhow::Result<()> { ----- stderr ----- WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. - "### + " ); // Now check only the `tests` and `other.py` files. @@ -524,6 +533,9 @@ fn check_specific_paths() -> anyhow::Result<()> { 3 | 4 | print(z) | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -533,6 +545,9 @@ fn check_specific_paths() -> anyhow::Result<()> { 2 | import does_not_exist # error: unresolved-import | ^^^^^^^^^^^^^^ | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default diff --git a/crates/ty/tests/cli/python_environment.rs b/crates/ty/tests/cli/python_environment.rs index 3c9714d00ef8b..d20a9c8add886 100644 --- a/crates/ty/tests/cli/python_environment.rs +++ b/crates/ty/tests/cli/python_environment.rs @@ -333,6 +333,10 @@ import bar", | ^^^ 2 | import bar | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) + info: 3. /strange-venv-location/lib/python3.13/site-packages (site-packages) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -378,6 +382,11 @@ fn lib64_site_packages_directory_on_unix() -> anyhow::Result<()> { 1 | import foo, bar, baz | ^^^ | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) + info: 3. /.venv/lib/python3.13/site-packages (site-packages) + info: 4. /.venv/lib64/python3.13/site-packages (site-packages) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -1273,6 +1282,9 @@ home = ./ 3 | from package1 import ChildConda 4 | from package1 import WorkingVenv | + info: Searched in the following paths during module resolution: + info: 1. /project (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -1285,6 +1297,9 @@ home = ./ 4 | from package1 import WorkingVenv 5 | from package1 import BaseConda | + info: Searched in the following paths during module resolution: + info: 1. /project (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -1297,6 +1312,9 @@ home = ./ | ^^^^^^^^ 5 | from package1 import BaseConda | + info: Searched in the following paths during module resolution: + info: 1. /project (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -1308,6 +1326,9 @@ home = ./ 5 | from package1 import BaseConda | ^^^^^^^^ | + info: Searched in the following paths during module resolution: + info: 1. /project (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -1716,6 +1737,10 @@ fn default_root_tests_package() -> anyhow::Result<()> { 4 | 5 | print(f"{foo} {bar}") | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. /src (first-party code) + info: 3. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default diff --git a/crates/ty/tests/cli/rule_selection.rs b/crates/ty/tests/cli/rule_selection.rs index 16a1d4eb74b66..8b5382f564390 100644 --- a/crates/ty/tests/cli/rule_selection.rs +++ b/crates/ty/tests/cli/rule_selection.rs @@ -89,7 +89,7 @@ fn cli_rule_severity() -> anyhow::Result<()> { // Assert that there's an `unresolved-reference` diagnostic (error) // and an unresolved-import (error) diagnostic by default. - assert_cmd_snapshot!(case.command(), @r###" + assert_cmd_snapshot!(case.command(), @r" success: false exit_code: 1 ----- stdout ----- @@ -101,6 +101,9 @@ fn cli_rule_severity() -> anyhow::Result<()> { 3 | 4 | y = 4 / 0 | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -118,7 +121,7 @@ fn cli_rule_severity() -> anyhow::Result<()> { ----- stderr ----- WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors. - "###); + "); assert_cmd_snapshot!( case @@ -141,6 +144,9 @@ fn cli_rule_severity() -> anyhow::Result<()> { 3 | 4 | y = 4 / 0 | + info: Searched in the following paths during module resolution: + info: 1. / (first-party code) + info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` was selected on the command line diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Multiple_objects_imp\342\200\246_(cbfbf5ff94e6e104).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Multiple_objects_imp\342\200\246_(cbfbf5ff94e6e104).snap" index 13b63a659f01c..79600310ea275 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Multiple_objects_imp\342\200\246_(cbfbf5ff94e6e104).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Multiple_objects_imp\342\200\246_(cbfbf5ff94e6e104).snap" @@ -26,6 +26,9 @@ error[unresolved-import]: Cannot resolve imported module `does_not_exist` 2 | from does_not_exist import foo, bar, baz | ^^^^^^^^^^^^^^ | +info: Searched in the following paths during module resolution: +info: 1. /src (first-party code) +info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_module_\342\200\246_(846453deaca1071c).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_module_\342\200\246_(846453deaca1071c).snap" index faa9a6155f984..af7b769b1f562 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_module_\342\200\246_(846453deaca1071c).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_module_\342\200\246_(846453deaca1071c).snap" @@ -24,6 +24,9 @@ error[unresolved-import]: Cannot resolve imported module `zqzqzqzqzqzqzq` 1 | import zqzqzqzqzqzqzq # error: [unresolved-import] "Cannot resolve imported module `zqzqzqzqzqzqzq`" | ^^^^^^^^^^^^^^ | +info: Searched in the following paths during module resolution: +info: 1. /src (first-party code) +info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_submodu\342\200\246_(4fad4be9778578b7).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_submodu\342\200\246_(4fad4be9778578b7).snap" index 1bbe221bb7bc2..f6ecd692f30ad 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_submodu\342\200\246_(4fad4be9778578b7).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/basic.md_-_Structures_-_Unresolvable_submodu\342\200\246_(4fad4be9778578b7).snap" @@ -36,6 +36,9 @@ error[unresolved-import]: Cannot resolve imported module `a.foo` 3 | 4 | # Topmost component unresolvable: | +info: Searched in the following paths during module resolution: +info: 1. /src (first-party code) +info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default @@ -49,6 +52,9 @@ error[unresolved-import]: Cannot resolve imported module `b.foo` 5 | import b.foo # error: [unresolved-import] "Cannot resolve imported module `b.foo`" | ^^^^^ | +info: Searched in the following paths during module resolution: +info: 1. /src (first-party code) +info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_An_unresolvable_impo\342\200\246_(72d090df51ea97b8).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_An_unresolvable_impo\342\200\246_(72d090df51ea97b8).snap" index 633cb50b16dd7..fbaa1abc00c9f 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_An_unresolvable_impo\342\200\246_(72d090df51ea97b8).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_An_unresolvable_impo\342\200\246_(72d090df51ea97b8).snap" @@ -28,6 +28,9 @@ error[unresolved-import]: Cannot resolve imported module `does_not_exist` 2 | 3 | x = does_not_exist.foo | +info: Searched in the following paths during module resolution: +info: 1. /src (first-party code) +info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default diff --git "a/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_Using_`from`_with_an\342\200\246_(9fa713dfa17cc404).snap" "b/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_Using_`from`_with_an\342\200\246_(9fa713dfa17cc404).snap" index 0d687bf11c773..83f03b79296f5 100644 --- "a/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_Using_`from`_with_an\342\200\246_(9fa713dfa17cc404).snap" +++ "b/crates/ty_python_semantic/resources/mdtest/snapshots/unresolved_import.md_-_Unresolved_import_di\342\200\246_-_Using_`from`_with_an\342\200\246_(9fa713dfa17cc404).snap" @@ -28,6 +28,9 @@ error[unresolved-import]: Cannot resolve imported module `does_not_exist` 2 | 3 | stat = add(10, 15) | +info: Searched in the following paths during module resolution: +info: 1. /src (first-party code) +info: 2. vendored://stdlib (stdlib typeshed stubs vendored by ty) info: make sure your Python environment is properly configured: https://docs.astral.sh/ty/modules/#python-environment info: rule `unresolved-import` is enabled by default diff --git a/crates/ty_python_semantic/src/module_resolver/mod.rs b/crates/ty_python_semantic/src/module_resolver/mod.rs index 901adbf4ef667..549ffa2c9678a 100644 --- a/crates/ty_python_semantic/src/module_resolver/mod.rs +++ b/crates/ty_python_semantic/src/module_resolver/mod.rs @@ -10,8 +10,7 @@ pub use resolver::{resolve_module, resolve_real_module}; use ruff_db::system::SystemPath; use crate::Db; -use crate::module_resolver::resolver::{ModuleResolveMode, search_paths}; -use resolver::SearchPathIterator; +pub(crate) use resolver::{ModuleResolveMode, SearchPathIterator, search_paths}; mod list; mod module; diff --git a/crates/ty_python_semantic/src/module_resolver/path.rs b/crates/ty_python_semantic/src/module_resolver/path.rs index 9a697f27f1fc2..cb524cb4aca11 100644 --- a/crates/ty_python_semantic/src/module_resolver/path.rs +++ b/crates/ty_python_semantic/src/module_resolver/path.rs @@ -700,6 +700,25 @@ impl SearchPath { SearchPathInner::StandardLibraryVendored(_) => "std-vendored", } } + + /// Returns a string suitable for describing what kind of search path this is + /// in user-facing diagnostics. + #[must_use] + pub(crate) fn describe_kind(&self) -> &'static str { + match *self.0 { + SearchPathInner::Extra(_) => { + "extra search path specified on the CLI or in your config file" + } + SearchPathInner::FirstParty(_) => "first-party code", + SearchPathInner::StandardLibraryCustom(_) => { + "custom stdlib stubs specified on the CLI or in your config file" + } + SearchPathInner::StandardLibraryReal(_) => "runtime stdlib source code", + SearchPathInner::SitePackages(_) => "site-packages", + SearchPathInner::Editable(_) => "editable install", + SearchPathInner::StandardLibraryVendored(_) => "stdlib typeshed stubs vendored by ty", + } + } } impl PartialEq for SearchPath { diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index abb032644e778..d76bb6b5c7ddd 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -64,7 +64,9 @@ use super::string_annotation::{ use super::subclass_of::SubclassOfInner; use super::{ClassBase, add_inferred_python_version_hint_to_diagnostic}; use crate::module_name::{ModuleName, ModuleNameResolutionError}; -use crate::module_resolver::{KnownModule, file_to_module, resolve_module}; +use crate::module_resolver::{ + KnownModule, ModuleResolveMode, file_to_module, resolve_module, search_paths, +}; use crate::node_key::NodeKey; use crate::place::{ Boundness, ConsideredDefinitions, LookupError, Place, PlaceAndQualifiers, @@ -4983,6 +4985,26 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } } + // Add search paths information to the diagnostic + // Use the same search paths function that is used in actual module resolution + let mut search_paths = + search_paths(self.db(), ModuleResolveMode::StubsAllowed).peekable(); + + if search_paths.peek().is_some() { + diagnostic.info(format_args!( + "Searched in the following paths during module resolution:" + )); + + for (index, path) in search_paths.enumerate() { + diagnostic.info(format_args!( + " {}. {} ({})", + index + 1, + path, + path.describe_kind() + )); + } + } + diagnostic.info( "make sure your Python environment is properly configured: \ https://docs.astral.sh/ty/modules/#python-environment", From ea1c08088193374a07663b444ce4f0745f734aee Mon Sep 17 00:00:00 2001 From: chiri Date: Tue, 26 Aug 2025 19:05:52 +0300 Subject: [PATCH 142/160] [`flake8-use-pathlib`] Delete unused `Rule::OsSymlink` enabled check (#20099) ## Summary Part of #20009 (i forgot to delete it in this PR) ## Test Plan --- crates/ruff_linter/src/checkers/ast/analyze/expression.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 60d3cce5d6a41..9a6c4b52c9c2b 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -1046,7 +1046,6 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { Rule::PyPath, Rule::Glob, Rule::OsListdir, - Rule::OsSymlink, ]) { flake8_use_pathlib::rules::replaceable_by_pathlib(checker, call); } From f558bf721c367142eaf2470b6004d42395d50702 Mon Sep 17 00:00:00 2001 From: chiri Date: Tue, 26 Aug 2025 21:59:12 +0300 Subject: [PATCH 143/160] [`flake8-use-pathlib`] Make `PTH100` fix unsafe because it can change behavior (#20100) ## Summary Fixes https://github.com/astral-sh/ruff/issues/20088 ## Test Plan `cargo nextest run flake8_use_pathlib` --------- Co-authored-by: Brent Westbrook --- .../rules/os_path_abspath.rs | 69 +++++++++++++++---- ..._pathlib__tests__preview_full_name.py.snap | 2 +- ..._pathlib__tests__preview_import_as.py.snap | 2 +- ...athlib__tests__preview_import_from.py.snap | 2 +- ...lib__tests__preview_import_from_as.py.snap | 2 +- 5 files changed, 60 insertions(+), 17 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_abspath.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_abspath.rs index a8961da959999..34860aee82877 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_abspath.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_abspath.rs @@ -1,9 +1,15 @@ +use ruff_diagnostics::{Edit, Fix}; +use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_ast::ExprCall; +use ruff_text_size::Ranged; + use crate::checkers::ast::Checker; +use crate::importer::ImportRequest; use crate::preview::is_fix_os_path_abspath_enabled; -use crate::rules::flake8_use_pathlib::helpers::check_os_pathlib_single_arg_calls; +use crate::rules::flake8_use_pathlib::helpers::{ + has_unknown_keywords_or_starred_expr, is_pathlib_path_call, +}; use crate::{FixAvailability, Violation}; -use ruff_macros::{ViolationMetadata, derive_message_formats}; -use ruff_python_ast::ExprCall; /// ## What it does /// Checks for uses of `os.path.abspath`. @@ -34,13 +40,18 @@ use ruff_python_ast::ExprCall; /// especially on older versions of Python. /// /// ## Fix Safety -/// This rule's fix is marked as unsafe if the replacement would remove comments attached to the original expression. +/// This rule's fix is always marked as unsafe because `Path.resolve()` resolves symlinks, while +/// `os.path.abspath()` does not. If resolving symlinks is important, you may need to use +/// `Path.absolute()`. However, `Path.absolute()` also does not remove any `..` components in a +/// path, unlike `os.path.abspath()` and `Path.resolve()`, so if that specific combination of +/// behaviors is required, there's no existing `pathlib` alternative. See CPython issue +/// [#69200](https://github.com/python/cpython/issues/69200). /// /// ## References /// - [Python documentation: `Path.resolve`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.resolve) /// - [Python documentation: `os.path.abspath`](https://docs.python.org/3/library/os.path.html#os.path.abspath) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] @@ -63,12 +74,44 @@ pub(crate) fn os_path_abspath(checker: &Checker, call: &ExprCall, segments: &[&s if segments != ["os", "path", "abspath"] { return; } - check_os_pathlib_single_arg_calls( - checker, - call, - "resolve()", - "path", - is_fix_os_path_abspath_enabled(checker.settings()), - OsPathAbspath, - ); + + if call.arguments.len() != 1 { + return; + } + + let Some(arg) = call.arguments.find_argument_value("path", 0) else { + return; + }; + + let arg_code = checker.locator().slice(arg.range()); + let range = call.range(); + + let mut diagnostic = checker.report_diagnostic(OsPathAbspath, call.func.range()); + + if has_unknown_keywords_or_starred_expr(&call.arguments, &["path"]) { + return; + } + + if !is_fix_os_path_abspath_enabled(checker.settings()) { + return; + } + + diagnostic.try_set_fix(|| { + let (import_edit, binding) = checker.importer().get_or_import_symbol( + &ImportRequest::import("pathlib", "Path"), + call.start(), + checker.semantic(), + )?; + + let replacement = if is_pathlib_path_call(checker, arg) { + format!("{arg_code}.resolve()") + } else { + format!("{binding}({arg_code}).resolve()") + }; + + Ok(Fix::unsafe_edits( + Edit::range_replacement(replacement, range), + [import_edit], + )) + }); } diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap index 8ed53256005eb..6fcb21851646f 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_full_name.py.snap @@ -13,7 +13,7 @@ PTH100 [*] `os.path.abspath()` should be replaced by `Path.resolve()` | help: Replace with `Path(...).resolve()` -ℹ Safe fix +ℹ Unsafe fix 1 1 | import os 2 2 | import os.path 3 |+import pathlib diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap index 167f4ecd2c771..4bb8b54649f79 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_as.py.snap @@ -13,7 +13,7 @@ PTH100 [*] `os.path.abspath()` should be replaced by `Path.resolve()` | help: Replace with `Path(...).resolve()` -ℹ Safe fix +ℹ Unsafe fix 1 1 | import os as foo 2 2 | import os.path as foo_p 3 |+import pathlib diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap index 9b1262c76c873..b98ec1009850f 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from.py.snap @@ -13,7 +13,7 @@ PTH100 [*] `os.path.abspath()` should be replaced by `Path.resolve()` | help: Replace with `Path(...).resolve()` -ℹ Safe fix +ℹ Unsafe fix 2 2 | from os import remove, unlink, getcwd, readlink, stat 3 3 | from os.path import abspath, exists, expanduser, isdir, isfile, islink 4 4 | from os.path import isabs, join, basename, dirname, samefile, splitext diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap index c964f4b1234a5..9ca00b20b2cd0 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/snapshots/ruff_linter__rules__flake8_use_pathlib__tests__preview_import_from_as.py.snap @@ -13,7 +13,7 @@ PTH100 [*] `os.path.abspath()` should be replaced by `Path.resolve()` | help: Replace with `Path(...).resolve()` -ℹ Safe fix +ℹ Unsafe fix 7 7 | from os.path import isfile as xisfile, islink as xislink, isabs as xisabs 8 8 | from os.path import join as xjoin, basename as xbasename, dirname as xdirname 9 9 | from os.path import samefile as xsamefile, splitext as xsplitext From a60fb3f2c88cd91c8f8ae5385812b5eee7ce43f1 Mon Sep 17 00:00:00 2001 From: chiri Date: Wed, 27 Aug 2025 00:33:33 +0300 Subject: [PATCH 144/160] [`flake8-use-pathlib`] Update links to the table showing the correspondence between `os` and `pathlib` (#20103) ## Summary Part of https://github.com/astral-sh/ruff/pull/20100 | https://github.com/astral-sh/ruff/pull/20100#issuecomment-3225349156 --- .../src/rules/flake8_use_pathlib/rules/os_chmod.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_getcwd.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_makedirs.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_mkdir.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_basename.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_dirname.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_exists.rs | 2 +- .../flake8_use_pathlib/rules/os_path_expanduser.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_getatime.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_getctime.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_getmtime.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_getsize.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_isabs.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_isdir.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_isfile.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_islink.rs | 2 +- .../rules/flake8_use_pathlib/rules/os_path_samefile.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_readlink.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_remove.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_rename.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_replace.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_rmdir.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_symlink.rs | 2 +- .../src/rules/flake8_use_pathlib/rules/os_unlink.rs | 2 +- .../src/rules/flake8_use_pathlib/violations.rs | 10 +++++----- 25 files changed, 29 insertions(+), 29 deletions(-) diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_chmod.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_chmod.rs index cca89e7278a27..f3db17bdf3015 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_chmod.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_chmod.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.chmod`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.chmod) /// - [Python documentation: `os.chmod`](https://docs.python.org/3/library/os.html#os.chmod) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_getcwd.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_getcwd.rs index 8ce71b158d181..33e45b488b182 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_getcwd.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_getcwd.rs @@ -43,7 +43,7 @@ use ruff_text_size::Ranged; /// - [Python documentation: `os.getcwd`](https://docs.python.org/3/library/os.html#os.getcwd) /// - [Python documentation: `os.getcwdb`](https://docs.python.org/3/library/os.html#os.getcwdb) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs index c280d3ef77415..f2c668c9b02e9 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_makedirs.rs @@ -46,7 +46,7 @@ use crate::{FixAvailability, Violation}; /// - [Python documentation: `Path.mkdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir) /// - [Python documentation: `os.makedirs`](https://docs.python.org/3/library/os.html#os.makedirs) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs index 754191910e5c9..c744d3ebd287b 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_mkdir.rs @@ -47,7 +47,7 @@ use crate::{FixAvailability, Violation}; /// - [Python documentation: `Path.mkdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.mkdir) /// - [Python documentation: `os.mkdir`](https://docs.python.org/3/library/os.html#os.mkdir) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_basename.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_basename.rs index f69526dd7abe3..a2c98821a5885 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_basename.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_basename.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `PurePath.name`](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.name) /// - [Python documentation: `os.path.basename`](https://docs.python.org/3/library/os.path.html#os.path.basename) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_dirname.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_dirname.rs index a39ebc2814a27..0ba27908afa5a 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_dirname.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_dirname.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `PurePath.parent`](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.parent) /// - [Python documentation: `os.path.dirname`](https://docs.python.org/3/library/os.path.html#os.path.dirname) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_exists.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_exists.rs index d56697b7b1852..3e880805e3a5e 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_exists.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_exists.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.exists`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.exists) /// - [Python documentation: `os.path.exists`](https://docs.python.org/3/library/os.path.html#os.path.exists) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_expanduser.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_expanduser.rs index 6c25e30a5fcd3..aa6f7cae71161 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_expanduser.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_expanduser.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.expanduser`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.expanduser) /// - [Python documentation: `os.path.expanduser`](https://docs.python.org/3/library/os.path.html#os.path.expanduser) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs index 435ec1a9393ad..a54e79d339fdb 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getatime.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat) /// - [Python documentation: `os.path.getatime`](https://docs.python.org/3/library/os.path.html#os.path.getatime) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs index 7b01da2234802..165c6eae94873 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getctime.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat) /// - [Python documentation: `os.path.getctime`](https://docs.python.org/3/library/os.path.html#os.path.getctime) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs index dbcc1d44b9535..0eec96ee2ace1 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getmtime.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat) /// - [Python documentation: `os.path.getmtime`](https://docs.python.org/3/library/os.path.html#os.path.getmtime) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs index 9dc2606d7f2a0..ea1cbfd3724b2 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_getsize.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.stat`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.stat) /// - [Python documentation: `os.path.getsize`](https://docs.python.org/3/library/os.path.html#os.path.getsize) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isabs.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isabs.rs index 482ec95f24484..69ccb55e8670a 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isabs.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isabs.rs @@ -39,7 +39,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `PurePath.is_absolute`](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.is_absolute) /// - [Python documentation: `os.path.isabs`](https://docs.python.org/3/library/os.path.html#os.path.isabs) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isdir.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isdir.rs index 4c33745e521c1..454415fabcae6 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isdir.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isdir.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.is_dir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_dir) /// - [Python documentation: `os.path.isdir`](https://docs.python.org/3/library/os.path.html#os.path.isdir) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isfile.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isfile.rs index 0fa2bd4fd8cbb..adfabd61c9a85 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isfile.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_isfile.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.is_file`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_file) /// - [Python documentation: `os.path.isfile`](https://docs.python.org/3/library/os.path.html#os.path.isfile) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_islink.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_islink.rs index db9aa3d5e93ff..bfd96e4b4bf8e 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_islink.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_islink.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.is_symlink`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.is_symlink) /// - [Python documentation: `os.path.islink`](https://docs.python.org/3/library/os.path.html#os.path.islink) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_samefile.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_samefile.rs index f761de962c00d..53d6851576b54 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_samefile.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_path_samefile.rs @@ -40,7 +40,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.samefile`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.samefile) /// - [Python documentation: `os.path.samefile`](https://docs.python.org/3/library/os.path.html#os.path.samefile) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_readlink.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_readlink.rs index 62526f6666a8e..c70636d5581d4 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_readlink.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_readlink.rs @@ -42,7 +42,7 @@ use ruff_python_ast::{ExprCall, PythonVersion}; /// - [Python documentation: `Path.readlink`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.readline) /// - [Python documentation: `os.readlink`](https://docs.python.org/3/library/os.html#os.readlink) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_remove.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_remove.rs index 3ec99469eae42..63ef37c411d9f 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_remove.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_remove.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.unlink`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.unlink) /// - [Python documentation: `os.remove`](https://docs.python.org/3/library/os.html#os.remove) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rename.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rename.rs index 63e9ac0d60829..4391ae81b717e 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rename.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rename.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.rename`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.rename) /// - [Python documentation: `os.rename`](https://docs.python.org/3/library/os.html#os.rename) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_replace.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_replace.rs index a63da9dc3760d..fa040264bde16 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_replace.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_replace.rs @@ -45,7 +45,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.replace`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.replace) /// - [Python documentation: `os.replace`](https://docs.python.org/3/library/os.html#os.replace) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rmdir.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rmdir.rs index bb85284f4e15f..6cc0eef0de827 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rmdir.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_rmdir.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.rmdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.rmdir) /// - [Python documentation: `os.rmdir`](https://docs.python.org/3/library/os.html#os.rmdir) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs index 57e068b93faab..0af9589c2cec5 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_symlink.rs @@ -44,7 +44,7 @@ use crate::{FixAvailability, Violation}; /// ## References /// - [Python documentation: `Path.symlink_to`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.symlink_to) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_unlink.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_unlink.rs index 5d97338e880d5..18fbce929c91f 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_unlink.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/rules/os_unlink.rs @@ -42,7 +42,7 @@ use ruff_python_ast::ExprCall; /// - [Python documentation: `Path.unlink`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.unlink) /// - [Python documentation: `os.unlink`](https://docs.python.org/3/library/os.html#os.unlink) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] diff --git a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs index a8b424065b9a0..7f95879a252af 100644 --- a/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs +++ b/crates/ruff_linter/src/rules/flake8_use_pathlib/violations.rs @@ -43,7 +43,7 @@ use crate::Violation; /// - [Python documentation: `Path.owner`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.owner) /// - [Python documentation: `os.stat`](https://docs.python.org/3/library/os.html#os.stat) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] @@ -89,7 +89,7 @@ impl Violation for OsStat { /// - [Python documentation: `PurePath.joinpath`](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.joinpath) /// - [Python documentation: `os.path.join`](https://docs.python.org/3/library/os.path.html#os.path.join) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] @@ -160,7 +160,7 @@ pub(crate) enum Joiner { /// - [Python documentation: `Path.suffixes`](https://docs.python.org/3/library/pathlib.html#pathlib.PurePath.suffixes) /// - [Python documentation: `os.path.splitext`](https://docs.python.org/3/library/os.path.html#os.path.splitext) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] @@ -205,7 +205,7 @@ impl Violation for OsPathSplitext { /// - [Python documentation: `Path.open`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.open) /// - [Python documentation: `open`](https://docs.python.org/3/library/functions.html#open) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] @@ -298,7 +298,7 @@ impl Violation for PyPath { /// - [Python documentation: `Path.iterdir`](https://docs.python.org/3/library/pathlib.html#pathlib.Path.iterdir) /// - [Python documentation: `os.listdir`](https://docs.python.org/3/library/os.html#os.listdir) /// - [PEP 428 – The pathlib module – object-oriented filesystem paths](https://peps.python.org/pep-0428/) -/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) +/// - [Correspondence between `os` and `pathlib`](https://docs.python.org/3/library/pathlib.html#corresponding-tools) /// - [Why you should be using pathlib](https://treyhunner.com/2018/12/why-you-should-be-using-pathlib/) /// - [No really, pathlib is great](https://treyhunner.com/2019/01/no-really-pathlib-is-great/) #[derive(ViolationMetadata)] From 9ab276b34527c6aa2a3fce3a786292a2c6c082f9 Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Tue, 26 Aug 2025 16:29:45 -0700 Subject: [PATCH 145/160] [ty] don't eagerly unpack aliases in user-authored unions (#20055) ## Summary Add a subtly different test case for recursive PEP 695 type aliases, which does require that we relax our union simplification, so we don't eagerly unpack aliases from user-provided union annotations. ## Test Plan Added mdtest. --- .../resources/mdtest/pep695_type_aliases.md | 47 ++++- crates/ty_python_semantic/src/types.rs | 15 ++ .../ty_python_semantic/src/types/builder.rs | 182 +++++++++++++----- crates/ty_python_semantic/src/types/infer.rs | 10 +- 4 files changed, 197 insertions(+), 57 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md b/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md index 32f64a246a1f5..e8c867fccd354 100644 --- a/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md +++ b/crates/ty_python_semantic/resources/mdtest/pep695_type_aliases.md @@ -204,13 +204,17 @@ def f(x: OptNestedInt) -> None: ### Invalid self-referential ```py -# TODO emit a diagnostic here +# TODO emit a diagnostic on these two lines type IntOr = int | IntOr +type OrInt = OrInt | int -def f(x: IntOr): +def f(x: IntOr, y: OrInt): reveal_type(x) # revealed: int + reveal_type(y) # revealed: int if not isinstance(x, int): reveal_type(x) # revealed: Never + if not isinstance(y, int): + reveal_type(y) # revealed: Never ``` ### Mutually recursive @@ -234,3 +238,42 @@ from ty_extensions import Intersection def h(x: Intersection[A, B]): reveal_type(x) # revealed: tuple[B] | None ``` + +### Union inside generic + +#### With old-style union + +```py +from typing import Union + +type A = list[Union["A", str]] + +def f(x: A): + reveal_type(x) # revealed: list[A | str] + for item in x: + reveal_type(item) # revealed: list[A | str] | str +``` + +#### With new-style union + +```py +type A = list["A" | str] + +def f(x: A): + reveal_type(x) # revealed: list[A | str] + for item in x: + reveal_type(item) # revealed: list[A | str] | str +``` + +#### With Optional + +```py +from typing import Optional, Union + +type A = list[Optional[Union["A", str]]] + +def f(x: A): + reveal_type(x) # revealed: list[A | str | None] + for item in x: + reveal_type(item) # revealed: list[A | str | None] | str | None +``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index d29130ebadd11..91fe0ee8fad14 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -9389,6 +9389,21 @@ impl<'db> UnionType<'db> { .build() } + /// Create a union from a list of elements without unpacking type aliases. + pub(crate) fn from_elements_leave_aliases(db: &'db dyn Db, elements: I) -> Type<'db> + where + I: IntoIterator, + T: Into>, + { + elements + .into_iter() + .fold( + UnionBuilder::new(db).unpack_aliases(false), + |builder, element| builder.add(element.into()), + ) + .build() + } + /// A fallible version of [`UnionType::from_elements`]. /// /// If all items in `elements` are `Some()`, the result of unioning all elements is returned. diff --git a/crates/ty_python_semantic/src/types/builder.rs b/crates/ty_python_semantic/src/types/builder.rs index 0f6ba1782d3e5..c33ed3fa09ab4 100644 --- a/crates/ty_python_semantic/src/types/builder.rs +++ b/crates/ty_python_semantic/src/types/builder.rs @@ -207,6 +207,7 @@ const MAX_UNION_LITERALS: usize = 200; pub(crate) struct UnionBuilder<'db> { elements: Vec>, db: &'db dyn Db, + unpack_aliases: bool, } impl<'db> UnionBuilder<'db> { @@ -214,9 +215,15 @@ impl<'db> UnionBuilder<'db> { Self { db, elements: vec![], + unpack_aliases: true, } } + pub(crate) fn unpack_aliases(mut self, val: bool) -> Self { + self.unpack_aliases = val; + self + } + pub(crate) fn is_empty(&self) -> bool { self.elements.is_empty() } @@ -236,17 +243,29 @@ impl<'db> UnionBuilder<'db> { /// Adds a type to this union. pub(crate) fn add_in_place(&mut self, ty: Type<'db>) { + self.add_in_place_impl(ty, &mut vec![]); + } + + pub(crate) fn add_in_place_impl(&mut self, ty: Type<'db>, seen_aliases: &mut Vec>) { match ty { Type::Union(union) => { let new_elements = union.elements(self.db); self.elements.reserve(new_elements.len()); for element in new_elements { - self.add_in_place(*element); + self.add_in_place_impl(*element, seen_aliases); } } // Adding `Never` to a union is a no-op. Type::Never => {} - Type::TypeAlias(alias) => self.add_in_place(alias.value_type(self.db)), + Type::TypeAlias(alias) if self.unpack_aliases => { + if seen_aliases.contains(&ty) { + // Union contains itself recursively via a type alias. This is an error, just + // leave out the recursive alias. TODO surface this error. + } else { + seen_aliases.push(ty); + self.add_in_place_impl(alias.value_type(self.db), seen_aliases); + } + } // If adding a string literal, look for an existing `UnionElement::StringLiterals` to // add it to, or an existing element that is a super-type of string literals, which // means we shouldn't add it. Otherwise, add a new `UnionElement::StringLiterals` @@ -260,7 +279,7 @@ impl<'db> UnionBuilder<'db> { UnionElement::StringLiterals(literals) => { if literals.len() >= MAX_UNION_LITERALS { let replace_with = KnownClass::Str.to_instance(self.db); - self.add_in_place(replace_with); + self.add_in_place_impl(replace_with, seen_aliases); return; } found = Some(literals); @@ -305,7 +324,7 @@ impl<'db> UnionBuilder<'db> { UnionElement::BytesLiterals(literals) => { if literals.len() >= MAX_UNION_LITERALS { let replace_with = KnownClass::Bytes.to_instance(self.db); - self.add_in_place(replace_with); + self.add_in_place_impl(replace_with, seen_aliases); return; } found = Some(literals); @@ -350,7 +369,7 @@ impl<'db> UnionBuilder<'db> { UnionElement::IntLiterals(literals) => { if literals.len() >= MAX_UNION_LITERALS { let replace_with = KnownClass::Int.to_instance(self.db); - self.add_in_place(replace_with); + self.add_in_place_impl(replace_with, seen_aliases); return; } found = Some(literals); @@ -404,7 +423,10 @@ impl<'db> UnionBuilder<'db> { .is_none(); if all_members_are_in_union { - self.add_in_place(enum_member_to_add.enum_class_instance(self.db)); + self.add_in_place_impl( + enum_member_to_add.enum_class_instance(self.db), + seen_aliases, + ); } else if !self .elements .iter() @@ -426,8 +448,17 @@ impl<'db> UnionBuilder<'db> { None }; + // If an alias gets here, it means we aren't unpacking aliases, and we also + // shouldn't try to simplify aliases out of the union, because that will require + // unpacking them. + let should_simplify_full = !matches!(ty, Type::TypeAlias(_)); + let mut to_remove = SmallVec::<[usize; 2]>::new(); - let ty_negated = ty.negate(self.db); + let ty_negated = if should_simplify_full { + ty.negate(self.db) + } else { + Type::Never // won't be used + }; for (index, element) in self.elements.iter_mut().enumerate() { let element_type = match element.try_reduce(self.db, ty) { @@ -446,30 +477,37 @@ impl<'db> UnionBuilder<'db> { return; } }; - if Some(element_type) == bool_pair { - self.add_in_place(KnownClass::Bool.to_instance(self.db)); + + if ty == element_type { return; } - if ty.is_equivalent_to(self.db, element_type) - || ty.is_subtype_of(self.db, element_type) - { - return; - } else if element_type.is_subtype_of(self.db, ty) { - to_remove.push(index); - } else if ty_negated.is_subtype_of(self.db, element_type) { - // We add `ty` to the union. We just checked that `~ty` is a subtype of an - // existing `element`. This also means that `~ty | ty` is a subtype of - // `element | ty`, because both elements in the first union are subtypes of - // the corresponding elements in the second union. But `~ty | ty` is just - // `object`. Since `object` is a subtype of `element | ty`, we can only - // conclude that `element | ty` must be `object` (object has no other - // supertypes). This means we can simplify the whole union to just - // `object`, since all other potential elements would also be subtypes of - // `object`. - self.collapse_to_object(); + if Some(element_type) == bool_pair { + self.add_in_place_impl(KnownClass::Bool.to_instance(self.db), seen_aliases); return; } + + if should_simplify_full && !matches!(element_type, Type::TypeAlias(_)) { + if ty.is_equivalent_to(self.db, element_type) + || ty.is_subtype_of(self.db, element_type) + { + return; + } else if element_type.is_subtype_of(self.db, ty) { + to_remove.push(index); + } else if ty_negated.is_subtype_of(self.db, element_type) { + // We add `ty` to the union. We just checked that `~ty` is a subtype of an + // existing `element`. This also means that `~ty | ty` is a subtype of + // `element | ty`, because both elements in the first union are subtypes of + // the corresponding elements in the second union. But `~ty | ty` is just + // `object`. Since `object` is a subtype of `element | ty`, we can only + // conclude that `element | ty` must be `object` (object has no other + // supertypes). This means we can simplify the whole union to just + // `object`, since all other potential elements would also be subtypes of + // `object`. + self.collapse_to_object(); + return; + } + } } if let Some((&first, rest)) = to_remove.split_first() { self.elements[first] = UnionElement::Type(ty); @@ -541,11 +579,27 @@ impl<'db> IntersectionBuilder<'db> { } } - pub(crate) fn add_positive(mut self, ty: Type<'db>) -> Self { + pub(crate) fn add_positive(self, ty: Type<'db>) -> Self { + self.add_positive_impl(ty, &mut vec![]) + } + + pub(crate) fn add_positive_impl( + mut self, + ty: Type<'db>, + seen_aliases: &mut Vec>, + ) -> Self { match ty { Type::TypeAlias(alias) => { + if seen_aliases.contains(&ty) { + // Recursive alias, add it without expanding to avoid infinite recursion. + for inner in &mut self.intersections { + inner.positive.insert(ty); + } + return self; + } + seen_aliases.push(ty); let value_type = alias.value_type(self.db); - self.add_positive(value_type) + self.add_positive_impl(value_type, seen_aliases) } Type::Union(union) => { // Distribute ourself over this union: for each union element, clone ourself and @@ -559,7 +613,7 @@ impl<'db> IntersectionBuilder<'db> { union .elements(self.db) .iter() - .map(|elem| self.clone().add_positive(*elem)) + .map(|elem| self.clone().add_positive_impl(*elem, seen_aliases)) .fold(IntersectionBuilder::empty(self.db), |mut builder, sub| { builder.intersections.extend(sub.intersections); builder @@ -569,10 +623,10 @@ impl<'db> IntersectionBuilder<'db> { Type::Intersection(other) => { let db = self.db; for pos in other.positive(db) { - self = self.add_positive(*pos); + self = self.add_positive_impl(*pos, seen_aliases); } for neg in other.negative(db) { - self = self.add_negative(*neg); + self = self.add_negative_impl(*neg, seen_aliases); } self } @@ -600,12 +654,15 @@ impl<'db> IntersectionBuilder<'db> { // `UnionBuilder` because we would simplify the union to just the enum instance // and end up in this branch again. let db = self.db; - self.add_positive(Type::Union(UnionType::new( - db, - enum_member_literals(db, instance.class(db).class_literal(db).0, None) - .expect("Calling `enum_member_literals` on an enum class") - .collect::>(), - ))) + self.add_positive_impl( + Type::Union(UnionType::new( + db, + enum_member_literals(db, instance.class(db).class_literal(db).0, None) + .expect("Calling `enum_member_literals` on an enum class") + .collect::>(), + )), + seen_aliases, + ) } else { for inner in &mut self.intersections { inner.add_positive(self.db, ty); @@ -624,7 +681,15 @@ impl<'db> IntersectionBuilder<'db> { } } - pub(crate) fn add_negative(mut self, ty: Type<'db>) -> Self { + pub(crate) fn add_negative(self, ty: Type<'db>) -> Self { + self.add_negative_impl(ty, &mut vec![]) + } + + pub(crate) fn add_negative_impl( + mut self, + ty: Type<'db>, + seen_aliases: &mut Vec>, + ) -> Self { let contains_enum = |enum_instance| { self.intersections .iter() @@ -635,12 +700,20 @@ impl<'db> IntersectionBuilder<'db> { // See comments above in `add_positive`; this is just the negated version. match ty { Type::TypeAlias(alias) => { + if seen_aliases.contains(&ty) { + // Recursive alias, add it without expanding to avoid infinite recursion. + for inner in &mut self.intersections { + inner.negative.insert(ty); + } + return self; + } + seen_aliases.push(ty); let value_type = alias.value_type(self.db); - self.add_negative(value_type) + self.add_negative_impl(value_type, seen_aliases) } Type::Union(union) => { for elem in union.elements(self.db) { - self = self.add_negative(*elem); + self = self.add_negative_impl(*elem, seen_aliases); } self } @@ -656,13 +729,19 @@ impl<'db> IntersectionBuilder<'db> { .positive(self.db) .iter() // we negate all the positive constraints while distributing - .map(|elem| self.clone().add_negative(*elem)); + .map(|elem| { + self.clone() + .add_negative_impl(*elem, &mut seen_aliases.clone()) + }); let negative_side = intersection .negative(self.db) .iter() // all negative constraints end up becoming positive constraints - .map(|elem| self.clone().add_positive(*elem)); + .map(|elem| { + self.clone() + .add_positive_impl(*elem, &mut seen_aliases.clone()) + }); positive_side.chain(negative_side).fold( IntersectionBuilder::empty(self.db), @@ -676,15 +755,18 @@ impl<'db> IntersectionBuilder<'db> { if contains_enum(enum_literal.enum_class_instance(self.db)) => { let db = self.db; - self.add_positive(UnionType::from_elements( - db, - enum_member_literals( + self.add_positive_impl( + UnionType::from_elements( db, - enum_literal.enum_class(db), - Some(enum_literal.name(db)), - ) - .expect("Calling `enum_member_literals` on an enum class"), - )) + enum_member_literals( + db, + enum_literal.enum_class(db), + Some(enum_literal.name(db)), + ) + .expect("Calling `enum_member_literals` on an enum class"), + ), + seen_aliases, + ) } _ => { for inner in &mut self.intersections { diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index d76bb6b5c7ddd..2c90af40c7416 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -9776,7 +9776,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { ast::Operator::BitOr => { let left_ty = self.infer_type_expression(&binary.left); let right_ty = self.infer_type_expression(&binary.right); - UnionType::from_elements(self.db(), [left_ty, right_ty]) + UnionType::from_elements_leave_aliases(self.db(), [left_ty, right_ty]) } // anything else is an invalid annotation: op => { @@ -10288,7 +10288,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { } } ast::Expr::BinOp(binary) if binary.op == ast::Operator::BitOr => { - let union_ty = UnionType::from_elements( + let union_ty = UnionType::from_elements_leave_aliases( self.db(), [ self.infer_subclass_of_type_expression(&binary.left), @@ -10314,7 +10314,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> { let parameters_ty = match self.infer_expression(value) { Type::SpecialForm(SpecialFormType::Union) => match &**parameters { ast::Expr::Tuple(tuple) => { - let ty = UnionType::from_elements( + let ty = UnionType::from_elements_leave_aliases( self.db(), tuple .iter() @@ -10548,11 +10548,11 @@ impl<'db> TypeInferenceBuilder<'db, '_> { }, SpecialFormType::Optional => { let param_type = self.infer_type_expression(arguments_slice); - UnionType::from_elements(db, [param_type, Type::none(db)]) + UnionType::from_elements_leave_aliases(db, [param_type, Type::none(db)]) } SpecialFormType::Union => match arguments_slice { ast::Expr::Tuple(t) => { - let union_ty = UnionType::from_elements( + let union_ty = UnionType::from_elements_leave_aliases( db, t.iter().map(|elt| self.infer_type_expression(elt)), ); From d71518b3690a56f519e70cf3a3dca7eccf36d7c8 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 27 Aug 2025 12:56:14 +0100 Subject: [PATCH 146/160] [ty] Add more tests for protocols (#20095) Co-authored-by: Shunsuke Shibayama --- .../resources/mdtest/protocols.md | 115 ++++++++++++++++-- 1 file changed, 108 insertions(+), 7 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/protocols.md b/crates/ty_python_semantic/resources/mdtest/protocols.md index 5ad6f576d518d..42971c61f4fd1 100644 --- a/crates/ty_python_semantic/resources/mdtest/protocols.md +++ b/crates/ty_python_semantic/resources/mdtest/protocols.md @@ -1392,10 +1392,16 @@ static_assert(is_subtype_of(XClassVar, HasXProperty)) static_assert(is_assignable_to(XClassVar, HasXProperty)) class XFinal: - x: Final = 42 + x: Final[int] = 42 static_assert(is_subtype_of(XFinal, HasXProperty)) static_assert(is_assignable_to(XFinal, HasXProperty)) + +class XImplicitFinal: + x: Final = 42 + +static_assert(is_subtype_of(XImplicitFinal, HasXProperty)) +static_assert(is_assignable_to(XImplicitFinal, HasXProperty)) ``` A read-only property on a protocol, unlike a mutable attribute, is covariant: `XSub` in the below @@ -1451,9 +1457,8 @@ static_assert(is_assignable_to(XReadWriteProperty, HasXProperty)) class XSub: x: MyInt -# TODO: should pass -static_assert(not is_subtype_of(XSub, HasXProperty)) # error: [static-assert-error] -static_assert(not is_assignable_to(XSub, HasXProperty)) # error: [static-assert-error] +static_assert(not is_subtype_of(XSub, XReadWriteProperty)) +static_assert(not is_assignable_to(XSub, XReadWriteProperty)) ``` A protocol with a read/write property `x` is exactly equivalent to a protocol with a mutable @@ -1549,7 +1554,7 @@ class Descriptor: def __get__(self, instance, owner) -> MyInt: return MyInt(0) - def __set__(self, value: int) -> None: ... + def __set__(self, instance, value: int) -> None: ... class XCustomDescriptor: x: Descriptor = Descriptor() @@ -1595,6 +1600,16 @@ static_assert(is_assignable_to(HasGetAttrAndSetAttr, HasXProperty)) # TODO: these should pass static_assert(is_subtype_of(HasGetAttrAndSetAttr, XAsymmetricProperty)) # error: [static-assert-error] static_assert(is_assignable_to(HasGetAttrAndSetAttr, XAsymmetricProperty)) # error: [static-assert-error] + +class HasSetAttrWithUnsuitableInput: + def __getattr__(self, attr: str) -> int: + return 1 + + def __setattr__(self, attr: str, value: str) -> None: ... + +# TODO: these should pass +static_assert(not is_subtype_of(HasSetAttrWithUnsuitableInput, HasMutableXProperty)) # error: [static-assert-error] +static_assert(not is_assignable_to(HasSetAttrWithUnsuitableInput, HasMutableXProperty)) # error: [static-assert-error] ``` ## Subtyping of protocols with method members @@ -1684,11 +1699,12 @@ class Bar: f(Bar()) # error: [invalid-argument-type] ``` -## Equivalence of protocols with method members +## Equivalence of protocols with method or property members Two protocols `P1` and `P2`, both with a method member `x`, are considered equivalent if the signature of `P1.x` is equivalent to the signature of `P2.x`, even though ty would normally model -any two function definitions as inhabiting distinct function-literal types. +any two function definitions as inhabiting distinct function-literal types. The same is also true +for property members. ```py from typing import Protocol @@ -1700,7 +1716,26 @@ class P1(Protocol): class P2(Protocol): def x(self, y: int) -> None: ... +class P3(Protocol): + @property + def y(self) -> str: ... + @property + def z(self) -> bytes: ... + @z.setter + def z(self, value: int) -> None: ... + +class P4(Protocol): + @property + def y(self) -> str: ... + @property + def z(self) -> bytes: ... + @z.setter + def z(self, value: int) -> None: ... + static_assert(is_equivalent_to(P1, P2)) + +# TODO: should pass +static_assert(is_equivalent_to(P3, P4)) # error: [static-assert-error] ``` As with protocols that only have non-method members, this also holds true when they appear in @@ -1711,6 +1746,9 @@ class A: ... class B: ... static_assert(is_equivalent_to(A | B | P1, P2 | B | A)) + +# TODO: should pass +static_assert(is_equivalent_to(A | B | P3, P4 | B | A)) # error: [static-assert-error] ``` ## Narrowing of protocols @@ -2198,6 +2236,69 @@ def f(value: Iterator): cast(Iterator, value) # error: [redundant-cast] ``` +### Recursive generic protocols + +This snippet caused us to stack overflow on an early version of +: + +```toml +[environment] +python-version = "3.12" +``` + +```py +from typing import Protocol, TypeVar + +class A: ... + +class Foo[T](Protocol): + def x(self) -> "T | Foo[T]": ... + +y: A | Foo[A] + +# The same thing, but using the legacy syntax: + +S = TypeVar("S") + +class Bar(Protocol[S]): + def x(self) -> "S | Bar[S]": ... + +z: S | Bar[S] +``` + +### Recursive generic protocols with property members + +An early version of caused stack overflows on this +snippet: + +```toml +[environment] +python-version = "3.12" +``` + +```py +from typing import Protocol + +class Foo[T]: ... + +class A(Protocol): + @property + def _(self: "A") -> Foo: ... + +class B(Protocol): + @property + def b(self) -> Foo[A]: ... + +class C(Undefined): ... # error: "Name `Undefined` used when not defined" + +class D: + b: Foo[C] + +class E[T: B](Protocol): ... + +x: E[D] +``` + ## Meta-protocols Where `P` is a protocol type, a class object `N` can be said to inhabit the type `type[P]` if: From 7d0c8e045c3ae090c007b83f79ae8914ae89bbaa Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 27 Aug 2025 13:21:47 +0100 Subject: [PATCH 147/160] [ty] Infer slightly more precise types for comprehensions (#20111) --- .../resources/mdtest/annotations/invalid.md | 18 ++++ .../mdtest/assignment/annotations.md | 2 +- .../resources/mdtest/del.md | 4 +- .../mdtest/directives/assert_never.md | 6 -- .../resources/mdtest/import/dunder_all.md | 2 +- .../mdtest/literal/collections/dictionary.md | 9 +- .../collections/generator_expressions.md | 6 ++ .../mdtest/literal/collections/list.md | 8 +- .../mdtest/literal/collections/set.md | 8 +- .../resources/mdtest/narrow/assignment.md | 2 +- .../mdtest/narrow/conditionals/nested.md | 2 +- ...lity_-_Diagnostics_(be8f5d8b0718ee54).snap | 86 +++++-------------- .../resources/mdtest/subscript/lists.md | 6 +- .../resources/mdtest/type_compendium/tuple.md | 4 +- .../resources/mdtest/unpacking.md | 4 +- crates/ty_python_semantic/src/types/infer.rs | 39 ++++++--- 16 files changed, 111 insertions(+), 95 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/literal/collections/generator_expressions.md diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/invalid.md b/crates/ty_python_semantic/resources/mdtest/annotations/invalid.md index 29542eb8d5a8c..91d55f7352684 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/invalid.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/invalid.md @@ -48,6 +48,24 @@ def _( reveal_type(h_) # revealed: Unknown reveal_type(i_) # revealed: Unknown reveal_type(j_) # revealed: Unknown + +# Inspired by the conformance test suite at +# https://github.com/python/typing/blob/d4f39b27a4a47aac8b6d4019e1b0b5b3156fabdc/conformance/tests/aliases_implicit.py#L88-L122 +B = [x for x in range(42)] +C = {x for x in range(42)} +D = {x: y for x, y in enumerate(range(42))} +E = (x for x in range(42)) + +def _( + b: B, # error: [invalid-type-form] + c: C, # error: [invalid-type-form] + d: D, # error: [invalid-type-form] + e: E, # error: [invalid-type-form] +): + reveal_type(b) # revealed: Unknown + reveal_type(c) # revealed: Unknown + reveal_type(d) # revealed: Unknown + reveal_type(e) # revealed: Unknown ``` ## Invalid AST nodes diff --git a/crates/ty_python_semantic/resources/mdtest/assignment/annotations.md b/crates/ty_python_semantic/resources/mdtest/assignment/annotations.md index f28e68c0d9db1..f684fd6f90000 100644 --- a/crates/ty_python_semantic/resources/mdtest/assignment/annotations.md +++ b/crates/ty_python_semantic/resources/mdtest/assignment/annotations.md @@ -75,7 +75,7 @@ a: tuple[()] = (1, 2) # error: [invalid-assignment] "Object of type `tuple[Literal["foo"]]` is not assignable to `tuple[int]`" b: tuple[int] = ("foo",) -# error: [invalid-assignment] "Object of type `tuple[list[Unknown], Literal["foo"]]` is not assignable to `tuple[str | int, str]`" +# error: [invalid-assignment] c: tuple[str | int, str] = ([], "foo") ``` diff --git a/crates/ty_python_semantic/resources/mdtest/del.md b/crates/ty_python_semantic/resources/mdtest/del.md index 247ae9e2756a2..7ba1505906194 100644 --- a/crates/ty_python_semantic/resources/mdtest/del.md +++ b/crates/ty_python_semantic/resources/mdtest/del.md @@ -46,7 +46,7 @@ def delete(): del d # error: [unresolved-reference] "Name `d` used when not defined" delete() -reveal_type(d) # revealed: list[Unknown] +reveal_type(d) # revealed: list[@Todo(list literal element type)] def delete_element(): # When the `del` target isn't a name, it doesn't force local resolution. @@ -62,7 +62,7 @@ def delete_global(): delete_global() # Again, the variable should have been removed, but we don't check it. -reveal_type(d) # revealed: list[Unknown] +reveal_type(d) # revealed: list[@Todo(list literal element type)] def delete_nonlocal(): e = 2 diff --git a/crates/ty_python_semantic/resources/mdtest/directives/assert_never.md b/crates/ty_python_semantic/resources/mdtest/directives/assert_never.md index f9e4ced7d542c..89c35aae5b0ca 100644 --- a/crates/ty_python_semantic/resources/mdtest/directives/assert_never.md +++ b/crates/ty_python_semantic/resources/mdtest/directives/assert_never.md @@ -33,12 +33,6 @@ def _(): def _(): assert_never(None) # error: [type-assertion-failure] -def _(): - assert_never([]) # error: [type-assertion-failure] - -def _(): - assert_never({}) # error: [type-assertion-failure] - def _(): assert_never(()) # error: [type-assertion-failure] diff --git a/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md b/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md index d77973265b0ac..7fbbb5907ec34 100644 --- a/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md +++ b/crates/ty_python_semantic/resources/mdtest/import/dunder_all.md @@ -785,7 +785,7 @@ from subexporter import * # TODO: Should be `list[str]` # TODO: Should we avoid including `Unknown` for this case? -reveal_type(__all__) # revealed: Unknown | list[Unknown] +reveal_type(__all__) # revealed: Unknown | list[@Todo(list literal element type)] __all__.append("B") diff --git a/crates/ty_python_semantic/resources/mdtest/literal/collections/dictionary.md b/crates/ty_python_semantic/resources/mdtest/literal/collections/dictionary.md index 37abd2b98bb20..31154c77d0075 100644 --- a/crates/ty_python_semantic/resources/mdtest/literal/collections/dictionary.md +++ b/crates/ty_python_semantic/resources/mdtest/literal/collections/dictionary.md @@ -3,5 +3,12 @@ ## Empty dictionary ```py -reveal_type({}) # revealed: dict[Unknown, Unknown] +reveal_type({}) # revealed: dict[@Todo(dict literal key type), @Todo(dict literal value type)] +``` + +## Dict comprehensions + +```py +# revealed: dict[@Todo(dict comprehension key type), @Todo(dict comprehension value type)] +reveal_type({x: y for x, y in enumerate(range(42))}) ``` diff --git a/crates/ty_python_semantic/resources/mdtest/literal/collections/generator_expressions.md b/crates/ty_python_semantic/resources/mdtest/literal/collections/generator_expressions.md new file mode 100644 index 0000000000000..1e266d92a8f75 --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/literal/collections/generator_expressions.md @@ -0,0 +1,6 @@ +# Generator expressions + +```py +# revealed: GeneratorType[@Todo(generator expression yield type), @Todo(generator expression send type), @Todo(generator expression return type)] +reveal_type((x for x in range(42))) +``` diff --git a/crates/ty_python_semantic/resources/mdtest/literal/collections/list.md b/crates/ty_python_semantic/resources/mdtest/literal/collections/list.md index 53915f27c2961..44f7eceec2eeb 100644 --- a/crates/ty_python_semantic/resources/mdtest/literal/collections/list.md +++ b/crates/ty_python_semantic/resources/mdtest/literal/collections/list.md @@ -3,5 +3,11 @@ ## Empty list ```py -reveal_type([]) # revealed: list[Unknown] +reveal_type([]) # revealed: list[@Todo(list literal element type)] +``` + +## List comprehensions + +```py +reveal_type([x for x in range(42)]) # revealed: list[@Todo(list comprehension element type)] ``` diff --git a/crates/ty_python_semantic/resources/mdtest/literal/collections/set.md b/crates/ty_python_semantic/resources/mdtest/literal/collections/set.md index 85acd78e3e1d2..39cd5ed5fa5c9 100644 --- a/crates/ty_python_semantic/resources/mdtest/literal/collections/set.md +++ b/crates/ty_python_semantic/resources/mdtest/literal/collections/set.md @@ -3,5 +3,11 @@ ## Basic set ```py -reveal_type({1, 2}) # revealed: set[Unknown] +reveal_type({1, 2}) # revealed: set[@Todo(set literal element type)] +``` + +## Set comprehensions + +```py +reveal_type({x for x in range(42)}) # revealed: set[@Todo(set comprehension element type)] ``` diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/assignment.md b/crates/ty_python_semantic/resources/mdtest/narrow/assignment.md index 65ff04b1077e8..18dc4242a5d30 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/assignment.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/assignment.md @@ -207,7 +207,7 @@ dd[0] = 0 cm: ChainMap[int, int] = ChainMap({1: 1}, {0: 0}) cm[0] = 0 # TODO: should be ChainMap[int, int] -reveal_type(cm) # revealed: ChainMap[Unknown, Unknown] +reveal_type(cm) # revealed: ChainMap[@Todo(dict literal key type), @Todo(dict literal value type)] reveal_type(l[0]) # revealed: Literal[0] reveal_type(d[0]) # revealed: Literal[0] diff --git a/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md b/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md index 4ab60f5e2c163..8236e0696e61a 100644 --- a/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md +++ b/crates/ty_python_semantic/resources/mdtest/narrow/conditionals/nested.md @@ -318,7 +318,7 @@ def f(l: list[str | None]): l: list[str | None] = [None] def _(): # TODO: should be `str | None` - reveal_type(l[0]) # revealed: Unknown + reveal_type(l[0]) # revealed: @Todo(list literal element type) def _(): def _(): diff --git a/crates/ty_python_semantic/resources/mdtest/snapshots/assert_never.md_-_`assert_never`_-_Basic_functionality_-_Diagnostics_(be8f5d8b0718ee54).snap b/crates/ty_python_semantic/resources/mdtest/snapshots/assert_never.md_-_`assert_never`_-_Basic_functionality_-_Diagnostics_(be8f5d8b0718ee54).snap index 8c2ae5522a0ec..a0576b55e0656 100644 --- a/crates/ty_python_semantic/resources/mdtest/snapshots/assert_never.md_-_`assert_never`_-_Basic_functionality_-_Diagnostics_(be8f5d8b0718ee54).snap +++ b/crates/ty_python_semantic/resources/mdtest/snapshots/assert_never.md_-_`assert_never`_-_Basic_functionality_-_Diagnostics_(be8f5d8b0718ee54).snap @@ -25,22 +25,16 @@ mdtest path: crates/ty_python_semantic/resources/mdtest/directives/assert_never. 11 | assert_never(None) # error: [type-assertion-failure] 12 | 13 | def _(): -14 | assert_never([]) # error: [type-assertion-failure] +14 | assert_never(()) # error: [type-assertion-failure] 15 | -16 | def _(): -17 | assert_never({}) # error: [type-assertion-failure] +16 | def _(flag: bool, never: Never): +17 | assert_never(1 if flag else never) # error: [type-assertion-failure] 18 | -19 | def _(): -20 | assert_never(()) # error: [type-assertion-failure] +19 | def _(any_: Any): +20 | assert_never(any_) # error: [type-assertion-failure] 21 | -22 | def _(flag: bool, never: Never): -23 | assert_never(1 if flag else never) # error: [type-assertion-failure] -24 | -25 | def _(any_: Any): -26 | assert_never(any_) # error: [type-assertion-failure] -27 | -28 | def _(unknown: Unknown): -29 | assert_never(unknown) # error: [type-assertion-failure] +22 | def _(unknown: Unknown): +23 | assert_never(unknown) # error: [type-assertion-failure] ``` # Diagnostics @@ -101,46 +95,12 @@ error[type-assertion-failure]: Argument does not have asserted type `Never` --> src/mdtest_snippet.py:14:5 | 13 | def _(): -14 | assert_never([]) # error: [type-assertion-failure] - | ^^^^^^^^^^^^^--^ - | | - | Inferred type of argument is `list[Unknown]` -15 | -16 | def _(): - | -info: `Never` and `list[Unknown]` are not equivalent types -info: rule `type-assertion-failure` is enabled by default - -``` - -``` -error[type-assertion-failure]: Argument does not have asserted type `Never` - --> src/mdtest_snippet.py:17:5 - | -16 | def _(): -17 | assert_never({}) # error: [type-assertion-failure] - | ^^^^^^^^^^^^^--^ - | | - | Inferred type of argument is `dict[Unknown, Unknown]` -18 | -19 | def _(): - | -info: `Never` and `dict[Unknown, Unknown]` are not equivalent types -info: rule `type-assertion-failure` is enabled by default - -``` - -``` -error[type-assertion-failure]: Argument does not have asserted type `Never` - --> src/mdtest_snippet.py:20:5 - | -19 | def _(): -20 | assert_never(()) # error: [type-assertion-failure] +14 | assert_never(()) # error: [type-assertion-failure] | ^^^^^^^^^^^^^--^ | | | Inferred type of argument is `tuple[()]` -21 | -22 | def _(flag: bool, never: Never): +15 | +16 | def _(flag: bool, never: Never): | info: `Never` and `tuple[()]` are not equivalent types info: rule `type-assertion-failure` is enabled by default @@ -149,15 +109,15 @@ info: rule `type-assertion-failure` is enabled by default ``` error[type-assertion-failure]: Argument does not have asserted type `Never` - --> src/mdtest_snippet.py:23:5 + --> src/mdtest_snippet.py:17:5 | -22 | def _(flag: bool, never: Never): -23 | assert_never(1 if flag else never) # error: [type-assertion-failure] +16 | def _(flag: bool, never: Never): +17 | assert_never(1 if flag else never) # error: [type-assertion-failure] | ^^^^^^^^^^^^^--------------------^ | | | Inferred type of argument is `Literal[1]` -24 | -25 | def _(any_: Any): +18 | +19 | def _(any_: Any): | info: `Never` and `Literal[1]` are not equivalent types info: rule `type-assertion-failure` is enabled by default @@ -166,15 +126,15 @@ info: rule `type-assertion-failure` is enabled by default ``` error[type-assertion-failure]: Argument does not have asserted type `Never` - --> src/mdtest_snippet.py:26:5 + --> src/mdtest_snippet.py:20:5 | -25 | def _(any_: Any): -26 | assert_never(any_) # error: [type-assertion-failure] +19 | def _(any_: Any): +20 | assert_never(any_) # error: [type-assertion-failure] | ^^^^^^^^^^^^^----^ | | | Inferred type of argument is `Any` -27 | -28 | def _(unknown: Unknown): +21 | +22 | def _(unknown: Unknown): | info: `Never` and `Any` are not equivalent types info: rule `type-assertion-failure` is enabled by default @@ -183,10 +143,10 @@ info: rule `type-assertion-failure` is enabled by default ``` error[type-assertion-failure]: Argument does not have asserted type `Never` - --> src/mdtest_snippet.py:29:5 + --> src/mdtest_snippet.py:23:5 | -28 | def _(unknown: Unknown): -29 | assert_never(unknown) # error: [type-assertion-failure] +22 | def _(unknown: Unknown): +23 | assert_never(unknown) # error: [type-assertion-failure] | ^^^^^^^^^^^^^-------^ | | | Inferred type of argument is `Unknown` diff --git a/crates/ty_python_semantic/resources/mdtest/subscript/lists.md b/crates/ty_python_semantic/resources/mdtest/subscript/lists.md index 98aeec813530f..2954092d2c420 100644 --- a/crates/ty_python_semantic/resources/mdtest/subscript/lists.md +++ b/crates/ty_python_semantic/resources/mdtest/subscript/lists.md @@ -9,13 +9,13 @@ A list can be indexed into with: ```py x = [1, 2, 3] -reveal_type(x) # revealed: list[Unknown] +reveal_type(x) # revealed: list[@Todo(list literal element type)] # TODO reveal int -reveal_type(x[0]) # revealed: Unknown +reveal_type(x[0]) # revealed: @Todo(list literal element type) # TODO reveal list[int] -reveal_type(x[0:1]) # revealed: list[Unknown] +reveal_type(x[0:1]) # revealed: list[@Todo(list literal element type)] # error: [invalid-argument-type] reveal_type(x["a"]) # revealed: Unknown diff --git a/crates/ty_python_semantic/resources/mdtest/type_compendium/tuple.md b/crates/ty_python_semantic/resources/mdtest/type_compendium/tuple.md index 71f177ed6aee5..d39ab532469b9 100644 --- a/crates/ty_python_semantic/resources/mdtest/type_compendium/tuple.md +++ b/crates/ty_python_semantic/resources/mdtest/type_compendium/tuple.md @@ -47,9 +47,9 @@ def f(x: Iterable[int], y: list[str], z: Never, aa: list[Never]): reveal_type(tuple((1, 2))) # revealed: tuple[Literal[1], Literal[2]] # TODO: should be `tuple[Literal[1], ...]` -reveal_type(tuple([1])) # revealed: tuple[Unknown, ...] +reveal_type(tuple([1])) # revealed: tuple[@Todo(list literal element type), ...] -# error: [invalid-argument-type] "Argument is incorrect: Expected `tuple[int]`, found `list[Unknown]`" +# error: [invalid-argument-type] reveal_type(tuple[int]([1])) # revealed: tuple[int] # error: [invalid-argument-type] "Argument is incorrect: Expected `tuple[int, str]`, found `tuple[Literal[1]]`" diff --git a/crates/ty_python_semantic/resources/mdtest/unpacking.md b/crates/ty_python_semantic/resources/mdtest/unpacking.md index 5944bcc115b8d..377fec25fb6a3 100644 --- a/crates/ty_python_semantic/resources/mdtest/unpacking.md +++ b/crates/ty_python_semantic/resources/mdtest/unpacking.md @@ -214,8 +214,8 @@ reveal_type(d) # revealed: Literal[2] ```py a, b = [1, 2] # TODO: should be `int` for both `a` and `b` -reveal_type(a) # revealed: Unknown -reveal_type(b) # revealed: Unknown +reveal_type(a) # revealed: @Todo(list literal element type) +reveal_type(b) # revealed: @Todo(list literal element type) ``` ### Simple unpacking diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 2c90af40c7416..6413bbefaa6ea 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -5805,8 +5805,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { self.infer_expression(elt); } - // TODO generic - KnownClass::List.to_instance(self.db()) + KnownClass::List + .to_specialized_instance(self.db(), [todo_type!("list literal element type")]) } fn infer_set_expression(&mut self, set: &ast::ExprSet) -> Type<'db> { @@ -5820,8 +5820,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { self.infer_expression(elt); } - // TODO generic - KnownClass::Set.to_instance(self.db()) + KnownClass::Set.to_specialized_instance(self.db(), [todo_type!("set literal element type")]) } fn infer_dict_expression(&mut self, dict: &ast::ExprDict) -> Type<'db> { @@ -5836,8 +5835,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { self.infer_expression(&item.value); } - // TODO generic - KnownClass::Dict.to_instance(self.db()) + KnownClass::Dict.to_specialized_instance( + self.db(), + [ + todo_type!("dict literal key type"), + todo_type!("dict literal value type"), + ], + ) } /// Infer the type of the `iter` expression of the first comprehension. @@ -5860,7 +5864,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { self.infer_first_comprehension_iter(generators); - todo_type!("generator type") + KnownClass::GeneratorType.to_specialized_instance( + self.db(), + [ + todo_type!("generator expression yield type"), + todo_type!("generator expression send type"), + todo_type!("generator expression return type"), + ], + ) } fn infer_list_comprehension_expression(&mut self, listcomp: &ast::ExprListComp) -> Type<'db> { @@ -5873,7 +5884,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { self.infer_first_comprehension_iter(generators); - todo_type!("list comprehension type") + KnownClass::List + .to_specialized_instance(self.db(), [todo_type!("list comprehension element type")]) } fn infer_dict_comprehension_expression(&mut self, dictcomp: &ast::ExprDictComp) -> Type<'db> { @@ -5887,7 +5899,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { self.infer_first_comprehension_iter(generators); - todo_type!("dict comprehension type") + KnownClass::Dict.to_specialized_instance( + self.db(), + [ + todo_type!("dict comprehension key type"), + todo_type!("dict comprehension value type"), + ], + ) } fn infer_set_comprehension_expression(&mut self, setcomp: &ast::ExprSetComp) -> Type<'db> { @@ -5900,7 +5918,8 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { self.infer_first_comprehension_iter(generators); - todo_type!("set comprehension type") + KnownClass::Set + .to_specialized_instance(self.db(), [todo_type!("set comprehension element type")]) } fn infer_generator_expression_scope(&mut self, generator: &ast::ExprGenerator) { From ce1dc21e7ee99eebd5c2a00c2a0c9be4827321d1 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Wed, 27 Aug 2025 18:16:15 +0100 Subject: [PATCH 148/160] [ty] Fix the inferred interface of specialized generic protocols (#19866) --- .../resources/mdtest/call/overloads.md | 43 +++++++++ .../resources/mdtest/protocols.md | 83 ++++++++++++++++- .../ty_python_semantic/src/types/call/bind.rs | 7 ++ crates/ty_python_semantic/src/types/class.rs | 8 ++ .../src/types/diagnostic.rs | 8 +- .../ty_python_semantic/src/types/function.rs | 2 +- crates/ty_python_semantic/src/types/infer.rs | 9 +- .../ty_python_semantic/src/types/instance.rs | 4 +- .../src/types/protocol_class.rs | 93 +++++++++++-------- 9 files changed, 200 insertions(+), 57 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/call/overloads.md b/crates/ty_python_semantic/resources/mdtest/call/overloads.md index c2cc47d1eed39..ca34c94b5e6a8 100644 --- a/crates/ty_python_semantic/resources/mdtest/call/overloads.md +++ b/crates/ty_python_semantic/resources/mdtest/call/overloads.md @@ -1038,6 +1038,49 @@ def _(int_str: tuple[int, str], int_any: tuple[int, Any], any_any: tuple[Any, An reveal_type(f(*(any_any,))) # revealed: Unknown ``` +### `Unknown` passed into an overloaded function annotated with protocols + +`Foo.join()` here has similar annotations to `str.join()` in typeshed: + +`module.pyi`: + +```pyi +from typing_extensions import Iterable, overload, LiteralString, Protocol +from ty_extensions import Unknown, is_assignable_to + +class Foo: + @overload + def join(self, iterable: Iterable[LiteralString], /) -> LiteralString: ... + @overload + def join(self, iterable: Iterable[str], /) -> str: ... +``` + +`main.py`: + +```py +from module import Foo +from typing_extensions import LiteralString + +def f(a: Foo, b: list[str], c: list[LiteralString], e): + reveal_type(e) # revealed: Unknown + + # TODO: we should select the second overload here and reveal `str` + # (the incorrect result is due to missing logic in protocol subtyping/assignability) + reveal_type(a.join(b)) # revealed: LiteralString + + reveal_type(a.join(c)) # revealed: LiteralString + + # since both overloads match and they have return types that are not equivalent, + # step (5) of the overload evaluation algorithm says we must evaluate the result of the + # call as `Unknown`. + # + # Note: although the spec does not state as such (since intersections in general are not + # specified currently), `(str | LiteralString) & Unknown` might also be a reasonable type + # here (the union of all overload returns, intersected with `Unknown`) -- here that would + # simplify to `str & Unknown`. + reveal_type(a.join(e)) # revealed: Unknown +``` + ### Multiple arguments `overloaded.pyi`: diff --git a/crates/ty_python_semantic/resources/mdtest/protocols.md b/crates/ty_python_semantic/resources/mdtest/protocols.md index 42971c61f4fd1..d0b72df047996 100644 --- a/crates/ty_python_semantic/resources/mdtest/protocols.md +++ b/crates/ty_python_semantic/resources/mdtest/protocols.md @@ -95,6 +95,20 @@ class NotAProtocol: ... reveal_type(is_protocol(NotAProtocol)) # revealed: Literal[False] ``` +Note, however, that `is_protocol` returns `False` at runtime for specializations of generic +protocols. We still consider these to be "protocol classes" internally, regardless: + +```py +class MyGenericProtocol[T](Protocol): + x: T + +reveal_type(is_protocol(MyGenericProtocol)) # revealed: Literal[True] + +# We still consider this a protocol class internally, +# but the inferred type of the call here reflects the result at runtime: +reveal_type(is_protocol(MyGenericProtocol[int])) # revealed: Literal[False] +``` + A type checker should follow the typeshed stubs if a non-class is passed in, and typeshed's stubs indicate that the argument passed in must be an instance of `type`. @@ -397,24 +411,38 @@ To see the kinds and types of the protocol members, you can use the debugging ai ```py from ty_extensions import reveal_protocol_interface -from typing import SupportsIndex, SupportsAbs, ClassVar +from typing import SupportsIndex, SupportsAbs, ClassVar, Iterator # error: [revealed-type] "Revealed protocol interface: `{"method_member": MethodMember(`(self) -> bytes`), "x": AttributeMember(`int`), "y": PropertyMember { getter: `def y(self) -> str` }, "z": PropertyMember { getter: `def z(self) -> int`, setter: `def z(self, z: int) -> None` }}`" reveal_protocol_interface(Foo) # error: [revealed-type] "Revealed protocol interface: `{"__index__": MethodMember(`(self) -> int`)}`" reveal_protocol_interface(SupportsIndex) -# error: [revealed-type] "Revealed protocol interface: `{"__abs__": MethodMember(`(self) -> _T_co@SupportsAbs`)}`" +# error: [revealed-type] "Revealed protocol interface: `{"__abs__": MethodMember(`(self) -> Unknown`)}`" reveal_protocol_interface(SupportsAbs) +# error: [revealed-type] "Revealed protocol interface: `{"__iter__": MethodMember(`(self) -> Iterator[Unknown]`), "__next__": MethodMember(`(self) -> Unknown`)}`" +reveal_protocol_interface(Iterator) # error: [invalid-argument-type] "Invalid argument to `reveal_protocol_interface`: Only protocol classes can be passed to `reveal_protocol_interface`" reveal_protocol_interface(int) # error: [invalid-argument-type] "Argument to function `reveal_protocol_interface` is incorrect: Expected `type`, found `Literal["foo"]`" reveal_protocol_interface("foo") +``` -# TODO: this should be a `revealed-type` diagnostic rather than `invalid-argument-type`, and it should reveal `{"__abs__": MethodMember(`(self) -> int`)}` for the protocol interface -# -# error: [invalid-argument-type] "Invalid argument to `reveal_protocol_interface`: Only protocol classes can be passed to `reveal_protocol_interface`" +Similar to the way that `typing.is_protocol` returns `False` at runtime for all generic aliases, +`typing.get_protocol_members` raises an exception at runtime if you pass it a generic alias, so we +do not implement any special handling for generic aliases passed to the function. +`ty_extensions.reveal_protocol_interface` can be used on both, however: + +```py +# TODO: these fail at runtime, but we don't emit `[invalid-argument-type]` diagnostics +# currently due to https://github.com/astral-sh/ty/issues/116 +reveal_type(get_protocol_members(SupportsAbs[int])) # revealed: frozenset[str] +reveal_type(get_protocol_members(Iterator[int])) # revealed: frozenset[str] + +# error: [revealed-type] "Revealed protocol interface: `{"__abs__": MethodMember(`(self) -> int`)}`" reveal_protocol_interface(SupportsAbs[int]) +# error: [revealed-type] "Revealed protocol interface: `{"__iter__": MethodMember(`(self) -> Iterator[int]`), "__next__": MethodMember(`(self) -> int`)}`" +reveal_protocol_interface(Iterator[int]) class BaseProto(Protocol): def member(self) -> int: ... @@ -1032,6 +1060,11 @@ class A(Protocol): ## Equivalence of protocols +```toml +[environment] +python-version = "3.12" +``` + Two protocols are considered equivalent types if they specify the same interface, even if they have different names: @@ -1080,6 +1113,46 @@ static_assert(is_equivalent_to(UnionProto1, UnionProto2)) static_assert(is_equivalent_to(UnionProto1 | A | B, B | UnionProto2 | A)) ``` +Different generic protocols with equivalent specializations can be equivalent, but generic protocols +with different specializations are not considered equivalent: + +```py +from typing import TypeVar + +S = TypeVar("S") + +class NonGenericProto1(Protocol): + x: int + y: str + +class NonGenericProto2(Protocol): + y: str + x: int + +class Nominal1: ... +class Nominal2: ... + +class GenericProto[T](Protocol): + x: T + +class LegacyGenericProto(Protocol[S]): + x: S + +static_assert(is_equivalent_to(GenericProto[int], LegacyGenericProto[int])) +static_assert(is_equivalent_to(GenericProto[NonGenericProto1], LegacyGenericProto[NonGenericProto2])) + +static_assert( + is_equivalent_to( + GenericProto[NonGenericProto1 | Nominal1 | Nominal2], LegacyGenericProto[Nominal2 | Nominal1 | NonGenericProto2] + ) +) + +static_assert(not is_equivalent_to(GenericProto[str], GenericProto[int])) +static_assert(not is_equivalent_to(GenericProto[str], LegacyGenericProto[int])) +static_assert(not is_equivalent_to(GenericProto, GenericProto[int])) +static_assert(not is_equivalent_to(LegacyGenericProto, LegacyGenericProto[int])) +``` + ## Intersections of protocols An intersection of two protocol types `X` and `Y` is equivalent to a protocol type `Z` that inherits diff --git a/crates/ty_python_semantic/src/types/call/bind.rs b/crates/ty_python_semantic/src/types/call/bind.rs index da1d962f9999b..4933e515e687f 100644 --- a/crates/ty_python_semantic/src/types/call/bind.rs +++ b/crates/ty_python_semantic/src/types/call/bind.rs @@ -748,6 +748,10 @@ impl<'db> Bindings<'db> { Some(KnownFunction::IsProtocol) => { if let [Some(ty)] = overload.parameter_types() { + // We evaluate this to `Literal[True]` only if the runtime function `typing.is_protocol` + // would return `True` for the given type. Internally we consider `SupportsAbs[int]` to + // be a "(specialised) protocol class", but `typing.is_protocol(SupportsAbs[int])` returns + // `False` at runtime, so we do not set the return type to `Literal[True]` in this case. overload.set_return_type(Type::BooleanLiteral( ty.into_class_literal() .is_some_and(|class| class.is_protocol(db)), @@ -756,6 +760,9 @@ impl<'db> Bindings<'db> { } Some(KnownFunction::GetProtocolMembers) => { + // Similarly to `is_protocol`, we only evaluate to this a frozenset of literal strings if a + // class-literal is passed in, not if a generic alias is passed in, to emulate the behaviour + // of `typing.get_protocol_members` at runtime. if let [Some(Type::ClassLiteral(class))] = overload.parameter_types() { if let Some(protocol_class) = class.into_protocol_class(db) { let member_names = protocol_class diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index d29a0afdee62a..a99a2af6ca874 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -1198,6 +1198,14 @@ impl<'db> ClassType<'db> { } } } + + pub(super) fn is_protocol(self, db: &'db dyn Db) -> bool { + self.class_literal(db).0.is_protocol(db) + } + + pub(super) fn header_span(self, db: &'db dyn Db) -> Span { + self.class_literal(db).0.header_span(db) + } } impl<'db> From> for ClassType<'db> { diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index 5377614e5a111..44981271c1249 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -20,7 +20,7 @@ use crate::types::string_annotation::{ use crate::types::{ DynamicType, LintDiagnosticGuard, Protocol, ProtocolInstanceType, SubclassOfInner, binding_type, }; -use crate::types::{SpecialFormType, Type, protocol_class::ProtocolClassLiteral}; +use crate::types::{SpecialFormType, Type, protocol_class::ProtocolClass}; use crate::util::diagnostics::format_enumeration; use crate::{Db, FxIndexMap, FxOrderMap, Module, ModuleName, Program, declare_lint}; use itertools::Itertools; @@ -2467,7 +2467,7 @@ pub(crate) fn add_type_expression_reference_link<'db, 'ctx>( pub(crate) fn report_runtime_check_against_non_runtime_checkable_protocol( context: &InferContext, call: &ast::ExprCall, - protocol: ProtocolClassLiteral, + protocol: ProtocolClass, function: KnownFunction, ) { let Some(builder) = context.report_lint(&INVALID_ARGUMENT_TYPE, call) else { @@ -2504,7 +2504,7 @@ pub(crate) fn report_runtime_check_against_non_runtime_checkable_protocol( pub(crate) fn report_attempted_protocol_instantiation( context: &InferContext, call: &ast::ExprCall, - protocol: ProtocolClassLiteral, + protocol: ProtocolClass, ) { let Some(builder) = context.report_lint(&CALL_NON_CALLABLE, call) else { return; @@ -2529,7 +2529,7 @@ pub(crate) fn report_attempted_protocol_instantiation( pub(crate) fn report_undeclared_protocol_member( context: &InferContext, definition: Definition, - protocol_class: ProtocolClassLiteral, + protocol_class: ProtocolClass, class_symbol_table: &PlaceTable, ) { /// We want to avoid suggesting an annotation for e.g. `x = None`, diff --git a/crates/ty_python_semantic/src/types/function.rs b/crates/ty_python_semantic/src/types/function.rs index 5fc02fc0c372b..8840e00413e29 100644 --- a/crates/ty_python_semantic/src/types/function.rs +++ b/crates/ty_python_semantic/src/types/function.rs @@ -1433,7 +1433,7 @@ impl KnownFunction { return; }; let Some(protocol_class) = param_type - .into_class_literal() + .to_class_type(db) .and_then(|class| class.into_protocol_class(db)) else { report_bad_argument_to_protocol_interface( diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 6413bbefaa6ea..67fb854f17816 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -1216,8 +1216,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } if is_protocol - && !(base_class.class_literal(self.db()).0.is_protocol(self.db()) - || base_class.is_known(self.db(), KnownClass::Object)) + && !(base_class.is_protocol(self.db()) || base_class.is_object(self.db())) { if let Some(builder) = self .context @@ -6249,11 +6248,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { // subclasses of the protocol to be passed to parameters that accept `type[SomeProtocol]`. // . if !callable_type.is_subclass_of() { - if let Some(protocol) = class - .class_literal(self.db()) - .0 - .into_protocol_class(self.db()) - { + if let Some(protocol) = class.into_protocol_class(self.db()) { report_attempted_protocol_instantiation( &self.context, call_expression, diff --git a/crates/ty_python_semantic/src/types/instance.rs b/crates/ty_python_semantic/src/types/instance.rs index 1a403e11ea17b..fb6bff18fc3e3 100644 --- a/crates/ty_python_semantic/src/types/instance.rs +++ b/crates/ty_python_semantic/src/types/instance.rs @@ -645,10 +645,8 @@ impl<'db> Protocol<'db> { fn interface(self, db: &'db dyn Db) -> ProtocolInterface<'db> { match self { Self::FromClass(class) => class - .class_literal(db) - .0 .into_protocol_class(db) - .expect("Protocol class literal should be a protocol class") + .expect("Class wrapped by `Protocol` should be a protocol class") .interface(db), Self::Synthesized(synthesized) => synthesized.interface(), } diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index 6bb6a16ac4027..ec1e394167114 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -9,6 +9,7 @@ use rustc_hash::FxHashMap; use super::TypeVarVariance; use crate::semantic_index::place::ScopedPlaceId; use crate::semantic_index::{SemanticIndex, place_table}; +use crate::types::ClassType; use crate::types::context::InferContext; use crate::types::diagnostic::report_undeclared_protocol_member; use crate::{ @@ -26,16 +27,24 @@ use crate::{ impl<'db> ClassLiteral<'db> { /// Returns `Some` if this is a protocol class, `None` otherwise. - pub(super) fn into_protocol_class(self, db: &'db dyn Db) -> Option> { - self.is_protocol(db).then_some(ProtocolClassLiteral(self)) + pub(super) fn into_protocol_class(self, db: &'db dyn Db) -> Option> { + self.is_protocol(db) + .then_some(ProtocolClass(ClassType::NonGeneric(self))) + } +} + +impl<'db> ClassType<'db> { + /// Returns `Some` if this is a protocol class, `None` otherwise. + pub(super) fn into_protocol_class(self, db: &'db dyn Db) -> Option> { + self.is_protocol(db).then_some(ProtocolClass(self)) } } /// Representation of a single `Protocol` class definition. #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub(super) struct ProtocolClassLiteral<'db>(ClassLiteral<'db>); +pub(super) struct ProtocolClass<'db>(ClassType<'db>); -impl<'db> ProtocolClassLiteral<'db> { +impl<'db> ProtocolClass<'db> { /// Returns the protocol members of this class. /// /// A protocol's members define the interface declared by the protocol. @@ -56,7 +65,9 @@ impl<'db> ProtocolClassLiteral<'db> { } pub(super) fn is_runtime_checkable(self, db: &'db dyn Db) -> bool { - self.known_function_decorators(db) + self.class_literal(db) + .0 + .known_function_decorators(db) .contains(&KnownFunction::RuntimeCheckable) } @@ -66,10 +77,11 @@ impl<'db> ProtocolClassLiteral<'db> { pub(super) fn validate_members(self, context: &InferContext, index: &SemanticIndex<'db>) { let db = context.db(); let interface = self.interface(db); - let class_place_table = index.place_table(self.body_scope(db).file_scope_id(db)); + let body_scope = self.class_literal(db).0.body_scope(db); + let class_place_table = index.place_table(body_scope.file_scope_id(db)); for (symbol_id, mut bindings_iterator) in - use_def_map(db, self.body_scope(db)).all_end_of_scope_symbol_bindings() + use_def_map(db, body_scope).all_end_of_scope_symbol_bindings() { let symbol_name = class_place_table.symbol(symbol_id).name(); @@ -77,27 +89,27 @@ impl<'db> ProtocolClassLiteral<'db> { continue; } - let has_declaration = self - .iter_mro(db, None) - .filter_map(ClassBase::into_class) - .any(|superclass| { - let superclass_scope = superclass.class_literal(db).0.body_scope(db); - let Some(scoped_symbol_id) = - place_table(db, superclass_scope).symbol_id(symbol_name) - else { - return false; - }; - !place_from_declarations( - db, - index - .use_def_map(superclass_scope.file_scope_id(db)) - .end_of_scope_declarations(ScopedPlaceId::Symbol(scoped_symbol_id)), - ) - .into_place_and_conflicting_declarations() - .0 - .place - .is_unbound() - }); + let has_declaration = + self.iter_mro(db) + .filter_map(ClassBase::into_class) + .any(|superclass| { + let superclass_scope = superclass.class_literal(db).0.body_scope(db); + let Some(scoped_symbol_id) = + place_table(db, superclass_scope).symbol_id(symbol_name) + else { + return false; + }; + !place_from_declarations( + db, + index + .use_def_map(superclass_scope.file_scope_id(db)) + .end_of_scope_declarations(ScopedPlaceId::Symbol(scoped_symbol_id)), + ) + .into_place_and_conflicting_declarations() + .0 + .place + .is_unbound() + }); if has_declaration { continue; @@ -114,8 +126,8 @@ impl<'db> ProtocolClassLiteral<'db> { } } -impl<'db> Deref for ProtocolClassLiteral<'db> { - type Target = ClassLiteral<'db>; +impl<'db> Deref for ProtocolClass<'db> { + type Target = ClassType<'db>; fn deref(&self) -> &Self::Target { &self.0 @@ -622,16 +634,19 @@ impl BoundOnClass { #[salsa::tracked(cycle_fn=proto_interface_cycle_recover, cycle_initial=proto_interface_cycle_initial, heap_size=ruff_memory_usage::heap_size)] fn cached_protocol_interface<'db>( db: &'db dyn Db, - class: ClassLiteral<'db>, + class: ClassType<'db>, ) -> ProtocolInterface<'db> { let mut members = BTreeMap::default(); - for parent_protocol in class - .iter_mro(db, None) + for (parent_protocol, specialization) in class + .iter_mro(db) .filter_map(ClassBase::into_class) - .filter_map(|class| class.class_literal(db).0.into_protocol_class(db)) + .filter_map(|class| { + let (class, specialization) = class.class_literal(db); + Some((class.into_protocol_class(db)?, specialization)) + }) { - let parent_scope = parent_protocol.body_scope(db); + let parent_scope = parent_protocol.class_literal(db).0.body_scope(db); let use_def_map = use_def_map(db, parent_scope); let place_table = place_table(db, parent_scope); let mut direct_members = FxHashMap::default(); @@ -676,6 +691,8 @@ fn cached_protocol_interface<'db>( continue; } + let ty = ty.apply_optional_specialization(db, specialization); + let member = match ty { Type::PropertyInstance(property) => ProtocolMemberKind::Property(property), Type::Callable(callable) @@ -702,19 +719,21 @@ fn cached_protocol_interface<'db>( ProtocolInterface::new(db, members) } +// If we use `expect(clippy::trivially_copy_pass_by_ref)` here, +// the lint expectation is unfulfilled on WASM #[allow(clippy::trivially_copy_pass_by_ref)] fn proto_interface_cycle_recover<'db>( _db: &dyn Db, _value: &ProtocolInterface<'db>, _count: u32, - _class: ClassLiteral<'db>, + _class: ClassType<'db>, ) -> salsa::CycleRecoveryAction> { salsa::CycleRecoveryAction::Iterate } fn proto_interface_cycle_initial<'db>( db: &'db dyn Db, - _class: ClassLiteral<'db>, + _class: ClassType<'db>, ) -> ProtocolInterface<'db> { ProtocolInterface::empty(db) } From 0b3548755c81d10d9f43d52c2a4516f4b903210b Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 27 Aug 2025 20:01:45 +0200 Subject: [PATCH 149/160] [ty] Preserve qualifiers when accessing attributes on unions/intersections (#20114) ## Summary Properly preserve type qualifiers when accessing attributes on unions and intersections. This is a prerequisite for https://github.com/astral-sh/ruff/pull/19579. Also fix a completely wrong implementation of `map_with_boundness_and_qualifiers`. It now closely follows `map_with_boundness` (just above). ## Test Plan I thought about it, but didn't find any easy way to test this. This only affected `Type::member`. Things like validation of attribute writes (where type qualifiers like `ClassVar` and `Final` are important) were already handling things correctly. --- .../resources/mdtest/annotations/callable.md | 2 +- crates/ty_python_semantic/src/types.rs | 36 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/annotations/callable.md b/crates/ty_python_semantic/resources/mdtest/annotations/callable.md index 1a7974089e4d4..37f5923496f6b 100644 --- a/crates/ty_python_semantic/resources/mdtest/annotations/callable.md +++ b/crates/ty_python_semantic/resources/mdtest/annotations/callable.md @@ -398,7 +398,7 @@ def f_okay(c: Callable[[], None]): c.__qualname__ = "my_callable" result = getattr_static(c, "__qualname__") - reveal_type(result) # revealed: Never + reveal_type(result) # revealed: property if isinstance(result, property) and result.fset: c.__qualname__ = "my_callable" # okay ``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 91fe0ee8fad14..3217f0bf05f21 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -3309,19 +3309,14 @@ impl<'db> Type<'db> { let name_str = name.as_str(); match self { - Type::Union(union) => union - .map_with_boundness(db, |elem| { - elem.member_lookup_with_policy(db, name_str.into(), policy) - .place - }) - .into(), + Type::Union(union) => union.map_with_boundness_and_qualifiers(db, |elem| { + elem.member_lookup_with_policy(db, name_str.into(), policy) + }), Type::Intersection(intersection) => intersection - .map_with_boundness(db, |elem| { + .map_with_boundness_and_qualifiers(db, |elem| { elem.member_lookup_with_policy(db, name_str.into(), policy) - .place - }) - .into(), + }), Type::Dynamic(..) | Type::Never => Place::bound(self).into(), @@ -9743,8 +9738,8 @@ impl<'db> IntersectionType<'db> { let mut builder = IntersectionBuilder::new(db); let mut qualifiers = TypeQualifiers::empty(); - let mut any_unbound = false; - let mut any_possibly_unbound = false; + let mut all_unbound = true; + let mut any_definitely_bound = false; for ty in self.positive_elements_or_object(db) { let PlaceAndQualifiers { place: member, @@ -9752,12 +9747,11 @@ impl<'db> IntersectionType<'db> { } = transform_fn(&ty); qualifiers |= new_qualifiers; match member { - Place::Unbound => { - any_unbound = true; - } + Place::Unbound => {} Place::Type(ty_member, member_boundness) => { - if member_boundness == Boundness::PossiblyUnbound { - any_possibly_unbound = true; + all_unbound = false; + if member_boundness == Boundness::Bound { + any_definitely_bound = true; } builder = builder.add_positive(ty_member); @@ -9766,15 +9760,15 @@ impl<'db> IntersectionType<'db> { } PlaceAndQualifiers { - place: if any_unbound { + place: if all_unbound { Place::Unbound } else { Place::Type( builder.build(), - if any_possibly_unbound { - Boundness::PossiblyUnbound - } else { + if any_definitely_bound { Boundness::Bound + } else { + Boundness::PossiblyUnbound }, ) }, From 5663426d73c2b2ca09fdd24b964c138ed4743cbd Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Thu, 28 Aug 2025 02:11:22 +0800 Subject: [PATCH 150/160] [`airflow`] Extend `AIR311` and `AIR312` rules (#20082) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Extend the following rules. ### AIR311 * `airflow.sensors.base.BaseSensorOperator` → airflow.sdk.bases.sensor.BaseSensorOperator` * `airflow.sensors.base.PokeReturnValue` → airflow.sdk.bases.sensor.PokeReturnValue` * `airflow.sensors.base.poke_mode_only` → airflow.sdk.bases.sensor.poke_mode_only` * `airflow.decorators.base.DecoratedOperator` → airflow.sdk.bases.decorator.DecoratedOperator` * `airflow.models.param.Param` → airflow.sdk.definitions.param.Param` * `airflow.decorators.base.DecoratedMappedOperator` → `airflow.sdk.bases.decorator.DecoratedMappedOperator` * `airflow.decorators.base.DecoratedOperator` → `airflow.sdk.bases.decorator.DecoratedOperator` * `airflow.decorators.base.TaskDecorator` → `airflow.sdk.bases.decorator.TaskDecorator` * `airflow.decorators.base.get_unique_task_id` → `airflow.sdk.bases.decorator.get_unique_task_id` * `airflow.decorators.base.task_decorator_factory` → `airflow.sdk.bases.decorator.task_decorator_factory` ### AIR312 * `airflow.sensors.bash.BashSensor` → `airflow.providers.standard.sensor.bash.BashSensor` * `airflow.sensors.python.PythonSensor` → `airflow.providers.standard.sensors.python.PythonSensor` ## Test Plan update the test fixture accordingly in the second commit and reorg in the third --- .../test/fixtures/airflow/AIR311_names.py | 33 + .../resources/test/fixtures/airflow/AIR312.py | 24 +- .../suggested_to_move_to_provider_in_3.rs | 12 + .../airflow/rules/suggested_to_update_3_0.rs | 31 + ...irflow__tests__AIR311_AIR311_names.py.snap | 210 ++++ ...les__airflow__tests__AIR312_AIR312.py.snap | 1011 ++++++++++------- 6 files changed, 875 insertions(+), 446 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py b/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py index 712957f3b1b93..9b4ce1e38ea8c 100644 --- a/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py +++ b/crates/ruff_linter/resources/test/fixtures/airflow/AIR311_names.py @@ -74,3 +74,36 @@ # airflow.utils.dag_parsing_context get_parsing_context() + +from airflow.decorators.base import ( + DecoratedMappedOperator, + DecoratedOperator, + TaskDecorator, + get_unique_task_id, + task_decorator_factory, +) + +# airflow.decorators.base +DecoratedMappedOperator() +DecoratedOperator() +TaskDecorator() +get_unique_task_id() +task_decorator_factory() + + +from airflow.models import Param + +# airflow.models +Param() + + +from airflow.sensors.base import ( + BaseSensorOperator, + PokeReturnValue, + poke_mode_only, +) + +# airflow.sensors.base +BaseSensorOperator() +PokeReturnValue() +poke_mode_only() diff --git a/crates/ruff_linter/resources/test/fixtures/airflow/AIR312.py b/crates/ruff_linter/resources/test/fixtures/airflow/AIR312.py index 0752511706ced..ae644bf9a5600 100644 --- a/crates/ruff_linter/resources/test/fixtures/airflow/AIR312.py +++ b/crates/ruff_linter/resources/test/fixtures/airflow/AIR312.py @@ -9,7 +9,6 @@ from airflow.operators.latest_only import LatestOnlyOperator from airflow.operators.trigger_dagrun import TriggerDagRunOperator from airflow.operators.weekday import BranchDayOfWeekOperator -from airflow.sensors.date_time import DateTimeSensor FSHook() PackageIndexHook() @@ -22,7 +21,6 @@ LatestOnlyOperator() BranchDayOfWeekOperator() -DateTimeSensor() from airflow.operators.python import ( BranchPythonOperator, @@ -30,16 +28,23 @@ PythonVirtualenvOperator, ShortCircuitOperator, ) +from airflow.sensors.bash import BashSensor +from airflow.sensors.date_time import DateTimeSensor + +BranchPythonOperator() +PythonOperator() +PythonVirtualenvOperator() +ShortCircuitOperator() + +BashSensor() +DateTimeSensor() from airflow.sensors.date_time import DateTimeSensorAsync from airflow.sensors.external_task import ( ExternalTaskMarker, ExternalTaskSensor, ) -from airflow.sensors.time_sensor import ( - TimeSensor, - TimeSensorAsync, -) from airflow.sensors.filesystem import FileSensor +from airflow.sensors.python import PythonSensor BranchPythonOperator() PythonOperator() @@ -49,6 +54,13 @@ ExternalTaskMarker() ExternalTaskSensor() FileSensor() +PythonSensor() + +from airflow.sensors.time_sensor import ( + TimeSensor, + TimeSensorAsync, +) + TimeSensor() TimeSensorAsync() diff --git a/crates/ruff_linter/src/rules/airflow/rules/suggested_to_move_to_provider_in_3.rs b/crates/ruff_linter/src/rules/airflow/rules/suggested_to_move_to_provider_in_3.rs index 9963635c2ef5b..5f88370c376e1 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/suggested_to_move_to_provider_in_3.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/suggested_to_move_to_provider_in_3.rs @@ -215,6 +215,12 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan version: "0.0.1", } } + ["airflow", "sensors", "bash", "BashSensor"] => ProviderReplacement::AutoImport { + module: "airflow.providers.standard.sensor.bash", + name: "BashSensor", + provider: "standard", + version: "0.0.1", + }, [ "airflow", "sensors", @@ -243,6 +249,12 @@ fn check_names_moved_to_provider(checker: &Checker, expr: &Expr, ranged: TextRan provider: "standard", version: "0.0.2", }, + ["airflow", "sensors", "python", "PythonSensor"] => ProviderReplacement::AutoImport { + module: "airflow.providers.standard.sensors.python", + name: "PythonSensor", + provider: "standard", + version: "0.0.1", + }, [ "airflow", "sensors", diff --git a/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs b/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs index c2c7a64fa3bb6..41bc35d352c32 100644 --- a/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs +++ b/crates/ruff_linter/src/rules/airflow/rules/suggested_to_update_3_0.rs @@ -227,6 +227,19 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) { module: "airflow.sdk", name: (*rest).to_string(), }, + [ + "airflow", + "decorators", + "base", + rest @ ("DecoratedMappedOperator" + | "DecoratedOperator" + | "TaskDecorator" + | "get_unique_task_id" + | "task_decorator_factory"), + ] => Replacement::SourceModuleMoved { + module: "airflow.sdk.bases.decorator", + name: (*rest).to_string(), + }, // airflow.io ["airflow", "io", "path", "ObjectStoragePath"] => Replacement::SourceModuleMoved { @@ -245,6 +258,10 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) { name: (*rest).to_string(), } } + ["airflow", "models", "Param"] => Replacement::AutoImport { + module: "airflow.sdk.definitions.param", + name: "Param", + }, // airflow.models.baseoperator [ @@ -260,16 +277,30 @@ fn check_name(checker: &Checker, expr: &Expr, range: TextRange) { module: "airflow.sdk", name: "BaseOperatorLink", }, + // airflow.model..DAG ["airflow", "models", .., "DAG"] => Replacement::SourceModuleMoved { module: "airflow.sdk", name: "DAG".to_string(), }, + + // airflow.sensors.base + [ + "airflow", + "sensors", + "base", + rest @ ("BaseSensorOperator" | "PokeReturnValue" | "poke_mode_only"), + ] => Replacement::SourceModuleMoved { + module: "airflow.sdk", + name: (*rest).to_string(), + }, + // airflow.timetables ["airflow", "timetables", "datasets", "DatasetOrTimeSchedule"] => Replacement::AutoImport { module: "airflow.timetables.assets", name: "AssetOrTimeSchedule", }, + // airflow.utils [ "airflow", diff --git a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap index fa121a1dce043..5db229912741f 100644 --- a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap +++ b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR311_AIR311_names.py.snap @@ -614,6 +614,8 @@ AIR311 [*] `airflow.utils.dag_parsing_context.get_parsing_context` is removed in 75 | # airflow.utils.dag_parsing_context 76 | get_parsing_context() | ^^^^^^^^^^^^^^^^^^^ +77 | +78 | from airflow.decorators.base import ( | help: Use `get_parsing_context` from `airflow.sdk` instead. @@ -626,3 +628,211 @@ help: Use `get_parsing_context` from `airflow.sdk` instead. 71 71 | 72 72 | # airflow.timetables.datasets 73 73 | DatasetOrTimeSchedule() + +AIR311 [*] `airflow.decorators.base.DecoratedMappedOperator` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:87:1 + | +86 | # airflow.decorators.base +87 | DecoratedMappedOperator() + | ^^^^^^^^^^^^^^^^^^^^^^^ +88 | DecoratedOperator() +89 | TaskDecorator() + | +help: Use `DecoratedMappedOperator` from `airflow.sdk.bases.decorator` instead. + +ℹ Unsafe fix +76 76 | get_parsing_context() +77 77 | +78 78 | from airflow.decorators.base import ( +79 |- DecoratedMappedOperator, +80 79 | DecoratedOperator, +81 80 | TaskDecorator, +82 81 | get_unique_task_id, +83 82 | task_decorator_factory, +84 83 | ) + 84 |+from airflow.sdk.bases.decorator import DecoratedMappedOperator +85 85 | +86 86 | # airflow.decorators.base +87 87 | DecoratedMappedOperator() + +AIR311 [*] `airflow.decorators.base.DecoratedOperator` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:88:1 + | +86 | # airflow.decorators.base +87 | DecoratedMappedOperator() +88 | DecoratedOperator() + | ^^^^^^^^^^^^^^^^^ +89 | TaskDecorator() +90 | get_unique_task_id() + | +help: Use `DecoratedOperator` from `airflow.sdk.bases.decorator` instead. + +ℹ Unsafe fix +77 77 | +78 78 | from airflow.decorators.base import ( +79 79 | DecoratedMappedOperator, +80 |- DecoratedOperator, +81 80 | TaskDecorator, +82 81 | get_unique_task_id, +83 82 | task_decorator_factory, +84 83 | ) + 84 |+from airflow.sdk.bases.decorator import DecoratedOperator +85 85 | +86 86 | # airflow.decorators.base +87 87 | DecoratedMappedOperator() + +AIR311 [*] `airflow.decorators.base.TaskDecorator` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:89:1 + | +87 | DecoratedMappedOperator() +88 | DecoratedOperator() +89 | TaskDecorator() + | ^^^^^^^^^^^^^ +90 | get_unique_task_id() +91 | task_decorator_factory() + | +help: Use `TaskDecorator` from `airflow.sdk.bases.decorator` instead. + +ℹ Unsafe fix +78 78 | from airflow.decorators.base import ( +79 79 | DecoratedMappedOperator, +80 80 | DecoratedOperator, +81 |- TaskDecorator, +82 81 | get_unique_task_id, +83 82 | task_decorator_factory, +84 83 | ) + 84 |+from airflow.sdk.bases.decorator import TaskDecorator +85 85 | +86 86 | # airflow.decorators.base +87 87 | DecoratedMappedOperator() + +AIR311 [*] `airflow.decorators.base.get_unique_task_id` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:90:1 + | +88 | DecoratedOperator() +89 | TaskDecorator() +90 | get_unique_task_id() + | ^^^^^^^^^^^^^^^^^^ +91 | task_decorator_factory() + | +help: Use `get_unique_task_id` from `airflow.sdk.bases.decorator` instead. + +ℹ Unsafe fix +79 79 | DecoratedMappedOperator, +80 80 | DecoratedOperator, +81 81 | TaskDecorator, +82 |- get_unique_task_id, +83 82 | task_decorator_factory, +84 83 | ) + 84 |+from airflow.sdk.bases.decorator import get_unique_task_id +85 85 | +86 86 | # airflow.decorators.base +87 87 | DecoratedMappedOperator() + +AIR311 [*] `airflow.decorators.base.task_decorator_factory` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:91:1 + | +89 | TaskDecorator() +90 | get_unique_task_id() +91 | task_decorator_factory() + | ^^^^^^^^^^^^^^^^^^^^^^ + | +help: Use `task_decorator_factory` from `airflow.sdk.bases.decorator` instead. + +ℹ Unsafe fix +80 80 | DecoratedOperator, +81 81 | TaskDecorator, +82 82 | get_unique_task_id, +83 |- task_decorator_factory, +84 83 | ) + 84 |+from airflow.sdk.bases.decorator import task_decorator_factory +85 85 | +86 86 | # airflow.decorators.base +87 87 | DecoratedMappedOperator() + +AIR311 [*] `airflow.models.Param` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:97:1 + | +96 | # airflow.models +97 | Param() + | ^^^^^ + | +help: Use `Param` from `airflow.sdk.definitions.param` instead. + +ℹ Unsafe fix +91 91 | task_decorator_factory() +92 92 | +93 93 | +94 |-from airflow.models import Param + 94 |+from airflow.sdk.definitions.param import Param +95 95 | +96 96 | # airflow.models +97 97 | Param() + +AIR311 [*] `airflow.sensors.base.BaseSensorOperator` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:107:1 + | +106 | # airflow.sensors.base +107 | BaseSensorOperator() + | ^^^^^^^^^^^^^^^^^^ +108 | PokeReturnValue() +109 | poke_mode_only() + | +help: Use `BaseSensorOperator` from `airflow.sdk` instead. + +ℹ Unsafe fix +98 98 | +99 99 | +100 100 | from airflow.sensors.base import ( +101 |- BaseSensorOperator, +102 101 | PokeReturnValue, +103 102 | poke_mode_only, +104 103 | ) + 104 |+from airflow.sdk import BaseSensorOperator +105 105 | +106 106 | # airflow.sensors.base +107 107 | BaseSensorOperator() + +AIR311 [*] `airflow.sensors.base.PokeReturnValue` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:108:1 + | +106 | # airflow.sensors.base +107 | BaseSensorOperator() +108 | PokeReturnValue() + | ^^^^^^^^^^^^^^^ +109 | poke_mode_only() + | +help: Use `PokeReturnValue` from `airflow.sdk` instead. + +ℹ Unsafe fix +99 99 | +100 100 | from airflow.sensors.base import ( +101 101 | BaseSensorOperator, +102 |- PokeReturnValue, +103 102 | poke_mode_only, +104 103 | ) + 104 |+from airflow.sdk import PokeReturnValue +105 105 | +106 106 | # airflow.sensors.base +107 107 | BaseSensorOperator() + +AIR311 [*] `airflow.sensors.base.poke_mode_only` is removed in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR311_names.py:109:1 + | +107 | BaseSensorOperator() +108 | PokeReturnValue() +109 | poke_mode_only() + | ^^^^^^^^^^^^^^ + | +help: Use `poke_mode_only` from `airflow.sdk` instead. + +ℹ Unsafe fix +100 100 | from airflow.sensors.base import ( +101 101 | BaseSensorOperator, +102 102 | PokeReturnValue, +103 |- poke_mode_only, +104 103 | ) + 104 |+from airflow.sdk import poke_mode_only +105 105 | +106 106 | # airflow.sensors.base +107 107 | BaseSensorOperator() diff --git a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR312_AIR312.py.snap b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR312_AIR312.py.snap index 628ffe31dc50f..14276da4c47bc 100644 --- a/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR312_AIR312.py.snap +++ b/crates/ruff_linter/src/rules/airflow/snapshots/ruff_linter__rules__airflow__tests__AIR312_AIR312.py.snap @@ -2,14 +2,14 @@ source: crates/ruff_linter/src/rules/airflow/mod.rs --- AIR312 [*] `airflow.hooks.filesystem.FSHook` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:14:1 + --> AIR312.py:13:1 | -12 | from airflow.sensors.date_time import DateTimeSensor -13 | -14 | FSHook() +11 | from airflow.operators.weekday import BranchDayOfWeekOperator +12 | +13 | FSHook() | ^^^^^^ -15 | PackageIndexHook() -16 | SubprocessHook() +14 | PackageIndexHook() +15 | SubprocessHook() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `FSHook` from `airflow.providers.standard.hooks.filesystem` instead. @@ -21,21 +21,21 @@ help: Install `apache-airflow-providers-standard>=0.0.1` and use `FSHook` from ` 5 4 | from airflow.hooks.subprocess import SubprocessHook 6 5 | from airflow.operators.bash import BashOperator -------------------------------------------------------------------------------- +9 8 | from airflow.operators.latest_only import LatestOnlyOperator 10 9 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.hooks.filesystem import FSHook -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.hooks.filesystem import FSHook +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.hooks.package_index.PackageIndexHook` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:15:1 + --> AIR312.py:14:1 | -14 | FSHook() -15 | PackageIndexHook() +13 | FSHook() +14 | PackageIndexHook() | ^^^^^^^^^^^^^^^^ -16 | SubprocessHook() +15 | SubprocessHook() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `PackageIndexHook` from `airflow.providers.standard.hooks.package_index` instead. @@ -48,23 +48,23 @@ help: Install `apache-airflow-providers-standard>=0.0.1` and use `PackageIndexHo 6 5 | from airflow.operators.bash import BashOperator 7 6 | from airflow.operators.datetime import BranchDateTimeOperator -------------------------------------------------------------------------------- +9 8 | from airflow.operators.latest_only import LatestOnlyOperator 10 9 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.hooks.package_index import PackageIndexHook -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.hooks.package_index import PackageIndexHook +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.hooks.subprocess.SubprocessHook` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:16:1 + --> AIR312.py:15:1 | -14 | FSHook() -15 | PackageIndexHook() -16 | SubprocessHook() +13 | FSHook() +14 | PackageIndexHook() +15 | SubprocessHook() | ^^^^^^^^^^^^^^ -17 | -18 | BashOperator() +16 | +17 | BashOperator() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `SubprocessHook` from `airflow.providers.standard.hooks.subprocess` instead. @@ -76,24 +76,23 @@ help: Install `apache-airflow-providers-standard>=0.0.3` and use `SubprocessHook 6 5 | from airflow.operators.bash import BashOperator 7 6 | from airflow.operators.datetime import BranchDateTimeOperator 8 7 | from airflow.operators.empty import EmptyOperator --------------------------------------------------------------------------------- +9 8 | from airflow.operators.latest_only import LatestOnlyOperator 10 9 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.hooks.subprocess import SubprocessHook -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.hooks.subprocess import SubprocessHook +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.operators.bash.BashOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:18:1 + --> AIR312.py:17:1 | -16 | SubprocessHook() -17 | -18 | BashOperator() +15 | SubprocessHook() +16 | +17 | BashOperator() | ^^^^^^^^^^^^ -19 | BranchDateTimeOperator() -20 | TriggerDagRunOperator() +18 | BranchDateTimeOperator() +19 | TriggerDagRunOperator() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `BashOperator` from `airflow.providers.standard.operators.bash` instead. @@ -107,20 +106,19 @@ help: Install `apache-airflow-providers-standard>=0.0.1` and use `BashOperator` 9 8 | from airflow.operators.latest_only import LatestOnlyOperator 10 9 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.operators.bash import BashOperator -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.operators.bash import BashOperator +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.operators.datetime.BranchDateTimeOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:19:1 + --> AIR312.py:18:1 | -18 | BashOperator() -19 | BranchDateTimeOperator() +17 | BashOperator() +18 | BranchDateTimeOperator() | ^^^^^^^^^^^^^^^^^^^^^^ -20 | TriggerDagRunOperator() -21 | EmptyOperator() +19 | TriggerDagRunOperator() +20 | EmptyOperator() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `BranchDateTimeOperator` from `airflow.providers.standard.operators.datetime` instead. @@ -133,20 +131,19 @@ help: Install `apache-airflow-providers-standard>=0.0.1` and use `BranchDateTime 9 8 | from airflow.operators.latest_only import LatestOnlyOperator 10 9 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.operators.datetime import BranchDateTimeOperator -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.operators.datetime import BranchDateTimeOperator +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.operators.trigger_dagrun.TriggerDagRunOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:20:1 + --> AIR312.py:19:1 | -18 | BashOperator() -19 | BranchDateTimeOperator() -20 | TriggerDagRunOperator() +17 | BashOperator() +18 | BranchDateTimeOperator() +19 | TriggerDagRunOperator() | ^^^^^^^^^^^^^^^^^^^^^ -21 | EmptyOperator() +20 | EmptyOperator() | help: Install `apache-airflow-providers-standard>=0.0.2` and use `TriggerDagRunOperator` from `airflow.providers.standard.operators.trigger_dagrun` instead. @@ -156,21 +153,20 @@ help: Install `apache-airflow-providers-standard>=0.0.2` and use `TriggerDagRunO 9 9 | from airflow.operators.latest_only import LatestOnlyOperator 10 |-from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.operators.trigger_dagrun import TriggerDagRunOperator -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.operators.trigger_dagrun import TriggerDagRunOperator +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.operators.empty.EmptyOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:21:1 + --> AIR312.py:20:1 | -19 | BranchDateTimeOperator() -20 | TriggerDagRunOperator() -21 | EmptyOperator() +18 | BranchDateTimeOperator() +19 | TriggerDagRunOperator() +20 | EmptyOperator() | ^^^^^^^^^^^^^ -22 | -23 | LatestOnlyOperator() +21 | +22 | LatestOnlyOperator() | help: Install `apache-airflow-providers-standard>=0.0.2` and use `EmptyOperator` from `airflow.providers.standard.operators.empty` instead. @@ -182,21 +178,19 @@ help: Install `apache-airflow-providers-standard>=0.0.2` and use `EmptyOperator` 9 8 | from airflow.operators.latest_only import LatestOnlyOperator 10 9 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.operators.empty import EmptyOperator -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.operators.empty import EmptyOperator +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.operators.latest_only.LatestOnlyOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:23:1 + --> AIR312.py:22:1 | -21 | EmptyOperator() -22 | -23 | LatestOnlyOperator() +20 | EmptyOperator() +21 | +22 | LatestOnlyOperator() | ^^^^^^^^^^^^^^^^^^ -24 | BranchDayOfWeekOperator() -25 | DateTimeSensor() +23 | BranchDayOfWeekOperator() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `LatestOnlyOperator` from `airflow.providers.standard.operators.latest_only` instead. @@ -207,19 +201,19 @@ help: Install `apache-airflow-providers-standard>=0.0.3` and use `LatestOnlyOper 9 |-from airflow.operators.latest_only import LatestOnlyOperator 10 9 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 10 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.operators.latest_only import LatestOnlyOperator -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.operators.latest_only import LatestOnlyOperator +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() AIR312 [*] `airflow.operators.weekday.BranchDayOfWeekOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:24:1 + --> AIR312.py:23:1 | -23 | LatestOnlyOperator() -24 | BranchDayOfWeekOperator() +22 | LatestOnlyOperator() +23 | BranchDayOfWeekOperator() | ^^^^^^^^^^^^^^^^^^^^^^^ -25 | DateTimeSensor() +24 | +25 | from airflow.operators.python import ( | help: Install `apache-airflow-providers-standard>=0.0.1` and use `BranchDayOfWeekOperator` from `airflow.providers.standard.operators.weekday` instead. @@ -228,514 +222,651 @@ help: Install `apache-airflow-providers-standard>=0.0.1` and use `BranchDayOfWee 9 9 | from airflow.operators.latest_only import LatestOnlyOperator 10 10 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator 11 |-from airflow.operators.weekday import BranchDayOfWeekOperator -12 11 | from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.operators.weekday import BranchDayOfWeekOperator -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() + 11 |+from airflow.providers.standard.operators.weekday import BranchDayOfWeekOperator +12 12 | +13 13 | FSHook() +14 14 | PackageIndexHook() + +AIR312 [*] `airflow.operators.python.BranchPythonOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR312.py:34:1 + | +32 | from airflow.sensors.date_time import DateTimeSensor +33 | +34 | BranchPythonOperator() + | ^^^^^^^^^^^^^^^^^^^^ +35 | PythonOperator() +36 | PythonVirtualenvOperator() + | +help: Install `apache-airflow-providers-standard>=0.0.1` and use `BranchPythonOperator` from `airflow.providers.standard.operators.python` instead. + +ℹ Unsafe fix +23 23 | BranchDayOfWeekOperator() +24 24 | +25 25 | from airflow.operators.python import ( +26 |- BranchPythonOperator, +27 26 | PythonOperator, +28 27 | PythonVirtualenvOperator, +29 28 | ShortCircuitOperator, +30 29 | ) +31 30 | from airflow.sensors.bash import BashSensor +32 31 | from airflow.sensors.date_time import DateTimeSensor + 32 |+from airflow.providers.standard.operators.python import BranchPythonOperator +33 33 | +34 34 | BranchPythonOperator() +35 35 | PythonOperator() + +AIR312 [*] `airflow.operators.python.PythonOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR312.py:35:1 + | +34 | BranchPythonOperator() +35 | PythonOperator() + | ^^^^^^^^^^^^^^ +36 | PythonVirtualenvOperator() +37 | ShortCircuitOperator() + | +help: Install `apache-airflow-providers-standard>=0.0.1` and use `PythonOperator` from `airflow.providers.standard.operators.python` instead. + +ℹ Unsafe fix +24 24 | +25 25 | from airflow.operators.python import ( +26 26 | BranchPythonOperator, +27 |- PythonOperator, +28 27 | PythonVirtualenvOperator, +29 28 | ShortCircuitOperator, +30 29 | ) +31 30 | from airflow.sensors.bash import BashSensor +32 31 | from airflow.sensors.date_time import DateTimeSensor + 32 |+from airflow.providers.standard.operators.python import PythonOperator +33 33 | +34 34 | BranchPythonOperator() +35 35 | PythonOperator() + +AIR312 [*] `airflow.operators.python.PythonVirtualenvOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR312.py:36:1 + | +34 | BranchPythonOperator() +35 | PythonOperator() +36 | PythonVirtualenvOperator() + | ^^^^^^^^^^^^^^^^^^^^^^^^ +37 | ShortCircuitOperator() + | +help: Install `apache-airflow-providers-standard>=0.0.1` and use `PythonVirtualenvOperator` from `airflow.providers.standard.operators.python` instead. + +ℹ Unsafe fix +25 25 | from airflow.operators.python import ( +26 26 | BranchPythonOperator, +27 27 | PythonOperator, +28 |- PythonVirtualenvOperator, +29 28 | ShortCircuitOperator, +30 29 | ) +31 30 | from airflow.sensors.bash import BashSensor +32 31 | from airflow.sensors.date_time import DateTimeSensor + 32 |+from airflow.providers.standard.operators.python import PythonVirtualenvOperator +33 33 | +34 34 | BranchPythonOperator() +35 35 | PythonOperator() + +AIR312 [*] `airflow.operators.python.ShortCircuitOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR312.py:37:1 + | +35 | PythonOperator() +36 | PythonVirtualenvOperator() +37 | ShortCircuitOperator() + | ^^^^^^^^^^^^^^^^^^^^ +38 | +39 | BashSensor() + | +help: Install `apache-airflow-providers-standard>=0.0.1` and use `ShortCircuitOperator` from `airflow.providers.standard.operators.python` instead. + +ℹ Unsafe fix +26 26 | BranchPythonOperator, +27 27 | PythonOperator, +28 28 | PythonVirtualenvOperator, +29 |- ShortCircuitOperator, +30 29 | ) +31 30 | from airflow.sensors.bash import BashSensor +32 31 | from airflow.sensors.date_time import DateTimeSensor + 32 |+from airflow.providers.standard.operators.python import ShortCircuitOperator +33 33 | +34 34 | BranchPythonOperator() +35 35 | PythonOperator() + +AIR312 [*] `airflow.sensors.bash.BashSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR312.py:39:1 + | +37 | ShortCircuitOperator() +38 | +39 | BashSensor() + | ^^^^^^^^^^ +40 | DateTimeSensor() +41 | from airflow.sensors.date_time import DateTimeSensorAsync + | +help: Install `apache-airflow-providers-standard>=0.0.1` and use `BashSensor` from `airflow.providers.standard.sensor.bash` instead. + +ℹ Unsafe fix +28 28 | PythonVirtualenvOperator, +29 29 | ShortCircuitOperator, +30 30 | ) +31 |-from airflow.sensors.bash import BashSensor +32 31 | from airflow.sensors.date_time import DateTimeSensor + 32 |+from airflow.providers.standard.sensor.bash import BashSensor +33 33 | +34 34 | BranchPythonOperator() +35 35 | PythonOperator() AIR312 [*] `airflow.sensors.date_time.DateTimeSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:25:1 + --> AIR312.py:40:1 | -23 | LatestOnlyOperator() -24 | BranchDayOfWeekOperator() -25 | DateTimeSensor() +39 | BashSensor() +40 | DateTimeSensor() | ^^^^^^^^^^^^^^ -26 | -27 | from airflow.operators.python import ( +41 | from airflow.sensors.date_time import DateTimeSensorAsync +42 | from airflow.sensors.external_task import ( | help: Install `apache-airflow-providers-standard>=0.0.1` and use `DateTimeSensor` from `airflow.providers.standard.sensors.date_time` instead. ℹ Unsafe fix -9 9 | from airflow.operators.latest_only import LatestOnlyOperator -10 10 | from airflow.operators.trigger_dagrun import TriggerDagRunOperator -11 11 | from airflow.operators.weekday import BranchDayOfWeekOperator -12 |-from airflow.sensors.date_time import DateTimeSensor - 12 |+from airflow.providers.standard.sensors.date_time import DateTimeSensor -13 13 | -14 14 | FSHook() -15 15 | PackageIndexHook() +29 29 | ShortCircuitOperator, +30 30 | ) +31 31 | from airflow.sensors.bash import BashSensor +32 |-from airflow.sensors.date_time import DateTimeSensor + 32 |+from airflow.providers.standard.sensors.date_time import DateTimeSensor +33 33 | +34 34 | BranchPythonOperator() +35 35 | PythonOperator() AIR312 [*] `airflow.operators.python.BranchPythonOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:44:1 + --> AIR312.py:49:1 | -42 | from airflow.sensors.filesystem import FileSensor -43 | -44 | BranchPythonOperator() +47 | from airflow.sensors.python import PythonSensor +48 | +49 | BranchPythonOperator() | ^^^^^^^^^^^^^^^^^^^^ -45 | PythonOperator() -46 | PythonVirtualenvOperator() +50 | PythonOperator() +51 | PythonVirtualenvOperator() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `BranchPythonOperator` from `airflow.providers.standard.operators.python` instead. ℹ Unsafe fix -25 25 | DateTimeSensor() -26 26 | -27 27 | from airflow.operators.python import ( -28 |- BranchPythonOperator, -29 28 | PythonOperator, -30 29 | PythonVirtualenvOperator, -31 30 | ShortCircuitOperator, +23 23 | BranchDayOfWeekOperator() +24 24 | +25 25 | from airflow.operators.python import ( +26 |- BranchPythonOperator, +27 26 | PythonOperator, +28 27 | PythonVirtualenvOperator, +29 28 | ShortCircuitOperator, -------------------------------------------------------------------------------- -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.operators.python import BranchPythonOperator -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +45 44 | ) +46 45 | from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.operators.python import BranchPythonOperator +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.operators.python.PythonOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:45:1 + --> AIR312.py:50:1 | -44 | BranchPythonOperator() -45 | PythonOperator() +49 | BranchPythonOperator() +50 | PythonOperator() | ^^^^^^^^^^^^^^ -46 | PythonVirtualenvOperator() -47 | ShortCircuitOperator() +51 | PythonVirtualenvOperator() +52 | ShortCircuitOperator() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `PythonOperator` from `airflow.providers.standard.operators.python` instead. ℹ Unsafe fix -26 26 | -27 27 | from airflow.operators.python import ( -28 28 | BranchPythonOperator, -29 |- PythonOperator, -30 29 | PythonVirtualenvOperator, -31 30 | ShortCircuitOperator, -32 31 | ) +24 24 | +25 25 | from airflow.operators.python import ( +26 26 | BranchPythonOperator, +27 |- PythonOperator, +28 27 | PythonVirtualenvOperator, +29 28 | ShortCircuitOperator, +30 29 | ) -------------------------------------------------------------------------------- -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.operators.python import PythonOperator -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +45 44 | ) +46 45 | from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.operators.python import PythonOperator +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.operators.python.PythonVirtualenvOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:46:1 + --> AIR312.py:51:1 | -44 | BranchPythonOperator() -45 | PythonOperator() -46 | PythonVirtualenvOperator() +49 | BranchPythonOperator() +50 | PythonOperator() +51 | PythonVirtualenvOperator() | ^^^^^^^^^^^^^^^^^^^^^^^^ -47 | ShortCircuitOperator() -48 | DateTimeSensorAsync() +52 | ShortCircuitOperator() +53 | DateTimeSensorAsync() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `PythonVirtualenvOperator` from `airflow.providers.standard.operators.python` instead. ℹ Unsafe fix -27 27 | from airflow.operators.python import ( -28 28 | BranchPythonOperator, -29 29 | PythonOperator, -30 |- PythonVirtualenvOperator, -31 30 | ShortCircuitOperator, -32 31 | ) -33 32 | from airflow.sensors.date_time import DateTimeSensorAsync +25 25 | from airflow.operators.python import ( +26 26 | BranchPythonOperator, +27 27 | PythonOperator, +28 |- PythonVirtualenvOperator, +29 28 | ShortCircuitOperator, +30 29 | ) +31 30 | from airflow.sensors.bash import BashSensor -------------------------------------------------------------------------------- -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.operators.python import PythonVirtualenvOperator -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +45 44 | ) +46 45 | from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.operators.python import PythonVirtualenvOperator +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.operators.python.ShortCircuitOperator` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:47:1 + --> AIR312.py:52:1 | -45 | PythonOperator() -46 | PythonVirtualenvOperator() -47 | ShortCircuitOperator() +50 | PythonOperator() +51 | PythonVirtualenvOperator() +52 | ShortCircuitOperator() | ^^^^^^^^^^^^^^^^^^^^ -48 | DateTimeSensorAsync() -49 | ExternalTaskMarker() +53 | DateTimeSensorAsync() +54 | ExternalTaskMarker() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `ShortCircuitOperator` from `airflow.providers.standard.operators.python` instead. ℹ Unsafe fix -28 28 | BranchPythonOperator, -29 29 | PythonOperator, -30 30 | PythonVirtualenvOperator, -31 |- ShortCircuitOperator, -32 31 | ) -33 32 | from airflow.sensors.date_time import DateTimeSensorAsync -34 33 | from airflow.sensors.external_task import ( +26 26 | BranchPythonOperator, +27 27 | PythonOperator, +28 28 | PythonVirtualenvOperator, +29 |- ShortCircuitOperator, +30 29 | ) +31 30 | from airflow.sensors.bash import BashSensor +32 31 | from airflow.sensors.date_time import DateTimeSensor -------------------------------------------------------------------------------- -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.operators.python import ShortCircuitOperator -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +45 44 | ) +46 45 | from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.operators.python import ShortCircuitOperator +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.sensors.date_time.DateTimeSensorAsync` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:48:1 + --> AIR312.py:53:1 | -46 | PythonVirtualenvOperator() -47 | ShortCircuitOperator() -48 | DateTimeSensorAsync() +51 | PythonVirtualenvOperator() +52 | ShortCircuitOperator() +53 | DateTimeSensorAsync() | ^^^^^^^^^^^^^^^^^^^ -49 | ExternalTaskMarker() -50 | ExternalTaskSensor() +54 | ExternalTaskMarker() +55 | ExternalTaskSensor() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `DateTimeSensorAsync` from `airflow.providers.standard.sensors.date_time` instead. ℹ Unsafe fix -30 30 | PythonVirtualenvOperator, -31 31 | ShortCircuitOperator, -32 32 | ) -33 |-from airflow.sensors.date_time import DateTimeSensorAsync -34 33 | from airflow.sensors.external_task import ( -35 34 | ExternalTaskMarker, -36 35 | ExternalTaskSensor, --------------------------------------------------------------------------------- -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.sensors.date_time import DateTimeSensorAsync -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +38 38 | +39 39 | BashSensor() +40 40 | DateTimeSensor() +41 |-from airflow.sensors.date_time import DateTimeSensorAsync +42 41 | from airflow.sensors.external_task import ( +43 42 | ExternalTaskMarker, +44 43 | ExternalTaskSensor, +45 44 | ) +46 45 | from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.sensors.date_time import DateTimeSensorAsync +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.sensors.external_task.ExternalTaskMarker` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:49:1 + --> AIR312.py:54:1 | -47 | ShortCircuitOperator() -48 | DateTimeSensorAsync() -49 | ExternalTaskMarker() +52 | ShortCircuitOperator() +53 | DateTimeSensorAsync() +54 | ExternalTaskMarker() | ^^^^^^^^^^^^^^^^^^ -50 | ExternalTaskSensor() -51 | FileSensor() +55 | ExternalTaskSensor() +56 | FileSensor() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `ExternalTaskMarker` from `airflow.providers.standard.sensors.external_task` instead. ℹ Unsafe fix -32 32 | ) -33 33 | from airflow.sensors.date_time import DateTimeSensorAsync -34 34 | from airflow.sensors.external_task import ( -35 |- ExternalTaskMarker, -36 35 | ExternalTaskSensor, -37 36 | ) -38 37 | from airflow.sensors.time_sensor import ( --------------------------------------------------------------------------------- -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.sensors.external_task import ExternalTaskMarker -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +40 40 | DateTimeSensor() +41 41 | from airflow.sensors.date_time import DateTimeSensorAsync +42 42 | from airflow.sensors.external_task import ( +43 |- ExternalTaskMarker, +44 43 | ExternalTaskSensor, +45 44 | ) +46 45 | from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.sensors.external_task import ExternalTaskMarker +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.sensors.external_task.ExternalTaskSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:50:1 + --> AIR312.py:55:1 | -48 | DateTimeSensorAsync() -49 | ExternalTaskMarker() -50 | ExternalTaskSensor() +53 | DateTimeSensorAsync() +54 | ExternalTaskMarker() +55 | ExternalTaskSensor() | ^^^^^^^^^^^^^^^^^^ -51 | FileSensor() -52 | TimeSensor() +56 | FileSensor() +57 | PythonSensor() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `ExternalTaskSensor` from `airflow.providers.standard.sensors.external_task` instead. ℹ Unsafe fix -33 33 | from airflow.sensors.date_time import DateTimeSensorAsync -34 34 | from airflow.sensors.external_task import ( -35 35 | ExternalTaskMarker, -36 |- ExternalTaskSensor, -37 36 | ) -38 37 | from airflow.sensors.time_sensor import ( -39 38 | TimeSensor, -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.sensors.external_task import ExternalTaskSensor -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +41 41 | from airflow.sensors.date_time import DateTimeSensorAsync +42 42 | from airflow.sensors.external_task import ( +43 43 | ExternalTaskMarker, +44 |- ExternalTaskSensor, +45 44 | ) +46 45 | from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.sensors.external_task import ExternalTaskSensor +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.sensors.filesystem.FileSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:51:1 + --> AIR312.py:56:1 | -49 | ExternalTaskMarker() -50 | ExternalTaskSensor() -51 | FileSensor() +54 | ExternalTaskMarker() +55 | ExternalTaskSensor() +56 | FileSensor() | ^^^^^^^^^^ -52 | TimeSensor() -53 | TimeSensorAsync() +57 | PythonSensor() | help: Install `apache-airflow-providers-standard>=0.0.2` and use `FileSensor` from `airflow.providers.standard.sensors.filesystem` instead. ℹ Unsafe fix -39 39 | TimeSensor, -40 40 | TimeSensorAsync, -41 41 | ) -42 |-from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.sensors.filesystem import FileSensor -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +43 43 | ExternalTaskMarker, +44 44 | ExternalTaskSensor, +45 45 | ) +46 |-from airflow.sensors.filesystem import FileSensor +47 46 | from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.sensors.filesystem import FileSensor +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() + +AIR312 [*] `airflow.sensors.python.PythonSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. + --> AIR312.py:57:1 + | +55 | ExternalTaskSensor() +56 | FileSensor() +57 | PythonSensor() + | ^^^^^^^^^^^^ +58 | +59 | from airflow.sensors.time_sensor import ( + | +help: Install `apache-airflow-providers-standard>=0.0.1` and use `PythonSensor` from `airflow.providers.standard.sensors.python` instead. + +ℹ Unsafe fix +44 44 | ExternalTaskSensor, +45 45 | ) +46 46 | from airflow.sensors.filesystem import FileSensor +47 |-from airflow.sensors.python import PythonSensor + 47 |+from airflow.providers.standard.sensors.python import PythonSensor +48 48 | +49 49 | BranchPythonOperator() +50 50 | PythonOperator() AIR312 [*] `airflow.sensors.time_sensor.TimeSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:52:1 + --> AIR312.py:64:1 | -50 | ExternalTaskSensor() -51 | FileSensor() -52 | TimeSensor() +62 | ) +63 | +64 | TimeSensor() | ^^^^^^^^^^ -53 | TimeSensorAsync() +65 | TimeSensorAsync() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `TimeSensor` from `airflow.providers.standard.sensors.time` instead. ℹ Unsafe fix -36 36 | ExternalTaskSensor, -37 37 | ) -38 38 | from airflow.sensors.time_sensor import ( -39 |- TimeSensor, -40 39 | TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.sensors.time import TimeSensor -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +57 57 | PythonSensor() +58 58 | +59 59 | from airflow.sensors.time_sensor import ( +60 |- TimeSensor, +61 60 | TimeSensorAsync, +62 61 | ) + 62 |+from airflow.providers.standard.sensors.time import TimeSensor +63 63 | +64 64 | TimeSensor() +65 65 | TimeSensorAsync() AIR312 [*] `airflow.sensors.time_sensor.TimeSensorAsync` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:53:1 + --> AIR312.py:65:1 | -51 | FileSensor() -52 | TimeSensor() -53 | TimeSensorAsync() +64 | TimeSensor() +65 | TimeSensorAsync() | ^^^^^^^^^^^^^^^ -54 | -55 | from airflow.sensors.time_delta import ( +66 | +67 | from airflow.sensors.time_delta import ( | help: Install `apache-airflow-providers-standard>=0.0.1` and use `TimeSensorAsync` from `airflow.providers.standard.sensors.time` instead. ℹ Unsafe fix -37 37 | ) -38 38 | from airflow.sensors.time_sensor import ( -39 39 | TimeSensor, -40 |- TimeSensorAsync, -41 40 | ) -42 41 | from airflow.sensors.filesystem import FileSensor - 42 |+from airflow.providers.standard.sensors.time import TimeSensorAsync -43 43 | -44 44 | BranchPythonOperator() -45 45 | PythonOperator() +58 58 | +59 59 | from airflow.sensors.time_sensor import ( +60 60 | TimeSensor, +61 |- TimeSensorAsync, +62 61 | ) + 62 |+from airflow.providers.standard.sensors.time import TimeSensorAsync +63 63 | +64 64 | TimeSensor() +65 65 | TimeSensorAsync() AIR312 [*] `airflow.sensors.time_delta.TimeDeltaSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:70:1 + --> AIR312.py:82:1 | -68 | ) -69 | -70 | TimeDeltaSensor() +80 | ) +81 | +82 | TimeDeltaSensor() | ^^^^^^^^^^^^^^^ -71 | TimeDeltaSensorAsync() -72 | DayOfWeekSensor() +83 | TimeDeltaSensorAsync() +84 | DayOfWeekSensor() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `TimeDeltaSensor` from `airflow.providers.standard.sensors.time_delta` instead. ℹ Unsafe fix -53 53 | TimeSensorAsync() -54 54 | -55 55 | from airflow.sensors.time_delta import ( -56 |- TimeDeltaSensor, -57 56 | TimeDeltaSensorAsync, -58 57 | ) -59 58 | from airflow.sensors.weekday import DayOfWeekSensor +65 65 | TimeSensorAsync() +66 66 | +67 67 | from airflow.sensors.time_delta import ( +68 |- TimeDeltaSensor, +69 68 | TimeDeltaSensorAsync, +70 69 | ) +71 70 | from airflow.sensors.weekday import DayOfWeekSensor -------------------------------------------------------------------------------- -66 65 | DateTimeTrigger, -67 66 | TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.sensors.time_delta import TimeDeltaSensor -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +78 77 | DateTimeTrigger, +79 78 | TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.sensors.time_delta import TimeDeltaSensor +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() AIR312 [*] `airflow.sensors.time_delta.TimeDeltaSensorAsync` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:71:1 + --> AIR312.py:83:1 | -70 | TimeDeltaSensor() -71 | TimeDeltaSensorAsync() +82 | TimeDeltaSensor() +83 | TimeDeltaSensorAsync() | ^^^^^^^^^^^^^^^^^^^^ -72 | DayOfWeekSensor() -73 | DagStateTrigger() +84 | DayOfWeekSensor() +85 | DagStateTrigger() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `TimeDeltaSensorAsync` from `airflow.providers.standard.sensors.time_delta` instead. ℹ Unsafe fix -54 54 | -55 55 | from airflow.sensors.time_delta import ( -56 56 | TimeDeltaSensor, -57 |- TimeDeltaSensorAsync, -58 57 | ) -59 58 | from airflow.sensors.weekday import DayOfWeekSensor -60 59 | from airflow.triggers.external_task import ( +66 66 | +67 67 | from airflow.sensors.time_delta import ( +68 68 | TimeDeltaSensor, +69 |- TimeDeltaSensorAsync, +70 69 | ) +71 70 | from airflow.sensors.weekday import DayOfWeekSensor +72 71 | from airflow.triggers.external_task import ( -------------------------------------------------------------------------------- -66 65 | DateTimeTrigger, -67 66 | TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.sensors.time_delta import TimeDeltaSensorAsync -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +78 77 | DateTimeTrigger, +79 78 | TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.sensors.time_delta import TimeDeltaSensorAsync +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() AIR312 [*] `airflow.sensors.weekday.DayOfWeekSensor` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:72:1 + --> AIR312.py:84:1 | -70 | TimeDeltaSensor() -71 | TimeDeltaSensorAsync() -72 | DayOfWeekSensor() +82 | TimeDeltaSensor() +83 | TimeDeltaSensorAsync() +84 | DayOfWeekSensor() | ^^^^^^^^^^^^^^^ -73 | DagStateTrigger() -74 | WorkflowTrigger() +85 | DagStateTrigger() +86 | WorkflowTrigger() | help: Install `apache-airflow-providers-standard>=0.0.1` and use `DayOfWeekSensor` from `airflow.providers.standard.sensors.weekday` instead. ℹ Unsafe fix -56 56 | TimeDeltaSensor, -57 57 | TimeDeltaSensorAsync, -58 58 | ) -59 |-from airflow.sensors.weekday import DayOfWeekSensor -60 59 | from airflow.triggers.external_task import ( -61 60 | DagStateTrigger, -62 61 | WorkflowTrigger, +68 68 | TimeDeltaSensor, +69 69 | TimeDeltaSensorAsync, +70 70 | ) +71 |-from airflow.sensors.weekday import DayOfWeekSensor +72 71 | from airflow.triggers.external_task import ( +73 72 | DagStateTrigger, +74 73 | WorkflowTrigger, -------------------------------------------------------------------------------- -66 65 | DateTimeTrigger, -67 66 | TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.sensors.weekday import DayOfWeekSensor -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +78 77 | DateTimeTrigger, +79 78 | TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.sensors.weekday import DayOfWeekSensor +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() AIR312 [*] `airflow.triggers.external_task.DagStateTrigger` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:73:1 + --> AIR312.py:85:1 | -71 | TimeDeltaSensorAsync() -72 | DayOfWeekSensor() -73 | DagStateTrigger() +83 | TimeDeltaSensorAsync() +84 | DayOfWeekSensor() +85 | DagStateTrigger() | ^^^^^^^^^^^^^^^ -74 | WorkflowTrigger() -75 | FileTrigger() +86 | WorkflowTrigger() +87 | FileTrigger() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `DagStateTrigger` from `airflow.providers.standard.triggers.external_task` instead. ℹ Unsafe fix -58 58 | ) -59 59 | from airflow.sensors.weekday import DayOfWeekSensor -60 60 | from airflow.triggers.external_task import ( -61 |- DagStateTrigger, -62 61 | WorkflowTrigger, -63 62 | ) -64 63 | from airflow.triggers.file import FileTrigger +70 70 | ) +71 71 | from airflow.sensors.weekday import DayOfWeekSensor +72 72 | from airflow.triggers.external_task import ( +73 |- DagStateTrigger, +74 73 | WorkflowTrigger, +75 74 | ) +76 75 | from airflow.triggers.file import FileTrigger -------------------------------------------------------------------------------- -66 65 | DateTimeTrigger, -67 66 | TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.triggers.external_task import DagStateTrigger -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +78 77 | DateTimeTrigger, +79 78 | TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.triggers.external_task import DagStateTrigger +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() AIR312 [*] `airflow.triggers.external_task.WorkflowTrigger` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:74:1 + --> AIR312.py:86:1 | -72 | DayOfWeekSensor() -73 | DagStateTrigger() -74 | WorkflowTrigger() +84 | DayOfWeekSensor() +85 | DagStateTrigger() +86 | WorkflowTrigger() | ^^^^^^^^^^^^^^^ -75 | FileTrigger() -76 | DateTimeTrigger() +87 | FileTrigger() +88 | DateTimeTrigger() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `WorkflowTrigger` from `airflow.providers.standard.triggers.external_task` instead. ℹ Unsafe fix -59 59 | from airflow.sensors.weekday import DayOfWeekSensor -60 60 | from airflow.triggers.external_task import ( -61 61 | DagStateTrigger, -62 |- WorkflowTrigger, -63 62 | ) -64 63 | from airflow.triggers.file import FileTrigger -65 64 | from airflow.triggers.temporal import ( -66 65 | DateTimeTrigger, -67 66 | TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.triggers.external_task import WorkflowTrigger -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +71 71 | from airflow.sensors.weekday import DayOfWeekSensor +72 72 | from airflow.triggers.external_task import ( +73 73 | DagStateTrigger, +74 |- WorkflowTrigger, +75 74 | ) +76 75 | from airflow.triggers.file import FileTrigger +77 76 | from airflow.triggers.temporal import ( +78 77 | DateTimeTrigger, +79 78 | TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.triggers.external_task import WorkflowTrigger +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() AIR312 [*] `airflow.triggers.file.FileTrigger` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:75:1 + --> AIR312.py:87:1 | -73 | DagStateTrigger() -74 | WorkflowTrigger() -75 | FileTrigger() +85 | DagStateTrigger() +86 | WorkflowTrigger() +87 | FileTrigger() | ^^^^^^^^^^^ -76 | DateTimeTrigger() -77 | TimeDeltaTrigger() +88 | DateTimeTrigger() +89 | TimeDeltaTrigger() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `FileTrigger` from `airflow.providers.standard.triggers.file` instead. ℹ Unsafe fix -61 61 | DagStateTrigger, -62 62 | WorkflowTrigger, -63 63 | ) -64 |-from airflow.triggers.file import FileTrigger -65 64 | from airflow.triggers.temporal import ( -66 65 | DateTimeTrigger, -67 66 | TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.triggers.file import FileTrigger -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +73 73 | DagStateTrigger, +74 74 | WorkflowTrigger, +75 75 | ) +76 |-from airflow.triggers.file import FileTrigger +77 76 | from airflow.triggers.temporal import ( +78 77 | DateTimeTrigger, +79 78 | TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.triggers.file import FileTrigger +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() AIR312 [*] `airflow.triggers.temporal.DateTimeTrigger` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:76:1 + --> AIR312.py:88:1 | -74 | WorkflowTrigger() -75 | FileTrigger() -76 | DateTimeTrigger() +86 | WorkflowTrigger() +87 | FileTrigger() +88 | DateTimeTrigger() | ^^^^^^^^^^^^^^^ -77 | TimeDeltaTrigger() +89 | TimeDeltaTrigger() | help: Install `apache-airflow-providers-standard>=0.0.3` and use `DateTimeTrigger` from `airflow.providers.standard.triggers.temporal` instead. ℹ Unsafe fix -63 63 | ) -64 64 | from airflow.triggers.file import FileTrigger -65 65 | from airflow.triggers.temporal import ( -66 |- DateTimeTrigger, -67 66 | TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.triggers.temporal import DateTimeTrigger -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +75 75 | ) +76 76 | from airflow.triggers.file import FileTrigger +77 77 | from airflow.triggers.temporal import ( +78 |- DateTimeTrigger, +79 78 | TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.triggers.temporal import DateTimeTrigger +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() AIR312 [*] `airflow.triggers.temporal.TimeDeltaTrigger` is deprecated and moved into `standard` provider in Airflow 3.0; It still works in Airflow 3.0 but is expected to be removed in a future version. - --> AIR312.py:77:1 + --> AIR312.py:89:1 | -75 | FileTrigger() -76 | DateTimeTrigger() -77 | TimeDeltaTrigger() +87 | FileTrigger() +88 | DateTimeTrigger() +89 | TimeDeltaTrigger() | ^^^^^^^^^^^^^^^^ | help: Install `apache-airflow-providers-standard>=0.0.3` and use `TimeDeltaTrigger` from `airflow.providers.standard.triggers.temporal` instead. ℹ Unsafe fix -64 64 | from airflow.triggers.file import FileTrigger -65 65 | from airflow.triggers.temporal import ( -66 66 | DateTimeTrigger, -67 |- TimeDeltaTrigger, -68 67 | ) - 68 |+from airflow.providers.standard.triggers.temporal import TimeDeltaTrigger -69 69 | -70 70 | TimeDeltaSensor() -71 71 | TimeDeltaSensorAsync() +76 76 | from airflow.triggers.file import FileTrigger +77 77 | from airflow.triggers.temporal import ( +78 78 | DateTimeTrigger, +79 |- TimeDeltaTrigger, +80 79 | ) + 80 |+from airflow.providers.standard.triggers.temporal import TimeDeltaTrigger +81 81 | +82 82 | TimeDeltaSensor() +83 83 | TimeDeltaSensorAsync() From 4b80f5fa4f08dd0948761e15e36f5138658793e4 Mon Sep 17 00:00:00 2001 From: David Peter Date: Wed, 27 Aug 2025 20:42:09 +0200 Subject: [PATCH 151/160] [ty] Optimize TDD atom ordering (#20098) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary While looking at some logging output that I added to `ReachabilityConstraintBuilder::add_and_constraint` in order to debug https://github.com/astral-sh/ty/issues/1091, I noticed that it seemed to suggest that the TDD was built in an imbalanced way for code like the following, where we have a sequence of non-nested `if` conditions: ```py def f(t1, t2, t3, t4, …): x = 0 if t1: x = 1 if t2: x = 2 if t3: x = 3 if t4: x = 4 … ``` To understand this a bit better, I added some code to the `ReachabilityConstraintBuilder` to render the resulting TDD. On `main`, we get a tree that looks like the following, where you can see a pattern of N sub-trees that grow linearly with N (number of `if` statements). This results in an overall tree structure that has N² nodes (see graph below): normal order If we zoom in to one of these subgraphs, we can see what the problem is. When we add new constraints that represent combinations like `t1 AND ~t2 AND ~t3 AND t4 AND …`, they start with the evaluation of "early" conditions (`t1`, `t2`, …). This means that we have to create new subgraphs for each new `if` condition because there is little sharing with the previous structure. We evaluate the Boolean condition in a right-associative way: `t1 AND (~t2 AND (~t3 AND t4)))`: If we change the ordering of TDD atoms, we can change that to a left-associative evaluation: `(((t1 AND ~t2) AND ~t3) AND t4) …`. This means that we can re-use previous subgraphs `(t1 AND ~t2)`, which results in a much more compact graph structure overall (note how "late" conditions are now at the top, and "early" conditions are further down in the graph): reverse order If we count the number of TDD nodes for a growing number if `if` statements, we can see that this change results in a slower growth. It's worth noting that the growth is still superlinear, though: plot On the actual code from the referenced ticket (the `t_main.py` file reduced to its main function, with the main function limited to 2000 lines instead of 11000 to allow the version on `main` to run to completion), the effect is much more dramatic. Instead of 26 million TDD nodes (`main`), we now only create 250 thousand (this branch), which is slightly less than 1%. The change in this PR allows us to build the semantic index and type-check the problematic `t_main.py` file in https://github.com/astral-sh/ty/issues/1091 in 9 seconds. This is still not great, but an obvious improvement compared to running out of memory after *minutes* of execution. An open question remains whether this change is beneficial for all kinds of code patterns, or just this linear sequence of `if` statements. It does not seem unreasonable to think that referring to "earlier" conditions is generally a good idea, but I learned from Doug that it's generally not possible to find a TDD-construction heuristic that is non-pathological for all kinds of inputs. Fortunately, it seems like this change here results in performance improvements across *all of our benchmarks*, which should increase the confidence in this change: | Benchmark | Improvement | |---------------------|-------------------------| | hydra-zen | +13% | | DateType | +5% | | sympy (walltime) | +4% | | attrs | +4% | | pydantic (walltime) | +2% | | pandas (walltime) | +2% | | altair (walltime) | +2% | | static-frame | +2% | | anyio | +1% | | freqtrade | +1% | | colour-science | +1% | | tanjun | +1% | closes https://github.com/astral-sh/ty/issues/1091 --------- Co-authored-by: Douglas Creager --- .../reachability_constraints.rs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs b/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs index 9042e919bee01..37f8539d93eca 100644 --- a/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs +++ b/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs @@ -424,9 +424,26 @@ impl ReachabilityConstraintsBuilder { } } - /// Returns whether `a` or `b` has a "larger" atom. TDDs are ordered such that interior nodes - /// can only have edges to "larger" nodes. Terminals are considered to have a larger atom than - /// any internal node, since they are leaf nodes. + /// Implements the ordering that determines which level a TDD node appears at. + /// + /// Each interior node checks the value of a single variable (for us, a `Predicate`). + /// TDDs are ordered such that every path from the root of the graph to the leaves must + /// check each variable at most once, and must check each variable in the same order. + /// + /// We can choose any ordering that we want, as long as it's consistent — with the + /// caveat that terminal nodes must always be last in the ordering, since they are the + /// leaf nodes of the graph. + /// + /// We currently compare interior nodes by looking at the Salsa IDs of each variable's + /// `Predicate`, since this is already available and easy to compare. We also _reverse_ + /// the comparison of those Salsa IDs. The Salsa IDs are assigned roughly sequentially + /// while traversing the source code. Reversing the comparison means `Predicate`s that + /// appear later in the source will tend to be placed "higher" (closer to the root) in + /// the TDD graph. We have found empirically that this leads to smaller TDD graphs [1], + /// since there are often repeated combinations of `Predicate`s from earlier in the + /// file. + /// + /// [1]: https://github.com/astral-sh/ruff/pull/20098 fn cmp_atoms( &self, a: ScopedReachabilityConstraintId, @@ -439,7 +456,12 @@ impl ReachabilityConstraintsBuilder { } else if b.is_terminal() { Ordering::Less } else { - self.interiors[a].atom.cmp(&self.interiors[b].atom) + // See https://github.com/astral-sh/ruff/pull/20098 for an explanation of why this + // ordering is reversed. + self.interiors[a] + .atom + .cmp(&self.interiors[b].atom) + .reverse() } } From 89ca493fd963bb3ba875b170989d9468d2d1a5bd Mon Sep 17 00:00:00 2001 From: Dan Parizher <105245560+danparizher@users.noreply.github.com> Date: Wed, 27 Aug 2025 15:15:44 -0400 Subject: [PATCH 152/160] [`ruff`] Preserve relative whitespace in multi-line expressions (`RUF033`) (#19647) ## Summary Fixes #19581 I decided to add in a `indent_first_line` function into [`textwrap.rs`](https://github.com/astral-sh/ruff/blob/main/crates/ruff_python_trivia/src/textwrap.rs), as it solely focuses on text manipulation utilities. It follows the same design as `indent()`, and there may be situations in the future where it can be reused as well. --------- Co-authored-by: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Co-authored-by: Brent Westbrook --- .../resources/test/fixtures/ruff/RUF033.py | 16 +++ .../src/rules/ruff/rules/post_init_default.rs | 2 +- ..._rules__ruff__tests__RUF033_RUF033.py.snap | 54 ++++++++ crates/ruff_python_trivia/src/textwrap.rs | 115 ++++++++++++++++++ 4 files changed, 186 insertions(+), 1 deletion(-) diff --git a/crates/ruff_linter/resources/test/fixtures/ruff/RUF033.py b/crates/ruff_linter/resources/test/fixtures/ruff/RUF033.py index b6a98dabf1409..f7a72a9dae17c 100644 --- a/crates/ruff_linter/resources/test/fixtures/ruff/RUF033.py +++ b/crates/ruff_linter/resources/test/fixtures/ruff/RUF033.py @@ -124,3 +124,19 @@ def __post_init__( ... return Foo + + +@dataclass +class C: + def __post_init__(self, x: tuple[int, ...] = ( + 1, + 2, + )) -> None: + self.x = x + + +@dataclass +class D: + def __post_init__(self, x: int = """ + """) -> None: + self.x = x diff --git a/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs b/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs index dbce5d423f8d5..b2a2da56a9756 100644 --- a/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs +++ b/crates/ruff_linter/src/rules/ruff/rules/post_init_default.rs @@ -186,7 +186,7 @@ fn use_initvar( let indentation = indentation_at_offset(post_init_def.start(), checker.source()) .context("Failed to calculate leading indentation of `__post_init__` method")?; - let content = textwrap::indent(&content, indentation); + let content = textwrap::indent_first_line(&content, indentation); let initvar_edit = Edit::insertion( content.into_owned(), diff --git a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF033_RUF033.py.snap b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF033_RUF033.py.snap index f73734afe8493..e3dc5e551eaba 100644 --- a/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF033_RUF033.py.snap +++ b/crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF033_RUF033.py.snap @@ -455,3 +455,57 @@ help: Use `dataclasses.InitVar` instead 122 123 | , 123 124 | ) -> None: 124 125 | ... + +RUF033 [*] `__post_init__` method with argument defaults + --> RUF033.py:131:50 + | +129 | @dataclass +130 | class C: +131 | def __post_init__(self, x: tuple[int, ...] = ( + | __________________________________________________^ +132 | | 1, +133 | | 2, +134 | | )) -> None: + | |_____^ +135 | self.x = x + | +help: Use `dataclasses.InitVar` instead + +ℹ Unsafe fix +128 128 | +129 129 | @dataclass +130 130 | class C: +131 |- def __post_init__(self, x: tuple[int, ...] = ( + 131 |+ x: InitVar[tuple[int, ...]] = ( +132 132 | 1, +133 133 | 2, +134 |- )) -> None: + 134 |+ ) + 135 |+ def __post_init__(self, x: tuple[int, ...]) -> None: +135 136 | self.x = x +136 137 | +137 138 | + +RUF033 [*] `__post_init__` method with argument defaults + --> RUF033.py:140:38 + | +138 | @dataclass +139 | class D: +140 | def __post_init__(self, x: int = """ + | ______________________________________^ +141 | | """) -> None: + | |_______^ +142 | self.x = x + | +help: Use `dataclasses.InitVar` instead + +ℹ Unsafe fix +137 137 | +138 138 | @dataclass +139 139 | class D: +140 |- def __post_init__(self, x: int = """ +141 |- """) -> None: + 140 |+ x: InitVar[int] = """ + 141 |+ """ + 142 |+ def __post_init__(self, x: int) -> None: +142 143 | self.x = x diff --git a/crates/ruff_python_trivia/src/textwrap.rs b/crates/ruff_python_trivia/src/textwrap.rs index ce5f46671a00f..50ce0cd08c32f 100644 --- a/crates/ruff_python_trivia/src/textwrap.rs +++ b/crates/ruff_python_trivia/src/textwrap.rs @@ -71,6 +71,66 @@ pub fn indent<'a>(text: &'a str, prefix: &str) -> Cow<'a, str> { Cow::Owned(result) } +/// Indent only the first line by the given prefix. +/// +/// This function is useful when you want to indent the first line of a multi-line +/// expression while preserving the relative indentation of subsequent lines. +/// +/// # Examples +/// +/// ``` +/// # use ruff_python_trivia::textwrap::indent_first_line; +/// +/// assert_eq!(indent_first_line("First line.\nSecond line.\n", " "), +/// " First line.\nSecond line.\n"); +/// ``` +/// +/// When indenting, trailing whitespace is stripped from the prefix. +/// This means that empty lines remain empty afterwards: +/// +/// ``` +/// # use ruff_python_trivia::textwrap::indent_first_line; +/// +/// assert_eq!(indent_first_line("\n\n\nSecond line.\n", " "), +/// "\n\n\nSecond line.\n"); +/// ``` +/// +/// Leading and trailing whitespace coming from the text itself is +/// kept unchanged: +/// +/// ``` +/// # use ruff_python_trivia::textwrap::indent_first_line; +/// +/// assert_eq!(indent_first_line(" \t Foo ", "->"), "-> \t Foo "); +/// ``` +pub fn indent_first_line<'a>(text: &'a str, prefix: &str) -> Cow<'a, str> { + if prefix.is_empty() { + return Cow::Borrowed(text); + } + + let mut lines = text.universal_newlines(); + let Some(first_line) = lines.next() else { + return Cow::Borrowed(text); + }; + + let mut result = String::with_capacity(text.len() + prefix.len()); + + // Indent only the first line + if first_line.trim_whitespace().is_empty() { + result.push_str(prefix.trim_whitespace_end()); + } else { + result.push_str(prefix); + } + result.push_str(first_line.as_full_str()); + + // Add remaining lines without indentation + for line in lines { + result.push_str(line.as_full_str()); + } + + Cow::Owned(result) +} + /// Removes common leading whitespace from each line. /// /// This function will look at each non-empty line and determine the @@ -409,6 +469,61 @@ mod tests { assert_eq!(dedent(text), text); } + #[test] + fn indent_first_line_empty() { + assert_eq!(indent_first_line("\n", " "), "\n"); + } + + #[test] + #[rustfmt::skip] + fn indent_first_line_nonempty() { + let text = [ + " foo\n", + "bar\n", + " baz\n", + ].join(""); + let expected = [ + "// foo\n", + "bar\n", + " baz\n", + ].join(""); + assert_eq!(indent_first_line(&text, "// "), expected); + } + + #[test] + #[rustfmt::skip] + fn indent_first_line_empty_line() { + let text = [ + " foo", + "bar", + "", + " baz", + ].join("\n"); + let expected = [ + "// foo", + "bar", + "", + " baz", + ].join("\n"); + assert_eq!(indent_first_line(&text, "// "), expected); + } + + #[test] + #[rustfmt::skip] + fn indent_first_line_mixed_newlines() { + let text = [ + " foo\r\n", + "bar\n", + " baz\r", + ].join(""); + let expected = [ + "// foo\r\n", + "bar\n", + " baz\r", + ].join(""); + assert_eq!(indent_first_line(&text, "// "), expected); + } + #[test] #[rustfmt::skip] fn adjust_indent() { From d75ef3823c7dc7c6a0dc38dbc42ab9f8075424b6 Mon Sep 17 00:00:00 2001 From: Leandro Braga <18340809+leandrobbraga@users.noreply.github.com> Date: Wed, 27 Aug 2025 17:46:07 -0300 Subject: [PATCH 153/160] [ty] print diagnostics with fully qualified name to disambiguate some cases (#19850) There are some situations that we have a confusing diagnostics due to identical class names. ## Class with same name from different modules ```python import pandas import polars df: pandas.DataFrame = polars.DataFrame() ``` This yields the following error: **Actual:** error: [invalid-assignment] "Object of type `DataFrame` is not assignable to `DataFrame`" **Expected**: error: [invalid-assignment] "Object of type `polars.DataFrame` is not assignable to `pandas.DataFrame`" ## Nested classes ```python from enum import Enum class A: class B(Enum): ACTIVE = "active" INACTIVE = "inactive" class C: class B(Enum): ACTIVE = "active" INACTIVE = "inactive" ``` **Actual**: error: [invalid-assignment] "Object of type `Literal[B.ACTIVE]` is not assignable to `B`" **Expected**: error: [invalid-assignment] "Object of type `Literal[my_module.C.B.ACTIVE]` is not assignable to `my_module.A.B`" ## Solution In this MR we added an heuristics to detect when to use a fully qualified name: - There is an invalid assignment and; - They are two different classes and; - They have the same name The fully qualified name always includes: - module name - nested classes name - actual class name There was no `QualifiedDisplay` so I had to implement it from scratch. I'm very new to the codebase, so I might have done things inefficiently, so I appreciate feedback. Should we pre-compute the fully qualified name or do it on demand? ## Not implemented ### Function-local classes Should we approach this in a different PR? **Example**: ```python # t.py from __future__ import annotations def function() -> A: class A: pass return A() class A: pass a: A = function() ``` #### mypy ```console t.py:8: error: Incompatible return value type (got "t.A@5", expected "t.A") [return-value] ``` From my testing the 5 in `A@5` comes from the like number. #### ty ```console error[invalid-return-type]: Return type does not match returned value --> t.py:4:19 | 4 | def function() -> A: | - Expected `A` because of return type 5 | class A: 6 | pass 7 | 8 | return A() | ^^^ expected `A`, found `A` | info: rule `invalid-return-type` is enabled by default ``` Fixes https://github.com/astral-sh/ty/issues/848 --------- Co-authored-by: Alex Waygood Co-authored-by: Carl Meyer --- crates/ty/docs/rules.md | 128 +++++----- .../mdtest/diagnostics/same_names.md | 230 ++++++++++++++++++ .../src/types/diagnostic.rs | 53 +++- .../ty_python_semantic/src/types/display.rs | 110 ++++++++- 4 files changed, 440 insertions(+), 81 deletions(-) create mode 100644 crates/ty_python_semantic/resources/mdtest/diagnostics/same_names.md diff --git a/crates/ty/docs/rules.md b/crates/ty/docs/rules.md index 25290865c8e58..d1c4e2e9a4eef 100644 --- a/crates/ty/docs/rules.md +++ b/crates/ty/docs/rules.md @@ -36,7 +36,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20call-non-callable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L110) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L112) **What it does** @@ -58,7 +58,7 @@ Calling a non-callable object will raise a `TypeError` at runtime. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-argument-forms) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L154) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L156) **What it does** @@ -88,7 +88,7 @@ f(int) # error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-declarations) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L180) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L182) **What it does** @@ -117,7 +117,7 @@ a = 1 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20conflicting-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L205) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L207) **What it does** @@ -147,7 +147,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20cyclic-class-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L231) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L233) **What it does** @@ -177,7 +177,7 @@ class B(A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L296) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L298) **What it does** @@ -202,7 +202,7 @@ class B(A, A): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20duplicate-kw-only) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L317) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L319) **What it does** @@ -306,7 +306,7 @@ def test(): -> "Literal[5]": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20inconsistent-mro) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L520) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L522) **What it does** @@ -334,7 +334,7 @@ class C(A, B): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20index-out-of-bounds) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L544) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L546) **What it does** @@ -358,7 +358,7 @@ t[3] # IndexError: tuple index out of range Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20instance-layout-conflict) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L349) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L351) **What it does** @@ -445,7 +445,7 @@ an atypical memory layout. Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-argument-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L589) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L591) **What it does** @@ -470,7 +470,7 @@ func("foo") # error: [invalid-argument-type] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-assignment) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L629) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L631) **What it does** @@ -496,7 +496,7 @@ a: int = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-attribute-access) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1663) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1665) **What it does** @@ -528,7 +528,7 @@ C.instance_var = 3 # error: Cannot assign to instance variable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-await) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L651) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L653) **What it does** @@ -562,7 +562,7 @@ asyncio.run(main()) Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L681) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L683) **What it does** @@ -584,7 +584,7 @@ class A(42): ... # error: [invalid-base] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-context-manager) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L732) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L734) **What it does** @@ -609,7 +609,7 @@ with 1: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-declaration) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L753) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L755) **What it does** @@ -636,7 +636,7 @@ a: str Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-exception-caught) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L776) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L778) **What it does** @@ -678,7 +678,7 @@ except ZeroDivisionError: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-generic-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L812) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L814) **What it does** @@ -709,7 +709,7 @@ class C[U](Generic[T]): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-key) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L564) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L566) **What it does** @@ -738,7 +738,7 @@ alice["height"] # KeyError: 'height' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-legacy-type-variable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L838) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L840) **What it does** @@ -771,7 +771,7 @@ def f(t: TypeVar("U")): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-metaclass) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L887) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L889) **What it does** @@ -803,7 +803,7 @@ class B(metaclass=f): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-named-tuple) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L494) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L496) **What it does** @@ -833,7 +833,7 @@ TypeError: can only inherit from a NamedTuple type and Generic Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L914) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L916) **What it does** @@ -881,7 +881,7 @@ def foo(x: int) -> int: ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-parameter-default) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L957) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L959) **What it does** @@ -905,7 +905,7 @@ def f(a: int = ''): ... Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-protocol) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L431) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L433) **What it does** @@ -937,7 +937,7 @@ TypeError: Protocols can only inherit from other protocols, got Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-raise) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L977) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L979) Checks for `raise` statements that raise non-exceptions or use invalid @@ -984,7 +984,7 @@ def g(): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-return-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L610) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L612) **What it does** @@ -1007,7 +1007,7 @@ def func() -> int: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-super-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1020) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1022) **What it does** @@ -1061,7 +1061,7 @@ TODO #14889 Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-alias-type) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L866) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L868) **What it does** @@ -1086,7 +1086,7 @@ NewAlias = TypeAliasType(get_name(), int) # error: TypeAliasType name mus Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-checking-constant) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1059) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1061) **What it does** @@ -1114,7 +1114,7 @@ TYPE_CHECKING = '' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-form) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1083) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1085) **What it does** @@ -1142,7 +1142,7 @@ b: Annotated[int] # `Annotated` expects at least two arguments Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1135) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1137) **What it does** @@ -1174,7 +1174,7 @@ f(10) # Error Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-guard-definition) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1107) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1109) **What it does** @@ -1206,7 +1206,7 @@ class C: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20invalid-type-variable-constraints) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1163) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1165) **What it does** @@ -1239,7 +1239,7 @@ T = TypeVar('T', bound=str) # valid bound TypeVar Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1192) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1194) **What it does** @@ -1262,7 +1262,7 @@ func() # TypeError: func() missing 1 required positional argument: 'x' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20missing-typed-dict-key) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1762) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1764) **What it does** @@ -1293,7 +1293,7 @@ alice["age"] # KeyError Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20no-matching-overload) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1211) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1213) **What it does** @@ -1320,7 +1320,7 @@ func("string") # error: [no-matching-overload] Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20non-subscriptable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1234) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1236) **What it does** @@ -1342,7 +1342,7 @@ Subscripting an object that does not support it will raise a `TypeError` at runt Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20not-iterable) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1252) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1254) **What it does** @@ -1366,7 +1366,7 @@ for i in 34: # TypeError: 'int' object is not iterable Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20parameter-already-assigned) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1303) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1305) **What it does** @@ -1420,7 +1420,7 @@ def test(): -> "int": Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20static-assert-error) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1639) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1641) **What it does** @@ -1448,7 +1448,7 @@ static_assert(int(2.0 * 3.0) == 6) # error: does not have a statically known tr Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20subclass-of-final-class) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1394) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1396) **What it does** @@ -1475,7 +1475,7 @@ class B(A): ... # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20too-many-positional-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1439) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1441) **What it does** @@ -1500,7 +1500,7 @@ f("foo") # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20type-assertion-failure) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1417) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1419) **What it does** @@ -1526,7 +1526,7 @@ def _(x: int): Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unavailable-implicit-super-arguments) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1460) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1462) **What it does** @@ -1570,7 +1570,7 @@ class A: Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unknown-argument) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1517) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1519) **What it does** @@ -1595,7 +1595,7 @@ f(x=1, y=2) # Error raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1538) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1540) **What it does** @@ -1621,7 +1621,7 @@ A().foo # AttributeError: 'A' object has no attribute 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1560) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1562) **What it does** @@ -1644,7 +1644,7 @@ import foo # ModuleNotFoundError: No module named 'foo' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1579) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1581) **What it does** @@ -1667,7 +1667,7 @@ print(x) # NameError: name 'x' is not defined Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-bool-conversion) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1272) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1274) **What it does** @@ -1702,7 +1702,7 @@ b1 < b2 < b1 # exception raised here Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-operator) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1598) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1600) **What it does** @@ -1728,7 +1728,7 @@ A() + A() # TypeError: unsupported operand type(s) for +: 'A' and 'A' Default level: [`error`](../rules.md#rule-levels "This lint has a default level of 'error'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20zero-stepsize-in-slice) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1620) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1622) **What it does** @@ -1751,7 +1751,7 @@ l[1:10:0] # ValueError: slice step cannot be zero Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20ambiguous-protocol-member) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L459) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L461) **What it does** @@ -1790,7 +1790,7 @@ class SubProto(BaseProto, Protocol): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20deprecated) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L275) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L277) **What it does** @@ -1843,7 +1843,7 @@ a = 20 / 0 # type: ignore Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-attribute) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1324) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1326) **What it does** @@ -1869,7 +1869,7 @@ A.c # AttributeError: type object 'A' has no attribute 'c' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-implicit-call) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L128) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L130) **What it does** @@ -1899,7 +1899,7 @@ A()[0] # TypeError: 'A' object is not subscriptable Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unbound-import) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1346) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1348) **What it does** @@ -1929,7 +1929,7 @@ from module import a # ImportError: cannot import name 'a' from 'module' Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20redundant-cast) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1691) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1693) **What it does** @@ -1954,7 +1954,7 @@ cast(int, f()) # Redundant Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20undefined-reveal) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1499) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1501) **What it does** @@ -2005,7 +2005,7 @@ a = 20 / 0 # ty: ignore[division-by-zero] Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unresolved-global) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1712) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1714) **What it does** @@ -2059,7 +2059,7 @@ def g(): Default level: [`warn`](../rules.md#rule-levels "This lint has a default level of 'warn'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20unsupported-base) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L699) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L701) **What it does** @@ -2096,7 +2096,7 @@ class D(C): ... # error: [unsupported-base] Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20division-by-zero) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L257) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L259) **What it does** @@ -2118,7 +2118,7 @@ Dividing by zero raises a `ZeroDivisionError` at runtime. Default level: [`ignore`](../rules.md#rule-levels "This lint has a default level of 'ignore'.") · [Related issues](https://github.com/astral-sh/ty/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20possibly-unresolved-reference) · -[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1372) +[View source](https://github.com/astral-sh/ruff/blob/main/crates%2Fty_python_semantic%2Fsrc%2Ftypes%2Fdiagnostic.rs#L1374) **What it does** diff --git a/crates/ty_python_semantic/resources/mdtest/diagnostics/same_names.md b/crates/ty_python_semantic/resources/mdtest/diagnostics/same_names.md new file mode 100644 index 0000000000000..1c4593fc6e4f0 --- /dev/null +++ b/crates/ty_python_semantic/resources/mdtest/diagnostics/same_names.md @@ -0,0 +1,230 @@ +# Identical type display names in diagnostics + +ty prints the fully qualified name to disambiguate objects with the same name. + +## Nested class + +`test.py`: + +```py +class A: + class B: + pass + +class C: + class B: + pass + +a: A.B = C.B() # error: [invalid-assignment] "Object of type `test.C.B` is not assignable to `test.A.B`" +``` + +## Nested class in function + +`test.py`: + +```py +class B: + pass + +def f(b: B): + class B: + pass + + # error: [invalid-assignment] "Object of type `test..B` is not assignable to `test.B`" + b = B() +``` + +## Class from different modules + +```py +import a +import b + +df: a.DataFrame = b.DataFrame() # error: [invalid-assignment] "Object of type `b.DataFrame` is not assignable to `a.DataFrame`" + +def _(dfs: list[b.DataFrame]): + # TODO should be"Object of type `list[b.DataFrame]` is not assignable to `list[a.DataFrame]` + # error: [invalid-assignment] "Object of type `list[DataFrame]` is not assignable to `list[DataFrame]`" + dataframes: list[a.DataFrame] = dfs +``` + +`a.py`: + +```py +class DataFrame: + pass +``` + +`b.py`: + +```py +class DataFrame: + pass +``` + +## Enum from different modules + +```py +import status_a +import status_b + +# error: [invalid-assignment] "Object of type `Literal[status_b.Status.ACTIVE]` is not assignable to `status_a.Status`" +s: status_a.Status = status_b.Status.ACTIVE +``` + +`status_a.py`: + +```py +from enum import Enum + +class Status(Enum): + ACTIVE = 1 + INACTIVE = 2 +``` + +`status_b.py`: + +```py +from enum import Enum + +class Status(Enum): + ACTIVE = "active" + INACTIVE = "inactive" +``` + +## Nested enum + +`test.py`: + +```py +from enum import Enum + +class A: + class B(Enum): + ACTIVE = "active" + INACTIVE = "inactive" + +class C: + class B(Enum): + ACTIVE = "active" + INACTIVE = "inactive" + +# error: [invalid-assignment] "Object of type `Literal[test.C.B.ACTIVE]` is not assignable to `test.A.B`" +a: A.B = C.B.ACTIVE +``` + +## Class literals + +```py +import cls_a +import cls_b + +# error: [invalid-assignment] "Object of type `` is not assignable to `type[cls_a.Config]`" +config_class: type[cls_a.Config] = cls_b.Config +``` + +`cls_a.py`: + +```py +class Config: + pass +``` + +`cls_b.py`: + +```py +class Config: + pass +``` + +## Generic aliases + +```py +import generic_a +import generic_b + +# TODO should be error: [invalid-assignment] "Object of type `` is not assignable to `type[generic_a.Container[int]]`" +container: type[generic_a.Container[int]] = generic_b.Container[int] +``` + +`generic_a.py`: + +```py +from typing import Generic, TypeVar + +T = TypeVar("T") + +class Container(Generic[T]): + pass +``` + +`generic_b.py`: + +```py +from typing import Generic, TypeVar + +T = TypeVar("T") + +class Container(Generic[T]): + pass +``` + +## Protocols + +```py +from typing import Protocol +import proto_a +import proto_b + +# TODO should be error: [invalid-assignment] "Object of type `proto_b.Drawable` is not assignable to `proto_a.Drawable`" +def _(drawable_b: proto_b.Drawable): + drawable: proto_a.Drawable = drawable_b +``` + +`proto_a.py`: + +```py +from typing import Protocol + +class Drawable(Protocol): + def draw(self) -> None: ... +``` + +`proto_b.py`: + +```py +from typing import Protocol + +class Drawable(Protocol): + def draw(self) -> int: ... +``` + +## TypedDict + +```py +from typing import TypedDict +import dict_a +import dict_b + +def _(b_person: dict_b.Person): + # TODO should be error: [invalid-assignment] "Object of type `dict_b.Person` is not assignable to `dict_a.Person`" + person_var: dict_a.Person = b_person +``` + +`dict_a.py`: + +```py +from typing import TypedDict + +class Person(TypedDict): + name: str +``` + +`dict_b.py`: + +```py +from typing import TypedDict + +class Person(TypedDict): + name: bytes +``` diff --git a/crates/ty_python_semantic/src/types/diagnostic.rs b/crates/ty_python_semantic/src/types/diagnostic.rs index 44981271c1249..ca953928ed7d2 100644 --- a/crates/ty_python_semantic/src/types/diagnostic.rs +++ b/crates/ty_python_semantic/src/types/diagnostic.rs @@ -10,7 +10,7 @@ use crate::semantic_index::SemanticIndex; use crate::semantic_index::definition::Definition; use crate::semantic_index::place::{PlaceTable, ScopedPlaceId}; use crate::suppression::FileSuppressionId; -use crate::types::class::{DisjointBase, DisjointBaseKind, Field}; +use crate::types::class::{ClassType, DisjointBase, DisjointBaseKind, Field}; use crate::types::function::KnownFunction; use crate::types::string_annotation::{ BYTE_STRING_TYPE_ANNOTATION, ESCAPE_CHARACTER_IN_FORWARD_ANNOTATION, FSTRING_TYPE_ANNOTATION, @@ -22,7 +22,9 @@ use crate::types::{ }; use crate::types::{SpecialFormType, Type, protocol_class::ProtocolClass}; use crate::util::diagnostics::format_enumeration; -use crate::{Db, FxIndexMap, FxOrderMap, Module, ModuleName, Program, declare_lint}; +use crate::{ + Db, DisplaySettings, FxIndexMap, FxOrderMap, Module, ModuleName, Program, declare_lint, +}; use itertools::Itertools; use ruff_db::diagnostic::{Annotation, Diagnostic, SubDiagnostic, SubDiagnosticSeverity}; use ruff_python_ast::name::Name; @@ -1943,18 +1945,61 @@ pub(super) fn report_invalid_assignment( target_ty: Type, source_ty: Type, ) { + let mut settings = DisplaySettings::default(); + // Handles the situation where the report naming is confusing, such as class with the same Name, + // but from different scopes. + if let Some(target_class) = type_to_class_literal(target_ty, context.db()) { + if let Some(source_class) = type_to_class_literal(source_ty, context.db()) { + if target_class != source_class + && target_class.name(context.db()) == source_class.name(context.db()) + { + settings = settings.qualified(); + } + } + } + report_invalid_assignment_with_message( context, node, target_ty, format_args!( "Object of type `{}` is not assignable to `{}`", - source_ty.display(context.db()), - target_ty.display(context.db()), + source_ty.display_with(context.db(), settings), + target_ty.display_with(context.db(), settings) ), ); } +// TODO: generalize this to a method that takes any two types, walks them recursively, and returns +// a set of types with ambiguous names whose display should be qualified. Then we can use this in +// any diagnostic that displays two types. +fn type_to_class_literal<'db>(ty: Type<'db>, db: &'db dyn crate::Db) -> Option> { + match ty { + Type::ClassLiteral(class) => Some(class), + Type::NominalInstance(instance) => match instance.class(db) { + crate::types::class::ClassType::NonGeneric(class) => Some(class), + crate::types::class::ClassType::Generic(alias) => Some(alias.origin(db)), + }, + Type::EnumLiteral(enum_literal) => Some(enum_literal.enum_class(db)), + Type::GenericAlias(alias) => Some(alias.origin(db)), + Type::ProtocolInstance(ProtocolInstanceType { + inner: Protocol::FromClass(class), + .. + }) => match class { + ClassType::NonGeneric(class) => Some(class), + ClassType::Generic(alias) => Some(alias.origin(db)), + }, + Type::TypedDict(typed_dict) => match typed_dict.defining_class() { + ClassType::NonGeneric(class) => Some(class), + ClassType::Generic(alias) => Some(alias.origin(db)), + }, + Type::SubclassOf(subclass_of) => { + type_to_class_literal(Type::from(subclass_of.subclass_of().into_class()?), db) + } + _ => None, + } +} + pub(super) fn report_invalid_attribute_assignment( context: &InferContext, node: AnyNodeRef, diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index 534cdf8e82808..ef5741ff5f814 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -8,6 +8,8 @@ use ruff_python_literal::escape::AsciiEscape; use ruff_text_size::{TextRange, TextSize}; use crate::Db; +use crate::module_resolver::file_to_module; +use crate::semantic_index::{scope::ScopeKind, semantic_index}; use crate::types::class::{ClassLiteral, ClassType, GenericAlias}; use crate::types::function::{FunctionType, OverloadLiteral}; use crate::types::generics::{GenericContext, Specialization}; @@ -17,23 +19,40 @@ use crate::types::{ CallableType, IntersectionType, KnownClass, MethodWrapperKind, Protocol, StringLiteralType, SubclassOfInner, Type, UnionType, WrapperDescriptorKind, }; +use ruff_db::parsed::parsed_module; /// Settings for displaying types and signatures #[derive(Debug, Copy, Clone, Default)] pub struct DisplaySettings { /// Whether rendering can be multiline pub multiline: bool, + /// Whether rendering will show qualified display (e.g., module.class) + pub qualified: bool, } impl DisplaySettings { #[must_use] pub fn multiline(self) -> Self { - Self { multiline: true } + Self { + multiline: true, + ..self + } } #[must_use] pub fn singleline(self) -> Self { - Self { multiline: false } + Self { + multiline: false, + ..self + } + } + + #[must_use] + pub fn qualified(self) -> Self { + Self { + qualified: true, + ..self + } } } @@ -103,6 +122,65 @@ struct DisplayRepresentation<'db> { settings: DisplaySettings, } +impl DisplayRepresentation<'_> { + fn class_parents(&self, class: ClassLiteral) -> Vec { + let body_scope = class.body_scope(self.db); + let file = body_scope.file(self.db); + let module_ast = parsed_module(self.db, file).load(self.db); + let index = semantic_index(self.db, file); + let file_scope_id = body_scope.file_scope_id(self.db); + + let mut name_parts = vec![]; + + // Skips itself + for (ancestor_file_scope_id, ancestor_scope) in index.ancestor_scopes(file_scope_id).skip(1) + { + let ancestor_scope_id = ancestor_file_scope_id.to_scope_id(self.db, file); + let node = ancestor_scope_id.node(self.db); + + match ancestor_scope.kind() { + ScopeKind::Class => { + if let Some(class_def) = node.as_class(&module_ast) { + name_parts.push(class_def.name.as_str().to_string()); + } + } + ScopeKind::Function => { + if let Some(function_def) = node.as_function(&module_ast) { + name_parts.push(format!( + "", + function_def.name.as_str() + )); + } + } + _ => {} + } + } + + if let Some(module) = file_to_module(self.db, file) { + let module_name = module.name(self.db); + name_parts.push(module_name.as_str().to_string()); + } + + name_parts.reverse(); + name_parts + } + + fn write_maybe_qualified_class( + &self, + f: &mut Formatter<'_>, + class: ClassLiteral, + ) -> fmt::Result { + if self.settings.qualified { + let parents = self.class_parents(class); + if !parents.is_empty() { + f.write_str(&parents.join("."))?; + f.write_char('.')?; + } + } + f.write_str(class.name(self.db)) + } +} + impl Display for DisplayRepresentation<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self.ty { @@ -120,13 +198,15 @@ impl Display for DisplayRepresentation<'_> { .expect("Specialization::tuple() should always return `Some()` for `KnownClass::Tuple`") .display_with(self.db, self.settings) .fmt(f), - (ClassType::NonGeneric(class), _) => f.write_str(class.name(self.db)), + (ClassType::NonGeneric(class), _) => { + self.write_maybe_qualified_class(f, class) + }, (ClassType::Generic(alias), _) => alias.display_with(self.db, self.settings).fmt(f), } } Type::ProtocolInstance(protocol) => match protocol.inner { Protocol::FromClass(ClassType::NonGeneric(class)) => { - f.write_str(class.name(self.db)) + self.write_maybe_qualified_class(f, class) } Protocol::FromClass(ClassType::Generic(alias)) => { alias.display_with(self.db, self.settings).fmt(f) @@ -151,7 +231,9 @@ impl Display for DisplayRepresentation<'_> { write!(f, "", module.module(self.db).name(self.db)) } Type::ClassLiteral(class) => { - write!(f, "", class.name(self.db)) + write!(f, "") } Type::GenericAlias(generic) => write!( f, @@ -160,7 +242,9 @@ impl Display for DisplayRepresentation<'_> { ), Type::SubclassOf(subclass_of_ty) => match subclass_of_ty.subclass_of() { SubclassOfInner::Class(ClassType::NonGeneric(class)) => { - write!(f, "type[{}]", class.name(self.db)) + write!(f, "type[")?; + self.write_maybe_qualified_class(f, class)?; + write!(f, "]") } SubclassOfInner::Class(ClassType::Generic(alias)) => { write!( @@ -271,12 +355,9 @@ impl Display for DisplayRepresentation<'_> { escape.bytes_repr(TripleQuotes::No).write(f) } Type::EnumLiteral(enum_literal) => { - write!( - f, - "{enum_class}.{name}", - enum_class = enum_literal.enum_class(self.db).name(self.db), - name = enum_literal.name(self.db), - ) + self.write_maybe_qualified_class(f, enum_literal.enum_class(self.db))?; + f.write_char('.')?; + f.write_str(enum_literal.name(self.db)) } Type::NonInferableTypeVar(bound_typevar) | Type::TypeVar(bound_typevar) => { f.write_str(bound_typevar.typevar(self.db).name(self.db))?; @@ -312,7 +393,10 @@ impl Display for DisplayRepresentation<'_> { } f.write_str("]") } - Type::TypedDict(typed_dict) => f.write_str(typed_dict.defining_class().name(self.db)), + Type::TypedDict(typed_dict) => self.write_maybe_qualified_class( + f, + typed_dict.defining_class().class_literal(self.db).0, + ), Type::TypeAlias(alias) => f.write_str(alias.name(self.db)), } } From af259faed57f2428da4fa09aab03dbb96b0f160e Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Wed, 27 Aug 2025 15:19:01 -0700 Subject: [PATCH 154/160] [`flake8-async`] Implement `blocking-http-call-httpx` (`ASYNC212`) (#20091) ## Summary Adds new rule to find and report use of `httpx.Client` in synchronous functions. See issue #8451 ## Test Plan New snapshots for `ASYNC212.py` with `cargo insta test`. --- .../test/fixtures/flake8_async/ASYNC212.py | 75 ++++++++ .../src/checkers/ast/analyze/expression.rs | 3 + crates/ruff_linter/src/codes.rs | 1 + .../ruff_linter/src/rules/flake8_async/mod.rs | 1 + .../rules/blocking_http_call_httpx.rs | 145 +++++++++++++++ .../src/rules/flake8_async/rules/mod.rs | 2 + ...e8_async__tests__ASYNC212_ASYNC212.py.snap | 168 ++++++++++++++++++ ruff.schema.json | 1 + 8 files changed, 396 insertions(+) create mode 100644 crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC212.py create mode 100644 crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call_httpx.rs create mode 100644 crates/ruff_linter/src/rules/flake8_async/snapshots/ruff_linter__rules__flake8_async__tests__ASYNC212_ASYNC212.py.snap diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC212.py b/crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC212.py new file mode 100644 index 0000000000000..d6a798debc4a2 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/flake8_async/ASYNC212.py @@ -0,0 +1,75 @@ +from typing import Optional + +import httpx + + +def foo(): + client = httpx.Client() + client.close() # Ok + client.delete() # Ok + client.get() # Ok + client.head() # Ok + client.options() # Ok + client.patch() # Ok + client.post() # Ok + client.put() # Ok + client.request() # Ok + client.send() # Ok + client.stream() # Ok + + client.anything() # Ok + client.build_request() # Ok + client.is_closed # Ok + + +async def foo(): + client = httpx.Client() + client.close() # ASYNC212 + client.delete() # ASYNC212 + client.get() # ASYNC212 + client.head() # ASYNC212 + client.options() # ASYNC212 + client.patch() # ASYNC212 + client.post() # ASYNC212 + client.put() # ASYNC212 + client.request() # ASYNC212 + client.send() # ASYNC212 + client.stream() # ASYNC212 + + client.anything() # Ok + client.build_request() # Ok + client.is_closed # Ok + + +async def foo(client: httpx.Client): + client.request() # ASYNC212 + client.anything() # Ok + + +async def foo(client: httpx.Client | None): + client.request() # ASYNC212 + client.anything() # Ok + + +async def foo(client: Optional[httpx.Client]): + client.request() # ASYNC212 + client.anything() # Ok + + +async def foo(): + client: httpx.Client = ... + client.request() # ASYNC212 + client.anything() # Ok + + +global_client = httpx.Client() + + +async def foo(): + global_client.request() # ASYNC212 + global_client.anything() # Ok + + +async def foo(): + async with httpx.AsyncClient() as client: + await client.get() # Ok diff --git a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs index 9a6c4b52c9c2b..c2f1afe5848b6 100644 --- a/crates/ruff_linter/src/checkers/ast/analyze/expression.rs +++ b/crates/ruff_linter/src/checkers/ast/analyze/expression.rs @@ -660,6 +660,9 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) { if checker.is_rule_enabled(Rule::BlockingHttpCallInAsyncFunction) { flake8_async::rules::blocking_http_call(checker, call); } + if checker.is_rule_enabled(Rule::BlockingHttpCallHttpxInAsyncFunction) { + flake8_async::rules::blocking_http_call_httpx(checker, call); + } if checker.is_rule_enabled(Rule::BlockingOpenCallInAsyncFunction) { flake8_async::rules::blocking_open_call(checker, call); } diff --git a/crates/ruff_linter/src/codes.rs b/crates/ruff_linter/src/codes.rs index bb29e285d744b..ebf0d7babb8b7 100644 --- a/crates/ruff_linter/src/codes.rs +++ b/crates/ruff_linter/src/codes.rs @@ -336,6 +336,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> { (Flake8Async, "115") => (RuleGroup::Stable, rules::flake8_async::rules::AsyncZeroSleep), (Flake8Async, "116") => (RuleGroup::Preview, rules::flake8_async::rules::LongSleepNotForever), (Flake8Async, "210") => (RuleGroup::Stable, rules::flake8_async::rules::BlockingHttpCallInAsyncFunction), + (Flake8Async, "212") => (RuleGroup::Preview, rules::flake8_async::rules::BlockingHttpCallHttpxInAsyncFunction), (Flake8Async, "220") => (RuleGroup::Stable, rules::flake8_async::rules::CreateSubprocessInAsyncFunction), (Flake8Async, "221") => (RuleGroup::Stable, rules::flake8_async::rules::RunProcessInAsyncFunction), (Flake8Async, "222") => (RuleGroup::Stable, rules::flake8_async::rules::WaitForProcessInAsyncFunction), diff --git a/crates/ruff_linter/src/rules/flake8_async/mod.rs b/crates/ruff_linter/src/rules/flake8_async/mod.rs index b7346e2429373..7389abf603f56 100644 --- a/crates/ruff_linter/src/rules/flake8_async/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_async/mod.rs @@ -23,6 +23,7 @@ mod tests { #[test_case(Rule::AsyncZeroSleep, Path::new("ASYNC115.py"))] #[test_case(Rule::LongSleepNotForever, Path::new("ASYNC116.py"))] #[test_case(Rule::BlockingHttpCallInAsyncFunction, Path::new("ASYNC210.py"))] + #[test_case(Rule::BlockingHttpCallHttpxInAsyncFunction, Path::new("ASYNC212.py"))] #[test_case(Rule::CreateSubprocessInAsyncFunction, Path::new("ASYNC22x.py"))] #[test_case(Rule::RunProcessInAsyncFunction, Path::new("ASYNC22x.py"))] #[test_case(Rule::WaitForProcessInAsyncFunction, Path::new("ASYNC22x.py"))] diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call_httpx.rs b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call_httpx.rs new file mode 100644 index 0000000000000..e46905774e309 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_async/rules/blocking_http_call_httpx.rs @@ -0,0 +1,145 @@ +use ruff_python_ast::{self as ast, Expr, ExprCall}; + +use ruff_macros::{ViolationMetadata, derive_message_formats}; +use ruff_python_semantic::analyze::typing::{TypeChecker, check_type, traverse_union_and_optional}; +use ruff_text_size::Ranged; + +use crate::Violation; +use crate::checkers::ast::Checker; + +/// ## What it does +/// Checks that async functions do not use blocking httpx clients. +/// +/// ## Why is this bad? +/// Blocking an async function via a blocking HTTP call will block the entire +/// event loop, preventing it from executing other tasks while waiting for the +/// HTTP response, negating the benefits of asynchronous programming. +/// +/// Instead of using the blocking `httpx` client, use the asynchronous client. +/// +/// ## Example +/// ```python +/// import httpx +/// +/// +/// async def fetch(): +/// client = httpx.Client() +/// response = client.get(...) +/// ``` +/// +/// Use instead: +/// ```python +/// import httpx +/// +/// +/// async def fetch(): +/// async with httpx.AsyncClient() as client: +/// response = await client.get(...) +/// ``` +#[derive(ViolationMetadata)] +pub(crate) struct BlockingHttpCallHttpxInAsyncFunction { + name: String, + call: String, +} + +impl Violation for BlockingHttpCallHttpxInAsyncFunction { + #[derive_message_formats] + fn message(&self) -> String { + format!( + "Blocking httpx method {name}.{call}() in async context, use httpx.AsyncClient", + name = self.name, + call = self.call, + ) + } +} + +struct HttpxClientChecker; + +impl TypeChecker for HttpxClientChecker { + fn match_annotation( + annotation: &ruff_python_ast::Expr, + semantic: &ruff_python_semantic::SemanticModel, + ) -> bool { + // match base annotation directly + if semantic + .resolve_qualified_name(annotation) + .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["httpx", "Client"])) + { + return true; + } + + // otherwise traverse any union or optional annotation + let mut found = false; + traverse_union_and_optional( + &mut |inner_expr, _| { + if semantic + .resolve_qualified_name(inner_expr) + .is_some_and(|qualified_name| { + matches!(qualified_name.segments(), ["httpx", "Client"]) + }) + { + found = true; + } + }, + semantic, + annotation, + ); + found + } + + fn match_initializer( + initializer: &ruff_python_ast::Expr, + semantic: &ruff_python_semantic::SemanticModel, + ) -> bool { + let Expr::Call(ExprCall { func, .. }) = initializer else { + return false; + }; + + semantic + .resolve_qualified_name(func) + .is_some_and(|qualified_name| matches!(qualified_name.segments(), ["httpx", "Client"])) + } +} + +/// ASYNC212 +pub(crate) fn blocking_http_call_httpx(checker: &Checker, call: &ExprCall) { + let semantic = checker.semantic(); + if !semantic.in_async_context() { + return; + } + + let Some(ast::ExprAttribute { value, attr, .. }) = call.func.as_attribute_expr() else { + return; + }; + let Some(name) = value.as_name_expr() else { + return; + }; + let Some(binding) = semantic.only_binding(name).map(|id| semantic.binding(id)) else { + return; + }; + + if check_type::(binding, semantic) { + if matches!( + attr.id.as_str(), + "close" + | "delete" + | "get" + | "head" + | "options" + | "patch" + | "post" + | "put" + | "request" + | "send" + | "stream" + ) { + checker.report_diagnostic( + BlockingHttpCallHttpxInAsyncFunction { + name: name.id.to_string(), + call: attr.id.to_string(), + }, + call.func.range(), + ); + } + } +} diff --git a/crates/ruff_linter/src/rules/flake8_async/rules/mod.rs b/crates/ruff_linter/src/rules/flake8_async/rules/mod.rs index 1b115a3c8b255..32b2fa8e366d4 100644 --- a/crates/ruff_linter/src/rules/flake8_async/rules/mod.rs +++ b/crates/ruff_linter/src/rules/flake8_async/rules/mod.rs @@ -2,6 +2,7 @@ pub(crate) use async_busy_wait::*; pub(crate) use async_function_with_timeout::*; pub(crate) use async_zero_sleep::*; pub(crate) use blocking_http_call::*; +pub(crate) use blocking_http_call_httpx::*; pub(crate) use blocking_open_call::*; pub(crate) use blocking_process_invocation::*; pub(crate) use blocking_sleep::*; @@ -13,6 +14,7 @@ mod async_busy_wait; mod async_function_with_timeout; mod async_zero_sleep; mod blocking_http_call; +mod blocking_http_call_httpx; mod blocking_open_call; mod blocking_process_invocation; mod blocking_sleep; diff --git a/crates/ruff_linter/src/rules/flake8_async/snapshots/ruff_linter__rules__flake8_async__tests__ASYNC212_ASYNC212.py.snap b/crates/ruff_linter/src/rules/flake8_async/snapshots/ruff_linter__rules__flake8_async__tests__ASYNC212_ASYNC212.py.snap new file mode 100644 index 0000000000000..9e641816a3cf5 --- /dev/null +++ b/crates/ruff_linter/src/rules/flake8_async/snapshots/ruff_linter__rules__flake8_async__tests__ASYNC212_ASYNC212.py.snap @@ -0,0 +1,168 @@ +--- +source: crates/ruff_linter/src/rules/flake8_async/mod.rs +--- +ASYNC212 Blocking httpx method client.close() in async context, use httpx.AsyncClient + --> ASYNC212.py:27:5 + | +25 | async def foo(): +26 | client = httpx.Client() +27 | client.close() # ASYNC212 + | ^^^^^^^^^^^^ +28 | client.delete() # ASYNC212 +29 | client.get() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.delete() in async context, use httpx.AsyncClient + --> ASYNC212.py:28:5 + | +26 | client = httpx.Client() +27 | client.close() # ASYNC212 +28 | client.delete() # ASYNC212 + | ^^^^^^^^^^^^^ +29 | client.get() # ASYNC212 +30 | client.head() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.get() in async context, use httpx.AsyncClient + --> ASYNC212.py:29:5 + | +27 | client.close() # ASYNC212 +28 | client.delete() # ASYNC212 +29 | client.get() # ASYNC212 + | ^^^^^^^^^^ +30 | client.head() # ASYNC212 +31 | client.options() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.head() in async context, use httpx.AsyncClient + --> ASYNC212.py:30:5 + | +28 | client.delete() # ASYNC212 +29 | client.get() # ASYNC212 +30 | client.head() # ASYNC212 + | ^^^^^^^^^^^ +31 | client.options() # ASYNC212 +32 | client.patch() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.options() in async context, use httpx.AsyncClient + --> ASYNC212.py:31:5 + | +29 | client.get() # ASYNC212 +30 | client.head() # ASYNC212 +31 | client.options() # ASYNC212 + | ^^^^^^^^^^^^^^ +32 | client.patch() # ASYNC212 +33 | client.post() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.patch() in async context, use httpx.AsyncClient + --> ASYNC212.py:32:5 + | +30 | client.head() # ASYNC212 +31 | client.options() # ASYNC212 +32 | client.patch() # ASYNC212 + | ^^^^^^^^^^^^ +33 | client.post() # ASYNC212 +34 | client.put() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.post() in async context, use httpx.AsyncClient + --> ASYNC212.py:33:5 + | +31 | client.options() # ASYNC212 +32 | client.patch() # ASYNC212 +33 | client.post() # ASYNC212 + | ^^^^^^^^^^^ +34 | client.put() # ASYNC212 +35 | client.request() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.put() in async context, use httpx.AsyncClient + --> ASYNC212.py:34:5 + | +32 | client.patch() # ASYNC212 +33 | client.post() # ASYNC212 +34 | client.put() # ASYNC212 + | ^^^^^^^^^^ +35 | client.request() # ASYNC212 +36 | client.send() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.request() in async context, use httpx.AsyncClient + --> ASYNC212.py:35:5 + | +33 | client.post() # ASYNC212 +34 | client.put() # ASYNC212 +35 | client.request() # ASYNC212 + | ^^^^^^^^^^^^^^ +36 | client.send() # ASYNC212 +37 | client.stream() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.send() in async context, use httpx.AsyncClient + --> ASYNC212.py:36:5 + | +34 | client.put() # ASYNC212 +35 | client.request() # ASYNC212 +36 | client.send() # ASYNC212 + | ^^^^^^^^^^^ +37 | client.stream() # ASYNC212 + | + +ASYNC212 Blocking httpx method client.stream() in async context, use httpx.AsyncClient + --> ASYNC212.py:37:5 + | +35 | client.request() # ASYNC212 +36 | client.send() # ASYNC212 +37 | client.stream() # ASYNC212 + | ^^^^^^^^^^^^^ +38 | +39 | client.anything() # Ok + | + +ASYNC212 Blocking httpx method client.request() in async context, use httpx.AsyncClient + --> ASYNC212.py:45:5 + | +44 | async def foo(client: httpx.Client): +45 | client.request() # ASYNC212 + | ^^^^^^^^^^^^^^ +46 | client.anything() # Ok + | + +ASYNC212 Blocking httpx method client.request() in async context, use httpx.AsyncClient + --> ASYNC212.py:50:5 + | +49 | async def foo(client: httpx.Client | None): +50 | client.request() # ASYNC212 + | ^^^^^^^^^^^^^^ +51 | client.anything() # Ok + | + +ASYNC212 Blocking httpx method client.request() in async context, use httpx.AsyncClient + --> ASYNC212.py:55:5 + | +54 | async def foo(client: Optional[httpx.Client]): +55 | client.request() # ASYNC212 + | ^^^^^^^^^^^^^^ +56 | client.anything() # Ok + | + +ASYNC212 Blocking httpx method client.request() in async context, use httpx.AsyncClient + --> ASYNC212.py:61:5 + | +59 | async def foo(): +60 | client: httpx.Client = ... +61 | client.request() # ASYNC212 + | ^^^^^^^^^^^^^^ +62 | client.anything() # Ok + | + +ASYNC212 Blocking httpx method global_client.request() in async context, use httpx.AsyncClient + --> ASYNC212.py:69:5 + | +68 | async def foo(): +69 | global_client.request() # ASYNC212 + | ^^^^^^^^^^^^^^^^^^^^^ +70 | global_client.anything() # Ok + | diff --git a/ruff.schema.json b/ruff.schema.json index 0866fc0426bc9..1b4d6ac27fc4e 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -3013,6 +3013,7 @@ "ASYNC2", "ASYNC21", "ASYNC210", + "ASYNC212", "ASYNC22", "ASYNC220", "ASYNC221", From 18eaa659c1ea9a03bee798e161d2f2db454e154f Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 27 Aug 2025 17:53:57 -0700 Subject: [PATCH 155/160] [ty] Introduce a representation for the top/bottom materialization of an invariant generic (#20076) Part of #994. This adds a new field to the Specialization struct to record when we're dealing with the top or bottom materialization of an invariant generic. It also implements subtyping and assignability for these objects. Next planned steps after this is done are to implement other operations on top/bottom materializations; probably attribute access is an important one. --------- Co-authored-by: Carl Meyer --- .../mdtest/type_properties/materialization.md | 250 ++++++++++++++-- crates/ty_python_semantic/src/types.rs | 151 ++++++---- crates/ty_python_semantic/src/types/class.rs | 25 +- .../ty_python_semantic/src/types/display.rs | 17 +- .../ty_python_semantic/src/types/generics.rs | 270 ++++++++++++++++-- .../ty_python_semantic/src/types/instance.rs | 35 ++- .../src/types/protocol_class.rs | 25 +- .../src/types/signatures.rs | 25 +- .../src/types/subclass_of.rs | 45 +-- crates/ty_python_semantic/src/types/tuple.rs | 44 ++- 10 files changed, 696 insertions(+), 191 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md b/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md index 2190fd879645b..65eeea44a0684 100644 --- a/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md +++ b/crates/ty_python_semantic/resources/mdtest/type_properties/materialization.md @@ -47,7 +47,7 @@ The invariant position is replaced with an unresolved type variable. ```py def _(top_list: Top[list[Any]]): - reveal_type(top_list) # revealed: list[T_all] + reveal_type(top_list) # revealed: Top[list[Any]] ``` ### Bottom materialization @@ -75,7 +75,7 @@ type variable. ```py def _(bottom_list: Bottom[list[Any]]): - reveal_type(bottom_list) # revealed: list[T_all] + reveal_type(bottom_list) # revealed: Bottom[list[Any]] ``` ## Fully static types @@ -230,14 +230,14 @@ def _( top_aiu: Top[LTAnyIntUnknown], bottom_aiu: Bottom[LTAnyIntUnknown], ): - reveal_type(top_ai) # revealed: list[tuple[T_all, int]] - reveal_type(bottom_ai) # revealed: list[tuple[T_all, int]] + reveal_type(top_ai) # revealed: Top[list[tuple[Any, int]]] + reveal_type(bottom_ai) # revealed: Bottom[list[tuple[Any, int]]] - reveal_type(top_su) # revealed: list[tuple[str, T_all]] - reveal_type(bottom_su) # revealed: list[tuple[str, T_all]] + reveal_type(top_su) # revealed: Top[list[tuple[str, Unknown]]] + reveal_type(bottom_su) # revealed: Bottom[list[tuple[str, Unknown]]] - reveal_type(top_aiu) # revealed: list[tuple[T_all, int, T_all]] - reveal_type(bottom_aiu) # revealed: list[tuple[T_all, int, T_all]] + reveal_type(top_aiu) # revealed: Top[list[tuple[Any, int, Unknown]]] + reveal_type(bottom_aiu) # revealed: Bottom[list[tuple[Any, int, Unknown]]] ``` ## Union @@ -286,14 +286,14 @@ def _( top_aiu: Top[list[Any | int | Unknown]], bottom_aiu: Bottom[list[Any | int | Unknown]], ): - reveal_type(top_ai) # revealed: list[T_all | int] - reveal_type(bottom_ai) # revealed: list[T_all | int] + reveal_type(top_ai) # revealed: Top[list[Any | int]] + reveal_type(bottom_ai) # revealed: Bottom[list[Any | int]] - reveal_type(top_su) # revealed: list[str | T_all] - reveal_type(bottom_su) # revealed: list[str | T_all] + reveal_type(top_su) # revealed: Top[list[str | Unknown]] + reveal_type(bottom_su) # revealed: Bottom[list[str | Unknown]] - reveal_type(top_aiu) # revealed: list[T_all | int] - reveal_type(bottom_aiu) # revealed: list[T_all | int] + reveal_type(top_aiu) # revealed: Top[list[Any | int]] + reveal_type(bottom_aiu) # revealed: Bottom[list[Any | int]] ``` ## Intersection @@ -320,8 +320,10 @@ def _( top: Top[Intersection[list[Any], list[int]]], bottom: Bottom[Intersection[list[Any], list[int]]], ): - reveal_type(top) # revealed: list[T_all] & list[int] - reveal_type(bottom) # revealed: list[T_all] & list[int] + # Top[list[Any] & list[int]] = Top[list[Any]] & list[int] = list[int] + reveal_type(top) # revealed: list[int] + # Bottom[list[Any] & list[int]] = Bottom[list[Any]] & list[int] = Bottom[list[Any]] + reveal_type(bottom) # revealed: Bottom[list[Any]] ``` ## Negation (via `Not`) @@ -366,8 +368,8 @@ static_assert(is_equivalent_to(Bottom[type[int | Any]], type[int])) # Here, `T` has an upper bound of `type` def _(top: Top[list[type[Any]]], bottom: Bottom[list[type[Any]]]): - reveal_type(top) # revealed: list[T_all] - reveal_type(bottom) # revealed: list[T_all] + reveal_type(top) # revealed: Top[list[type[Any]]] + reveal_type(bottom) # revealed: Bottom[list[type[Any]]] ``` ## Type variables @@ -427,8 +429,8 @@ class GenericContravariant(Generic[T_contra]): pass def _(top: Top[GenericInvariant[Any]], bottom: Bottom[GenericInvariant[Any]]): - reveal_type(top) # revealed: GenericInvariant[T_all] - reveal_type(bottom) # revealed: GenericInvariant[T_all] + reveal_type(top) # revealed: Top[GenericInvariant[Any]] + reveal_type(bottom) # revealed: Bottom[GenericInvariant[Any]] static_assert(is_equivalent_to(Top[GenericCovariant[Any]], GenericCovariant[object])) static_assert(is_equivalent_to(Bottom[GenericCovariant[Any]], GenericCovariant[Never])) @@ -448,8 +450,8 @@ type CovariantCallable = Callable[[GenericCovariant[Any]], None] type ContravariantCallable = Callable[[GenericContravariant[Any]], None] def invariant(top: Top[InvariantCallable], bottom: Bottom[InvariantCallable]) -> None: - reveal_type(top) # revealed: (GenericInvariant[T_all], /) -> None - reveal_type(bottom) # revealed: (GenericInvariant[T_all], /) -> None + reveal_type(top) # revealed: (Bottom[GenericInvariant[Any]], /) -> None + reveal_type(bottom) # revealed: (Top[GenericInvariant[Any]], /) -> None def covariant(top: Top[CovariantCallable], bottom: Bottom[CovariantCallable]) -> None: reveal_type(top) # revealed: (GenericCovariant[Never], /) -> None @@ -492,3 +494,207 @@ def _( bottom_1: Bottom[1], # error: [invalid-type-form] ): ... ``` + +## Nested use + +`Top[T]` and `Bottom[T]` are always fully static types. Therefore, they have only one +materialization (themselves) and applying `Top` or `Bottom` again does nothing. + +```py +from typing import Any +from ty_extensions import Top, Bottom, static_assert, is_equivalent_to + +static_assert(is_equivalent_to(Top[Top[list[Any]]], Top[list[Any]])) +static_assert(is_equivalent_to(Bottom[Top[list[Any]]], Top[list[Any]])) + +static_assert(is_equivalent_to(Bottom[Bottom[list[Any]]], Bottom[list[Any]])) +static_assert(is_equivalent_to(Top[Bottom[list[Any]]], Bottom[list[Any]])) +``` + +## Subtyping + +Any `list[T]` is a subtype of `Top[list[Any]]`, but with more restrictive gradual types, not all +other specializations are subtypes. + +```py +from typing import Any, Literal +from ty_extensions import is_subtype_of, static_assert, Top, Intersection, Bottom + +# None and Top +static_assert(is_subtype_of(list[int], Top[list[Any]])) +static_assert(not is_subtype_of(Top[list[Any]], list[int])) +static_assert(is_subtype_of(list[bool], Top[list[Intersection[int, Any]]])) +static_assert(is_subtype_of(list[int], Top[list[Intersection[int, Any]]])) +static_assert(not is_subtype_of(list[int | str], Top[list[Intersection[int, Any]]])) +static_assert(not is_subtype_of(list[object], Top[list[Intersection[int, Any]]])) +static_assert(not is_subtype_of(list[str], Top[list[Intersection[int, Any]]])) +static_assert(not is_subtype_of(list[str | bool], Top[list[Intersection[int, Any]]])) + +# Top and Top +static_assert(is_subtype_of(Top[list[int | Any]], Top[list[Any]])) +static_assert(not is_subtype_of(Top[list[Any]], Top[list[int | Any]])) +static_assert(is_subtype_of(Top[list[Intersection[int, Any]]], Top[list[Any]])) +static_assert(not is_subtype_of(Top[list[Any]], Top[list[Intersection[int, Any]]])) +static_assert(not is_subtype_of(Top[list[Intersection[int, Any]]], Top[list[int | Any]])) +static_assert(not is_subtype_of(Top[list[int | Any]], Top[list[Intersection[int, Any]]])) +static_assert(not is_subtype_of(Top[list[str | Any]], Top[list[int | Any]])) +static_assert(is_subtype_of(Top[list[str | int | Any]], Top[list[int | Any]])) +static_assert(not is_subtype_of(Top[list[int | Any]], Top[list[str | int | Any]])) + +# Bottom and Top +static_assert(is_subtype_of(Bottom[list[Any]], Top[list[Any]])) +static_assert(is_subtype_of(Bottom[list[Any]], Top[list[int | Any]])) +static_assert(is_subtype_of(Bottom[list[int | Any]], Top[list[Any]])) +static_assert(is_subtype_of(Bottom[list[int | Any]], Top[list[int | str]])) +static_assert(is_subtype_of(Bottom[list[Intersection[int, Any]]], Top[list[Intersection[str, Any]]])) +static_assert(not is_subtype_of(Bottom[list[Intersection[int, bool | Any]]], Bottom[list[Intersection[str, Literal["x"] | Any]]])) + +# None and None +static_assert(not is_subtype_of(list[int], list[Any])) +static_assert(not is_subtype_of(list[Any], list[int])) +static_assert(is_subtype_of(list[int], list[int])) +static_assert(not is_subtype_of(list[int], list[object])) +static_assert(not is_subtype_of(list[object], list[int])) + +# Top and None +static_assert(not is_subtype_of(Top[list[Any]], list[Any])) +static_assert(not is_subtype_of(Top[list[Any]], list[int])) +static_assert(is_subtype_of(Top[list[int]], list[int])) + +# Bottom and None +static_assert(is_subtype_of(Bottom[list[Any]], list[object])) +static_assert(is_subtype_of(Bottom[list[int | Any]], list[str | int])) +static_assert(not is_subtype_of(Bottom[list[str | Any]], list[Intersection[int, bool | Any]])) + +# None and Bottom +static_assert(not is_subtype_of(list[int], Bottom[list[Any]])) +static_assert(not is_subtype_of(list[int], Bottom[list[int | Any]])) +static_assert(is_subtype_of(list[int], Bottom[list[int]])) + +# Top and Bottom +static_assert(not is_subtype_of(Top[list[Any]], Bottom[list[Any]])) +static_assert(not is_subtype_of(Top[list[int | Any]], Bottom[list[int | Any]])) +static_assert(is_subtype_of(Top[list[int]], Bottom[list[int]])) + +# Bottom and Bottom +static_assert(is_subtype_of(Bottom[list[Any]], Bottom[list[int | str | Any]])) +static_assert(is_subtype_of(Bottom[list[int | Any]], Bottom[list[int | str | Any]])) +static_assert(is_subtype_of(Bottom[list[bool | Any]], Bottom[list[int | Any]])) +static_assert(not is_subtype_of(Bottom[list[int | Any]], Bottom[list[bool | Any]])) +static_assert(not is_subtype_of(Bottom[list[int | Any]], Bottom[list[Any]])) +``` + +## Assignability + +### General + +Assignability is the same as subtyping for top and bottom materializations, because those are fully +static types, but some gradual types are assignable even if they are not subtypes. + +```py +from typing import Any, Literal +from ty_extensions import is_assignable_to, static_assert, Top, Intersection, Bottom + +# None and Top +static_assert(is_assignable_to(list[Any], Top[list[Any]])) +static_assert(is_assignable_to(list[int], Top[list[Any]])) +static_assert(not is_assignable_to(Top[list[Any]], list[int])) +static_assert(is_assignable_to(list[bool], Top[list[Intersection[int, Any]]])) +static_assert(is_assignable_to(list[int], Top[list[Intersection[int, Any]]])) +static_assert(is_assignable_to(list[Any], Top[list[Intersection[int, Any]]])) +static_assert(not is_assignable_to(list[int | str], Top[list[Intersection[int, Any]]])) +static_assert(not is_assignable_to(list[object], Top[list[Intersection[int, Any]]])) +static_assert(not is_assignable_to(list[str], Top[list[Intersection[int, Any]]])) +static_assert(not is_assignable_to(list[str | bool], Top[list[Intersection[int, Any]]])) + +# Top and Top +static_assert(is_assignable_to(Top[list[int | Any]], Top[list[Any]])) +static_assert(not is_assignable_to(Top[list[Any]], Top[list[int | Any]])) +static_assert(is_assignable_to(Top[list[Intersection[int, Any]]], Top[list[Any]])) +static_assert(not is_assignable_to(Top[list[Any]], Top[list[Intersection[int, Any]]])) +static_assert(not is_assignable_to(Top[list[Intersection[int, Any]]], Top[list[int | Any]])) +static_assert(not is_assignable_to(Top[list[int | Any]], Top[list[Intersection[int, Any]]])) +static_assert(not is_assignable_to(Top[list[str | Any]], Top[list[int | Any]])) +static_assert(is_assignable_to(Top[list[str | int | Any]], Top[list[int | Any]])) +static_assert(not is_assignable_to(Top[list[int | Any]], Top[list[str | int | Any]])) + +# Bottom and Top +static_assert(is_assignable_to(Bottom[list[Any]], Top[list[Any]])) +static_assert(is_assignable_to(Bottom[list[Any]], Top[list[int | Any]])) +static_assert(is_assignable_to(Bottom[list[int | Any]], Top[list[Any]])) +static_assert(is_assignable_to(Bottom[list[Intersection[int, Any]]], Top[list[Intersection[str, Any]]])) +static_assert( + not is_assignable_to(Bottom[list[Intersection[int, bool | Any]]], Bottom[list[Intersection[str, Literal["x"] | Any]]]) +) + +# None and None +static_assert(is_assignable_to(list[int], list[Any])) +static_assert(is_assignable_to(list[Any], list[int])) +static_assert(is_assignable_to(list[int], list[int])) +static_assert(not is_assignable_to(list[int], list[object])) +static_assert(not is_assignable_to(list[object], list[int])) + +# Top and None +static_assert(is_assignable_to(Top[list[Any]], list[Any])) +static_assert(not is_assignable_to(Top[list[Any]], list[int])) +static_assert(is_assignable_to(Top[list[int]], list[int])) + +# Bottom and None +static_assert(is_assignable_to(Bottom[list[Any]], list[object])) +static_assert(is_assignable_to(Bottom[list[int | Any]], Top[list[str | int]])) +static_assert(not is_assignable_to(Bottom[list[str | Any]], list[Intersection[int, bool | Any]])) + +# None and Bottom +static_assert(is_assignable_to(list[Any], Bottom[list[Any]])) +static_assert(not is_assignable_to(list[int], Bottom[list[Any]])) +static_assert(not is_assignable_to(list[int], Bottom[list[int | Any]])) +static_assert(is_assignable_to(list[int], Bottom[list[int]])) + +# Top and Bottom +static_assert(not is_assignable_to(Top[list[Any]], Bottom[list[Any]])) +static_assert(not is_assignable_to(Top[list[int | Any]], Bottom[list[int | Any]])) +static_assert(is_assignable_to(Top[list[int]], Bottom[list[int]])) + +# Bottom and Bottom +static_assert(is_assignable_to(Bottom[list[Any]], Bottom[list[int | str | Any]])) +static_assert(is_assignable_to(Bottom[list[int | Any]], Bottom[list[int | str | Any]])) +static_assert(is_assignable_to(Bottom[list[bool | Any]], Bottom[list[int | Any]])) +static_assert(not is_assignable_to(Bottom[list[int | Any]], Bottom[list[bool | Any]])) +static_assert(not is_assignable_to(Bottom[list[int | Any]], Bottom[list[Any]])) +``` + +### Subclasses with different variance + +We need to take special care when an invariant class inherits from a covariant or contravariant one. +This comes up frequently in practice because `list` (invariant) inherits from `Sequence` and a +number of other covariant ABCs, but we'll use a synthetic example. + +```py +from typing import Generic, TypeVar, Any +from ty_extensions import static_assert, is_assignable_to, is_equivalent_to, Top + +class A: + pass + +class B(A): + pass + +T_co = TypeVar("T_co", covariant=True) +T = TypeVar("T") + +class CovariantBase(Generic[T_co]): + def get(self) -> T_co: + raise NotImplementedError + +class InvariantChild(CovariantBase[T]): + def push(self, obj: T) -> None: ... + +static_assert(is_assignable_to(InvariantChild[A], CovariantBase[A])) +static_assert(is_assignable_to(InvariantChild[B], CovariantBase[A])) +static_assert(not is_assignable_to(InvariantChild[A], CovariantBase[B])) +static_assert(not is_assignable_to(InvariantChild[B], InvariantChild[A])) +static_assert(is_equivalent_to(Top[CovariantBase[Any]], CovariantBase[object])) +static_assert(is_assignable_to(InvariantChild[Any], CovariantBase[A])) + +static_assert(not is_assignable_to(Top[InvariantChild[Any]], CovariantBase[A])) +``` diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index 3217f0bf05f21..ec64c817dd65f 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -195,6 +195,34 @@ pub(crate) struct IsEquivalent; pub(crate) type NormalizedVisitor<'db> = TypeTransformer<'db, Normalized>; pub(crate) struct Normalized; +/// How a generic type has been specialized. +/// +/// This matters only if there is at least one invariant type parameter. +/// For example, we represent `Top[list[Any]]` as a `GenericAlias` with +/// `MaterializationKind` set to Top, which we denote as `Top[list[Any]]`. +/// A type `Top[list[T]]` includes all fully static list types `list[U]` where `U` is +/// a supertype of `Bottom[T]` and a subtype of `Top[T]`. +/// +/// Similarly, there is `Bottom[list[Any]]`. +/// This type is harder to make sense of in a set-theoretic framework, but +/// it is a subtype of all materializations of `list[Any]`. +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, get_size2::GetSize)] +pub enum MaterializationKind { + Top, + Bottom, +} + +impl MaterializationKind { + /// Flip the materialization type: `Top` becomes `Bottom` and vice versa. + #[must_use] + pub const fn flip(self) -> Self { + match self { + Self::Top => Self::Bottom, + Self::Bottom => Self::Top, + } + } +} + /// The descriptor protocol distinguishes two kinds of descriptors. Non-data descriptors /// define a `__get__` method, while data descriptors additionally define a `__set__` /// method or a `__delete__` method. This enum is used to categorize attributes into two @@ -489,11 +517,13 @@ impl<'db> PropertyInstanceType<'db> { } } - fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { Self::new( db, - self.getter(db).map(|ty| ty.materialize(db, variance)), - self.setter(db).map(|ty| ty.materialize(db, variance)), + self.getter(db) + .map(|ty| ty.materialize(db, materialization_kind)), + self.setter(db) + .map(|ty| ty.materialize(db, materialization_kind)), ) } } @@ -738,14 +768,14 @@ impl<'db> Type<'db> { /// most general form of the type that is fully static. #[must_use] pub(crate) fn top_materialization(&self, db: &'db dyn Db) -> Type<'db> { - self.materialize(db, TypeVarVariance::Covariant) + self.materialize(db, MaterializationKind::Top) } /// Returns the bottom materialization (or lower bound materialization) of this type, which is /// the most specific form of the type that is fully static. #[must_use] pub(crate) fn bottom_materialization(&self, db: &'db dyn Db) -> Type<'db> { - self.materialize(db, TypeVarVariance::Contravariant) + self.materialize(db, MaterializationKind::Bottom) } /// If this type is an instance type where the class has a tuple spec, returns the tuple spec. @@ -780,29 +810,11 @@ impl<'db> Type<'db> { /// - In covariant position, it's replaced with `object` /// - In contravariant position, it's replaced with `Never` /// - In invariant position, it's replaced with an unresolved type variable - fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Type<'db> { + fn materialize(&self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Type<'db> { match self { - Type::Dynamic(_) => match variance { - // TODO: For an invariant position, e.g. `list[Any]`, it should be replaced with an - // existential type representing "all lists, containing any type." We currently - // represent this by replacing `Any` in invariant position with an unresolved type - // variable. - TypeVarVariance::Invariant => Type::TypeVar(BoundTypeVarInstance::new( - db, - TypeVarInstance::new( - db, - Name::new_static("T_all"), - None, - None, - Some(variance), - None, - TypeVarKind::Pep695, - ), - BindingContext::Synthetic, - )), - TypeVarVariance::Covariant => Type::object(db), - TypeVarVariance::Contravariant => Type::Never, - TypeVarVariance::Bivariant => unreachable!(), + Type::Dynamic(_) => match materialization_kind { + MaterializationKind::Top => Type::object(db), + MaterializationKind::Bottom => Type::Never, }, Type::Never @@ -825,7 +837,7 @@ impl<'db> Type<'db> { | Type::BoundSuper(_) => *self, Type::PropertyInstance(property_instance) => { - Type::PropertyInstance(property_instance.materialize(db, variance)) + Type::PropertyInstance(property_instance.materialize(db, materialization_kind)) } Type::FunctionLiteral(_) | Type::BoundMethod(_) => { @@ -834,14 +846,16 @@ impl<'db> Type<'db> { *self } - Type::NominalInstance(instance) => instance.materialize(db, variance), + Type::NominalInstance(instance) => instance.materialize(db, materialization_kind), Type::GenericAlias(generic_alias) => { - Type::GenericAlias(generic_alias.materialize(db, variance)) + Type::GenericAlias(generic_alias.materialize(db, materialization_kind)) } Type::Callable(callable_type) => { - Type::Callable(callable_type.materialize(db, variance)) + Type::Callable(callable_type.materialize(db, materialization_kind)) + } + Type::SubclassOf(subclass_of_type) => { + subclass_of_type.materialize(db, materialization_kind) } - Type::SubclassOf(subclass_of_type) => subclass_of_type.materialize(db, variance), Type::ProtocolInstance(protocol_instance_type) => { // TODO: Add tests for this once subtyping/assignability is implemented for // protocols. It _might_ require changing the logic here because: @@ -850,35 +864,45 @@ impl<'db> Type<'db> { // > read-only property members, and method members, on protocols act covariantly; // > write-only property members act contravariantly; and read/write attribute // > members on protocols act invariantly - Type::ProtocolInstance(protocol_instance_type.materialize(db, variance)) + Type::ProtocolInstance(protocol_instance_type.materialize(db, materialization_kind)) + } + Type::Union(union_type) => { + union_type.map(db, |ty| ty.materialize(db, materialization_kind)) } - Type::Union(union_type) => union_type.map(db, |ty| ty.materialize(db, variance)), Type::Intersection(intersection_type) => IntersectionBuilder::new(db) .positive_elements( intersection_type .positive(db) .iter() - .map(|ty| ty.materialize(db, variance)), + .map(|ty| ty.materialize(db, materialization_kind)), ) .negative_elements( intersection_type .negative(db) .iter() - .map(|ty| ty.materialize(db, variance.flip())), + .map(|ty| ty.materialize(db, materialization_kind.flip())), ) .build(), - Type::TypeVar(bound_typevar) => Type::TypeVar(bound_typevar.materialize(db, variance)), + Type::TypeVar(bound_typevar) => { + Type::TypeVar(bound_typevar.materialize(db, materialization_kind)) + } Type::NonInferableTypeVar(bound_typevar) => { - Type::NonInferableTypeVar(bound_typevar.materialize(db, variance)) + Type::NonInferableTypeVar(bound_typevar.materialize(db, materialization_kind)) } Type::TypeIs(type_is) => { - type_is.with_type(db, type_is.return_type(db).materialize(db, variance)) + // TODO(jelle): this seems wrong, should be invariant? + type_is.with_type( + db, + type_is + .return_type(db) + .materialize(db, materialization_kind), + ) } Type::TypedDict(_) => { // TODO: Materialization of gradual TypedDicts *self } - Type::TypeAlias(alias) => alias.value_type(db).materialize(db, variance), + Type::TypeAlias(alias) => alias.value_type(db).materialize(db, materialization_kind), } } @@ -6637,6 +6661,13 @@ impl<'db> TypeMapping<'_, 'db> { } } } + + fn materialization_kind(&self, db: &'db dyn Db) -> Option { + match self { + TypeMapping::Specialization(specialization) => specialization.materialization_kind(db), + _ => None, + } + } } /// Singleton types that are heavily special-cased by ty. Despite its name, @@ -7321,29 +7352,35 @@ impl<'db> TypeVarInstance<'db> { ) } - fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { Self::new( db, self.name(db), self.definition(db), self._bound_or_constraints(db) .and_then(|bound_or_constraints| match bound_or_constraints { - TypeVarBoundOrConstraintsEvaluation::Eager(bound_or_constraints) => { - Some(bound_or_constraints.materialize(db, variance).into()) - } + TypeVarBoundOrConstraintsEvaluation::Eager(bound_or_constraints) => Some( + bound_or_constraints + .materialize(db, materialization_kind) + .into(), + ), TypeVarBoundOrConstraintsEvaluation::LazyUpperBound => self .lazy_bound(db) - .map(|bound| bound.materialize(db, variance).into()), - TypeVarBoundOrConstraintsEvaluation::LazyConstraints => self - .lazy_constraints(db) - .map(|constraints| constraints.materialize(db, variance).into()), + .map(|bound| bound.materialize(db, materialization_kind).into()), + TypeVarBoundOrConstraintsEvaluation::LazyConstraints => { + self.lazy_constraints(db).map(|constraints| { + constraints.materialize(db, materialization_kind).into() + }) + } }), self.explicit_variance(db), self._default(db).and_then(|default| match default { - TypeVarDefaultEvaluation::Eager(ty) => Some(ty.materialize(db, variance).into()), + TypeVarDefaultEvaluation::Eager(ty) => { + Some(ty.materialize(db, materialization_kind).into()) + } TypeVarDefaultEvaluation::Lazy => self .lazy_default(db) - .map(|ty| ty.materialize(db, variance).into()), + .map(|ty| ty.materialize(db, materialization_kind).into()), }), self.kind(db), ) @@ -7505,10 +7542,10 @@ impl<'db> BoundTypeVarInstance<'db> { ) } - fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { Self::new( db, - self.typevar(db).materialize(db, variance), + self.typevar(db).materialize(db, materialization_kind), self.binding_context(db), ) } @@ -7585,10 +7622,10 @@ impl<'db> TypeVarBoundOrConstraints<'db> { } } - fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { match self { TypeVarBoundOrConstraints::UpperBound(bound) => { - TypeVarBoundOrConstraints::UpperBound(bound.materialize(db, variance)) + TypeVarBoundOrConstraints::UpperBound(bound.materialize(db, materialization_kind)) } TypeVarBoundOrConstraints::Constraints(constraints) => { TypeVarBoundOrConstraints::Constraints(UnionType::new( @@ -7596,7 +7633,7 @@ impl<'db> TypeVarBoundOrConstraints<'db> { constraints .elements(db) .iter() - .map(|ty| ty.materialize(db, variance)) + .map(|ty| ty.materialize(db, materialization_kind)) .collect::>() .into_boxed_slice(), )) @@ -8838,10 +8875,10 @@ impl<'db> CallableType<'db> { )) } - fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { CallableType::new( db, - self.signatures(db).materialize(db, variance), + self.signatures(db).materialize(db, materialization_kind), self.is_function_like(db), ) } diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index a99a2af6ca874..3bf1f4e679bdf 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -31,10 +31,10 @@ use crate::types::typed_dict::typed_dict_params_from_class_def; use crate::types::{ ApplyTypeMappingVisitor, Binding, BoundSuperError, BoundSuperType, CallableType, DataclassParams, DeprecatedInstance, HasRelationToVisitor, IsEquivalentVisitor, - KnownInstanceType, ManualPEP695TypeAliasType, NormalizedVisitor, PropertyInstanceType, - StringLiteralType, TypeAliasType, TypeMapping, TypeRelation, TypeVarBoundOrConstraints, - TypeVarInstance, TypeVarKind, TypedDictParams, VarianceInferable, declaration_type, - infer_definition_types, todo_type, + KnownInstanceType, ManualPEP695TypeAliasType, MaterializationKind, NormalizedVisitor, + PropertyInstanceType, StringLiteralType, TypeAliasType, TypeMapping, TypeRelation, + TypeVarBoundOrConstraints, TypeVarInstance, TypeVarKind, TypedDictParams, VarianceInferable, + declaration_type, infer_definition_types, todo_type, }; use crate::{ Db, FxIndexMap, FxOrderSet, Program, @@ -272,11 +272,16 @@ impl<'db> GenericAlias<'db> { ) } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { Self::new( db, self.origin(db), - self.specialization(db).materialize(db, variance), + self.specialization(db) + .materialize(db, materialization_kind), ) } @@ -404,10 +409,14 @@ impl<'db> ClassType<'db> { } } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { match self { Self::NonGeneric(_) => self, - Self::Generic(generic) => Self::Generic(generic.materialize(db, variance)), + Self::Generic(generic) => Self::Generic(generic.materialize(db, materialization_kind)), } } diff --git a/crates/ty_python_semantic/src/types/display.rs b/crates/ty_python_semantic/src/types/display.rs index ef5741ff5f814..63c34478891d8 100644 --- a/crates/ty_python_semantic/src/types/display.rs +++ b/crates/ty_python_semantic/src/types/display.rs @@ -16,8 +16,8 @@ use crate::types::generics::{GenericContext, Specialization}; use crate::types::signatures::{CallableSignature, Parameter, Parameters, Signature}; use crate::types::tuple::TupleSpec; use crate::types::{ - CallableType, IntersectionType, KnownClass, MethodWrapperKind, Protocol, StringLiteralType, - SubclassOfInner, Type, UnionType, WrapperDescriptorKind, + CallableType, IntersectionType, KnownClass, MaterializationKind, MethodWrapperKind, Protocol, + StringLiteralType, SubclassOfInner, Type, UnionType, WrapperDescriptorKind, }; use ruff_db::parsed::parsed_module; @@ -614,14 +614,25 @@ impl Display for DisplayGenericAlias<'_> { if let Some(tuple) = self.specialization.tuple(self.db) { tuple.display_with(self.db, self.settings).fmt(f) } else { + let prefix = match self.specialization.materialization_kind(self.db) { + None => "", + Some(MaterializationKind::Top) => "Top[", + Some(MaterializationKind::Bottom) => "Bottom[", + }; + let suffix = match self.specialization.materialization_kind(self.db) { + None => "", + Some(_) => "]", + }; write!( f, - "{origin}{specialization}", + "{prefix}{origin}{specialization}{suffix}", + prefix = prefix, origin = self.origin.name(self.db), specialization = self.specialization.display_short( self.db, TupleSpecialization::from_class(self.db, self.origin) ), + suffix = suffix, ) } } diff --git a/crates/ty_python_semantic/src/types/generics.rs b/crates/ty_python_semantic/src/types/generics.rs index 2a686ef80a4f5..2752340eeadb8 100644 --- a/crates/ty_python_semantic/src/types/generics.rs +++ b/crates/ty_python_semantic/src/types/generics.rs @@ -16,9 +16,9 @@ use crate::types::signatures::{Parameter, Parameters, Signature}; use crate::types::tuple::{TupleSpec, TupleType, walk_tuple_type}; use crate::types::{ ApplyTypeMappingVisitor, BoundTypeVarInstance, HasRelationToVisitor, IsEquivalentVisitor, - KnownClass, KnownInstanceType, NormalizedVisitor, Type, TypeMapping, TypeRelation, - TypeVarBoundOrConstraints, TypeVarInstance, TypeVarVariance, UnionType, binding_type, - declaration_type, + KnownClass, KnownInstanceType, MaterializationKind, NormalizedVisitor, Type, TypeMapping, + TypeRelation, TypeVarBoundOrConstraints, TypeVarInstance, TypeVarVariance, UnionType, + binding_type, declaration_type, }; use crate::{Db, FxOrderSet}; @@ -244,6 +244,7 @@ impl<'db> GenericContext<'db> { db, self, partial.types(db), + None, Some(TupleType::homogeneous(db, Type::unknown())), ) } else { @@ -304,7 +305,7 @@ impl<'db> GenericContext<'db> { types: Box<[Type<'db>]>, ) -> Specialization<'db> { assert!(self.variables(db).len() == types.len()); - Specialization::new(db, self, types, None) + Specialization::new(db, self, types, None, None) } /// Creates a specialization of this generic context for the `tuple` class. @@ -314,7 +315,7 @@ impl<'db> GenericContext<'db> { element_type: Type<'db>, tuple: TupleType<'db>, ) -> Specialization<'db> { - Specialization::new(db, self, Box::from([element_type]), Some(tuple)) + Specialization::new(db, self, Box::from([element_type]), None, Some(tuple)) } /// Creates a specialization of this generic context. Panics if the length of `types` does not @@ -360,7 +361,7 @@ impl<'db> GenericContext<'db> { expanded[idx] = default; } - Specialization::new(db, self, expanded.into_boxed_slice(), None) + Specialization::new(db, self, expanded.into_boxed_slice(), None, None) } pub(crate) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { @@ -407,6 +408,14 @@ pub struct Specialization<'db> { pub(crate) generic_context: GenericContext<'db>, #[returns(deref)] pub(crate) types: Box<[Type<'db>]>, + /// The materialization kind of the specialization. For example, given an invariant + /// generic type `A`, `Top[A[Any]]` is a supertype of all materializations of `A[Any]`, + /// and is represented here with `Some(MaterializationKind::Top)`. Similarly, + /// `Bottom[A[Any]]` is a subtype of all materializations of `A[Any]`, and is represented + /// with `Some(MaterializationKind::Bottom)`. + /// The `materialization_kind` field may be non-`None` only if the specialization contains + /// dynamic types in invariant positions. + pub(crate) materialization_kind: Option, /// For specializations of `tuple`, we also store more detailed information about the tuple's /// elements, above what the class's (single) typevar can represent. @@ -430,6 +439,114 @@ pub(super) fn walk_specialization<'db, V: super::visitor::TypeVisitor<'db> + ?Si } } +fn is_subtype_in_invariant_position<'db, C: Constraints<'db>>( + db: &'db dyn Db, + derived_type: &Type<'db>, + derived_materialization: MaterializationKind, + base_type: &Type<'db>, + base_materialization: MaterializationKind, +) -> C { + let derived_top = derived_type.top_materialization(db); + let derived_bottom = derived_type.bottom_materialization(db); + let base_top = base_type.top_materialization(db); + let base_bottom = base_type.bottom_materialization(db); + match (derived_materialization, base_materialization) { + // `Derived` is a subtype of `Base` if the range of materializations covered by `Derived` + // is a subset of the range covered by `Base`. + (MaterializationKind::Top, MaterializationKind::Top) => C::from_bool( + db, + base_bottom.is_subtype_of(db, derived_bottom) + && derived_top.is_subtype_of(db, base_top), + ), + // One bottom is a subtype of another if it covers a strictly larger set of materializations. + (MaterializationKind::Bottom, MaterializationKind::Bottom) => C::from_bool( + db, + derived_bottom.is_subtype_of(db, base_bottom) + && base_top.is_subtype_of(db, derived_top), + ), + // The bottom materialization of `Derived` is a subtype of the top materialization + // of `Base` if there is some type that is both within the + // range of types covered by derived and within the range covered by base, because if such a type + // exists, it's a subtype of `Top[base]` and a supertype of `Bottom[derived]`. + (MaterializationKind::Bottom, MaterializationKind::Top) => C::from_bool( + db, + (base_bottom.is_subtype_of(db, derived_bottom) + && derived_bottom.is_subtype_of(db, base_top)) + || (base_bottom.is_subtype_of(db, derived_top) + && derived_top.is_subtype_of(db, base_top) + || (base_top.is_subtype_of(db, derived_top) + && derived_bottom.is_subtype_of(db, base_top))), + ), + // A top materialization is a subtype of a bottom materialization only if both original + // un-materialized types are the same fully static type. + (MaterializationKind::Top, MaterializationKind::Bottom) => C::from_bool( + db, + derived_top.is_subtype_of(db, base_bottom) + && base_top.is_subtype_of(db, derived_bottom), + ), + } +} + +/// Whether two types encountered in an invariant position +/// have a relation (subtyping or assignability), taking into account +/// that the two types may come from a top or bottom materialization. +fn has_relation_in_invariant_position<'db, C: Constraints<'db>>( + db: &'db dyn Db, + derived_type: &Type<'db>, + derived_materialization: Option, + base_type: &Type<'db>, + base_materialization: Option, + relation: TypeRelation, +) -> C { + match (derived_materialization, base_materialization, relation) { + // Top and bottom materializations are fully static types, so subtyping + // is the same as assignability. + (Some(derived_mat), Some(base_mat), _) => { + is_subtype_in_invariant_position(db, derived_type, derived_mat, base_type, base_mat) + } + // Subtyping between invariant type parameters without a top/bottom materialization involved + // is equivalence + (None, None, TypeRelation::Subtyping) => { + C::from_bool(db, derived_type.is_equivalent_to(db, *base_type)) + } + (None, None, TypeRelation::Assignability) => C::from_bool( + db, + derived_type.is_assignable_to(db, *base_type) + && base_type.is_assignable_to(db, *derived_type), + ), + // For gradual types, A <: B (subtyping) is defined as Top[A] <: Bottom[B] + (None, Some(base_mat), TypeRelation::Subtyping) => is_subtype_in_invariant_position( + db, + derived_type, + MaterializationKind::Top, + base_type, + base_mat, + ), + (Some(derived_mat), None, TypeRelation::Subtyping) => is_subtype_in_invariant_position( + db, + derived_type, + derived_mat, + base_type, + MaterializationKind::Bottom, + ), + // And A <~ B (assignability) is Bottom[A] <: Top[B] + (None, Some(base_mat), TypeRelation::Assignability) => is_subtype_in_invariant_position( + db, + derived_type, + MaterializationKind::Bottom, + base_type, + base_mat, + ), + (Some(derived_mat), None, TypeRelation::Assignability) => is_subtype_in_invariant_position( + db, + derived_type, + derived_mat, + base_type, + MaterializationKind::Top, + ), + } +} + impl<'db> Specialization<'db> { /// Returns the tuple spec for a specialization of the `tuple` class. pub(crate) fn tuple(self, db: &'db dyn Db) -> Option<&'db TupleSpec<'db>> { @@ -481,15 +598,61 @@ impl<'db> Specialization<'db> { type_mapping: &TypeMapping<'a, 'db>, visitor: &ApplyTypeMappingVisitor<'db>, ) -> Self { + // TODO it seems like this should be possible to do in a much simpler way in + // `Self::apply_specialization`; just apply the type mapping to create the new + // specialization, then materialize the new specialization appropriately, if the type + // mapping is a materialization. But this doesn't work; see discussion in + // https://github.com/astral-sh/ruff/pull/20076 + let applied_materialization_kind = type_mapping.materialization_kind(db); + let mut has_dynamic_invariant_typevar = false; let types: Box<[_]> = self - .types(db) - .iter() - .map(|ty| ty.apply_type_mapping_impl(db, type_mapping, visitor)) + .generic_context(db) + .variables(db) + .into_iter() + .zip(self.types(db)) + .map(|(bound_typevar, vartype)| { + let ty = vartype.apply_type_mapping_impl(db, type_mapping, visitor); + match (applied_materialization_kind, bound_typevar.variance(db)) { + (None, _) => ty, + (Some(_), TypeVarVariance::Bivariant) => + // With bivariance, all specializations are subtypes of each other, + // so any materialization is acceptable. + { + ty.materialize(db, MaterializationKind::Top) + } + (Some(materialization_kind), TypeVarVariance::Covariant) => { + ty.materialize(db, materialization_kind) + } + (Some(materialization_kind), TypeVarVariance::Contravariant) => { + ty.materialize(db, materialization_kind.flip()) + } + (Some(_), TypeVarVariance::Invariant) => { + let top_materialization = ty.materialize(db, MaterializationKind::Top); + if !ty.is_equivalent_to(db, top_materialization) { + has_dynamic_invariant_typevar = true; + } + ty + } + } + }) .collect(); + let tuple_inner = self .tuple_inner(db) .and_then(|tuple| tuple.apply_type_mapping_impl(db, type_mapping, visitor)); - Specialization::new(db, self.generic_context(db), types, tuple_inner) + let new_materialization_kind = if has_dynamic_invariant_typevar { + self.materialization_kind(db) + .or(applied_materialization_kind) + } else { + None + }; + Specialization::new( + db, + self.generic_context(db), + types, + new_materialization_kind, + tuple_inner, + ) } /// Applies an optional specialization to this specialization. @@ -527,7 +690,8 @@ impl<'db> Specialization<'db> { }) .collect(); // TODO: Combine the tuple specs too - Specialization::new(db, self.generic_context(db), types, None) + // TODO(jelle): specialization type? + Specialization::new(db, self.generic_context(db), types, None, None) } pub(crate) fn normalized_impl(self, db: &'db dyn Db, visitor: &NormalizedVisitor<'db>) -> Self { @@ -540,25 +704,68 @@ impl<'db> Specialization<'db> { .tuple_inner(db) .and_then(|tuple| tuple.normalized_impl(db, visitor)); let context = self.generic_context(db).normalized_impl(db, visitor); - Self::new(db, context, types, tuple_inner) + Self::new( + db, + context, + types, + self.materialization_kind(db), + tuple_inner, + ) } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { + // The top and bottom materializations are fully static types already, so materializing them + // further does nothing. + if self.materialization_kind(db).is_some() { + return self; + } + let mut has_dynamic_invariant_typevar = false; let types: Box<[_]> = self .generic_context(db) .variables(db) .into_iter() .zip(self.types(db)) .map(|(bound_typevar, vartype)| { - let variance = bound_typevar.variance_with_polarity(db, variance); - vartype.materialize(db, variance) + match bound_typevar.variance(db) { + TypeVarVariance::Bivariant => { + // With bivariance, all specializations are subtypes of each other, + // so any materialization is acceptable. + vartype.materialize(db, MaterializationKind::Top) + } + TypeVarVariance::Covariant => vartype.materialize(db, materialization_kind), + TypeVarVariance::Contravariant => { + vartype.materialize(db, materialization_kind.flip()) + } + TypeVarVariance::Invariant => { + let top_materialization = vartype.materialize(db, MaterializationKind::Top); + if !vartype.is_equivalent_to(db, top_materialization) { + has_dynamic_invariant_typevar = true; + } + *vartype + } + } }) .collect(); let tuple_inner = self.tuple_inner(db).and_then(|tuple| { // Tuples are immutable, so tuple element types are always in covariant position. - tuple.materialize(db, variance) + tuple.materialize(db, materialization_kind) }); - Specialization::new(db, self.generic_context(db), types, tuple_inner) + let new_materialization_kind = if has_dynamic_invariant_typevar { + Some(materialization_kind) + } else { + None + }; + Specialization::new( + db, + self.generic_context(db), + types, + new_materialization_kind, + tuple_inner, + ) } pub(crate) fn has_relation_to_impl>( @@ -578,12 +785,20 @@ impl<'db> Specialization<'db> { return self_tuple.has_relation_to_impl(db, other_tuple, relation, visitor); } + let self_materialization_kind = self.materialization_kind(db); + let other_materialization_kind = other.materialization_kind(db); + let mut result = C::always_satisfiable(db); for ((bound_typevar, self_type), other_type) in (generic_context.variables(db).into_iter()) .zip(self.types(db)) .zip(other.types(db)) { - if self_type.is_dynamic() || other_type.is_dynamic() { + // As an optimization, we can return early if either type is dynamic, unless + // we're dealing with a top or bottom materialization. + if other_materialization_kind.is_none() + && self_materialization_kind.is_none() + && (self_type.is_dynamic() || other_type.is_dynamic()) + { match relation { TypeRelation::Assignability => continue, TypeRelation::Subtyping => return C::unsatisfiable(db), @@ -597,14 +812,14 @@ impl<'db> Specialization<'db> { // - invariant: verify that self_type <: other_type AND other_type <: self_type // - bivariant: skip, can't make subtyping/assignability false let compatible = match bound_typevar.variance(db) { - TypeVarVariance::Invariant => match relation { - TypeRelation::Subtyping => self_type.when_equivalent_to(db, *other_type), - TypeRelation::Assignability => C::from_bool( - db, - self_type.is_assignable_to(db, *other_type) - && other_type.is_assignable_to(db, *self_type), - ), - }, + TypeVarVariance::Invariant => has_relation_in_invariant_position( + db, + self_type, + self_materialization_kind, + other_type, + other_materialization_kind, + relation, + ), TypeVarVariance::Covariant => { self_type.has_relation_to_impl(db, *other_type, relation, visitor) } @@ -627,6 +842,9 @@ impl<'db> Specialization<'db> { other: Specialization<'db>, visitor: &IsEquivalentVisitor<'db, C>, ) -> C { + if self.materialization_kind(db) != other.materialization_kind(db) { + return C::unsatisfiable(db); + } let generic_context = self.generic_context(db); if generic_context != other.generic_context(db) { return C::unsatisfiable(db); diff --git a/crates/ty_python_semantic/src/types/instance.rs b/crates/ty_python_semantic/src/types/instance.rs index fb6bff18fc3e3..825b767b55b2e 100644 --- a/crates/ty_python_semantic/src/types/instance.rs +++ b/crates/ty_python_semantic/src/types/instance.rs @@ -13,7 +13,8 @@ use crate::types::protocol_class::walk_protocol_interface; use crate::types::tuple::{TupleSpec, TupleType}; use crate::types::{ ApplyTypeMappingVisitor, ClassBase, HasRelationToVisitor, IsDisjointVisitor, - IsEquivalentVisitor, NormalizedVisitor, TypeMapping, TypeRelation, VarianceInferable, + IsEquivalentVisitor, MaterializationKind, NormalizedVisitor, TypeMapping, TypeRelation, + VarianceInferable, }; use crate::{Db, FxOrderSet}; @@ -259,11 +260,17 @@ impl<'db> NominalInstanceType<'db> { } } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Type<'db> { + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Type<'db> { match self.0 { - NominalInstanceInner::ExactTuple(tuple) => Type::tuple(tuple.materialize(db, variance)), + NominalInstanceInner::ExactTuple(tuple) => { + Type::tuple(tuple.materialize(db, materialization_kind)) + } NominalInstanceInner::NonTuple(class) => { - Type::non_tuple_instance(class.materialize(db, variance)) + Type::non_tuple_instance(class.materialize(db, materialization_kind)) } } } @@ -577,12 +584,16 @@ impl<'db> ProtocolInstanceType<'db> { } } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { match self.inner { // TODO: This should also materialize via `class.materialize(db, variance)` Protocol::FromClass(class) => Self::from_class(class), Protocol::Synthesized(synthesized) => { - Self::synthesized(synthesized.materialize(db, variance)) + Self::synthesized(synthesized.materialize(db, materialization_kind)) } } } @@ -668,8 +679,8 @@ mod synthesized_protocol { use crate::semantic_index::definition::Definition; use crate::types::protocol_class::ProtocolInterface; use crate::types::{ - ApplyTypeMappingVisitor, BoundTypeVarInstance, NormalizedVisitor, TypeMapping, - TypeVarVariance, VarianceInferable, + ApplyTypeMappingVisitor, BoundTypeVarInstance, MaterializationKind, NormalizedVisitor, + TypeMapping, TypeVarVariance, VarianceInferable, }; use crate::{Db, FxOrderSet}; @@ -696,8 +707,12 @@ mod synthesized_protocol { Self(interface.normalized_impl(db, visitor)) } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { - Self(self.0.materialize(db, variance)) + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { + Self(self.0.materialize(db, materialization_kind)) } pub(super) fn apply_type_mapping_impl<'a>( diff --git a/crates/ty_python_semantic/src/types/protocol_class.rs b/crates/ty_python_semantic/src/types/protocol_class.rs index ec1e394167114..21c189e5c98a3 100644 --- a/crates/ty_python_semantic/src/types/protocol_class.rs +++ b/crates/ty_python_semantic/src/types/protocol_class.rs @@ -18,8 +18,9 @@ use crate::{ semantic_index::{definition::Definition, use_def_map}, types::{ BoundTypeVarInstance, CallableType, ClassBase, ClassLiteral, HasRelationToVisitor, - IsDisjointVisitor, KnownFunction, NormalizedVisitor, PropertyInstanceType, Signature, Type, - TypeMapping, TypeQualifiers, TypeRelation, VarianceInferable, + IsDisjointVisitor, KnownFunction, MaterializationKind, NormalizedVisitor, + PropertyInstanceType, Signature, Type, TypeMapping, TypeQualifiers, TypeRelation, + VarianceInferable, constraints::{Constraints, IteratorConstraintsExtension}, signatures::{Parameter, Parameters}, }, @@ -255,12 +256,16 @@ impl<'db> ProtocolInterface<'db> { ) } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { Self::new( db, self.inner(db) .iter() - .map(|(name, data)| (name.clone(), data.materialize(db, variance))) + .map(|(name, data)| (name.clone(), data.materialize(db, materialization_kind))) .collect::>(), ) } @@ -365,9 +370,9 @@ impl<'db> ProtocolMemberData<'db> { .find_legacy_typevars(db, binding_context, typevars); } - fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(&self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { Self { - kind: self.kind.materialize(db, variance), + kind: self.kind.materialize(db, materialization_kind), qualifiers: self.qualifiers, } } @@ -470,16 +475,16 @@ impl<'db> ProtocolMemberKind<'db> { } } - fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { match self { ProtocolMemberKind::Method(callable) => { - ProtocolMemberKind::Method(callable.materialize(db, variance)) + ProtocolMemberKind::Method(callable.materialize(db, materialization_kind)) } ProtocolMemberKind::Property(property) => { - ProtocolMemberKind::Property(property.materialize(db, variance)) + ProtocolMemberKind::Property(property.materialize(db, materialization_kind)) } ProtocolMemberKind::Other(ty) => { - ProtocolMemberKind::Other(ty.materialize(db, variance)) + ProtocolMemberKind::Other(ty.materialize(db, materialization_kind)) } } } diff --git a/crates/ty_python_semantic/src/types/signatures.rs b/crates/ty_python_semantic/src/types/signatures.rs index 061c9b513d76e..abec350323fde 100644 --- a/crates/ty_python_semantic/src/types/signatures.rs +++ b/crates/ty_python_semantic/src/types/signatures.rs @@ -21,7 +21,8 @@ use crate::types::constraints::{Constraints, IteratorConstraintsExtension}; use crate::types::generics::{GenericContext, walk_generic_context}; use crate::types::{ BindingContext, BoundTypeVarInstance, HasRelationToVisitor, IsEquivalentVisitor, KnownClass, - NormalizedVisitor, TypeMapping, TypeRelation, VarianceInferable, todo_type, + MaterializationKind, NormalizedVisitor, TypeMapping, TypeRelation, VarianceInferable, + todo_type, }; use crate::{Db, FxOrderSet}; use ruff_python_ast::{self as ast, name::Name}; @@ -57,11 +58,15 @@ impl<'db> CallableSignature<'db> { self.overloads.iter() } - pub(super) fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + pub(super) fn materialize( + &self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { Self::from_overloads( self.overloads .iter() - .map(|signature| signature.materialize(db, variance)), + .map(|signature| signature.materialize(db, materialization_kind)), ) } @@ -405,17 +410,17 @@ impl<'db> Signature<'db> { self } - fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(&self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { Self { generic_context: self.generic_context, inherited_generic_context: self.inherited_generic_context, definition: self.definition, // Parameters are at contravariant position, so the variance is flipped. - parameters: self.parameters.materialize(db, variance.flip()), + parameters: self.parameters.materialize(db, materialization_kind.flip()), return_ty: Some( self.return_ty .unwrap_or(Type::unknown()) - .materialize(db, variance), + .materialize(db, materialization_kind), ), } } @@ -1063,13 +1068,13 @@ impl<'db> Parameters<'db> { } } - fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(&self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { if self.is_gradual { Parameters::object(db) } else { Parameters::new( self.iter() - .map(|parameter| parameter.materialize(db, variance)), + .map(|parameter| parameter.materialize(db, materialization_kind)), ) } } @@ -1395,12 +1400,12 @@ impl<'db> Parameter<'db> { self } - fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + fn materialize(&self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { Self { annotated_type: Some( self.annotated_type .unwrap_or(Type::unknown()) - .materialize(db, variance), + .materialize(db, materialization_kind), ), kind: self.kind.clone(), form: self.form, diff --git a/crates/ty_python_semantic/src/types/subclass_of.rs b/crates/ty_python_semantic/src/types/subclass_of.rs index 63c7c13d51979..6a49aa130c4c4 100644 --- a/crates/ty_python_semantic/src/types/subclass_of.rs +++ b/crates/ty_python_semantic/src/types/subclass_of.rs @@ -1,17 +1,15 @@ -use ruff_python_ast::name::Name; - use crate::place::PlaceAndQualifiers; use crate::semantic_index::definition::Definition; use crate::types::constraints::Constraints; use crate::types::variance::VarianceInferable; use crate::types::{ - ApplyTypeMappingVisitor, BindingContext, BoundTypeVarInstance, ClassType, DynamicType, - HasRelationToVisitor, IsDisjointVisitor, KnownClass, MemberLookupPolicy, NormalizedVisitor, - SpecialFormType, Type, TypeMapping, TypeRelation, TypeVarInstance, + ApplyTypeMappingVisitor, BoundTypeVarInstance, ClassType, DynamicType, HasRelationToVisitor, + IsDisjointVisitor, KnownClass, MaterializationKind, MemberLookupPolicy, NormalizedVisitor, + SpecialFormType, Type, TypeMapping, TypeRelation, }; use crate::{Db, FxOrderSet}; -use super::{TypeVarBoundOrConstraints, TypeVarKind, TypeVarVariance}; +use super::TypeVarVariance; /// A type that represents `type[C]`, i.e. the class object `C` and class objects that are subclasses of `C`. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, salsa::Update, get_size2::GetSize)] @@ -81,34 +79,15 @@ impl<'db> SubclassOfType<'db> { subclass_of.is_dynamic() } - pub(super) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Type<'db> { + pub(super) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Type<'db> { match self.subclass_of { - SubclassOfInner::Dynamic(_) => match variance { - TypeVarVariance::Covariant => KnownClass::Type.to_instance(db), - TypeVarVariance::Contravariant => Type::Never, - TypeVarVariance::Invariant => { - // We need to materialize this to `type[T]` but that isn't representable so - // we instead use a type variable with an upper bound of `type`. - Type::NonInferableTypeVar(BoundTypeVarInstance::new( - db, - TypeVarInstance::new( - db, - Name::new_static("T_all"), - None, - Some( - TypeVarBoundOrConstraints::UpperBound( - KnownClass::Type.to_instance(db), - ) - .into(), - ), - Some(variance), - None, - TypeVarKind::Pep695, - ), - BindingContext::Synthetic, - )) - } - TypeVarVariance::Bivariant => unreachable!(), + SubclassOfInner::Dynamic(_) => match materialization_kind { + MaterializationKind::Top => KnownClass::Type.to_instance(db), + MaterializationKind::Bottom => Type::Never, }, SubclassOfInner::Class(_) => Type::SubclassOf(self), } diff --git a/crates/ty_python_semantic/src/types/tuple.rs b/crates/ty_python_semantic/src/types/tuple.rs index 35de11013de42..cc48fab9dbc28 100644 --- a/crates/ty_python_semantic/src/types/tuple.rs +++ b/crates/ty_python_semantic/src/types/tuple.rs @@ -27,7 +27,7 @@ use crate::types::class::{ClassType, KnownClass}; use crate::types::constraints::{Constraints, IteratorConstraintsExtension}; use crate::types::{ ApplyTypeMappingVisitor, BoundTypeVarInstance, HasRelationToVisitor, IsDisjointVisitor, - IsEquivalentVisitor, NormalizedVisitor, Type, TypeMapping, TypeRelation, TypeVarVariance, + IsEquivalentVisitor, MaterializationKind, NormalizedVisitor, Type, TypeMapping, TypeRelation, UnionBuilder, UnionType, }; use crate::util::subscript::{Nth, OutOfBoundsError, PyIndex, PySlice, StepSizeZeroError}; @@ -228,8 +228,12 @@ impl<'db> TupleType<'db> { TupleType::new(db, &self.tuple(db).normalized_impl(db, visitor)) } - pub(crate) fn materialize(self, db: &'db dyn Db, variance: TypeVarVariance) -> Option { - TupleType::new(db, &self.tuple(db).materialize(db, variance)) + pub(crate) fn materialize( + self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Option { + TupleType::new(db, &self.tuple(db).materialize(db, materialization_kind)) } pub(crate) fn apply_type_mapping_impl<'a>( @@ -389,8 +393,12 @@ impl<'db> FixedLengthTuple> { Self::from_elements(self.0.iter().map(|ty| ty.normalized_impl(db, visitor))) } - fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { - Self::from_elements(self.0.iter().map(|ty| ty.materialize(db, variance))) + fn materialize(&self, db: &'db dyn Db, materialization_kind: MaterializationKind) -> Self { + Self::from_elements( + self.0 + .iter() + .map(|ty| ty.materialize(db, materialization_kind)), + ) } fn apply_type_mapping_impl<'a>( @@ -703,11 +711,19 @@ impl<'db> VariableLengthTuple> { }) } - fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> TupleSpec<'db> { + fn materialize( + &self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> TupleSpec<'db> { Self::mixed( - self.prefix.iter().map(|ty| ty.materialize(db, variance)), - self.variable.materialize(db, variance), - self.suffix.iter().map(|ty| ty.materialize(db, variance)), + self.prefix + .iter() + .map(|ty| ty.materialize(db, materialization_kind)), + self.variable.materialize(db, materialization_kind), + self.suffix + .iter() + .map(|ty| ty.materialize(db, materialization_kind)), ) } @@ -1058,10 +1074,14 @@ impl<'db> Tuple> { } } - pub(crate) fn materialize(&self, db: &'db dyn Db, variance: TypeVarVariance) -> Self { + pub(crate) fn materialize( + &self, + db: &'db dyn Db, + materialization_kind: MaterializationKind, + ) -> Self { match self { - Tuple::Fixed(tuple) => Tuple::Fixed(tuple.materialize(db, variance)), - Tuple::Variable(tuple) => tuple.materialize(db, variance), + Tuple::Fixed(tuple) => Tuple::Fixed(tuple.materialize(db, materialization_kind)), + Tuple::Variable(tuple) => tuple.materialize(db, materialization_kind), } } From d9aaacd01f9da1219013c5413a94db7d487298d7 Mon Sep 17 00:00:00 2001 From: Shaygan Hooshyari Date: Thu, 28 Aug 2025 14:34:49 +0200 Subject: [PATCH 156/160] [ty] Evaluate reachability of non-definitely-bound to Ambiguous (#19579) ## Summary closes https://github.com/astral-sh/ty/issues/692 If the expression (or any child expressions) is not definitely bound the reachability constraint evaluation is determined as ambiguous. This fixes the infinite cycles panic in the following code: ```py from typing import Literal class Toggle: def __init__(self: "Toggle"): if not self.x: self.x: Literal[True] = True ``` Credit of this solution is for David. ## Test Plan - Added a test case with too many cycle iterations panic. - Previous tests. --------- Co-authored-by: David Peter --- .../resources/mdtest/attributes.md | 20 ++++ .../mdtest/statically_known_branches.md | 18 ++++ crates/ty_python_semantic/src/place.rs | 4 + .../reachability_constraints.rs | 4 +- .../src/semantic_index/use_def.rs | 4 +- crates/ty_python_semantic/src/types.rs | 8 +- crates/ty_python_semantic/src/types/class.rs | 25 +++-- crates/ty_python_semantic/src/types/infer.rs | 97 ++++++++++++++++--- 8 files changed, 153 insertions(+), 27 deletions(-) diff --git a/crates/ty_python_semantic/resources/mdtest/attributes.md b/crates/ty_python_semantic/resources/mdtest/attributes.md index 2afe8617ac4e5..929b076e91998 100644 --- a/crates/ty_python_semantic/resources/mdtest/attributes.md +++ b/crates/ty_python_semantic/resources/mdtest/attributes.md @@ -2288,6 +2288,26 @@ class H: self.x = other.x or self.x ``` +An attribute definition can be guarded by a condition involving that attribute. This is a regression +test for : + +```py +from typing import Literal + +def check(x) -> Literal[False]: + return False + +class Toggle: + def __init__(self: "Toggle"): + if not self.x: + self.x: Literal[True] = True + if check(self.y): + self.y = True + +reveal_type(Toggle().x) # revealed: Literal[True] +reveal_type(Toggle().y) # revealed: Unknown | Literal[True] +``` + ### Builtin types attributes This test can probably be removed eventually, but we currently include it because we do not yet diff --git a/crates/ty_python_semantic/resources/mdtest/statically_known_branches.md b/crates/ty_python_semantic/resources/mdtest/statically_known_branches.md index f6d65447cf1d3..3416d124e3871 100644 --- a/crates/ty_python_semantic/resources/mdtest/statically_known_branches.md +++ b/crates/ty_python_semantic/resources/mdtest/statically_known_branches.md @@ -1564,6 +1564,24 @@ if True: from module import symbol ``` +## Non-definitely bound symbols in conditions + +When a non-definitely bound symbol is used as a (part of a) condition, we always infer an ambiguous +truthiness. If we didn't do that, `x` would be considered definitely bound in the following example: + +```py +def _(flag: bool): + if flag: + ALWAYS_TRUE_IF_BOUND = True + + # error: [possibly-unresolved-reference] "Name `ALWAYS_TRUE_IF_BOUND` used when possibly not defined" + if True and ALWAYS_TRUE_IF_BOUND: + x = 1 + + # error: [possibly-unresolved-reference] "Name `x` used when possibly not defined" + x +``` + ## Unreachable code A closely related feature is the ability to detect unreachable code. For example, we do not emit a diff --git a/crates/ty_python_semantic/src/place.rs b/crates/ty_python_semantic/src/place.rs index b55129513ab54..764fdc1a5d243 100644 --- a/crates/ty_python_semantic/src/place.rs +++ b/crates/ty_python_semantic/src/place.rs @@ -135,6 +135,10 @@ impl<'db> Place<'db> { Place::Unbound => Place::Unbound, } } + + pub(crate) const fn is_definitely_bound(&self) -> bool { + matches!(self, Place::Type(_, Boundness::Bound)) + } } impl<'db> From> for PlaceAndQualifiers<'db> { diff --git a/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs b/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs index 37f8539d93eca..01a0a09513068 100644 --- a/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs +++ b/crates/ty_python_semantic/src/semantic_index/reachability_constraints.rs @@ -209,6 +209,7 @@ use crate::semantic_index::predicate::{ }; use crate::types::{ IntersectionBuilder, Truthiness, Type, UnionBuilder, UnionType, infer_expression_type, + static_expression_truthiness, }; /// A ternary formula that defines under what conditions a binding is visible. (A ternary formula @@ -821,8 +822,7 @@ impl ReachabilityConstraints { fn analyze_single(db: &dyn Db, predicate: &Predicate) -> Truthiness { match predicate.node { PredicateNode::Expression(test_expr) => { - let ty = infer_expression_type(db, test_expr); - ty.bool(db).negate_if(!predicate.is_positive) + static_expression_truthiness(db, test_expr).negate_if(!predicate.is_positive) } PredicateNode::ReturnsNever(CallableAndCallExpr { callable, diff --git a/crates/ty_python_semantic/src/semantic_index/use_def.rs b/crates/ty_python_semantic/src/semantic_index/use_def.rs index 136287a5c131d..c1440a6c79b4d 100644 --- a/crates/ty_python_semantic/src/semantic_index/use_def.rs +++ b/crates/ty_python_semantic/src/semantic_index/use_def.rs @@ -598,7 +598,7 @@ impl<'db> UseDefMap<'db> { .is_always_false() } - pub(crate) fn is_declaration_reachable( + pub(crate) fn declaration_reachability( &self, db: &dyn crate::Db, declaration: &DeclarationWithConstraint<'db>, @@ -610,7 +610,7 @@ impl<'db> UseDefMap<'db> { ) } - pub(crate) fn is_binding_reachable( + pub(crate) fn binding_reachability( &self, db: &dyn crate::Db, binding: &BindingWithConstraints<'_, 'db>, diff --git a/crates/ty_python_semantic/src/types.rs b/crates/ty_python_semantic/src/types.rs index ec64c817dd65f..ca0e7c786f551 100644 --- a/crates/ty_python_semantic/src/types.rs +++ b/crates/ty_python_semantic/src/types.rs @@ -24,7 +24,7 @@ pub use self::diagnostic::TypeCheckDiagnostics; pub(crate) use self::diagnostic::register_lints; pub(crate) use self::infer::{ infer_deferred_types, infer_definition_types, infer_expression_type, infer_expression_types, - infer_scope_types, + infer_scope_types, static_expression_truthiness, }; pub(crate) use self::signatures::{CallableSignature, Signature}; pub(crate) use self::subclass_of::{SubclassOfInner, SubclassOfType}; @@ -6910,6 +6910,10 @@ bitflags! { const NOT_REQUIRED = 1 << 4; /// `typing_extensions.ReadOnly` const READ_ONLY = 1 << 5; + /// An implicit instance attribute which is possibly unbound according + /// to local control flow within the method it is defined in. This flag + /// overrules the `Boundness` information on `PlaceAndQualifiers`. + const POSSIBLY_UNBOUND_IMPLICIT_ATTRIBUTE = 1 << 6; } } @@ -8620,7 +8624,7 @@ impl TypeRelation { } } -#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, get_size2::GetSize)] pub enum Truthiness { /// For an object `x`, `bool(x)` will always return `True` AlwaysTrue, diff --git a/crates/ty_python_semantic/src/types/class.rs b/crates/ty_python_semantic/src/types/class.rs index 3bf1f4e679bdf..cc79b7ab70456 100644 --- a/crates/ty_python_semantic/src/types/class.rs +++ b/crates/ty_python_semantic/src/types/class.rs @@ -2736,17 +2736,20 @@ impl<'db> ClassLiteral<'db> { // self.name: // self.name: = … - if use_def_map(db, method_scope) - .is_declaration_reachable(db, &attribute_declaration) - .is_always_false() - { + let reachability = use_def_map(db, method_scope) + .declaration_reachability(db, &attribute_declaration); + + if reachability.is_always_false() { continue; } let annotation = declaration_type(db, declaration); - let annotation = + let mut annotation = Place::bound(annotation.inner).with_qualifiers(annotation.qualifiers); + if reachability.is_ambiguous() { + annotation.qualifiers |= TypeQualifiers::POSSIBLY_UNBOUND_IMPLICIT_ATTRIBUTE; + } if let Some(all_qualifiers) = annotation.is_bare_final() { if let Some(value) = assignment.value(&module) { // If we see an annotated assignment with a bare `Final` as in @@ -2789,7 +2792,7 @@ impl<'db> ClassLiteral<'db> { .all_reachable_symbol_bindings(method_place) .find_map(|bind| { (bind.binding.is_defined_and(|def| def == method)) - .then(|| class_map.is_binding_reachable(db, &bind)) + .then(|| class_map.binding_reachability(db, &bind)) }) .unwrap_or(Truthiness::AlwaysFalse) } else { @@ -2818,11 +2821,15 @@ impl<'db> ClassLiteral<'db> { continue; }; match method_map - .is_binding_reachable(db, &attribute_assignment) + .binding_reachability(db, &attribute_assignment) .and(is_method_reachable) { - Truthiness::AlwaysTrue | Truthiness::Ambiguous => { + Truthiness::AlwaysTrue => { + is_attribute_bound = true; + } + Truthiness::Ambiguous => { is_attribute_bound = true; + qualifiers |= TypeQualifiers::POSSIBLY_UNBOUND_IMPLICIT_ATTRIBUTE; } Truthiness::AlwaysFalse => { continue; @@ -2834,7 +2841,7 @@ impl<'db> ClassLiteral<'db> { // TODO: this is incomplete logic since the attributes bound after termination are considered reachable. let unbound_reachability = unbound_binding .as_ref() - .map(|binding| method_map.is_binding_reachable(db, binding)) + .map(|binding| method_map.binding_reachability(db, binding)) .unwrap_or(Truthiness::AlwaysFalse); if unbound_reachability diff --git a/crates/ty_python_semantic/src/types/infer.rs b/crates/ty_python_semantic/src/types/infer.rs index 67fb854f17816..e644c47e6408e 100644 --- a/crates/ty_python_semantic/src/types/infer.rs +++ b/crates/ty_python_semantic/src/types/infer.rs @@ -337,6 +337,45 @@ fn single_expression_cycle_initial<'db>( Type::Never } +/// Returns the statically-known truthiness of a given expression. +/// +/// Returns [`Truthiness::Ambiguous`] in case any non-definitely bound places +/// were encountered while inferring the type of the expression. +#[salsa::tracked(cycle_fn=static_expression_truthiness_cycle_recover, cycle_initial=static_expression_truthiness_cycle_initial, heap_size=get_size2::GetSize::get_heap_size)] +pub(crate) fn static_expression_truthiness<'db>( + db: &'db dyn Db, + expression: Expression<'db>, +) -> Truthiness { + let inference = infer_expression_types(db, expression); + + if !inference.all_places_definitely_bound() { + return Truthiness::Ambiguous; + } + + let file = expression.file(db); + let module = parsed_module(db, file).load(db); + let node = expression.node_ref(db, &module); + + inference.expression_type(node).bool(db) +} + +#[expect(clippy::trivially_copy_pass_by_ref)] +fn static_expression_truthiness_cycle_recover<'db>( + _db: &'db dyn Db, + _value: &Truthiness, + _count: u32, + _expression: Expression<'db>, +) -> salsa::CycleRecoveryAction { + salsa::CycleRecoveryAction::Iterate +} + +fn static_expression_truthiness_cycle_initial<'db>( + _db: &'db dyn Db, + _expression: Expression<'db>, +) -> Truthiness { + Truthiness::Ambiguous +} + /// Infer the types for an [`Unpack`] operation. /// /// This infers the expression type and performs structural match against the target expression @@ -657,6 +696,9 @@ struct ExpressionInferenceExtra<'db> { /// /// Falls back to `Type::Never` if an expression is missing. cycle_fallback: bool, + + /// `true` if all places in this expression are definitely bound + all_definitely_bound: bool, } impl<'db> ExpressionInference<'db> { @@ -665,6 +707,7 @@ impl<'db> ExpressionInference<'db> { Self { extra: Some(Box::new(ExpressionInferenceExtra { cycle_fallback: true, + all_definitely_bound: true, ..ExpressionInferenceExtra::default() })), expressions: FxHashMap::default(), @@ -698,6 +741,14 @@ impl<'db> ExpressionInference<'db> { fn fallback_type(&self) -> Option> { self.is_cycle_callback().then_some(Type::Never) } + + /// Returns true if all places in this expression are definitely bound. + pub(crate) fn all_places_definitely_bound(&self) -> bool { + self.extra + .as_ref() + .map(|e| e.all_definitely_bound) + .unwrap_or(true) + } } /// Whether the intersection type is on the left or right side of the comparison. @@ -847,6 +898,9 @@ pub(super) struct TypeInferenceBuilder<'db, 'ast> { /// /// This is used only when constructing a cycle-recovery `TypeInference`. cycle_fallback: bool, + + /// `true` if all places in this expression are definitely bound + all_definitely_bound: bool, } impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { @@ -880,6 +934,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { deferred: VecSet::default(), undecorated_type: None, cycle_fallback: false, + all_definitely_bound: true, } } @@ -6614,7 +6669,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { let (resolved, constraint_keys) = self.infer_place_load(PlaceExprRef::from(&expr), ast::ExprRef::Name(name_node)); - resolved + let resolved_after_fallback = resolved // Not found in the module's explicitly declared global symbols? // Check the "implicit globals" such as `__doc__`, `__file__`, `__name__`, etc. // These are looked up as attributes on `types.ModuleType`. @@ -6650,8 +6705,14 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } else { Place::Unbound.into() } - }) - .unwrap_with_diagnostic(|lookup_error| match lookup_error { + }); + + if !resolved_after_fallback.place.is_definitely_bound() { + self.all_definitely_bound = false; + } + + let ty = + resolved_after_fallback.unwrap_with_diagnostic(|lookup_error| match lookup_error { LookupError::Unbound(qualifiers) => { self.report_unresolved_reference(name_node); TypeAndQualifiers::new(Type::unknown(), qualifiers) @@ -6662,8 +6723,9 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } type_when_bound } - }) - .inner_type() + }); + + ty.inner_type() } fn infer_local_place_load( @@ -7093,7 +7155,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { } fn narrow_expr_with_applicable_constraints<'r>( - &self, + &mut self, target: impl Into>, target_ty: Type<'db>, constraint_keys: &[(FileScopeId, ConstraintKey)], @@ -7136,11 +7198,19 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { assigned_type = Some(ty); } } + let fallback_place = value_type.member(db, &attr.id); + if !fallback_place.place.is_definitely_bound() + || fallback_place + .qualifiers + .contains(TypeQualifiers::POSSIBLY_UNBOUND_IMPLICIT_ATTRIBUTE) + { + self.all_definitely_bound = false; + } - let resolved_type = value_type - .member(db, &attr.id) - .map_type(|ty| self.narrow_expr_with_applicable_constraints(attribute, ty, &constraint_keys)) - .unwrap_with_diagnostic(|lookup_error| match lookup_error { + let resolved_type = + fallback_place.map_type(|ty| { + self.narrow_expr_with_applicable_constraints(attribute, ty, &constraint_keys) + }).unwrap_with_diagnostic(|lookup_error| match lookup_error { LookupError::Unbound(_) => { let report_unresolved_attribute = self.is_reachable(attribute); @@ -9248,6 +9318,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { declarations, deferred, cycle_fallback, + all_definitely_bound, // Ignored; only relevant to definition regions undecorated_type: _, @@ -9274,7 +9345,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { ); let extra = - (cycle_fallback || !bindings.is_empty() || !diagnostics.is_empty()).then(|| { + (cycle_fallback || !bindings.is_empty() || !diagnostics.is_empty() || !all_definitely_bound).then(|| { if bindings.len() > 20 { tracing::debug!( "Inferred expression region `{:?}` contains {} bindings. Lookups by linear scan might be slow.", @@ -9287,6 +9358,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { bindings: bindings.into_boxed_slice(), diagnostics, cycle_fallback, + all_definitely_bound, }) }); @@ -9312,7 +9384,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { deferred, cycle_fallback, undecorated_type, - + all_definitely_bound: _, // builder only state typevar_binding_context: _, deferred_state: _, @@ -9379,6 +9451,7 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> { deferred: _, bindings: _, declarations: _, + all_definitely_bound: _, // Ignored; only relevant to definition regions undecorated_type: _, From 1ce65714c05faa85b177d5be8d16814820e23032 Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Thu, 28 Aug 2025 08:56:33 -0400 Subject: [PATCH 157/160] Move GitLab output rendering to `ruff_db` (#20117) ## Summary This PR is a first step toward adding a GitLab output format to ty. It converts the `GitlabEmitter` from `ruff_linter` to a `GitlabRenderer` in `ruff_db` and updates its implementation to handle non-Ruff files and diagnostics without primary spans. I tried to break up the changes here so that they're easy to review commit-by-commit, or at least in groups of commits: - [preparatory changes in-place in `ruff_linter` and a `ruff_db` skeleton](https://github.com/astral-sh/ruff/pull/20117/files/0761b73a615537fe75fc54ba8f7d5f52c28b2a2a) - [moving the code over with no implementation changes mixed in](https://github.com/astral-sh/ruff/pull/20117/files/0761b73a615537fe75fc54ba8f7d5f52c28b2a2a..8f909ea0bb0892107824b311f3982eb3cb1833ed) - [tidying up the code now in `ruff_db`](https://github.com/astral-sh/ruff/pull/20117/files/9f047c4f9f1c826b963f0fa82ca2411d01d6ec83..e5e217fcd611ab24f516b2af4fa21e25eadc5645) This wasn't strictly necessary, but I also added some `Serialize` structs instead of calling `json!` to make it a little clearer that we weren't modifying the schema (e4c4bee35d39eb0aff4cae4a62823279b99c6d9c). I plan to follow this up with a separate PR exposing this output format in the ty CLI, which should be quite straightforward. ## Test Plan Existing tests, especially the two that show up in the diff as renamed nearly without changes --- Cargo.lock | 2 +- crates/ruff/src/printer.rs | 9 +- .../snapshots/lint__output_format_gitlab.snap | 36 +-- crates/ruff_db/Cargo.toml | 3 +- crates/ruff_db/src/diagnostic/mod.rs | 5 + crates/ruff_db/src/diagnostic/render.rs | 6 + .../ruff_db/src/diagnostic/render/gitlab.rs | 205 ++++++++++++++++++ ...ostic__render__gitlab__tests__output.snap} | 40 ++-- ...render__gitlab__tests__syntax_errors.snap} | 28 +-- crates/ruff_linter/Cargo.toml | 1 - crates/ruff_linter/src/fs.rs | 10 - crates/ruff_linter/src/message/gitlab.rs | 174 --------------- crates/ruff_linter/src/message/mod.rs | 2 - 13 files changed, 277 insertions(+), 244 deletions(-) create mode 100644 crates/ruff_db/src/diagnostic/render/gitlab.rs rename crates/{ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap => ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__output.snap} (63%) rename crates/{ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap => ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__syntax_errors.snap} (63%) delete mode 100644 crates/ruff_linter/src/message/gitlab.rs diff --git a/Cargo.lock b/Cargo.lock index 609eae3468475..929d5439127cc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2870,6 +2870,7 @@ dependencies = [ "insta", "matchit", "path-slash", + "pathdiff", "quick-junit", "ruff_annotate_snippets", "ruff_cache", @@ -3020,7 +3021,6 @@ dependencies = [ "memchr", "natord", "path-absolutize", - "pathdiff", "pep440_rs", "pyproject-toml", "regex", diff --git a/crates/ruff/src/printer.rs b/crates/ruff/src/printer.rs index 186c481890104..5ed78b895c8eb 100644 --- a/crates/ruff/src/printer.rs +++ b/crates/ruff/src/printer.rs @@ -15,8 +15,7 @@ use ruff_db::diagnostic::{ use ruff_linter::fs::relativize_path; use ruff_linter::logging::LogLevel; use ruff_linter::message::{ - Emitter, EmitterContext, GithubEmitter, GitlabEmitter, GroupedEmitter, SarifEmitter, - TextEmitter, + Emitter, EmitterContext, GithubEmitter, GroupedEmitter, SarifEmitter, TextEmitter, }; use ruff_linter::notify_user; use ruff_linter::settings::flags::{self}; @@ -296,7 +295,11 @@ impl Printer { GithubEmitter.emit(writer, &diagnostics.inner, &context)?; } OutputFormat::Gitlab => { - GitlabEmitter::default().emit(writer, &diagnostics.inner, &context)?; + let config = DisplayDiagnosticConfig::default() + .format(DiagnosticFormat::Gitlab) + .preview(preview); + let value = DisplayDiagnostics::new(&context, &config, &diagnostics.inner); + write!(writer, "{value}")?; } OutputFormat::Pylint => { let config = DisplayDiagnosticConfig::default() diff --git a/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap b/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap index 7596f0d0862c7..f16851bb3a8b7 100644 --- a/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap +++ b/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap @@ -20,59 +20,59 @@ exit_code: 1 { "check_name": "F401", "description": "F401: `os` imported but unused", + "severity": "major", "fingerprint": "4dbad37161e65c72", "location": { "path": "input.py", "positions": { "begin": { - "column": 8, - "line": 1 + "line": 1, + "column": 8 }, "end": { - "column": 10, - "line": 1 + "line": 1, + "column": 10 } } - }, - "severity": "major" + } }, { "check_name": "F821", "description": "F821: Undefined name `y`", + "severity": "major", "fingerprint": "7af59862a085230", "location": { "path": "input.py", "positions": { "begin": { - "column": 5, - "line": 2 + "line": 2, + "column": 5 }, "end": { - "column": 6, - "line": 2 + "line": 2, + "column": 6 } } - }, - "severity": "major" + } }, { "check_name": "invalid-syntax", "description": "invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)", + "severity": "major", "fingerprint": "e558cec859bb66e8", "location": { "path": "input.py", "positions": { "begin": { - "column": 1, - "line": 3 + "line": 3, + "column": 1 }, "end": { - "column": 6, - "line": 3 + "line": 3, + "column": 6 } } - }, - "severity": "major" + } } ] ----- stderr ----- diff --git a/crates/ruff_db/Cargo.toml b/crates/ruff_db/Cargo.toml index 40eb42ec8f949..25f0024b80fdb 100644 --- a/crates/ruff_db/Cargo.toml +++ b/crates/ruff_db/Cargo.toml @@ -34,6 +34,7 @@ glob = { workspace = true } ignore = { workspace = true, optional = true } matchit = { workspace = true } path-slash = { workspace = true } +pathdiff = { workspace = true } quick-junit = { workspace = true, optional = true } rustc-hash = { workspace = true } salsa = { workspace = true } @@ -53,7 +54,7 @@ web-time = { version = "1.1.0" } etcetera = { workspace = true, optional = true } [dev-dependencies] -insta = { workspace = true } +insta = { workspace = true, features = ["filters"] } tempfile = { workspace = true } [features] diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index a7e85edaf3cc4..5b706e8eb1f2c 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -1435,6 +1435,11 @@ pub enum DiagnosticFormat { /// Print diagnostics in the format expected by JUnit. #[cfg(feature = "junit")] Junit, + /// Print diagnostics in the JSON format used by GitLab [Code Quality] reports. + /// + /// [Code Quality]: https://docs.gitlab.com/ee/ci/testing/code_quality.html#implement-a-custom-tool + #[cfg(feature = "serde")] + Gitlab, } /// A representation of the kinds of messages inside a diagnostic. diff --git a/crates/ruff_db/src/diagnostic/render.rs b/crates/ruff_db/src/diagnostic/render.rs index 35cf2ff0514de..89285fe402a45 100644 --- a/crates/ruff_db/src/diagnostic/render.rs +++ b/crates/ruff_db/src/diagnostic/render.rs @@ -31,6 +31,8 @@ mod azure; mod concise; mod full; #[cfg(feature = "serde")] +mod gitlab; +#[cfg(feature = "serde")] mod json; #[cfg(feature = "serde")] mod json_lines; @@ -136,6 +138,10 @@ impl std::fmt::Display for DisplayDiagnostics<'_> { DiagnosticFormat::Junit => { junit::JunitRenderer::new(self.resolver).render(f, self.diagnostics)?; } + #[cfg(feature = "serde")] + DiagnosticFormat::Gitlab => { + gitlab::GitlabRenderer::new(self.resolver).render(f, self.diagnostics)?; + } } Ok(()) diff --git a/crates/ruff_db/src/diagnostic/render/gitlab.rs b/crates/ruff_db/src/diagnostic/render/gitlab.rs new file mode 100644 index 0000000000000..0d25da4dc6c0d --- /dev/null +++ b/crates/ruff_db/src/diagnostic/render/gitlab.rs @@ -0,0 +1,205 @@ +use std::{ + collections::HashSet, + hash::{DefaultHasher, Hash, Hasher}, + path::Path, +}; + +use ruff_source_file::LineColumn; +use serde::{Serialize, Serializer, ser::SerializeSeq}; + +use crate::diagnostic::{Diagnostic, Severity}; + +use super::FileResolver; + +pub(super) struct GitlabRenderer<'a> { + resolver: &'a dyn FileResolver, +} + +impl<'a> GitlabRenderer<'a> { + pub(super) fn new(resolver: &'a dyn FileResolver) -> Self { + Self { resolver } + } +} + +impl GitlabRenderer<'_> { + pub(super) fn render( + &self, + f: &mut std::fmt::Formatter, + diagnostics: &[Diagnostic], + ) -> std::fmt::Result { + write!( + f, + "{}", + serde_json::to_string_pretty(&SerializedMessages { + diagnostics, + resolver: self.resolver, + #[expect( + clippy::disallowed_methods, + reason = "We don't have access to a `System` here, \ + and this is only intended for use by GitLab CI, \ + which runs on a real `System`." + )] + project_dir: std::env::var("CI_PROJECT_DIR").ok().as_deref(), + }) + .unwrap() + ) + } +} + +struct SerializedMessages<'a> { + diagnostics: &'a [Diagnostic], + resolver: &'a dyn FileResolver, + project_dir: Option<&'a str>, +} + +impl Serialize for SerializedMessages<'_> { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut s = serializer.serialize_seq(Some(self.diagnostics.len()))?; + let mut fingerprints = HashSet::::with_capacity(self.diagnostics.len()); + + for diagnostic in self.diagnostics { + let location = diagnostic + .primary_span() + .map(|span| { + let file = span.file(); + let positions = if self.resolver.is_notebook(file) { + // We can't give a reasonable location for the structured formats, + // so we show one that's clearly a fallback + Default::default() + } else { + let diagnostic_source = file.diagnostic_source(self.resolver); + let source_code = diagnostic_source.as_source_code(); + span.range() + .map(|range| Positions { + begin: source_code.line_column(range.start()), + end: source_code.line_column(range.end()), + }) + .unwrap_or_default() + }; + + let path = self.project_dir.as_ref().map_or_else( + || file.relative_path(self.resolver).display().to_string(), + |project_dir| relativize_path_to(file.path(self.resolver), project_dir), + ); + + Location { path, positions } + }) + .unwrap_or_default(); + + let mut message_fingerprint = fingerprint(diagnostic, &location.path, 0); + + // Make sure that we do not get a fingerprint that is already in use + // by adding in the previously generated one. + while fingerprints.contains(&message_fingerprint) { + message_fingerprint = fingerprint(diagnostic, &location.path, message_fingerprint); + } + fingerprints.insert(message_fingerprint); + + let description = diagnostic.body(); + let check_name = diagnostic.secondary_code_or_id(); + let severity = match diagnostic.severity() { + Severity::Info => "info", + Severity::Warning => "minor", + Severity::Error => "major", + // Another option here is `blocker` + Severity::Fatal => "critical", + }; + + let value = Message { + check_name, + // GitLab doesn't display the separate `check_name` field in a Code Quality report, + // so prepend it to the description too. + description: format!("{check_name}: {description}"), + severity, + fingerprint: format!("{:x}", message_fingerprint), + location, + }; + + s.serialize_element(&value)?; + } + + s.end() + } +} + +#[derive(Serialize)] +struct Message<'a> { + check_name: &'a str, + description: String, + severity: &'static str, + fingerprint: String, + location: Location, +} + +/// The place in the source code where the issue was discovered. +/// +/// According to the CodeClimate report format [specification] linked from the GitLab [docs], this +/// field is required, so we fall back on a default `path` and position if the diagnostic doesn't +/// have a primary span. +/// +/// [specification]: https://github.com/codeclimate/platform/blob/master/spec/analyzers/SPEC.md#data-types +/// [docs]: https://docs.gitlab.com/ci/testing/code_quality/#code-quality-report-format +#[derive(Default, Serialize)] +struct Location { + path: String, + positions: Positions, +} + +#[derive(Default, Serialize)] +struct Positions { + begin: LineColumn, + end: LineColumn, +} + +/// Generate a unique fingerprint to identify a violation. +fn fingerprint(diagnostic: &Diagnostic, project_path: &str, salt: u64) -> u64 { + let mut hasher = DefaultHasher::new(); + + salt.hash(&mut hasher); + diagnostic.name().hash(&mut hasher); + project_path.hash(&mut hasher); + + hasher.finish() +} + +/// Convert an absolute path to be relative to the specified project root. +fn relativize_path_to, R: AsRef>(path: P, project_root: R) -> String { + format!( + "{}", + pathdiff::diff_paths(&path, project_root) + .expect("Could not diff paths") + .display() + ) +} + +#[cfg(test)] +mod tests { + use crate::diagnostic::{ + DiagnosticFormat, + render::tests::{create_diagnostics, create_syntax_error_diagnostics}, + }; + + const FINGERPRINT_FILTERS: [(&str, &str); 1] = [( + r#""fingerprint": "[a-z0-9]+","#, + r#""fingerprint": "","#, + )]; + + #[test] + fn output() { + let (env, diagnostics) = create_diagnostics(DiagnosticFormat::Gitlab); + insta::with_settings!({filters => FINGERPRINT_FILTERS}, { + insta::assert_snapshot!(env.render_diagnostics(&diagnostics)); + }); + } + + #[test] + fn syntax_errors() { + let (env, diagnostics) = create_syntax_error_diagnostics(DiagnosticFormat::Gitlab); + insta::with_settings!({filters => FINGERPRINT_FILTERS}, { + insta::assert_snapshot!(env.render_diagnostics(&diagnostics)); + }); + } +} diff --git a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap b/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__output.snap similarity index 63% rename from crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap rename to crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__output.snap index c106eb70bae2f..a50787f92833e 100644 --- a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap +++ b/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__output.snap @@ -1,63 +1,63 @@ --- -source: crates/ruff_linter/src/message/gitlab.rs -expression: redact_fingerprint(&content) +source: crates/ruff_db/src/diagnostic/render/gitlab.rs +expression: env.render_diagnostics(&diagnostics) --- [ { "check_name": "F401", "description": "F401: `os` imported but unused", + "severity": "major", "fingerprint": "", "location": { "path": "fib.py", "positions": { "begin": { - "column": 8, - "line": 1 + "line": 1, + "column": 8 }, "end": { - "column": 10, - "line": 1 + "line": 1, + "column": 10 } } - }, - "severity": "major" + } }, { "check_name": "F841", "description": "F841: Local variable `x` is assigned to but never used", + "severity": "major", "fingerprint": "", "location": { "path": "fib.py", "positions": { "begin": { - "column": 5, - "line": 6 + "line": 6, + "column": 5 }, "end": { - "column": 6, - "line": 6 + "line": 6, + "column": 6 } } - }, - "severity": "major" + } }, { "check_name": "F821", "description": "F821: Undefined name `a`", + "severity": "major", "fingerprint": "", "location": { "path": "undef.py", "positions": { "begin": { - "column": 4, - "line": 1 + "line": 1, + "column": 4 }, "end": { - "column": 5, - "line": 1 + "line": 1, + "column": 5 } } - }, - "severity": "major" + } } ] diff --git a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap b/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__syntax_errors.snap similarity index 63% rename from crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap rename to crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__syntax_errors.snap index 7979aa977a0d4..0e2de764531b8 100644 --- a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap +++ b/crates/ruff_db/src/diagnostic/render/snapshots/ruff_db__diagnostic__render__gitlab__tests__syntax_errors.snap @@ -1,44 +1,44 @@ --- -source: crates/ruff_linter/src/message/gitlab.rs -expression: redact_fingerprint(&content) +source: crates/ruff_db/src/diagnostic/render/gitlab.rs +expression: env.render_diagnostics(&diagnostics) --- [ { "check_name": "invalid-syntax", "description": "invalid-syntax: Expected one or more symbol names after import", + "severity": "major", "fingerprint": "", "location": { "path": "syntax_errors.py", "positions": { "begin": { - "column": 15, - "line": 1 + "line": 1, + "column": 15 }, "end": { - "column": 1, - "line": 2 + "line": 2, + "column": 1 } } - }, - "severity": "major" + } }, { "check_name": "invalid-syntax", "description": "invalid-syntax: Expected ')', found newline", + "severity": "major", "fingerprint": "", "location": { "path": "syntax_errors.py", "positions": { "begin": { - "column": 12, - "line": 3 + "line": 3, + "column": 12 }, "end": { - "column": 1, - "line": 4 + "line": 4, + "column": 1 } } - }, - "severity": "major" + } } ] diff --git a/crates/ruff_linter/Cargo.toml b/crates/ruff_linter/Cargo.toml index 50dfb754e612a..e924d61085b41 100644 --- a/crates/ruff_linter/Cargo.toml +++ b/crates/ruff_linter/Cargo.toml @@ -51,7 +51,6 @@ path-absolutize = { workspace = true, features = [ "once_cell_cache", "use_unix_paths_on_wasm", ] } -pathdiff = { workspace = true } pep440_rs = { workspace = true } pyproject-toml = { workspace = true } regex = { workspace = true } diff --git a/crates/ruff_linter/src/fs.rs b/crates/ruff_linter/src/fs.rs index 37fbf36bc6a1a..ce1a1abe87ceb 100644 --- a/crates/ruff_linter/src/fs.rs +++ b/crates/ruff_linter/src/fs.rs @@ -58,13 +58,3 @@ pub fn relativize_path>(path: P) -> String { } format!("{}", path.display()) } - -/// Convert an absolute path to be relative to the specified project root. -pub fn relativize_path_to, R: AsRef>(path: P, project_root: R) -> String { - format!( - "{}", - pathdiff::diff_paths(&path, project_root) - .expect("Could not diff paths") - .display() - ) -} diff --git a/crates/ruff_linter/src/message/gitlab.rs b/crates/ruff_linter/src/message/gitlab.rs deleted file mode 100644 index fbf5643697889..0000000000000 --- a/crates/ruff_linter/src/message/gitlab.rs +++ /dev/null @@ -1,174 +0,0 @@ -use std::collections::HashSet; -use std::collections::hash_map::DefaultHasher; -use std::hash::{Hash, Hasher}; -use std::io::Write; - -use serde::ser::SerializeSeq; -use serde::{Serialize, Serializer}; -use serde_json::json; - -use ruff_db::diagnostic::Diagnostic; - -use crate::fs::{relativize_path, relativize_path_to}; -use crate::message::{Emitter, EmitterContext}; - -/// Generate JSON with violations in GitLab CI format -// https://docs.gitlab.com/ee/ci/testing/code_quality.html#implement-a-custom-tool -pub struct GitlabEmitter { - project_dir: Option, -} - -impl Default for GitlabEmitter { - fn default() -> Self { - Self { - project_dir: std::env::var("CI_PROJECT_DIR").ok(), - } - } -} - -impl Emitter for GitlabEmitter { - fn emit( - &mut self, - writer: &mut dyn Write, - diagnostics: &[Diagnostic], - context: &EmitterContext, - ) -> anyhow::Result<()> { - serde_json::to_writer_pretty( - writer, - &SerializedMessages { - diagnostics, - context, - project_dir: self.project_dir.as_deref(), - }, - )?; - - Ok(()) - } -} - -struct SerializedMessages<'a> { - diagnostics: &'a [Diagnostic], - context: &'a EmitterContext<'a>, - project_dir: Option<&'a str>, -} - -impl Serialize for SerializedMessages<'_> { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { - let mut s = serializer.serialize_seq(Some(self.diagnostics.len()))?; - let mut fingerprints = HashSet::::with_capacity(self.diagnostics.len()); - - for diagnostic in self.diagnostics { - let filename = diagnostic.expect_ruff_filename(); - - let (start_location, end_location) = if self.context.is_notebook(&filename) { - // We can't give a reasonable location for the structured formats, - // so we show one that's clearly a fallback - Default::default() - } else { - ( - diagnostic.expect_ruff_start_location(), - diagnostic.expect_ruff_end_location(), - ) - }; - - let path = self.project_dir.as_ref().map_or_else( - || relativize_path(&filename), - |project_dir| relativize_path_to(&filename, project_dir), - ); - - let mut message_fingerprint = fingerprint(diagnostic, &path, 0); - - // Make sure that we do not get a fingerprint that is already in use - // by adding in the previously generated one. - while fingerprints.contains(&message_fingerprint) { - message_fingerprint = fingerprint(diagnostic, &path, message_fingerprint); - } - fingerprints.insert(message_fingerprint); - - let description = diagnostic.body(); - let check_name = diagnostic.secondary_code_or_id(); - - let value = json!({ - "check_name": check_name, - // GitLab doesn't display the separate `check_name` field in a Code Quality report, - // so prepend it to the description too. - "description": format!("{check_name}: {description}"), - "severity": "major", - "fingerprint": format!("{:x}", message_fingerprint), - "location": { - "path": path, - "positions": { - "begin": start_location, - "end": end_location, - }, - }, - }); - - s.serialize_element(&value)?; - } - - s.end() - } -} - -/// Generate a unique fingerprint to identify a violation. -fn fingerprint(message: &Diagnostic, project_path: &str, salt: u64) -> u64 { - let mut hasher = DefaultHasher::new(); - - salt.hash(&mut hasher); - message.name().hash(&mut hasher); - project_path.hash(&mut hasher); - - hasher.finish() -} - -#[cfg(test)] -mod tests { - use insta::assert_snapshot; - - use crate::message::GitlabEmitter; - use crate::message::tests::{ - capture_emitter_output, create_diagnostics, create_syntax_error_diagnostics, - }; - - #[test] - fn output() { - let mut emitter = GitlabEmitter::default(); - let content = capture_emitter_output(&mut emitter, &create_diagnostics()); - - assert_snapshot!(redact_fingerprint(&content)); - } - - #[test] - fn syntax_errors() { - let mut emitter = GitlabEmitter::default(); - let content = capture_emitter_output(&mut emitter, &create_syntax_error_diagnostics()); - - assert_snapshot!(redact_fingerprint(&content)); - } - - // Redact the fingerprint because the default hasher isn't stable across platforms. - fn redact_fingerprint(content: &str) -> String { - static FINGERPRINT_HAY_KEY: &str = r#""fingerprint": ""#; - - let mut output = String::with_capacity(content.len()); - let mut last = 0; - - for (start, _) in content.match_indices(FINGERPRINT_HAY_KEY) { - let fingerprint_hash_start = start + FINGERPRINT_HAY_KEY.len(); - output.push_str(&content[last..fingerprint_hash_start]); - output.push_str(""); - last = fingerprint_hash_start - + content[fingerprint_hash_start..] - .find('"') - .expect("Expected terminating quote"); - } - - output.push_str(&content[last..]); - - output - } -} diff --git a/crates/ruff_linter/src/message/mod.rs b/crates/ruff_linter/src/message/mod.rs index 1918575a2b933..fe97c1ca52870 100644 --- a/crates/ruff_linter/src/message/mod.rs +++ b/crates/ruff_linter/src/message/mod.rs @@ -10,7 +10,6 @@ use ruff_db::diagnostic::{ use ruff_db::files::File; pub use github::GithubEmitter; -pub use gitlab::GitlabEmitter; pub use grouped::GroupedEmitter; use ruff_notebook::NotebookIndex; use ruff_source_file::SourceFile; @@ -22,7 +21,6 @@ use crate::Fix; use crate::registry::Rule; mod github; -mod gitlab; mod grouped; mod sarif; mod text; From 76a6b7e3e2061de320a17ab7513708809019aecc Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Thu, 28 Aug 2025 22:02:50 +0900 Subject: [PATCH 158/160] [`pyflakes`] Fix `allowed-unused-imports` matching for top-level modules (`F401`) (#20115) ## Summary Fixes #19664 Fix allowed unused imports matching for top-level modules. I've simply replaced `from_dotted_name` with `user_defined`. Since QualifiedName for imports is created in crates/ruff_python_semantic/src/imports.rs, I guess it's acceptable to use `user_defined` here. Please tell me if there is better way. https://github.com/astral-sh/ruff/blob/0c5089ed9e180da7bc76733ffe1a1d132e9142b0/crates/ruff_python_semantic/src/imports.rs#L62 ## Test Plan I've added a snapshot test `f401_allowed_unused_imports_top_level_module`. --- .../resources/test/fixtures/pyflakes/F401_35.py | 16 ++++++++++++++++ crates/ruff_linter/src/rules/pyflakes/mod.rs | 16 ++++++++++++++++ .../src/rules/pyflakes/rules/unused_import.rs | 2 +- ..._allowed_unused_imports_top_level_module.snap | 4 ++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 crates/ruff_linter/resources/test/fixtures/pyflakes/F401_35.py create mode 100644 crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f401_allowed_unused_imports_top_level_module.snap diff --git a/crates/ruff_linter/resources/test/fixtures/pyflakes/F401_35.py b/crates/ruff_linter/resources/test/fixtures/pyflakes/F401_35.py new file mode 100644 index 0000000000000..0b1cb0644f395 --- /dev/null +++ b/crates/ruff_linter/resources/test/fixtures/pyflakes/F401_35.py @@ -0,0 +1,16 @@ +""" +Test: allowed-unused-imports-top-level-module +""" + +# No errors + +def f(): + import hvplot +def f(): + import hvplot.pandas +def f(): + import hvplot.pandas.plots +def f(): + from hvplot.pandas import scatter_matrix +def f(): + from hvplot.pandas.plots import scatter_matrix diff --git a/crates/ruff_linter/src/rules/pyflakes/mod.rs b/crates/ruff_linter/src/rules/pyflakes/mod.rs index 12b7d5ce86424..ab553e2b72c4c 100644 --- a/crates/ruff_linter/src/rules/pyflakes/mod.rs +++ b/crates/ruff_linter/src/rules/pyflakes/mod.rs @@ -376,6 +376,22 @@ mod tests { Ok(()) } + #[test_case(Rule::UnusedImport, Path::new("F401_35.py"))] + fn f401_allowed_unused_imports_top_level_module(rule_code: Rule, path: &Path) -> Result<()> { + let diagnostics = test_path( + Path::new("pyflakes").join(path).as_path(), + &LinterSettings { + pyflakes: pyflakes::settings::Settings { + allowed_unused_imports: vec!["hvplot".to_string()], + ..pyflakes::settings::Settings::default() + }, + ..LinterSettings::for_rule(rule_code) + }, + )?; + assert_diagnostics!(diagnostics); + Ok(()) + } + #[test] fn f841_dummy_variable_rgx() -> Result<()> { let diagnostics = test_path( diff --git a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs index 5af5312af5fef..130c614ae79ca 100644 --- a/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs +++ b/crates/ruff_linter/src/rules/pyflakes/rules/unused_import.rs @@ -334,7 +334,7 @@ pub(crate) fn unused_import(checker: &Checker, scope: &Scope) { .allowed_unused_imports .iter() .any(|allowed_unused_import| { - let allowed_unused_import = QualifiedName::from_dotted_name(allowed_unused_import); + let allowed_unused_import = QualifiedName::user_defined(allowed_unused_import); import.qualified_name().starts_with(&allowed_unused_import) }) { diff --git a/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f401_allowed_unused_imports_top_level_module.snap b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f401_allowed_unused_imports_top_level_module.snap new file mode 100644 index 0000000000000..d0b409f39ee0b --- /dev/null +++ b/crates/ruff_linter/src/rules/pyflakes/snapshots/ruff_linter__rules__pyflakes__tests__f401_allowed_unused_imports_top_level_module.snap @@ -0,0 +1,4 @@ +--- +source: crates/ruff_linter/src/rules/pyflakes/mod.rs +--- + From e586f6dcc426bdceddf43e811aaace460e4f56f9 Mon Sep 17 00:00:00 2001 From: David Peter Date: Thu, 28 Aug 2025 15:25:25 +0200 Subject: [PATCH 159/160] [ty] Benchmarks for problematic implicit instance attributes cases (#20133) ## Summary Add regression benchmarks for the problematic cases in https://github.com/astral-sh/ty/issues/758. I'd like to merge this before https://github.com/astral-sh/ruff/pull/20128 to measure the impact (local tests show that this will "solve" both cases). --- crates/ruff_benchmark/benches/ty.rs | 54 +++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/crates/ruff_benchmark/benches/ty.rs b/crates/ruff_benchmark/benches/ty.rs index 02a10a41008c9..f1000fb0503ed 100644 --- a/crates/ruff_benchmark/benches/ty.rs +++ b/crates/ruff_benchmark/benches/ty.rs @@ -450,9 +450,6 @@ fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) { r#" class C: def f(self: "C"): - self.a = "" - self.b = "" - if isinstance(self.a, str): return @@ -466,6 +463,56 @@ fn benchmark_complex_constrained_attributes_2(criterion: &mut Criterion) { return if isinstance(self.b, str): return + if isinstance(self.b, str): + return + if isinstance(self.b, str): + return + + self.a = "" + self.b = "" + "#, + ) + }, + |case| { + let Case { db, .. } = case; + let result = db.check(); + assert_eq!(result.len(), 0); + }, + BatchSize::SmallInput, + ); + }); +} + +fn benchmark_complex_constrained_attributes_3(criterion: &mut Criterion) { + setup_rayon(); + + criterion.bench_function("ty_micro[complex_constrained_attributes_3]", |b| { + b.iter_batched_ref( + || { + // This is a regression test for https://github.com/astral-sh/ty/issues/758 + setup_micro_case( + r#" + class GridOut: + def __init__(self: "GridOut") -> None: + self._buffer = b"" + + def _read_size_or_line(self: "GridOut", size: int = -1): + if size > self._position: + size = self._position + pass + if size == 0: + return bytes() + + while size > 0: + if self._buffer: + buf = self._buffer + self._buffer = b"" + else: + buf = b"" + + if len(buf) > size: + self._buffer = buf + self._position -= len(self._buffer) "#, ) }, @@ -668,6 +715,7 @@ criterion_group!( benchmark_tuple_implicit_instance_attributes, benchmark_complex_constrained_attributes_1, benchmark_complex_constrained_attributes_2, + benchmark_complex_constrained_attributes_3, benchmark_many_enum_members, ); criterion_group!(project, anyio, attrs, hydra, datetype); From c2bc15bc15103f46b55b6f35b1d0ce815fdfc547 Mon Sep 17 00:00:00 2001 From: Brent Westbrook <36778786+ntBre@users.noreply.github.com> Date: Thu, 28 Aug 2025 09:45:01 -0400 Subject: [PATCH 160/160] Bump 0.12.11 (#20136) --- CHANGELOG.md | 27 +++++++++++++++++++++++++++ Cargo.lock | 6 +++--- README.md | 6 +++--- crates/ruff/Cargo.toml | 2 +- crates/ruff_linter/Cargo.toml | 2 +- crates/ruff_wasm/Cargo.toml | 2 +- docs/integrations.md | 8 ++++---- docs/tutorial.md | 2 +- pyproject.toml | 2 +- scripts/benchmarks/pyproject.toml | 2 +- 10 files changed, 43 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8772a86039a20..0fa48df8ed225 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,32 @@ # Changelog +## 0.12.11 + +### Preview features + +- \[`airflow`\] Extend `AIR311` and `AIR312` rules ([#20082](https://github.com/astral-sh/ruff/pull/20082)) +- \[`airflow`\] Replace wrong path `airflow.io.storage` with `airflow.io.store` (`AIR311`) ([#20081](https://github.com/astral-sh/ruff/pull/20081)) +- \[`flake8-async`\] Implement `blocking-http-call-httpx-in-async-function` (`ASYNC212`) ([#20091](https://github.com/astral-sh/ruff/pull/20091)) +- \[`flake8-logging-format`\] Add auto-fix for f-string logging calls (`G004`) ([#19303](https://github.com/astral-sh/ruff/pull/19303)) +- \[`flake8-use-pathlib`\] Add autofix for `PTH211` ([#20009](https://github.com/astral-sh/ruff/pull/20009)) +- \[`flake8-use-pathlib`\] Make `PTH100` fix unsafe because it can change behavior ([#20100](https://github.com/astral-sh/ruff/pull/20100)) + +### Bug fixes + +- \[`pyflakes`, `pylint`\] Fix false positives caused by `__class__` cell handling (`F841`, `PLE0117`) ([#20048](https://github.com/astral-sh/ruff/pull/20048)) +- \[`pyflakes`\] Fix `allowed-unused-imports` matching for top-level modules (`F401`) ([#20115](https://github.com/astral-sh/ruff/pull/20115)) +- \[`ruff`\] Fix false positive for t-strings in `default-factory-kwarg` (`RUF026`) ([#20032](https://github.com/astral-sh/ruff/pull/20032)) +- \[`ruff`\] Preserve relative whitespace in multi-line expressions (`RUF033`) ([#19647](https://github.com/astral-sh/ruff/pull/19647)) + +### Rule changes + +- \[`ruff`\] Handle empty t-strings in `unnecessary-empty-iterable-within-deque-call` (`RUF037`) ([#20045](https://github.com/astral-sh/ruff/pull/20045)) + +### Documentation + +- Fix incorrect `D413` links in docstrings convention FAQ ([#20089](https://github.com/astral-sh/ruff/pull/20089)) +- \[`flake8-use-pathlib`\] Update links to the table showing the correspondence between `os` and `pathlib` ([#20103](https://github.com/astral-sh/ruff/pull/20103)) + ## 0.12.10 ### Preview features diff --git a/Cargo.lock b/Cargo.lock index 929d5439127cc..ad35f49f7c1ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2743,7 +2743,7 @@ dependencies = [ [[package]] name = "ruff" -version = "0.12.10" +version = "0.12.11" dependencies = [ "anyhow", "argfile", @@ -2999,7 +2999,7 @@ dependencies = [ [[package]] name = "ruff_linter" -version = "0.12.10" +version = "0.12.11" dependencies = [ "aho-corasick", "anyhow", @@ -3337,7 +3337,7 @@ dependencies = [ [[package]] name = "ruff_wasm" -version = "0.12.10" +version = "0.12.11" dependencies = [ "console_error_panic_hook", "console_log", diff --git a/README.md b/README.md index b18b8307b42a9..879c6950aafee 100644 --- a/README.md +++ b/README.md @@ -148,8 +148,8 @@ curl -LsSf https://astral.sh/ruff/install.sh | sh powershell -c "irm https://astral.sh/ruff/install.ps1 | iex" # For a specific version. -curl -LsSf https://astral.sh/ruff/0.12.10/install.sh | sh -powershell -c "irm https://astral.sh/ruff/0.12.10/install.ps1 | iex" +curl -LsSf https://astral.sh/ruff/0.12.11/install.sh | sh +powershell -c "irm https://astral.sh/ruff/0.12.11/install.ps1 | iex" ``` You can also install Ruff via [Homebrew](https://formulae.brew.sh/formula/ruff), [Conda](https://anaconda.org/conda-forge/ruff), @@ -182,7 +182,7 @@ Ruff can also be used as a [pre-commit](https://pre-commit.com/) hook via [`ruff ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.10 + rev: v0.12.11 hooks: # Run the linter. - id: ruff-check diff --git a/crates/ruff/Cargo.toml b/crates/ruff/Cargo.toml index dd57a997078ff..ceb0797ac7a49 100644 --- a/crates/ruff/Cargo.toml +++ b/crates/ruff/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruff" -version = "0.12.10" +version = "0.12.11" publish = true authors = { workspace = true } edition = { workspace = true } diff --git a/crates/ruff_linter/Cargo.toml b/crates/ruff_linter/Cargo.toml index e924d61085b41..418e62f483b67 100644 --- a/crates/ruff_linter/Cargo.toml +++ b/crates/ruff_linter/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruff_linter" -version = "0.12.10" +version = "0.12.11" publish = false authors = { workspace = true } edition = { workspace = true } diff --git a/crates/ruff_wasm/Cargo.toml b/crates/ruff_wasm/Cargo.toml index 59224e461ae16..f738512a1a7d3 100644 --- a/crates/ruff_wasm/Cargo.toml +++ b/crates/ruff_wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ruff_wasm" -version = "0.12.10" +version = "0.12.11" publish = false authors = { workspace = true } edition = { workspace = true } diff --git a/docs/integrations.md b/docs/integrations.md index ef431f2d911b9..10e2eaee550e3 100644 --- a/docs/integrations.md +++ b/docs/integrations.md @@ -80,7 +80,7 @@ You can add the following configuration to `.gitlab-ci.yml` to run a `ruff forma stage: build interruptible: true image: - name: ghcr.io/astral-sh/ruff:0.12.10-alpine + name: ghcr.io/astral-sh/ruff:0.12.11-alpine before_script: - cd $CI_PROJECT_DIR - ruff --version @@ -106,7 +106,7 @@ Ruff can be used as a [pre-commit](https://pre-commit.com) hook via [`ruff-pre-c ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.10 + rev: v0.12.11 hooks: # Run the linter. - id: ruff-check @@ -119,7 +119,7 @@ To enable lint fixes, add the `--fix` argument to the lint hook: ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.10 + rev: v0.12.11 hooks: # Run the linter. - id: ruff-check @@ -133,7 +133,7 @@ To avoid running on Jupyter Notebooks, remove `jupyter` from the list of allowed ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.10 + rev: v0.12.11 hooks: # Run the linter. - id: ruff-check diff --git a/docs/tutorial.md b/docs/tutorial.md index 56f119bac325b..355d4d0d7adaa 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -369,7 +369,7 @@ This tutorial has focused on Ruff's command-line interface, but Ruff can also be ```yaml - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: v0.12.10 + rev: v0.12.11 hooks: # Run the linter. - id: ruff diff --git a/pyproject.toml b/pyproject.toml index 499a0dac08bdb..6daea1705f3b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "maturin" [project] name = "ruff" -version = "0.12.10" +version = "0.12.11" description = "An extremely fast Python linter and code formatter, written in Rust." authors = [{ name = "Astral Software Inc.", email = "hey@astral.sh" }] readme = "README.md" diff --git a/scripts/benchmarks/pyproject.toml b/scripts/benchmarks/pyproject.toml index 839e01432114f..6aadfb4b104a5 100644 --- a/scripts/benchmarks/pyproject.toml +++ b/scripts/benchmarks/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "scripts" -version = "0.12.10" +version = "0.12.11" description = "" authors = ["Charles Marsh "]