Skip to content

Commit

Permalink
make fields private
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Mar 22, 2024
1 parent 56b28d2 commit a6fc510
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
7 changes: 4 additions & 3 deletions crates/ruff_linter/src/checkers/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2110,7 +2110,8 @@ impl<'a> Checker<'a> {
.flatten()
.collect();

for DunderAllName { name, range } in exports {
for export in exports {
let (name, range) = (export.name(), export.range());
if let Some(binding_id) = self.semantic.global_scope().get(name) {
// Mark anything referenced in `__all__` as used.
self.semantic
Expand All @@ -2120,7 +2121,7 @@ impl<'a> Checker<'a> {
if self.enabled(Rule::UndefinedLocalWithImportStarUsage) {
self.diagnostics.push(Diagnostic::new(
pyflakes::rules::UndefinedLocalWithImportStarUsage {
name: (*name).to_string(),
name: name.to_string(),
},
range,
));
Expand All @@ -2130,7 +2131,7 @@ impl<'a> Checker<'a> {
if !self.path.ends_with("__init__.py") {
self.diagnostics.push(Diagnostic::new(
pyflakes::rules::UndefinedExport {
name: (*name).to_string(),
name: name.to_string(),
},
range,
));
Expand Down
10 changes: 8 additions & 2 deletions crates/ruff_python_ast/src/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ bitflags! {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DunderAllName<'a> {
/// The value of the string inside the `__all__` definition
pub name: &'a str,
name: &'a str,

/// The range of the string inside the `__all__` definition
pub range: TextRange,
range: TextRange,
}

impl DunderAllName<'_> {
pub fn name(&self) -> &str {
self.name
}
}

impl Ranged for DunderAllName<'_> {
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_python_semantic/src/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'a> Definitions<'a> {
let parent = &definitions[member.parent];
if parent.visibility.is_private()
|| exports.is_some_and(|exports| {
!exports.iter().any(|export| export.name == member.name())
!exports.iter().any(|export| export.name() == member.name())
})
{
Visibility::Private
Expand All @@ -224,7 +224,7 @@ impl<'a> Definitions<'a> {
let parent = &definitions[member.parent];
if parent.visibility.is_private()
|| exports.is_some_and(|exports| {
!exports.iter().any(|export| export.name == member.name())
!exports.iter().any(|export| export.name() == member.name())
})
{
Visibility::Private
Expand Down

0 comments on commit a6fc510

Please sign in to comment.