Commit fe548261 authored by Matti Picus's avatar Matti Picus
Browse files

merge py3.8 into release

--HG--
branch : release-pypy3.8-v7.x
Pipeline #27658 passed with stage
in 28 minutes and 46 seconds
......@@ -10,6 +10,8 @@ _lock = _thread.allocate_lock()
try: from __pypy__ import builtinify
except ImportError: builtinify = lambda f: f
if sys.platform == 'win32':
raise ImportError("The crypt module is not supported on Windows")
ffi = cffi.FFI()
ffi.cdef('char *crypt(char *word, char *salt);')
......
......@@ -34,6 +34,9 @@ def time_(space):
@unwrap_spec(seconds=float)
def sleep(space, seconds):
'''sleep(seconds: float) -> None
pause for a float number of seconds'''
time.sleep(seconds)
"""
......@@ -67,3 +70,4 @@ class AppTestExtModules(object):
import extmod
assert not hasattr(extmod, '__file__')
assert type(extmod.time()) is float
assert extmod.sleep.__doc__.endswith('float number of seconds')
......@@ -44,6 +44,8 @@ class AppTestBuiltinApp:
assert m.__name__ == "sys"
raises(ImportError, __import__, 'spamspam')
raises(TypeError, __import__, 1, 2, 3, 4)
print(__import__.__doc__)
assert __import__.__doc__.endswith('relative to the current module.')
def test_ascii(self):
assert ascii('') == '\'\''
......
......@@ -11,6 +11,21 @@ class FrozenCache(SpaceCache):
def import_with_frames_removed(space, __args__):
"""__import__(name, globals=None, locals=None, fromlist=(), level=0) -> module
Import a module. Because this function is meant for use by the Python
interpreter and not for general use, it is better to use
importlib.import_module() to programmatically import a module.
The globals argument is only used to determine the context;
they are not modified. The locals argument is unused. The fromlist
should be a list of names to emulate ``from name import ...'', or an
empty list to emulate ``import name''.
When importing a module from a package, note that __import__('A.B', ...)
returns package A when fromlist is empty, but its submodule B when
fromlist is not empty. The level argument is used to determine whether to
perform absolute or relative imports: 0 is absolute, while a positive number
is the number of parent directories to search relative to the current module."""
try:
return space.call_args(
space.fromcache(FrozenCache).w_frozen_import, __args__)
......
......@@ -90,6 +90,8 @@ def _readall(space, filename):
@unwrap_spec(modulename='fsencode', level=int)
def importhook(space, modulename, w_globals=None, w_locals=None, w_fromlist=None, level=0):
# A minimal version, that can only import builtin and lib_pypy modules!
# The actual __import__ is
# pypy.module._frozenimportlib.interp_import.import_with_frames_removed
assert w_locals is w_globals
assert level == 0
......@@ -512,10 +514,14 @@ def is_spec_initializing(space, w_spec):
return space.is_true(w_initializing)
def get_path(space, w_module):
default = space.newtext("unknown location")
try:
return space.getattr(w_module, space.newtext('__file__'))
w_ret = space.getattr(w_module, space.newtext('__file__'))
except OperationError as e:
if not e.match(space, space.w_AttributeError):
raise
return space.newtext("unknown location")
return default
if w_ret is space.w_None:
return default
return w_ret
......@@ -218,6 +218,13 @@ class AppTestImport(BaseFSEncodeTest):
def test_import_namespace_package(self):
import packagenamespace
try:
from packagenamespace import nothing
except ImportError as e:
assert str(e) == ("cannot import name 'nothing' from "
"'packagenamespace' (unknown location)")
else:
assert False
def test_import_sys(self):
import sys
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment