Re-export ruff_python_semantic members (#5094)

## Summary

This PR adds a more unified public API to `ruff_python_semantic`, so
that we don't need to do deeply nested imports all over the place.
This commit is contained in:
Charlie Marsh 2023-06-14 14:23:38 -04:00 committed by GitHub
parent a33bbe6335
commit 86ff1febea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
69 changed files with 129 additions and 146 deletions

View file

@ -1,7 +1,7 @@
use ruff_text_size::TextRange;
use rustpython_parser::ast::Expr;
use ruff_python_semantic::model::Snapshot;
use ruff_python_semantic::Snapshot;
/// A collection of AST nodes that are deferred for later analysis.
/// Used to, e.g., store functions, whose bodies shouldn't be analyzed until all

View file

@ -18,19 +18,13 @@ use ruff_python_ast::types::Node;
use ruff_python_ast::typing::{parse_type_annotation, AnnotationKind};
use ruff_python_ast::visitor::{walk_excepthandler, walk_pattern, Visitor};
use ruff_python_ast::{cast, helpers, str, visitor};
use ruff_python_semantic::analyze;
use ruff_python_semantic::analyze::branch_detection;
use ruff_python_semantic::analyze::typing::{Callable, SubscriptKind};
use ruff_python_semantic::analyze::visibility::ModuleSource;
use ruff_python_semantic::binding::{
Binding, BindingFlags, BindingId, BindingKind, Exceptions, Export, FromImportation,
Importation, StarImportation, SubmoduleImportation,
use ruff_python_semantic::analyze::{branch_detection, typing, visibility};
use ruff_python_semantic::{
Binding, BindingFlags, BindingId, BindingKind, ContextualizedDefinition, Exceptions,
ExecutionContext, Export, FromImportation, Globals, Importation, Module, ModuleKind,
ResolvedRead, Scope, ScopeId, ScopeKind, SemanticModel, SemanticModelFlags, StarImportation,
SubmoduleImportation,
};
use ruff_python_semantic::context::ExecutionContext;
use ruff_python_semantic::definition::{ContextualizedDefinition, Module, ModuleKind};
use ruff_python_semantic::globals::Globals;
use ruff_python_semantic::model::{ResolvedRead, SemanticModel, SemanticModelFlags};
use ruff_python_semantic::scope::{Scope, ScopeId, ScopeKind};
use ruff_python_stdlib::builtins::{BUILTINS, MAGIC_GLOBALS};
use ruff_python_stdlib::path::is_python_stub_file;
@ -2079,7 +2073,7 @@ where
) => {
self.visit_boolean_test(test);
if analyze::typing::is_type_checking_block(stmt_if, &self.semantic_model) {
if typing::is_type_checking_block(stmt_if, &self.semantic_model) {
if self.semantic_model.at_top_level() {
self.importer.visit_type_checking_block(stmt);
}
@ -2179,7 +2173,7 @@ where
Rule::NonPEP604Annotation,
]) {
if let Some(operator) =
analyze::typing::to_pep604_operator(value, slice, &self.semantic_model)
typing::to_pep604_operator(value, slice, &self.semantic_model)
{
if self.enabled(Rule::FutureRewritableTypeAnnotation) {
if self.settings.target_version < PythonVersion::Py310
@ -2211,7 +2205,7 @@ where
if self.settings.target_version < PythonVersion::Py39
&& !self.semantic_model.future_annotations()
&& self.semantic_model.in_annotation()
&& analyze::typing::is_pep585_generic(value, &self.semantic_model)
&& typing::is_pep585_generic(value, &self.semantic_model)
{
flake8_future_annotations::rules::future_required_type_annotation(
self,
@ -2284,7 +2278,7 @@ where
Rule::NonPEP585Annotation,
]) {
if let Some(replacement) =
analyze::typing::to_pep585_generic(expr, &self.semantic_model)
typing::to_pep585_generic(expr, &self.semantic_model)
{
if self.enabled(Rule::FutureRewritableTypeAnnotation) {
if self.settings.target_version < PythonVersion::Py39
@ -2360,8 +2354,7 @@ where
Rule::FutureRewritableTypeAnnotation,
Rule::NonPEP585Annotation,
]) {
if let Some(replacement) =
analyze::typing::to_pep585_generic(expr, &self.semantic_model)
if let Some(replacement) = typing::to_pep585_generic(expr, &self.semantic_model)
{
if self.enabled(Rule::FutureRewritableTypeAnnotation) {
if self.settings.target_version < PythonVersion::Py39
@ -3576,27 +3569,27 @@ where
.semantic_model
.match_typing_call_path(&call_path, "cast")
{
Some(Callable::Cast)
Some(typing::Callable::Cast)
} else if self
.semantic_model
.match_typing_call_path(&call_path, "NewType")
{
Some(Callable::NewType)
Some(typing::Callable::NewType)
} else if self
.semantic_model
.match_typing_call_path(&call_path, "TypeVar")
{
Some(Callable::TypeVar)
Some(typing::Callable::TypeVar)
} else if self
.semantic_model
.match_typing_call_path(&call_path, "NamedTuple")
{
Some(Callable::NamedTuple)
Some(typing::Callable::NamedTuple)
} else if self
.semantic_model
.match_typing_call_path(&call_path, "TypedDict")
{
Some(Callable::TypedDict)
Some(typing::Callable::TypedDict)
} else if [
"Arg",
"DefaultArg",
@ -3608,15 +3601,15 @@ where
.iter()
.any(|target| call_path.as_slice() == ["mypy_extensions", target])
{
Some(Callable::MypyExtension)
Some(typing::Callable::MypyExtension)
} else if call_path.as_slice() == ["", "bool"] {
Some(Callable::Bool)
Some(typing::Callable::Bool)
} else {
None
}
});
match callable {
Some(Callable::Bool) => {
Some(typing::Callable::Bool) => {
self.visit_expr(func);
let mut args = args.iter();
if let Some(arg) = args.next() {
@ -3626,7 +3619,7 @@ where
self.visit_expr(arg);
}
}
Some(Callable::Cast) => {
Some(typing::Callable::Cast) => {
self.visit_expr(func);
let mut args = args.iter();
if let Some(arg) = args.next() {
@ -3636,7 +3629,7 @@ where
self.visit_expr(arg);
}
}
Some(Callable::NewType) => {
Some(typing::Callable::NewType) => {
self.visit_expr(func);
let mut args = args.iter();
if let Some(arg) = args.next() {
@ -3646,7 +3639,7 @@ where
self.visit_type_definition(arg);
}
}
Some(Callable::TypeVar) => {
Some(typing::Callable::TypeVar) => {
self.visit_expr(func);
let mut args = args.iter();
if let Some(arg) = args.next() {
@ -3670,7 +3663,7 @@ where
}
}
}
Some(Callable::NamedTuple) => {
Some(typing::Callable::NamedTuple) => {
self.visit_expr(func);
// Ex) NamedTuple("a", [("a", int)])
@ -3707,7 +3700,7 @@ where
self.visit_type_definition(value);
}
}
Some(Callable::TypedDict) => {
Some(typing::Callable::TypedDict) => {
self.visit_expr(func);
// Ex) TypedDict("a", {"a": int})
@ -3739,7 +3732,7 @@ where
self.visit_type_definition(value);
}
}
Some(Callable::MypyExtension) => {
Some(typing::Callable::MypyExtension) => {
self.visit_expr(func);
let mut args = args.iter();
@ -3801,7 +3794,7 @@ where
self.semantic_model.flags |= SemanticModelFlags::SUBSCRIPT;
visitor::walk_expr(self, expr);
} else {
match analyze::typing::match_annotated_subscript(
match typing::match_annotated_subscript(
value,
&self.semantic_model,
self.settings.typing_modules.iter().map(String::as_str),
@ -3810,13 +3803,13 @@ where
Some(subscript) => {
match subscript {
// Ex) Optional[int]
SubscriptKind::AnnotatedSubscript => {
typing::SubscriptKind::AnnotatedSubscript => {
self.visit_expr(value);
self.visit_type_definition(slice);
self.visit_expr_context(ctx);
}
// Ex) Annotated[int, "Hello, world!"]
SubscriptKind::PEP593AnnotatedSubscript => {
typing::SubscriptKind::PEP593AnnotatedSubscript => {
// First argument is a type (including forward references); the
// rest are arbitrary Python objects.
self.visit_expr(value);
@ -4291,7 +4284,7 @@ impl<'a> Checker<'a> {
&& binding.redefines(shadowed)
&& (!self.settings.dummy_variable_rgx.is_match(name) || shadows_import)
&& !(shadowed.kind.is_function_definition()
&& analyze::visibility::is_overload(
&& visibility::is_overload(
&self.semantic_model,
cast::decorator_list(
self.semantic_model.stmts[shadowed.source.unwrap()],
@ -5298,9 +5291,9 @@ pub(crate) fn check_ast(
ModuleKind::Module
},
source: if let Some(module_path) = module_path.as_ref() {
ModuleSource::Path(module_path)
visibility::ModuleSource::Path(module_path)
} else {
ModuleSource::File(path)
visibility::ModuleSource::File(path)
},
python_ast,
};

View file

@ -2,7 +2,7 @@
use rustpython_parser::ast::{self, Constant, Expr, Stmt};
use ruff_python_semantic::definition::{Definition, DefinitionId, Definitions, Member, MemberKind};
use ruff_python_semantic::{Definition, DefinitionId, Definitions, Member, MemberKind};
/// Extract a docstring from a function or class body.
pub(crate) fn docstring_from(suite: &[Stmt]) -> Option<&Expr> {

View file

@ -4,7 +4,7 @@ use std::ops::Deref;
use ruff_text_size::{TextRange, TextSize};
use rustpython_parser::ast::{Expr, Ranged};
use ruff_python_semantic::definition::Definition;
use ruff_python_semantic::Definition;
pub(crate) mod extraction;
pub(crate) mod google;

View file

@ -10,7 +10,7 @@ use rustpython_parser::ast::{self, Ranged, Stmt, Suite};
use ruff_diagnostics::Edit;
use ruff_python_ast::imports::{AnyImport, Import, ImportFrom};
use ruff_python_ast::source_code::{Locator, Stylist};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_textwrap::indent;
use crate::autofix;

View file

@ -1,6 +1,7 @@
use ruff_python_semantic::model::SemanticModel;
use rustpython_parser::ast::Expr;
use ruff_python_semantic::SemanticModel;
pub(super) fn is_sys(model: &SemanticModel, expr: &Expr, target: &str) -> bool {
model
.resolve_call_path(expr)

View file

@ -2,8 +2,7 @@ use rustpython_parser::ast::{self, Arguments, Expr, Stmt};
use ruff_python_ast::cast;
use ruff_python_semantic::analyze::visibility;
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::{Definition, Member, MemberKind, SemanticModel};
pub(super) fn match_function_def(
stmt: &Stmt,

View file

@ -6,9 +6,7 @@ use ruff_python_ast::helpers::ReturnStatementVisitor;
use ruff_python_ast::statement_visitor::StatementVisitor;
use ruff_python_ast::{cast, helpers};
use ruff_python_semantic::analyze::visibility;
use ruff_python_semantic::analyze::visibility::Visibility;
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::{Definition, Member, MemberKind, SemanticModel};
use ruff_python_stdlib::typing::SIMPLE_MAGIC_RETURN_TYPES;
use crate::checkers::ast::Checker;
@ -453,7 +451,7 @@ fn check_dynamically_typed<F>(
pub(crate) fn definition(
checker: &Checker,
definition: &Definition,
visibility: Visibility,
visibility: visibility::Visibility,
) -> Vec<Diagnostic> {
// TODO(charlie): Consider using the AST directly here rather than `Definition`.
// We could adhere more closely to `flake8-annotations` by defining public
@ -705,7 +703,7 @@ pub(crate) fn definition(
}
} else {
match visibility {
Visibility::Public => {
visibility::Visibility::Public => {
if checker.enabled(Rule::MissingReturnTypeUndocumentedPublicFunction) {
diagnostics.push(Diagnostic::new(
MissingReturnTypeUndocumentedPublicFunction {
@ -715,7 +713,7 @@ pub(crate) fn definition(
));
}
}
Visibility::Private => {
visibility::Visibility::Private => {
if checker.enabled(Rule::MissingReturnTypePrivateFunction) {
diagnostics.push(Diagnostic::new(
MissingReturnTypePrivateFunction {

View file

@ -2,7 +2,7 @@ use once_cell::sync::Lazy;
use regex::Regex;
use rustpython_parser::ast::{self, Constant, Expr};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
static PASSWORD_CANDIDATE_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"(^|_)(?i)(pas+wo?r?d|pass(phrase)?|pwd|token|secrete?)($|_)").unwrap()

View file

@ -5,7 +5,7 @@ use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::Truthiness;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::{
checkers::ast::Checker, registry::Rule, rules::flake8_bandit::helpers::string_literal,

View file

@ -4,7 +4,7 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::identifier_range;
use ruff_python_semantic::analyze::visibility::{is_abstract, is_overload};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;
use crate::registry::Rule;

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Decorator, Expr, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -8,7 +8,7 @@ use ruff_python_ast::call_path::{compose_call_path, from_qualified_name, CallPat
use ruff_python_ast::visitor;
use ruff_python_ast::visitor::Visitor;
use ruff_python_semantic::analyze::typing::is_immutable_func;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;
use crate::rules::flake8_bugbear::rules::mutable_argument_default::is_mutable_func;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::{self, Arguments, Expr, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::analyze::typing::is_immutable_annotation;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::{self, Expr, Keyword, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::is_const_none;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -1,6 +1,6 @@
use rustpython_parser::ast::Expr;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
/// Return `true` if a Python class appears to be a Django model, based on its base classes.
pub(super) fn is_model(model: &SemanticModel, base: &Expr) -> bool {

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Expr, Keyword, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Constant, Expr, Ranged, Stmt};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -4,7 +4,7 @@ use rustpython_parser::ast::{self, Expr, Ranged, Stmt};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -4,7 +4,6 @@ use rustpython_parser::ast::{self, Constant, Expr, Keyword, Operator, Ranged};
use ruff_diagnostics::{Diagnostic, Edit, Fix};
use ruff_python_ast::helpers::{find_keyword, SimpleCallArgs};
use ruff_python_semantic::analyze::logging;
use ruff_python_semantic::analyze::logging::exc_info;
use ruff_python_stdlib::logging::LoggingLevel;
use crate::checkers::ast::Checker;
@ -197,7 +196,7 @@ pub(crate) fn logging_call(
if !checker.semantic_model().in_exception_handler() {
return;
}
let Some(exc_info) = exc_info(keywords, checker.semantic_model()) else {
let Some(exc_info) = logging::exc_info(keywords, checker.semantic_model()) else {
return;
};
if let LoggingCallType::LevelCall(logging_level) = logging_call_type {

View file

@ -4,7 +4,7 @@ use rustpython_parser::ast::{Ranged, Stmt};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::prelude::Expr;
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use crate::checkers::ast::Checker;

View file

@ -4,8 +4,7 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::{identifier_range, map_subscript};
use ruff_python_semantic::analyze::visibility::{is_abstract, is_final, is_overload};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::scope::ScopeKind;
use ruff_python_semantic::{ScopeKind, SemanticModel};
use crate::checkers::ast::Checker;

View file

@ -3,8 +3,7 @@ use rustpython_parser::ast::{self, Arguments, Constant, Expr, Operator, Ranged,
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::source_code::Locator;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::scope::ScopeKind;
use ruff_python_semantic::{ScopeKind, SemanticModel};
use crate::checkers::ast::Checker;
use crate::registry::AsRule;

View file

@ -14,7 +14,7 @@ use ruff_python_ast::source_code::Locator;
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::{helpers, visitor};
use ruff_python_semantic::analyze::visibility::is_abstract;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::autofix::edits::remove_argument;
use crate::checkers::ast::Checker;

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Constant, Decorator, Expr, Keyword};
use ruff_python_ast::call_path::{collect_call_path, CallPath};
use ruff_python_ast::helpers::map_callable;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_python_whitespace::PythonWhitespace;
pub(super) fn get_mark_decorators(

View file

@ -4,7 +4,7 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::call_path::format_call_path;
use ruff_python_ast::call_path::from_qualified_name;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;
use crate::registry::Rule;

View file

@ -10,7 +10,7 @@ use ruff_python_ast::helpers::elif_else_range;
use ruff_python_ast::helpers::is_const_none;
use ruff_python_ast::visitor::Visitor;
use ruff_python_ast::whitespace::indentation;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::autofix::edits;
use crate::checkers::ast::Checker;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::{self, Expr, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::call_path::collect_call_path;
use ruff_python_semantic::scope::ScopeKind;
use ruff_python_semantic::ScopeKind;
use crate::checkers::ast::Checker;

View file

@ -9,7 +9,7 @@ use ruff_python_ast::comparable::{ComparableConstant, ComparableExpr, Comparable
use ruff_python_ast::helpers::{
any_over_expr, contains_effect, first_colon_range, has_comments, has_comments_in,
};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_python_whitespace::UniversalNewlines;
use crate::checkers::ast::Checker;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::{self, Cmpop, Expr, ExprContext, Ranged, Stmt, Unary
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::scope::ScopeKind;
use ruff_python_semantic::ScopeKind;
use crate::checkers::ast::Checker;
use crate::registry::AsRule;

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Expr, Ranged, Stmt};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -2,9 +2,7 @@ use rustpython_parser::ast;
use ruff_python_ast::call_path::from_qualified_name;
use ruff_python_ast::helpers::map_callable;
use ruff_python_semantic::binding::{Binding, BindingKind};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::scope::ScopeKind;
use ruff_python_semantic::{Binding, BindingKind, ScopeKind, SemanticModel};
pub(crate) fn is_valid_runtime_import(semantic_model: &SemanticModel, binding: &Binding) -> bool {
if matches!(

View file

@ -4,9 +4,7 @@ use rustc_hash::FxHashMap;
use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::node::NodeId;
use ruff_python_semantic::reference::ReferenceId;
use ruff_python_semantic::scope::Scope;
use ruff_python_semantic::{NodeId, ReferenceId, Scope};
use crate::autofix;
use crate::checkers::ast::Checker;

View file

@ -4,10 +4,7 @@ use rustc_hash::FxHashMap;
use ruff_diagnostics::{AutofixKind, Diagnostic, DiagnosticKind, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::binding::Binding;
use ruff_python_semantic::node::NodeId;
use ruff_python_semantic::reference::ReferenceId;
use ruff_python_semantic::scope::Scope;
use ruff_python_semantic::{Binding, NodeId, ReferenceId, Scope};
use crate::autofix;
use crate::checkers::ast::Checker;

View file

@ -7,11 +7,8 @@ use rustpython_parser::ast::{Arg, Arguments};
use ruff_diagnostics::DiagnosticKind;
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::analyze::function_type::FunctionType;
use ruff_python_semantic::analyze::visibility;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::scope::{Scope, ScopeKind};
use ruff_python_semantic::analyze::{function_type, visibility};
use ruff_python_semantic::{Scope, ScopeKind, SemanticModel};
use crate::checkers::ast::Checker;
use crate::registry::Rule;
@ -327,7 +324,7 @@ pub(crate) fn unused_arguments(
&checker.settings.pep8_naming.classmethod_decorators,
&checker.settings.pep8_naming.staticmethod_decorators,
) {
FunctionType::Function => {
function_type::FunctionType::Function => {
if checker.enabled(Argumentable::Function.rule_code())
&& !visibility::is_overload(checker.semantic_model(), decorator_list)
{
@ -346,7 +343,7 @@ pub(crate) fn unused_arguments(
vec![]
}
}
FunctionType::Method => {
function_type::FunctionType::Method => {
if checker.enabled(Argumentable::Method.rule_code())
&& !helpers::is_empty(body)
&& (!visibility::is_magic(name)
@ -372,7 +369,7 @@ pub(crate) fn unused_arguments(
vec![]
}
}
FunctionType::ClassMethod => {
function_type::FunctionType::ClassMethod => {
if checker.enabled(Argumentable::ClassMethod.rule_code())
&& !helpers::is_empty(body)
&& (!visibility::is_magic(name)
@ -398,7 +395,7 @@ pub(crate) fn unused_arguments(
vec![]
}
}
FunctionType::StaticMethod => {
function_type::FunctionType::StaticMethod => {
if checker.enabled(Argumentable::StaticMethod.rule_code())
&& !helpers::is_empty(body)
&& (!visibility::is_magic(name)

View file

@ -1,8 +1,7 @@
use rustpython_parser::ast;
use rustpython_parser::ast::Expr;
use ruff_python_semantic::binding::{BindingKind, Importation};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::{BindingKind, Importation, SemanticModel};
pub(super) enum Resolution {
/// The expression resolves to an irrelevant expression type (e.g., a constant).

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Constant, Expr, Keyword, Ranged};
use ruff_diagnostics::{AutofixKind, Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::binding::{BindingKind, Importation};
use ruff_python_semantic::{BindingKind, Importation};
use crate::checkers::ast::Checker;
use crate::registry::AsRule;

View file

@ -1,7 +1,7 @@
use itertools::Itertools;
use rustpython_parser::ast::{self, Expr, Stmt};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_python_stdlib::str::{is_lower, is_upper};
pub(super) fn is_camelcase(name: &str) -> bool {

View file

@ -4,7 +4,7 @@ use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::identifier_range;
use ruff_python_ast::source_code::Locator;
use ruff_python_semantic::scope::{Scope, ScopeKind};
use ruff_python_semantic::{Scope, ScopeKind};
use crate::settings::types::IdentifierPattern;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::{Arguments, Decorator, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::scope::Scope;
use ruff_python_semantic::Scope;
use crate::checkers::ast::Checker;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::{Arguments, Decorator, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::scope::Scope;
use ruff_python_semantic::Scope;
use crate::checkers::ast::Checker;

View file

@ -5,7 +5,7 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::identifier_range;
use ruff_python_ast::source_code::Locator;
use ruff_python_semantic::analyze::visibility;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::settings::types::IdentifierPattern;

View file

@ -5,7 +5,7 @@ use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::{has_leading_content, has_trailing_content};
use ruff_python_ast::source_code::Generator;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_python_whitespace::{leading_indentation, UniversalNewlines};
use crate::checkers::ast::Checker;

View file

@ -4,8 +4,7 @@ use ruff_python_ast::call_path::from_qualified_name;
use ruff_python_ast::cast;
use ruff_python_ast::helpers::map_callable;
use ruff_python_ast::str::is_implicit_concatenation;
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::{Definition, Member, MemberKind, SemanticModel};
use ruff_python_whitespace::UniversalNewlines;
/// Return the index of the first logical line in a string.

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::Ranged;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use ruff_python_whitespace::{PythonWhitespace, UniversalNewlineIterator, UniversalNewlines};
use crate::checkers::ast::Checker;

View file

@ -5,7 +5,7 @@ use rustpython_parser::ast::Ranged;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use ruff_python_whitespace::{PythonWhitespace, UniversalNewlineIterator, UniversalNewlines};
use crate::checkers::ast::Checker;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::Ranged;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use crate::checkers::ast::Checker;
use crate::docstrings::Docstring;

View file

@ -3,7 +3,7 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::cast;
use ruff_python_ast::helpers::identifier_range;
use ruff_python_semantic::analyze::visibility::is_overload;
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use crate::checkers::ast::Checker;
use crate::docstrings::Docstring;

View file

@ -4,7 +4,7 @@ use rustpython_parser::ast::Ranged;
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::str::{is_triple_quote, leading_quote};
use ruff_python_semantic::definition::{Definition, Member};
use ruff_python_semantic::{Definition, Member};
use ruff_python_whitespace::{NewlineWithTrailingNewline, UniversalNewlineIterator};
use crate::checkers::ast::Checker;

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{self, Stmt};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use ruff_python_whitespace::UniversalNewlines;
use crate::checkers::ast::Checker;

View file

@ -8,7 +8,7 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::call_path::{from_qualified_name, CallPath};
use ruff_python_ast::cast;
use ruff_python_semantic::analyze::visibility::{is_property, is_test};
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use ruff_python_whitespace::UniversalNewlines;
use crate::checkers::ast::Checker;

View file

@ -7,7 +7,7 @@ use ruff_python_ast::helpers::identifier_range;
use ruff_python_semantic::analyze::visibility::{
is_call, is_init, is_magic, is_new, is_overload, is_override, Visibility,
};
use ruff_python_semantic::definition::{Definition, Member, MemberKind, Module, ModuleKind};
use ruff_python_semantic::{Definition, Member, MemberKind, Module, ModuleKind};
use crate::checkers::ast::Checker;
use crate::registry::Rule;

View file

@ -12,7 +12,7 @@ use ruff_python_ast::cast;
use ruff_python_ast::docstrings::{clean_space, leading_space};
use ruff_python_ast::helpers::identifier_range;
use ruff_python_semantic::analyze::visibility::is_staticmethod;
use ruff_python_semantic::definition::{Definition, Member, MemberKind};
use ruff_python_semantic::{Definition, Member, MemberKind};
use ruff_python_whitespace::NewlineWithTrailingNewline;
use ruff_textwrap::dedent;

View file

@ -2,7 +2,7 @@ use rustpython_parser::ast::{Ranged, Stmt};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::scope::ScopeKind;
use ruff_python_semantic::ScopeKind;
use crate::checkers::ast::Checker;

View file

@ -2,7 +2,7 @@ use ruff_text_size::TextRange;
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::scope::Scope;
use ruff_python_semantic::Scope;
/// ## What it does
/// Checks for undefined names in `__all__`.

View file

@ -1,6 +1,6 @@
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::scope::ScopeId;
use ruff_python_semantic::ScopeId;
use crate::checkers::ast::Checker;

View file

@ -4,9 +4,7 @@ use rustc_hash::FxHashMap;
use ruff_diagnostics::{AutofixKind, Diagnostic, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::binding::Exceptions;
use ruff_python_semantic::node::NodeId;
use ruff_python_semantic::scope::Scope;
use ruff_python_semantic::{Exceptions, NodeId, Scope};
use crate::autofix;
use crate::checkers::ast::Checker;

View file

@ -7,7 +7,7 @@ use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::contains_effect;
use ruff_python_ast::source_code::Locator;
use ruff_python_semantic::scope::ScopeId;
use ruff_python_semantic::ScopeId;
use crate::autofix::edits::delete_stmt;
use crate::checkers::ast::Checker;

View file

@ -4,7 +4,7 @@ use rustpython_parser::ast::{Expr, Ranged};
use ruff_diagnostics::{Diagnostic, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::scope::ScopeKind;
use ruff_python_semantic::ScopeKind;
use crate::checkers::ast::Checker;

View file

@ -1,10 +1,10 @@
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::analyze::function_type::FunctionType;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::scope::ScopeKind;
use std::fmt;
use rustpython_parser::ast;
use rustpython_parser::ast::Cmpop;
use std::fmt;
use ruff_python_semantic::analyze::function_type;
use ruff_python_semantic::{ScopeKind, SemanticModel};
use crate::settings::Settings;
@ -40,7 +40,7 @@ pub(super) fn in_dunder_init(model: &SemanticModel, settings: &Settings) -> bool
&settings.pep8_naming.classmethod_decorators,
&settings.pep8_naming.staticmethod_decorators,
),
FunctionType::Method
function_type::FunctionType::Method
) {
return false;
}

View file

@ -4,7 +4,7 @@ use rustpython_parser::ast::{self, Expr, Keyword, Ranged};
use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::has_comments;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::{checkers::ast::Checker, registry::AsRule};

View file

@ -8,7 +8,7 @@ use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::comparable::ComparableExpr;
use ruff_python_ast::statement_visitor::{walk_stmt, StatementVisitor};
use ruff_python_ast::types::Node;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;

View file

@ -7,7 +7,7 @@ use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::is_dunder;
use ruff_python_ast::source_code::Generator;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_python_stdlib::identifiers::is_identifier;
use crate::checkers::ast::Checker;

View file

@ -7,7 +7,7 @@ use ruff_diagnostics::{AutofixKind, Diagnostic, Edit, Fix, Violation};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::helpers::is_dunder;
use ruff_python_ast::source_code::Generator;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_python_stdlib::identifiers::is_identifier;
use crate::checkers::ast::Checker;

View file

@ -4,7 +4,7 @@ use rustpython_parser::ast::{self, Excepthandler, Expr, ExprContext, Ranged};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_ast::call_path::compose_call_path;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use crate::checkers::ast::Checker;
use crate::registry::AsRule;

View file

@ -1,7 +1,7 @@
use ruff_python_ast::helpers::map_callable;
use rustpython_parser::ast::{self, Expr};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
pub(super) fn is_mutable_expr(expr: &Expr) -> bool {
matches!(

View file

@ -5,7 +5,7 @@ use rustpython_parser::ast::{self, Arguments, Constant, Expr, Operator, Ranged};
use ruff_diagnostics::{AlwaysAutofixableViolation, Diagnostic, Edit, Fix};
use ruff_macros::{derive_message_formats, violation};
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
use ruff_text_size::TextRange;
use crate::checkers::ast::Checker;

View file

@ -3,7 +3,7 @@ use rustpython_parser::ast::{self, Expr};
use ruff_python_ast::visitor;
use ruff_python_ast::visitor::Visitor;
use ruff_python_semantic::analyze::logging;
use ruff_python_semantic::model::SemanticModel;
use ruff_python_semantic::SemanticModel;
/// Collect `logging`-like calls from an AST.
pub(super) struct LoggerCandidateVisitor<'a, 'b> {

View file

@ -1,9 +1,18 @@
pub mod analyze;
pub mod binding;
pub mod context;
pub mod definition;
pub mod globals;
pub mod model;
pub mod node;
pub mod reference;
pub mod scope;
mod binding;
mod context;
mod definition;
mod globals;
mod model;
mod node;
mod reference;
mod scope;
pub use binding::*;
pub use context::*;
pub use definition::*;
pub use globals::*;
pub use model::*;
pub use node::*;
pub use reference::*;
pub use scope::*;