Respect all `__all__` definitions for docstring visibility (#5052)

## Summary

We changed the semantics around `__all__` in #4885, but didn't update
the docstring visibility code to match those changes.
This commit is contained in:
Charlie Marsh 2023-06-13 12:22:20 -04:00 committed by GitHub
parent 099a9152d1
commit a431dd0368
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 10 deletions

View File

@ -5038,21 +5038,26 @@ impl<'a> Checker<'a> {
}
// Compute visibility of all definitions.
let global_scope = self.semantic_model.global_scope();
let exports: Option<&[&str]> = global_scope
.get("__all__")
.map(|binding_id| &self.semantic_model.bindings[binding_id])
.and_then(|binding| match &binding.kind {
BindingKind::Export(Export { names }) => Some(names.as_slice()),
_ => None,
});
let definitions = std::mem::take(&mut self.semantic_model.definitions);
let exports: Option<Vec<&str>> = {
let global_scope = self.semantic_model.global_scope();
global_scope
.bindings_for_name("__all__")
.map(|binding_id| &self.semantic_model.bindings[binding_id])
.filter_map(|binding| match &binding.kind {
BindingKind::Export(Export { names }) => Some(names.iter().copied()),
_ => None,
})
.fold(None, |acc, names| {
Some(acc.into_iter().flatten().chain(names).collect())
})
};
let definitions = std::mem::take(&mut self.semantic_model.definitions);
let mut overloaded_name: Option<String> = None;
for ContextualizedDefinition {
definition,
visibility,
} in definitions.resolve(exports).iter()
} in definitions.resolve(exports.as_deref()).iter()
{
let docstring = docstrings::extraction::extract_docstring(definition);