mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[ty] improve lazy scope place lookup (#19321)
Co-authored-by: David Peter <sharkdp@users.noreply.github.com> Co-authored-by: Carl Meyer <carl@oddbird.net> Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
57373a7e4d
commit
b124e182ca
15 changed files with 493 additions and 179 deletions
|
@ -768,12 +768,14 @@ fn place_by_id<'db>(
|
|||
.expr
|
||||
.is_name_and(|name| matches!(name, "__slots__" | "TYPE_CHECKING"));
|
||||
|
||||
if scope.file(db).is_stub(db) {
|
||||
if scope.file(db).is_stub(db) || scope.scope(db).visibility().is_private() {
|
||||
// We generally trust module-level undeclared places in stubs and do not union
|
||||
// with `Unknown`. If we don't do this, simple aliases like `IOError = OSError` in
|
||||
// stubs would result in `IOError` being a union of `OSError` and `Unknown`, which
|
||||
// leads to all sorts of downstream problems. Similarly, type variables are often
|
||||
// defined as `_T = TypeVar("_T")`, without being declared.
|
||||
// Also, if the scope is private, such as a function scope,
|
||||
// meaning that the place cannot be rewritten from elsewhere, we do not union with `Unknown`.
|
||||
|
||||
inferred.into()
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue