microsoft / pylance-release

Documentation and issues for Pylance
Creative Commons Attribution 4.0 International
1.7k stars 768 forks source link

`reportShadowedImports` doesn't report diagnostics for files that are overriding a `stdlib` module #5979

Open StellaHuang95 opened 3 months ago

StellaHuang95 commented 3 months ago

Environment data

Repro Steps

  1. Create a workspace in VSCode
  2. Set the "reportShadowedImports": "error" in settings.json
  3. Create 2 python files sys.py and mailbox.py

Expected behavior

I am expecting to see 2 diagnostics:

"xxx\folder1\mailbox.py" is overriding the stdlib module "mailbox" and "xxx\folder1\sys.py" is overriding the stdlib module "sys"

Actual behavior

Only getting 1 diagnostic:

"xxx\folder1\mailbox.py" is overriding the stdlib module "mailbox"

Only repros with certain stdlib modules such as os, json, sys

StellaHuang95 commented 3 months ago

The _buildStdlibCache in importResolver.ts finds all the stdlib modules in typeshed stdlib to return a Set with all the names. sys in typeshed is a directory but not a file, so it doesn't get added in.