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

Method check_stmt

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

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
to_stringMethod · 0.45
in_module_scopeMethod · 0.45
visit_patternMethod · 0.45

Tested by

no test coverage detected