diff --git a/src/pynguin/analyses/controlflow.py b/src/pynguin/analyses/controlflow.py index ebe10b1a..88b9ce28 100644 --- a/src/pynguin/analyses/controlflow.py +++ b/src/pynguin/analyses/controlflow.py @@ -200,10 +200,7 @@ def get_predecessors(self, node: N) -> set[N]: Returns: A set of direct predecessors of the node """ - predecessors: set[N] = set() - for predecessor in self._graph.predecessors(node): - predecessors.add(predecessor) - return predecessors + return set(self._graph.predecessors(node)) def get_successors(self, node: N) -> set[N]: """Provides a set of all direct successors of a node. @@ -214,10 +211,7 @@ def get_successors(self, node: N) -> set[N]: Returns: A set of direct successors of the node """ - successors: set[N] = set() - for successor in self._graph.successors(node): - successors.add(successor) - return successors + return set(self._graph.successors(node)) @property def nodes(self) -> set[N]: diff --git a/src/pynguin/analyses/typesystem.py b/src/pynguin/analyses/typesystem.py index ec19a064..eeb9f0b4 100644 --- a/src/pynguin/analyses/typesystem.py +++ b/src/pynguin/analyses/typesystem.py @@ -943,13 +943,7 @@ def _guess_generic_type_parameters_for_builtins( InferredSignature._LIST_ELEMENT_FROM_ARGUMENT_TYPES_PATH, argument_idx=0, ) - args = ( - ( - guessed_element_type - if guessed_element_type - else guessed_type.args[0] - ), - ) + args = ((guessed_element_type or guessed_type.args[0]),) case "builtins.set": guessed_element_type = self._guess_generic_arguments( knowledge, @@ -959,13 +953,7 @@ def _guess_generic_type_parameters_for_builtins( InferredSignature._SET_ELEMENT_FROM_ARGUMENT_TYPES_PATH, argument_idx=0, ) - args = ( - ( - guessed_element_type - if guessed_element_type - else guessed_type.args[0] - ), - ) + args = ((guessed_element_type or guessed_type.args[0]),) case "builtins.dict": guessed_key_type = self._guess_generic_arguments( knowledge, @@ -984,12 +972,8 @@ def _guess_generic_type_parameters_for_builtins( argument_idx=1, ) args = ( - guessed_key_type if guessed_key_type else guessed_type.args[0], - ( - guessed_value_type - if guessed_value_type - else guessed_type.args[1] - ), + guessed_key_type or guessed_type.args[0], + (guessed_value_type or guessed_type.args[1]), ) guessed_type = Instance(guessed_type.type, args) elif isinstance(guessed_type, TupleType): @@ -1748,7 +1732,7 @@ def _fixup_known_generics(result: Instance) -> Instance: args = tuple(result.args) if len(result.args) < result.type.num_hardcoded_generic_parameters: # Fill with AnyType if to small - args = args + (ANY,) * ( + args += (ANY,) * ( result.type.num_hardcoded_generic_parameters - len(args) ) elif len(result.args) > result.type.num_hardcoded_generic_parameters: diff --git a/src/pynguin/ga/computations.py b/src/pynguin/ga/computations.py index a1dbc036..60f67fe3 100644 --- a/src/pynguin/ga/computations.py +++ b/src/pynguin/ga/computations.py @@ -440,17 +440,11 @@ def __init__( # noqa: D107 coverage_cache: dict[CoverageFunction, float] | None = None, ): self._chromosome = chromosome - self._fitness_functions = fitness_functions if fitness_functions else [] - self._coverage_functions = coverage_functions if coverage_functions else [] - self._fitness_cache: dict[FitnessFunction, float] = ( - fitness_cache if fitness_cache else {} - ) - self._is_covered_cache: dict[FitnessFunction, bool] = ( - is_covered_cache if is_covered_cache else {} - ) - self._coverage_cache: dict[CoverageFunction, float] = ( - coverage_cache if coverage_cache else {} - ) + self._fitness_functions = fitness_functions or [] + self._coverage_functions = coverage_functions or [] + self._fitness_cache: dict[FitnessFunction, float] = fitness_cache or {} + self._is_covered_cache: dict[FitnessFunction, bool] = is_covered_cache or {} + self._coverage_cache: dict[CoverageFunction, float] = coverage_cache or {} def clone(self, new_chromosome) -> ComputationCache: """Create a deep copy of this cache. diff --git a/src/pynguin/slicer/executedinstruction.py b/src/pynguin/slicer/executedinstruction.py index aeb5c000..420472a8 100644 --- a/src/pynguin/slicer/executedinstruction.py +++ b/src/pynguin/slicer/executedinstruction.py @@ -58,7 +58,7 @@ class ExecutedMemoryInstruction(ExecutedInstruction): object_creation: bool def __str__(self) -> str: - arg_address = self.arg_address if self.arg_address else -1 + arg_address = self.arg_address or -1 return ( f"{'(mem)':<7} {self.file:<40} {opname[self.opcode]:<20} " f"{self.argument:<25} {hex(arg_address):<25} {self.code_object_id:02d}" diff --git a/src/pynguin/slicer/executionflowbuilder.py b/src/pynguin/slicer/executionflowbuilder.py index 615ebf22..8275be54 100644 --- a/src/pynguin/slicer/executionflowbuilder.py +++ b/src/pynguin/slicer/executionflowbuilder.py @@ -521,7 +521,7 @@ def _continue_at_last_basic_block( last_instr = None if efb_state.bb_id > 0: - efb_state.bb_id = efb_state.bb_id - 1 + efb_state.bb_id -= 1 last_instr = self._get_last_in_basic_block(efb_state.co_id, efb_state.bb_id) efb_state.offset -= 2 diff --git a/src/pynguin/testcase/statement.py b/src/pynguin/testcase/statement.py index 166f9a58..be9a5946 100644 --- a/src/pynguin/testcase/statement.py +++ b/src/pynguin/testcase/statement.py @@ -1008,7 +1008,7 @@ def __init__( vr.CallBasedVariableReference(test_case, generic_callable), ) self._generic_callable = generic_callable - self._args = args if args else {} + self._args = args or {} @property def args(self) -> dict[str, vr.VariableReference]: