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

Method check_stmt

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

Source from the content-addressed store, hash-verified

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