Skip to content

Commit e432558

Browse files
committed
Merge remote-tracking branch 'origin/main' into dcreager/nondeterminism
* origin/main: [ty] Improve `@override`, `@final` and Liskov checks in cases where there are multiple reachable definitions (#21767) [ty] Extend `invalid-explicit-override` to also cover properties decorated with `@override` that do not override anything (#21756) [ty] Enable LRU collection for parsed module (#21749) [ty] Support typevar-specialized dynamic types in generic type aliases (#21730) Add token based `parenthesized_ranges` implementation (#21738) [ty] Default-specialization of generic type aliases (#21765) [ty] Suppress false positives when `dataclasses.dataclass(...)(cls)` is called imperatively (#21729) [syntax-error] Default type parameter followed by non-default type parameter (#21657) new module for parsing ranged suppressions (#21441) [ty] `type[T]` is assignable to an inferable typevar (#21766) Fix syntax error false positives for `await` outside functions (#21763) [ty] Improve diagnostics for unsupported comparison operations (#21737) Move `Token`, `TokenKind` and `Tokens` to `ruff-python-ast` (#21760) [ty] Don't confuse multiple occurrences of `typing.Self` when binding bound methods (#21754) Use our org-wide Renovate preset (#21759) Delete `my-script.py` (#21751) [ty] Move `all_members`, and related types/routines, out of `ide_support.rs` (#21695)
2 parents 9e5ea4b + cd079bd commit e432558

File tree

158 files changed

+6794
-2694
lines changed

Some content is hidden

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

158 files changed

+6794
-2694
lines changed

.github/renovate.json5

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
$schema: "https://docs.renovatebot.com/renovate-schema.json",
33
dependencyDashboard: true,
44
suppressNotifications: ["prEditedNotification"],
5-
extends: ["config:recommended"],
5+
extends: ["github>astral-sh/renovate-config"],
66
labels: ["internal"],
77
schedule: ["before 4am on Monday"],
88
semanticCommits: "disabled",
99
separateMajorMinor: false,
10-
prHourlyLimit: 10,
1110
enabledManagers: ["github-actions", "pre-commit", "cargo", "pep621", "pip_requirements", "npm"],
1211
cargo: {
1312
// See https://docs.renovatebot.com/configuration-options/#rangestrategy
@@ -16,7 +15,7 @@
1615
pep621: {
1716
// The default for this package manager is to only search for `pyproject.toml` files
1817
// found at the repository root: https://docs.renovatebot.com/modules/manager/pep621/#file-matching
19-
fileMatch: ["^(python|scripts)/.*pyproject\\.toml$"],
18+
managerFilePatterns: ["^(python|scripts)/.*pyproject\\.toml$"],
2019
},
2120
pip_requirements: {
2221
// The default for this package manager is to run on all requirements.txt files:
@@ -34,7 +33,7 @@
3433
npm: {
3534
// The default for this package manager is to only search for `package.json` files
3635
// found at the repository root: https://docs.renovatebot.com/modules/manager/npm/#file-matching
37-
fileMatch: ["^playground/.*package\\.json$"],
36+
managerFilePatterns: ["^playground/.*package\\.json$"],
3837
},
3938
"pre-commit": {
4039
enabled: true,

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ruff_benchmark/benches/lexer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use criterion::{
66
use ruff_benchmark::{
77
LARGE_DATASET, NUMPY_CTYPESLIB, NUMPY_GLOBALS, PYDANTIC_TYPES, TestCase, UNICODE_PYPINYIN,
88
};
9-
use ruff_python_parser::{Mode, TokenKind, lexer};
9+
use ruff_python_ast::token::TokenKind;
10+
use ruff_python_parser::{Mode, lexer};
1011

1112
#[cfg(target_os = "windows")]
1213
#[global_allocator]

crates/ruff_db/src/parsed.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ use crate::source::source_text;
2121
/// reflected in the changed AST offsets.
2222
/// The other reason is that Ruff's AST doesn't implement `Eq` which Salsa requires
2323
/// for determining if a query result is unchanged.
24-
#[salsa::tracked(returns(ref), no_eq, heap_size=ruff_memory_usage::heap_size)]
24+
///
25+
/// The LRU capacity of 200 was picked without any empirical evidence that it's optimal,
26+
/// instead it's a wild guess that it should be unlikely that incremental changes involve
27+
/// more than 200 modules. Parsed ASTs within the same revision are never evicted by Salsa.
28+
#[salsa::tracked(returns(ref), no_eq, heap_size=ruff_memory_usage::heap_size, lru=200)]
2529
pub fn parsed_module(db: &dyn Db, file: File) -> ParsedModule {
2630
let _span = tracing::trace_span!("parsed_module", ?file).entered();
2731

@@ -92,14 +96,9 @@ impl ParsedModule {
9296
self.inner.store(None);
9397
}
9498

95-
/// Returns the pointer address of this [`ParsedModule`].
96-
///
97-
/// The pointer uniquely identifies the module within the current Salsa revision,
98-
/// regardless of whether particular [`ParsedModuleRef`] instances are garbage collected.
99-
pub fn addr(&self) -> usize {
100-
// Note that the outer `Arc` in `inner` is stable across garbage collection, while the inner
101-
// `Arc` within the `ArcSwap` may change.
102-
Arc::as_ptr(&self.inner).addr()
99+
/// Returns the file to which this module belongs.
100+
pub fn file(&self) -> File {
101+
self.file
103102
}
104103
}
105104

crates/ruff_linter/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ anyhow = { workspace = true }
3535
bitflags = { workspace = true }
3636
clap = { workspace = true, features = ["derive", "string"], optional = true }
3737
colored = { workspace = true }
38+
compact_str = { workspace = true }
3839
fern = { workspace = true }
3940
glob = { workspace = true }
4041
globset = { workspace = true }

crates/ruff_linter/resources/test/fixtures/pyflakes/F704.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,24 @@ def _():
1717

1818
# Valid yield scope
1919
yield 3
20+
21+
22+
# await is valid in any generator, sync or async
23+
(await cor async for cor in f()) # ok
24+
(await cor for cor in f()) # ok
25+
26+
# but not in comprehensions
27+
[await cor async for cor in f()] # F704
28+
{await cor async for cor in f()} # F704
29+
{await cor: 1 async for cor in f()} # F704
30+
[await cor for cor in f()] # F704
31+
{await cor for cor in f()} # F704
32+
{await cor: 1 for cor in f()} # F704
33+
34+
# or in the iterator of an async generator, which is evaluated in the parent
35+
# scope
36+
(cor async for cor in await f()) # F704
37+
(await cor async for cor in [await c for c in f()]) # F704
38+
39+
# this is also okay because the comprehension is within the generator scope
40+
([await c for c in cor] async for cor in f()) # ok

crates/ruff_linter/resources/test/fixtures/syntax_errors/await_outside_async_function.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ def func():
33

44
# Top-level await
55
await 1
6+
7+
([await c for c in cor] async for cor in func()) # ok

crates/ruff_linter/src/checkers/ast/mod.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use ruff_python_ast::helpers::{collect_import_from_member, is_docstring_stmt, to
3535
use ruff_python_ast::identifier::Identifier;
3636
use ruff_python_ast::name::QualifiedName;
3737
use ruff_python_ast::str::Quote;
38+
use ruff_python_ast::token::Tokens;
3839
use ruff_python_ast::visitor::{Visitor, walk_except_handler, walk_pattern};
3940
use ruff_python_ast::{
4041
self as ast, AnyParameterRef, ArgOrKeyword, Comprehension, ElifElseClause, ExceptHandler, Expr,
@@ -48,7 +49,7 @@ use ruff_python_parser::semantic_errors::{
4849
SemanticSyntaxChecker, SemanticSyntaxContext, SemanticSyntaxError, SemanticSyntaxErrorKind,
4950
};
5051
use ruff_python_parser::typing::{AnnotationKind, ParsedAnnotation, parse_type_annotation};
51-
use ruff_python_parser::{ParseError, Parsed, Tokens};
52+
use ruff_python_parser::{ParseError, Parsed};
5253
use ruff_python_semantic::all::{DunderAllDefinition, DunderAllFlags};
5354
use ruff_python_semantic::analyze::{imports, typing};
5455
use ruff_python_semantic::{
@@ -746,6 +747,7 @@ impl SemanticSyntaxContext for Checker<'_> {
746747
| SemanticSyntaxErrorKind::LoadBeforeNonlocalDeclaration { .. }
747748
| SemanticSyntaxErrorKind::NonlocalAndGlobal(_)
748749
| SemanticSyntaxErrorKind::AnnotatedGlobal(_)
750+
| SemanticSyntaxErrorKind::TypeParameterDefaultOrder(_)
749751
| SemanticSyntaxErrorKind::AnnotatedNonlocal(_) => {
750752
self.semantic_errors.borrow_mut().push(error);
751753
}
@@ -779,6 +781,10 @@ impl SemanticSyntaxContext for Checker<'_> {
779781
match scope.kind {
780782
ScopeKind::Class(_) => return false,
781783
ScopeKind::Function(_) | ScopeKind::Lambda(_) => return true,
784+
ScopeKind::Generator {
785+
kind: GeneratorKind::Generator,
786+
..
787+
} => return true,
782788
ScopeKind::Generator { .. }
783789
| ScopeKind::Module
784790
| ScopeKind::Type
@@ -828,14 +834,19 @@ impl SemanticSyntaxContext for Checker<'_> {
828834
self.source_type.is_ipynb()
829835
}
830836

831-
fn in_generator_scope(&self) -> bool {
832-
matches!(
833-
&self.semantic.current_scope().kind,
834-
ScopeKind::Generator {
835-
kind: GeneratorKind::Generator,
836-
..
837+
fn in_generator_context(&self) -> bool {
838+
for scope in self.semantic.current_scopes() {
839+
if matches!(
840+
scope.kind,
841+
ScopeKind::Generator {
842+
kind: GeneratorKind::Generator,
843+
..
844+
}
845+
) {
846+
return true;
837847
}
838-
)
848+
}
849+
false
839850
}
840851

841852
fn in_loop_context(&self) -> bool {

crates/ruff_linter/src/checkers/logical_lines.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use ruff_python_ast::token::{TokenKind, Tokens};
12
use ruff_python_codegen::Stylist;
23
use ruff_python_index::Indexer;
3-
use ruff_python_parser::{TokenKind, Tokens};
44
use ruff_source_file::LineRanges;
55
use ruff_text_size::{Ranged, TextRange};
66

crates/ruff_linter/src/checkers/tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use std::path::Path;
44

55
use ruff_notebook::CellOffsets;
66
use ruff_python_ast::PySourceType;
7+
use ruff_python_ast::token::Tokens;
78
use ruff_python_codegen::Stylist;
89
use ruff_python_index::Indexer;
9-
use ruff_python_parser::Tokens;
1010

1111
use crate::Locator;
1212
use crate::directives::TodoComment;

0 commit comments

Comments
 (0)