facebookincubator / cinder

Cinder is Meta's internal performance-oriented production version of CPython.
https://trycinder.com
Other
3.42k stars 122 forks source link

Add lazy import error in import from #83

Closed chuanzzx closed 2 years ago

chuanzzx commented 2 years ago

Summary

Test Plan

Pre-req

We has the same test plan as https://github.com/facebookincubator/cinder/pull/82, but we additionally create foo2.py and run_foo2.py under the same path of python.exe.

foo2.py

from bakery import applepie
applepie

run_foo2.py

import foo2
foo2

Test without Lazy Import

Run

./python.exe run_foo2.py

Expected result:

Traceback (most recent call last):
  File "/Users/harperlin/Documents/GitHub/crashy_0623/run_foo2.py", line 1, in <module>
    import foo2
    ^^^^^^^^^^^
  File "/Users/harperlin/Documents/GitHub/crashy_0623/foo2.py", line 1, in <module>
    from bakery import applepie
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'bakery'

Other testing results should be the same as https://github.com/facebookincubator/cinder/pull/82.

Test with Lazy Import

Run

./python.exe -L run_foo2.py

Expected result:

Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'bakery'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/harperlin/Documents/GitHub/crashy_0623/run_foo2.py", line 2, in <module>
    foo2
    ^^^^
  File "/Users/harperlin/Documents/GitHub/crashy_0623/foo2.py", line 2, in <module>
    applepie
    ^^^^^^^^
LazyImportError: Error occurred when loading a lazy import. Original import was at file /Users/harperlin/Documents/GitHub/crashy_0623/foo2.py, line 1

Other testing results should be the same as https://github.com/facebookincubator/cinder/pull/82.

Fix test_doctest failure in cinder3.10

We should increase one object count in builtins for LazyImportError. Therefore, if we change the upper bound value from 836 to 837, we can fix this testing failure. image

chuanzzx commented 2 years ago

I rebased this PR, so it only contains new changes now. Thank you. 😃