Support --package-root with native parser#21321
Conversation
This comment has been minimized.
This comment has been minimized.
JukkaL
left a comment
There was a problem hiding this comment.
The way the fake package cache interacts with the native parser is pretty sketchy and we may want to do it differently eventually, but this is fine as a quick fix.
| if st is None: | ||
| return False | ||
| if real_only: | ||
| dirname, _ = os.path.split(path) |
There was a problem hiding this comment.
os.path.dirname(path) may be faster, as it may construct one fewer substring (but haven't verified).
There was a problem hiding this comment.
OoC I checked and it is indeed ~20% faster.
Yeah, |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
When
--package-rootis used,fscachecreates some fake__init__.pyfiles on-the-fly (that don't actually exist). These obviously can't be handed by the native parser, butfscache.exists()returnsTruefor them, causing a crash. One possible fix is to simply useos.path.isfile()everywhere. But I thinkfscachecan give us a little perf boost, so I instead add areal_onlyflag tofscache.exists().cc @JukkaL