Skip to content
5 changes: 3 additions & 2 deletions numba_cuda/numba/cuda/cgutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ def create_struct_proxy(fe_type, kind="value"):
return res


def copy_struct(dst, src, repl={}):
def copy_struct(dst, src, repl=None):
"""
Copy structure from *src* to *dst* with replacement from *repl*.
"""
repl = repl.copy()

repl = (repl or {}).copy()
# copy data from src or use those in repl
for k in src._datamodel._fields:
v = repl.pop(k, getattr(src, k))
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,7 @@ def _code_reduce(obj):
def _cell_reduce(obj):
"""Cell (containing values of a function's free variables) reducer."""
try:
obj.cell_contents
obj.cell_contents # noqa: B018
except ValueError: # cell is empty
return _make_empty_cell, ()
else:
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ def kernel_fixup(kernel, debug):
# ret void

for block in kernel.blocks:
for i, inst in enumerate(block.instructions):
for inst in block.instructions:
if isinstance(inst, ir.Ret):
old_ret = block.instructions.pop()
block.terminator = None
Expand Down
12 changes: 6 additions & 6 deletions numba_cuda/numba/cuda/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ def get_dummy_type(self):
return GENERIC_POINTER

def _compile_subroutine_no_cache(
self, builder, impl, sig, locals={}, flags=None
self, builder, impl, sig, locals=None, flags=None
):
"""
Invoke the compiler to compile a function to be used inside a
Expand Down Expand Up @@ -916,15 +916,15 @@ def _compile_subroutine_no_cache(
sig.args,
sig.return_type,
flags,
locals=locals,
locals=locals or {},
)

# Allow inlining the function inside callers.
self.active_code_library.add_linking_library(cres.library)
return cres

def compile_subroutine(
self, builder, impl, sig, locals={}, flags=None, caching=True
self, builder, impl, sig, locals=None, flags=None, caching=True
):
"""
Compile the function *impl* for the given *sig* (in nopython mode).
Expand All @@ -949,7 +949,7 @@ def compile_subroutine(
cached = self.cached_internal_func.get(cache_key)
if cached is None:
cres = self._compile_subroutine_no_cache(
builder, impl, sig, locals=locals, flags=flags
builder, impl, sig, locals=locals or {}, flags=flags
)
self.cached_internal_func[cache_key] = cres

Expand All @@ -958,12 +958,12 @@ def compile_subroutine(
self.active_code_library.add_linking_library(cres.library)
return cres

def compile_internal(self, builder, impl, sig, args, locals={}):
def compile_internal(self, builder, impl, sig, args, locals=None):
"""
Like compile_subroutine(), but also call the function with the given
*args*.
"""
cres = self.compile_subroutine(builder, impl, sig, locals)
cres = self.compile_subroutine(builder, impl, sig, locals or {})
return self.call_internal(builder, cres.fndesc, sig, args)

def call_internal(self, builder, fndesc, sig, args):
Expand Down
14 changes: 4 additions & 10 deletions numba_cuda/numba/cuda/core/boxing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,11 +1270,9 @@ def object_getattr_safely(obj, attr):
):
handle_failure()

setattr(
struct_ptr,
"state_address",
c.unbox(types.uintp, interface_state_address).value,
)
struct_ptr.state_address = c.unbox(
types.uintp, interface_state_address
).value

# Look up the "state" member and wire it into the struct
interface_state = object_getattr_safely(ctypes_binding, "state")
Expand All @@ -1286,11 +1284,7 @@ def object_getattr_safely(obj, attr):
c.builder, stack, interface_state_value
):
handle_failure()
setattr(
struct_ptr,
"state",
c.unbox(types.uintp, interface_state_value).value,
)
struct_ptr.state = c.unbox(types.uintp, interface_state_value).value

# Want to store callable function pointers to these CFunctionTypes, so
# import ctypes and use it to cast the CFunctionTypes to c_void_p and
Expand Down
7 changes: 4 additions & 3 deletions numba_cuda/numba/cuda/core/bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,10 @@ def block_effect(self):
if PYVERSION in ((3, 13), (3, 14)):

def _unpack_opargs(code):
buf = []
for i, start_offset, op, arg in dis._unpack_opargs(code):
buf.append((start_offset, op, arg))
buf = [
(start_offset, op, arg)
for _, start_offset, op, arg in dis._unpack_opargs(code)
]
for i, (start_offset, op, arg) in enumerate(buf):
if i + 1 < len(buf):
next_offset = buf[i + 1][0]
Expand Down
9 changes: 4 additions & 5 deletions numba_cuda/numba/cuda/core/byteflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def propagate_phi_map(phismap):

