py3: conditionalize test-demandimport.py for Python 3
ClosedPublic

Authored by indygreg on Feb 1 2019, 7:48 PM.

Details

Summary

The Python 3 lazy importer uses the LazyLoader that is part of
importlib.

On Python 3 and later, LazyLoader is implemented using a custom module
type that defines a getattribute which triggers module loading.

Furthermore, there are additional differences as well. For example,
it appears that Python 3 will return an existing sys.modules
entry instead of constructing a new module object.

This commit adds additional test coverage for lazy importing
behavior to cover the differences between Python 2 and 3. This
reveals that the test and some lazy import functionality is kinda
busted. For example, the test assumes "contextlib" will be lazy.
But in reality an import before it has already imported contextlib!

There's definitely room to improve the behavior of the demand
importer code, both for Python 2 and 3. But at least the test
passes on Python 3 now.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped
indygreg created this revision.Feb 1 2019, 7:48 PM
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Feb 1 2019, 10:52 PM

Fixed various check-code errors by black -l 80 -S tests/test-demandimport.py.

indygreg updated this revision to Diff 13697.Feb 2 2019, 12:07 AM

I didn't realize this was already queued with formatting changes fixed in flight. Ignore my latest upload.