Skip to content

Commit 215190e

Browse files
committed
Fix ImportError on wasm.
1 parent 88c1b86 commit 215190e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

Lib/random.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,19 @@
4141
from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
4242
from math import log as _log, exp as _exp, pi as _pi, e as _e, ceil as _ceil
4343
from math import sqrt as _sqrt, acos as _acos, cos as _cos, sin as _sin
44-
from os import urandom as _urandom
44+
try:
45+
from os import urandom as _urandom
46+
import os as _os
47+
except ImportError:
48+
# On wasm, _random.Random.random() does give a proper random value, but
49+
# we don't have the os module
50+
def _urandom(*args, **kwargs):
51+
raise NotImplementedError("urandom")
52+
_os = None
4553
from _collections_abc import Set as _Set, Sequence as _Sequence
4654
from hashlib import sha512 as _sha512
4755
import itertools as _itertools
4856
import bisect as _bisect
49-
import os as _os
5057

5158
__all__ = ["Random","seed","random","uniform","randint","choice","sample",
5259
"randrange","shuffle","normalvariate","lognormvariate",

0 commit comments

Comments
 (0)