def is_type_unknown(self) -> bool: """Is the type of this variable unknown? Returns: True if this variable has unknown type """ return is_type_unknown(self._variable_type)
def get_objects(self, parameter_type: Optional[Type], position: int) -> List[vr.VariableReference]: """Provides a list of variable references satisfying a certain type before a given position. If the position value is larger than the number of statements, only these statements will be considered. Otherwise the first `position` statements of the test case will be considered. If the type for which we search is not specified, all objects up to the given position are returned. Args: parameter_type: The type of the parameter we search references for position: The position in the statement list until we search Returns: A list of variable references satisfying the parameter type """ if is_type_unknown(parameter_type): return self.get_all_objects(position) variables: List[vr.VariableReference] = [] bound = min(len(self._statements), position) for i in range(bound): statement = self._statements[i] var = statement.ret_val if not var.is_none_type() and is_assignable_to( var.variable_type, parameter_type): variables.append(var) return variables
def _discard_accessible_with_missing_type_hints( accessible_object: GenericCallableAccessibleObject, ) -> bool: """Should we discard accessible objects that are not fully type hinted? Args: accessible_object: the object to check Returns: Whether or not the accessible should be discarded """ if config.configuration.guess_unknown_types: return False inf_sig = accessible_object.inferred_signature return any( is_type_unknown(type_) for param, type_ in inf_sig.parameters.items())
def _create_or_reuse_variable( self, test_case: tc.TestCase, parameter_type: Optional[Type], position: int, recursion_depth: int, allow_none: bool, exclude: Optional[vr.VariableReference] = None, ) -> Optional[vr.VariableReference]: if is_type_unknown(parameter_type): if config.INSTANCE.guess_unknown_types: parameter_type = randomness.choice( self._test_cluster.get_all_generatable_types()) else: return None if (reused_variable := self._reuse_variable(test_case, parameter_type, position)) is not None: return reused_variable
def is_type_unknown(self) -> bool: """Is the type of this variable unknown?""" return is_type_unknown(self._variable_type)
def test_is_type_unknown(type_, result): assert is_type_unknown(type_) == result