Commit 31b0413
authored
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.1 parent 2514610 commit 31b0413
2 files changed
+47
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
283 | 284 | | |
284 | 285 | | |
285 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
286 | 317 | | |
287 | 318 | | |
288 | 319 | | |
| |||
312 | 343 | | |
313 | 344 | | |
314 | 345 | | |
| 346 | + | |
| 347 | + | |
315 | 348 | | |
316 | 349 | | |
317 | | - | |
318 | | - | |
319 | | - | |
| 350 | + | |
320 | 351 | | |
321 | | - | |
322 | | - | |
323 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
324 | 362 | | |
325 | 363 | | |
326 | 364 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1082 | 1082 | | |
1083 | 1083 | | |
1084 | 1084 | | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1085 | 1088 | | |
1086 | 1089 | | |
1087 | 1090 | | |
| |||
0 commit comments