Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc47a89

Browse files
committed
SF patch 483059: Avoid use of eval() in random.py, from Finn Bock.
_verify(): Pass in the values of globals insted of eval()ing their names. The use of eval() was obscure and unnecessary, and the patch claimed random.py couldn't be used in Jython applets because of it.
1 parent 652e191 commit dc47a89

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Lib/random.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,23 @@ def create_generators(num, delta, firstseed=None):
8282
"stdgamma","gauss","betavariate","paretovariate","weibullvariate",
8383
"getstate","setstate","jumpahead","whseed"]
8484

85-
def _verify(name, expected):
86-
computed = eval(name)
85+
def _verify(name, computed, expected):
8786
if abs(computed - expected) > 1e-7:
8887
raise ValueError(
8988
"computed value for %s deviates too much "
9089
"(computed %g, expected %g)" % (name, computed, expected))
9190

9291
NV_MAGICCONST = 4 * _exp(-0.5)/_sqrt(2.0)
93-
_verify('NV_MAGICCONST', 1.71552776992141)
92+
_verify('NV_MAGICCONST', NV_MAGICCONST, 1.71552776992141)
9493

9594
TWOPI = 2.0*_pi
96-
_verify('TWOPI', 6.28318530718)
95+
_verify('TWOPI', TWOPI, 6.28318530718)
9796

9897
LOG4 = _log(4.0)
99-
_verify('LOG4', 1.38629436111989)
98+
_verify('LOG4', LOG4, 1.38629436111989)
10099

101100
SG_MAGICCONST = 1.0 + _log(4.5)
102-
_verify('SG_MAGICCONST', 2.50407739677627)
101+
_verify('SG_MAGICCONST', SG_MAGICCONST, 2.50407739677627)
103102

104103
del _verify
105104

0 commit comments

Comments
 (0)