Description
When checking local test files against an installed stub-only package (e.g. pandas-stubs), Pyrefly resolves third-party types inconsistently between the two contexts. This leads to false-positive type mismatch errors where the identical underlying type is treated as two separate nominal types.
For example, when both contexts import openpyxl.workbook.workbook.Workbook:
- The installed stub package resolves it to the source implementation (
<site-packages>/openpyxl/workbook/workbook.py at line 51).
- The local test file resolves it to Pyrefly's bundled typeshed stub (
<pyrefly-typeshed>/stubs/openpyxl/openpyxl/workbook/workbook.pyi at line 39).
This causes assert-type and bad-specialization errors because Workbook@39 is not recognized as the same type as Workbook@51.
(Note: See pandas-dev/pandas-stubs#1801 for the original upstream issue where this was identified).
To Reproduce
Using the pandas-stubs repository:
- Clone
pandas-stubs and install dependencies.
pyrefly_dist is currently disabled in main. Re-enable it by uncommenting _step.pyrefly_dist in scripts/test/__init__.py under _DIST_STEPS.
- Run
poe pyrefly_dist (this command builds/installs the pandas-stubs wheel, hides the local source directory, and runs pyrefly check tests).
Observed Error:
ERROR assert_type(ExcelWriter[Workbook], ExcelWriter[Workbook]) failed [assert-type]
--> tests/test_io.py:1360:24
ERROR `openpyxl.workbook.workbook.Workbook@39:7-15` is not assignable to upper bound `OpenDocument | xlsxwriter.workbook.Workbook | openpyxl.workbook.workbook.Workbook@51:7-15` of type variable `_WorkbookT` [bad-specialization]
--> tests/test_io.py:1360:29
Expected Behavior
Pyrefly should resolve the third-party import consistently to the same path (either both to the typeshed stub or both to the site-packages source) regardless of whether the import originates from an installed package or a local test file, avoiding split-identity errors.
Description
When checking local test files against an installed stub-only package (e.g.
pandas-stubs), Pyrefly resolves third-party types inconsistently between the two contexts. This leads to false-positive type mismatch errors where the identical underlying type is treated as two separate nominal types.For example, when both contexts import
openpyxl.workbook.workbook.Workbook:<site-packages>/openpyxl/workbook/workbook.pyat line 51).<pyrefly-typeshed>/stubs/openpyxl/openpyxl/workbook/workbook.pyiat line 39).This causes
assert-typeandbad-specializationerrors becauseWorkbook@39is not recognized as the same type asWorkbook@51.(Note: See pandas-dev/pandas-stubs#1801 for the original upstream issue where this was identified).
To Reproduce
Using the
pandas-stubsrepository:pandas-stubsand install dependencies.pyrefly_distis currently disabled in main. Re-enable it by uncommenting_step.pyrefly_distinscripts/test/__init__.pyunder_DIST_STEPS.poe pyrefly_dist(this command builds/installs thepandas-stubswheel, hides the local source directory, and runspyrefly check tests).Observed Error:
Expected Behavior
Pyrefly should resolve the third-party import consistently to the same path (either both to the typeshed stub or both to the site-packages source) regardless of whether the import originates from an installed package or a local test file, avoiding split-identity errors.