Detect state variables that could be const

def _detect(self):
        """ Detect state variables that could be const
        """
        results = []
        all_info = ''

        all_variables = [c.state_variables for c in self.slither.contracts]
        all_variables = set([item for sublist in all_variables for item in sublist])
        all_non_constant_elementary_variables = set([v for v in all_variables
                                                     if self._valid_candidate(v)])

        all_functions = [c.all_functions_called for c in self.slither.contracts]
        all_functions = list(set([item for sublist in all_functions for item in sublist]))

        all_variables_written = [f.state_variables_written for f in all_functions]
        all_variables_written = set([item for sublist in all_variables_written for item in sublist])

        constable_variables = [v for v in all_non_constant_elementary_variables
                               if (not v in all_variables_written) and self._constant_initial_expression(v)]
        # Order for deterministic results
        constable_variables = sorted(constable_variables, key=lambda x: x.canonical_name)
        for v in constable_variables:
            info = "{}.{} should be constant ({})\n".format(v.contract.name,
                                                            v.name,
                                                            v.source_mapping_str)
            all_info += info
        if all_info != '':
            json = self.generate_json_result(all_info)
            self.add_variables_to_json(constable_variables, json)
            results.append(json)
        return results