[ty] No union with Unknown for module-global symbols
This commit is contained in:
@@ -822,7 +822,9 @@ fn place_by_id<'db>(
|
||||
)
|
||||
});
|
||||
|
||||
if scope.file(db).is_stub(db) || scope.scope(db).visibility().is_private() {
|
||||
if scope.node(db).scope_kind().is_module() {
|
||||
inferred.map_type(|ty| ty.promote_literals(db)).into()
|
||||
} else 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
|
||||
|
||||
@@ -6227,6 +6227,12 @@ impl<'db> Type<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Replaces any literal types with their corresponding promoted type form (e.g. `Literal["string"]`
|
||||
/// to `str`, or `def _() -> int` to `Callable[[], int]`).
|
||||
pub(crate) fn promote_literals(self, db: &'db dyn Db) -> Type<'db> {
|
||||
self.apply_type_mapping(db, &TypeMapping::PromoteLiterals)
|
||||
}
|
||||
|
||||
/// Locates any legacy `TypeVar`s in this type, and adds them to a set. This is used to build
|
||||
/// up a generic context from any legacy `TypeVar`s that appear in a function parameter list or
|
||||
/// `Generic` specialization.
|
||||
|
||||
Reference in New Issue
Block a user