-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve DeprecationWarning: Seeding based on hashing #656
Conversation
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
Pull Request Test Coverage Report for Build 8238402266Details
💛 - Coveralls |
columns, rows = 3, 10 | ||
table = randomtable(columns, rows) | ||
|
||
assert len(table[0]) == columns |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
columns, rows = 4, 60 | ||
table = RandomTable(numflds=columns, numrows=rows, wait=0, seed=None) | ||
|
||
assert len(table[0]) == columns |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
fields=columns, | ||
) | ||
assert len(table[0]) == 4 | ||
assert len(table) == rows + 1 |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
table = randomtable(columns, rows) | ||
|
||
assert len(table[0]) == columns | ||
assert len(table) == rows + 1 |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
rows = 70 | ||
table = dummytable(numrows=rows, fields=None, wait=0, seed=None) | ||
|
||
assert len(table) == rows + 1 |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
numrows=rows, | ||
seed=42 | ||
) | ||
assert len(table[0]) == 3 |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
table = RandomTable(numflds=columns, numrows=rows, wait=0, seed=None) | ||
|
||
assert len(table[0]) == columns | ||
assert len(table) == rows + 1 |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
table = randomtable(columns, rows) | ||
|
||
assert len(table[0]) == columns | ||
assert len(table) == rows + 1 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
fields=columns, | ||
) | ||
assert len(table[0]) == 4 | ||
assert len(table) == rows + 1 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
rows = 70 | ||
table = dummytable(numrows=rows, fields=None, wait=0, seed=None) | ||
|
||
assert len(table) == rows + 1 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
numrows=rows, | ||
) | ||
assert len(table[0]) == 3 | ||
assert len(table) == rows + 1 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
table = dummytable( | ||
numrows=rows, | ||
) | ||
assert len(table[0]) == 3 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
numrows=rows, | ||
seed=42 | ||
) | ||
assert len(table[0]) == 3 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
seed=42 | ||
) | ||
assert len(table[0]) == 3 | ||
assert len(table) == rows + 1 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
table = RandomTable(numflds=columns, numrows=rows, wait=0, seed=None) | ||
|
||
assert len(table[0]) == columns | ||
assert len(table) == rows + 1 |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
rows = 35 | ||
|
||
table = dummytable(numrows=rows, fields=columns) | ||
assert table[0] == ('count', 'pet', 'color', 'value') |
Check warning
Code scanning / Bandit (reported by Codacy)
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Warning test
…tions and classes.
… Python 3.9 and will be removed in a subsequent version.
|
||
assert isinstance(seed_1, str) | ||
assert seed_1 != "" | ||
assert seed_1 != seed_2 |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
time.sleep(1) | ||
seed_2 = randomseed() | ||
|
||
assert isinstance(seed_1, str) |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
seed_2 = randomseed() | ||
|
||
assert isinstance(seed_1, str) | ||
assert seed_1 != "" |
Check notice
Code scanning / Semgrep (reported by Codacy)
The application was found using assert in non-test code. Note test
|
||
# construct fields | ||
flds = ['f%s' % n for n in range(nf)] | ||
flds = ["f%s" % n for n in range(nf)] |
Check warning
Code scanning / Prospector (reported by Codacy)
Formatting a regular string which could be a f-string (consider-using-f-string) Warning
yield tuple(flds) | ||
|
||
# construct data rows | ||
for _ in xrange(nr): | ||
# artificial delay | ||
if self.wait: | ||
time.sleep(self.wait) | ||
yield tuple(random.random() for n in range(nf)) | ||
yield tuple(pyrandom.random() for n in range(nf)) |
Check warning
Code scanning / Bandit (reported by Codacy)
Standard pseudo-random generators are not suitable for security/cryptographic purposes. Warning
@@ -0,0 +1,93 @@ | |||
import random as pyrandom |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Missing module docstring Warning test
""" | ||
columns = ( | ||
('count', partial(pyrandom.randint, 0, 100)), | ||
('pet', partial(pyrandom.choice, ['dog', 'cat', 'cow', ])), |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Module 'random' has no 'choice' member Warning test
and that it accepts and uses custom column names provided. | ||
""" | ||
columns = ( | ||
('count', partial(pyrandom.randint, 0, 100)), |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Module 'random' has no 'randint' member Warning test
columns = ( | ||
('count', partial(pyrandom.randint, 0, 100)), | ||
('pet', partial(pyrandom.choice, ['dog', 'cat', 'cow', ])), | ||
('color', partial(pyrandom.choice, ['yellow', 'orange', 'brown'])), |
Check warning
Code scanning / Pylintpython3 (reported by Codacy)
Module 'random' has no 'choice' member Warning test
fields=( | ||
('foo', partial(pyrandom.randint, 0, 100)), | ||
('bar', partial(pyrandom.choice, ('apples', 'pears', 'bananas', 'oranges'))), | ||
('baz', pyrandom.random), |
Check warning
Code scanning / Pylint (reported by Codacy)
Wrong hanging indentation (remove 4 spaces). Warning
numrows=100, | ||
fields=( | ||
('foo', partial(pyrandom.randint, 0, 100)), | ||
('bar', partial(pyrandom.choice, ('apples', 'pears', 'bananas', 'oranges'))), |
Check warning
Code scanning / Pylint (reported by Codacy)
Wrong hanging indentation (remove 4 spaces). Warning
and that it accepts and uses custom column names provided. | ||
""" | ||
columns = ( | ||
('count', partial(pyrandom.randint, 0, 100)), |
Check warning
Code scanning / Pylint (reported by Codacy)
Module 'random' has no 'randint' member Warning test
columns = ( | ||
('count', partial(pyrandom.randint, 0, 100)), | ||
('pet', partial(pyrandom.choice, ['dog', 'cat', 'cow', ])), | ||
('color', partial(pyrandom.choice, ['yellow', 'orange', 'brown'])), |
Check warning
Code scanning / Pylint (reported by Codacy)
Module 'random' has no 'choice' member Warning test
""" | ||
columns = ( | ||
('count', partial(pyrandom.randint, 0, 100)), | ||
('pet', partial(pyrandom.choice, ['dog', 'cat', 'cow', ])), |
Check warning
Code scanning / Pylint (reported by Codacy)
Module 'random' has no 'choice' member Warning test
@@ -0,0 +1,93 @@ | |||
import random as pyrandom |
Check warning
Code scanning / Pylint (reported by Codacy)
Missing module docstring Warning test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
When calling randomtable without providing a seed, the warning
DeprecationWarning: Seeding based on hashing is deprecated since Python 3.9 and will be removed in a subsequent version. The only supported seed types are: None, int, float, str, bytes, and bytearray.
is emitted.This actually becomes a TypeError in 3.11 and 3.12.
closes #657
It also seems like we don't even need to provide a seed based on the documentation, but I stuck to the way it was implemented before (using a hashed version of the date).
2.7: https://docs.python.org/2.7/library/random.html#random.seed
3.12: https://docs.python.org/3.12/library/random.html#random.seed
I also noticed that the filename utils/random.py seems to be conflicting with python's random module. When debugging the doctests in that file, I had to rename it.
Changes
Checklist
Use this checklist to ensure the quality of pull requests that include new code and/or make changes to existing code.
tox
/pytest
master
branch and tested before sending the PR