Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stubtest: Improve heuristics for determining whether global-namespace…
… names are imported (#14270) Stubtest currently has both false-positives and false-negatives when it comes to verifying constants in the global namespace of a module. This PR fixes the false positive by using `inspect.getsourcelines()` to dynamically retrieve the module source code. It then uses `symtable` to analyse that source code to gather a list of names which are known to be imported. The PR fixes the false negative by only using the `__module__` heuristic on objects which are callable. The vast majority of callable objects will be types or functions. For these objects, the `__module__` attribute will give a good indication of whether the object originates from another module or not; for other objects, it's less useful.
- Loading branch information