Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion packages/pyright-internal/src/analyzer/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,32 @@ export class Binder extends ParseTreeWalker {
return true;
}

// A source file was found, but the type stub was missing.
// See if a source file was found but it's not part of a py.typed
// library and no type stub is found.
let reportStubMissing = false;
if (
!importResult.isStubFile &&
importResult.importType === ImportType.ThirdParty &&
!importResult.pyTypedInfo
) {
reportStubMissing = true;

// If the import is a namespace package, it's possible that all of
// the targeted import symbols are py.typed submodules. In this case,
// suppress the missing stub diagnostic.
if (importResult.isNamespacePackage && node.parent?.nodeType === ParseNodeType.ImportFrom) {
if (
node.parent.d.imports.every((importAs) => {
const implicitImport = importResult.filteredImplicitImports.get(importAs.d.name.d.value);
return !!implicitImport?.pyTypedInfo;
})
) {
reportStubMissing = false;
}
}
}

if (reportStubMissing) {
const diagnostic = this._addDiagnostic(
DiagnosticRule.reportMissingTypeStubs,
LocMessage.stubFileMissing().format({ importName: importResult.importName }),
Expand Down