def apply_changes(used_phis, phismap):
keep = {}
for state, used_set in used_phis.items():
for used_set in used_phis.values():
for phi in used_set:
keep[phi] = phismap[phi]
_logger.debug("keep phismap: %s", _lazy_pformat(keep))
Expand Down Expand Up @@ -1139,7 +1139,7 @@ def op_RAISE_VARARGS(self, state, inst):

def op_BEGIN_FINALLY(self, state, inst):
temps = []
for i in range(_EXCEPT_STACK_OFFSET):
for _ in range(_EXCEPT_STACK_OFFSET):
tmp = state.make_temp()
temps.append(tmp)
state.push(tmp)
Expand Down Expand Up @@ -1656,7 +1656,7 @@ def op_BUILD_MAP(self, state, inst):
count = inst.arg
items = []
# In 3.5+, BUILD_MAP takes <count> pairs from the stack
for i in range(count):
for _ in range(count):
v, k = state.pop(), state.pop()
items.append((k, v))
state.append(inst, items=items[::-1], size=count, res=dct)
Expand Down Expand Up @@ -2360,8 +2360,7 @@ def fork(self, pc, npop=0, npush=0, extra_block=None):
stack = stack[:nstack]
if npush:
assert 0 <= npush
for i in range(npush):
stack.append(self.make_temp())
stack.extend(self.make_temp() for _ in range(npush))
# Handle changes on the blockstack
blockstack = list(self._blockstack)
if PYVERSION in ((3, 11), (3, 12), (3, 13), (3, 14)):
Expand Down
5 changes: 2 additions & 3 deletions numba_cuda/numba/cuda/core/compiler_machinery.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,8 @@ def run_finalizer(self, *args, **kwargs):
"""
return False

def get_analysis_usage(self, AU):
def get_analysis_usage(self, AU): # noqa: B027
"""Override to set analysis usage"""
pass

def get_analysis(self, pass_name):
"""
Expand Down Expand Up @@ -230,7 +229,7 @@ def add_pass_after(self, pass_cls, location):
assert self.passes
self._validate_pass(pass_cls)
self._validate_pass(location)
for idx, (x, _) in enumerate(self.passes):
for idx, (x, _) in enumerate(self.passes): # noqa: B007
if x == location:
break
else:
Expand Down
4 changes: 2 additions & 2 deletions numba_cuda/numba/cuda/core/cuda_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _is_numba_core_config_loaded():
To detect if numba.core.config has been initialized due to circular imports.
"""
try:
numba.cuda.core.config
numba.cuda.core.config # noqa: B018
except AttributeError:
return False
else:
Expand Down Expand Up @@ -261,7 +261,7 @@ def __enter__(self):
reinit()

def __exit__(self, *exc_detail):
Style.RESET_ALL
Style.RESET_ALL # noqa: B018
deinit()

class reset_terminal(object):
Expand Down
4 changes: 2 additions & 2 deletions numba_cuda/numba/cuda/core/inline_closurecall.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def run(self):
sized_loops = [(k, len(loops[k].body)) for k in loops.keys()]
visited = []
# We go over all loops, bigger loops first (outer first)
for k, s in sorted(
for k, _ in sorted(
sized_loops, key=lambda tup: tup[1], reverse=True
):
visited.append(k)
Expand Down Expand Up @@ -1398,7 +1398,7 @@ def is_removed(val, removed):


def _find_unsafe_empty_inferred(func_ir, expr):
unsafe_empty_inferred
unsafe_empty_inferred # noqa: B018
require(isinstance(expr, ir.expr_types) and expr.op == "call")
callee = expr.func
callee_def = get_definition(func_ir, callee)
Expand Down
36 changes: 19 additions & 17 deletions numba_cuda/numba/cuda/core/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ def foo(a):
while True:
# first try and find a matching region
# i.e. BUILD_LIST...<stuff>...LIST_TO_TUPLE
def find_postive_region():
def find_postive_region(blk):
found = False
for idx in reversed(range(len(blk.body))):
stmt = blk.body[idx]
Expand All @@ -798,7 +798,7 @@ def find_postive_region():
region = (bt, (idx, stmt))
return region

region = find_postive_region()
region = find_postive_region(blk)
# if there's a peep hole region then do something with it
if region is not None:
peep_hole = blk.body[region[1][0] : region[0][0]]
Expand Down Expand Up @@ -836,7 +836,7 @@ def find_postive_region():

def append_and_fix(x):
"""Adds to the new_hole and fixes up definitions"""
new_hole.append(x)
new_hole.append(x) # noqa: B023
if x.target.name in func_ir._definitions:
# if there's already a definition, drop it, should only
# be 1 as the way cpython emits the sequence for
Expand Down Expand Up @@ -1484,7 +1484,21 @@ def _end_try_blocks(self):
See also: _insert_try_block_end
"""
assert PYVERSION in ((3, 11), (3, 12), (3, 13), (3, 14))

