MCPcopy Create free account
hub / github.com/astral-sh/ruff / check_stmt

Method check_stmt

crates/ruff_python_parser/src/semantic_errors.rs:79–376  ·  view source on GitHub ↗
(&mut self, stmt: &ast::Stmt, ctx: &Ctx)

Source from the content-addressed store, hash-verified

77 }
78
79 fn check_stmt<Ctx: SemanticSyntaxContext>(&mut self, stmt: &ast::Stmt, ctx: &Ctx) {
80 match stmt {
81 Stmt::ImportFrom(import_from) => {
82 let StmtImportFrom {
83 range,
84 module,
85 level,
86 names,
87 is_lazy,
88 ..
89 } = import_from;
90 let mut handled_lazy_error = false;
91
92 if *is_lazy {
93 // test_ok lazy_import_semantic_ok_py315
94 // # parse_options: {"target-version": "3.15"}
95 // import contextlib
96 // with contextlib.nullcontext():
97 // lazy import os
98 // with contextlib.nullcontext():
99 // lazy from sys import path
100 // lazy from .__future__ import feature
101
102 // test_err lazy_import_invalid_context_py315
103 // # parse_options: {"target-version": "3.15"}
104 // try:
105 // lazy import os
106 // except:
107 // pass
108 //
109 // try:
110 // x
111 // except* Exception:
112 // lazy import sys
113 //
114 // def func():
115 // lazy import math
116 //
117 // async def async_func():
118 // lazy from json import loads
119 //
120 // class MyClass:
121 // lazy import typing
122 //
123 // def outer():
124 // class Inner:
125 // lazy import json
126 if Self::check_lazy_import_context(ctx, *range, LazyImportKind::ImportFrom) {
127 handled_lazy_error = true;
128 } else if names.iter().any(|alias| alias.name.as_str() == "*") {
129 // test_err lazy_import_invalid_from_py315
130 // # parse_options: {"target-version": "3.15"}
131 // lazy from os import *
132 // lazy from __future__ import annotations
133 //
134 // def func():
135 // lazy from sys import *
136 Self::add_error(ctx, SemanticSyntaxErrorKind::LazyImportStar, *range);

Callers 1

visit_stmtMethod · 0.80

Calls 15

is_known_future_featureFunction · 0.85
check_annotationFunction · 0.85
format_import_fromFunction · 0.50
defaultFunction · 0.50
anyMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45
is_future_importMethod · 0.45
python_versionMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected