Skip to content

Approve functions used as default arguments #4699

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

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion other/linear_congruential_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ class LinearCongruentialGenerator:
A pseudorandom number generator.
"""

def __init__(self, multiplier, increment, modulo, seed=int(time())):
def __init__(self, multiplier, increment, modulo, seed=int(time())): # noqa: B008
"""
These parameters are saved and used when nextNumber() is called.

modulo is the largest number that can be generated (exclusive). The most
efficient values are powers of 2. 2^32 is a common value.

The default value for **seed** is the result of a function call which is not
normally recommended and causes flake8-bugbear to raise a B008 error. However,
in this case, it is accptable because `LinearCongruentialGenerator.__init__()`
will only be called once per instance and it ensures that each instance will
generate a unique sequence of numbers.
"""
self.multiplier = multiplier
self.increment = increment
Expand Down
13 changes: 10 additions & 3 deletions quantum/ripple_adder_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def full_adder(


def ripple_adder(
val1: int, val2: int, backend: BaseBackend = Aer.get_backend("qasm_simulator")
val1: int,
val2: int,
backend: BaseBackend = Aer.get_backend("qasm_simulator"), # noqa: B008
) -> int:
"""
Quantum Equivalent of a Ripple Adder Circuit
Expand All @@ -63,7 +65,12 @@ def ripple_adder(
Currently only adds 'emulated' Classical Bits
but nothing prevents us from doing this with hadamard'd bits :)

Only supports adding +ve Integers
Only supports adding positive integers

The default value for **backend** is the result of a function call which is not
normally recommended and causes flake8-bugbear to raise a B008 error. However,
in this case, it is accptable because `Aer.get_backend()` is called when the
function is definition and that same backend is then reused for function calls.

>>> ripple_adder(3, 4)
7
Expand Down Expand Up @@ -99,7 +106,7 @@ def ripple_adder(
res = execute(circuit, backend, shots=1).result()

# The result is in binary. Convert it back to int
return int(list(res.get_counts().keys())[0], 2)
return int(list(res.get_counts())[0], 2)


if __name__ == "__main__":
Expand Down