def do_change(remain, block):
while remain:
ent = remain.pop()
if ent["kind"] == BlockKind("TRY"):
# Extend block with marker for end of try
self.current_block = block
oldbody = list(block.body)
block.body.clear()
self._insert_try_block_end()
block.body.extend(oldbody)
return True

graph = self.cfa.graph

for offset, block in self.blocks.items():
# Get current blockstack
cur_bs = self.dfa.infos[offset].blockstack
Expand All @@ -1493,25 +1507,13 @@ def _end_try_blocks(self):
inc_bs = self.dfa.infos[inc].blockstack

# find first diff in the blockstack
for i, (x, y) in enumerate(zip(cur_bs, inc_bs)):
for i, (x, y) in enumerate(zip(cur_bs, inc_bs)): # noqa: B007
if x != y:
break
else:
i = min(len(cur_bs), len(inc_bs))

def do_change(remain):
while remain:
ent = remain.pop()
if ent["kind"] == BlockKind("TRY"):
# Extend block with marker for end of try
self.current_block = block
oldbody = list(block.body)
block.body.clear()
self._insert_try_block_end()
block.body.extend(oldbody)
return True

if do_change(list(inc_bs[i:])):
if do_change(list(inc_bs[i:]), block):
break

def _legalize_exception_vars(self):
Expand Down
13 changes: 6 additions & 7 deletions numba_cuda/numba/cuda/core/ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,9 @@ def strformat(self, nlines_up=2):
if lines and use_line > 0:

def count_spaces(string):
spaces = 0
for x in itertools.takewhile(str.isspace, str(string)):
spaces += 1
return spaces
return sum(
1 for _ in itertools.takewhile(str.isspace, str(string))
)

# A few places in the code still use no `loc` or default to line 1
# this is often in places where exceptions are used for the purposes
Expand Down Expand Up @@ -1547,15 +1546,15 @@ def diff_str(self, other):
msg.append("Other block contains more statements")

# find the indexes where they don't match
tmp = []
tmp = set()
for idx, stmts in enumerate(
zip(block.body, other_blk.body)
):
b_s, o_s = stmts
if b_s != o_s:
tmp.append(idx)
tmp.add(idx)

def get_pad(ablock, l):
def get_pad(ablock, l, tmp=tmp):
pointer = "-> "
sp = len(pointer) * " "
pad = []
Expand Down
4 changes: 2 additions & 2 deletions numba_cuda/numba/cuda/core/ir_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ def find_single_branch(label):
inst = blocks[label].body[0]
predecessors = cfg.predecessors(label)
delete_block = True
for p, q in predecessors:
for p, _ in predecessors:
block = blocks[p]
if isinstance(block.body[-1], ir.jump_types):
block.body[-1] = copy.copy(inst)
Expand Down Expand Up @@ -2617,7 +2617,7 @@ def fixup_var_define_in_scope(blocks):
# Ensure the scope of each block defines all used variables.
for blk in blocks.values():
scope = blk.scope
for var, inst in used_var.items():
for var in used_var.keys():
# add this variable if it's not in scope
if var.name not in scope.localvars:
# Note: using a internal method to reuse the same
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def __init__(self, value):
if value in ("always", "never"):
ok = True
else:
ok = hasattr(value, "__call__")
ok = callable(value)

if ok:
self._inline = value
Expand Down
6 changes: 2 additions & 4 deletions numba_cuda/numba/cuda/core/pythonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def add_const(self, const):
# All constants are frozen inside the environment
if isinstance(const, str):
const = sys.intern(const)
for index, val in enumerate(self.env.consts):
for val in self.env.consts:
if val is const:
break
else:
Expand Down Expand Up @@ -189,9 +189,7 @@ def __init__(self, context, builder):

self.module = builder.basic_block.function.module
# A unique mapping of serialized objects in this module
try:
self.module.__serialized
except AttributeError:
if not hasattr(self.module, "__serialized"):
self.module.__serialized = {}

# Initialize types
Expand Down
2 changes: 1 addition & 1 deletion numba_cuda/numba/cuda/core/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def wrapper(*args, **kwds):
if inspect.ismodule(arg0):
for n, f in inspect.getmembers(arg0, inspect.isfunction):
setattr(arg0, n, decorator(f))
for n, c in inspect.getmembers(arg0, inspect.isclass):
for _, c in inspect.getmembers(arg0, inspect.isclass):
dotrace(c, *args, recursive=recursive)
elif inspect.isclass(arg0):
for n, f in inspect.getmembers(
Expand Down
Loading
Loading