Match import name ignores against both name and alias (#12033)

## Summary

Right now, it's inconsistent... We sometimes match against the name, and
sometimes against the alias (`asname`). I could see a case for always
matching against the name, but matching against both seems fine too,
since the rule is really about the combination of the two?

Closes https://github.com/astral-sh/ruff/issues/12031.
This commit is contained in:
Charlie Marsh 2024-06-25 18:47:19 -04:00 committed by GitHub
parent 00e456ead4
commit 83fe44728b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 5 additions and 5 deletions

View file

@ -62,7 +62,7 @@ pub(crate) fn camelcase_imported_as_acronym(
&& helpers::is_acronym(name, asname)
{
// Ignore any explicitly-allowed names.
if ignore_names.matches(name) {
if ignore_names.matches(name) || ignore_names.matches(asname) {
return None;
}
let mut diagnostic = Diagnostic::new(

View file

@ -59,7 +59,7 @@ pub(crate) fn camelcase_imported_as_constant(
&& !helpers::is_acronym(name, asname)
{
// Ignore any explicitly-allowed names.
if ignore_names.matches(asname) {
if ignore_names.matches(name) || ignore_names.matches(asname) {
return None;
}
let mut diagnostic = Diagnostic::new(

View file

@ -54,7 +54,7 @@ pub(crate) fn camelcase_imported_as_lowercase(
) -> Option<Diagnostic> {
if helpers::is_camelcase(name) && ruff_python_stdlib::str::is_cased_lowercase(asname) {
// Ignore any explicitly-allowed names.
if ignore_names.matches(asname) {
if ignore_names.matches(name) || ignore_names.matches(asname) {
return None;
}
let mut diagnostic = Diagnostic::new(

View file

@ -54,7 +54,7 @@ pub(crate) fn constant_imported_as_non_constant(
) -> Option<Diagnostic> {
if str::is_cased_uppercase(name) && !str::is_cased_uppercase(asname) {
// Ignore any explicitly-allowed names.
if ignore_names.matches(asname) {
if ignore_names.matches(name) || ignore_names.matches(asname) {
return None;
}
let mut diagnostic = Diagnostic::new(

View file

@ -54,7 +54,7 @@ pub(crate) fn lowercase_imported_as_non_lowercase(
if !str::is_cased_uppercase(name) && str::is_cased_lowercase(name) && !str::is_lowercase(asname)
{
// Ignore any explicitly-allowed names.
if ignore_names.matches(asname) {
if ignore_names.matches(name) || ignore_names.matches(asname) {
return None;
}
let mut diagnostic = Diagnostic::new(