Python typing.List() Examples
The following are 30
code examples of typing.List().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
typing
, or try the search function
.
Example #1
Source File: conftest.py From mutatest with MIT License | 8 votes |
def write_cov_file(line_data: Dict[str, List[int]], fname: str) -> None: """Write a coverage file supporting both Coverage v4 and v5. Args: line_data: Dictionary of line data for the coverage file. fname: string filename for output location (absolute path) Returns: None """ if coverage.version_info[0] == 4: covdata = coverage.CoverageData() covdata.add_lines(line_data) covdata.write_file(fname) else: # assume coverage v 5 covdata = coverage.CoverageData(basename=fname) covdata.add_lines(line_data) covdata.write() #################################################################################################### # CLI: MOCK ARGS ####################################################################################################
Example #2
Source File: run.py From mutatest with MIT License | 7 votes |
def clean_trial(src_loc: Path, test_cmds: List[str]) -> timedelta: """Remove all existing cache files and run the test suite. Args: src_loc: the directory of the package for cache removal, may be a file test_cmds: test running commands for subprocess.run() Returns: None Raises: BaselineTestException: if the clean trial does not pass from the test run. """ cache.remove_existing_cache_files(src_loc) LOGGER.info("Running clean trial") # clean trial will show output all the time for diagnostic purposes start = datetime.now() clean_run = subprocess.run(test_cmds, capture_output=False) end = datetime.now() if clean_run.returncode != 0: raise BaselineTestException( f"Clean trial does not pass, mutant tests will be meaningless.\n" f"Output: {str(clean_run.stdout)}" ) return end - start #################################################################################################### # MUTATION SAMPLE GENERATION ####################################################################################################
Example #3
Source File: event_dispatcher.py From clikit with MIT License | 7 votes |
def get_listeners( self, event_name=None ): # type: (str) -> Union[List[Callable], Dict[str, Callable]] if event_name is not None: if event_name not in self._listeners: return [] if event_name not in self._sorted: self._sort_listeners(event_name) return self._sorted[event_name] for event_name, event_listeners in self._listeners.items(): if event_name not in self._sorted: self._sort_listeners(event_name) return self._sorted
Example #4
Source File: args_format.py From clikit with MIT License | 6 votes |
def _create_builder_for_elements( self, elements, base_format=None ): # type: (List[Any], Optional[ArgsFormat]) -> ArgsFormatBuilder from .args_format_builder import ArgsFormatBuilder builder = ArgsFormatBuilder(base_format) for element in elements: if isinstance(element, CommandName): builder.add_command_name(element) elif isinstance(element, CommandOption): builder.add_command_option(element) elif isinstance(element, Option): builder.add_option(element) elif isinstance(element, Argument): builder.add_argument(element) return builder
Example #5
Source File: default_resolver.py From clikit with MIT License | 6 votes |
def process_arguments( self, args, named_commands, arguments_to_test, options_to_test ): # type: (RawArgs, CommandCollection, List[str], List[str]) -> Optional[ResolveResult] current_command = None # Parse the arguments for command names until we fail to find a # matching command for name in arguments_to_test: if name not in named_commands: break next_command = named_commands.get(name) current_command = next_command named_commands = current_command.named_sub_commands if not current_command: return return self.process_options(args, current_command, options_to_test)
Example #6
Source File: default_args_parser.py From clikit with MIT License | 6 votes |
def _parse_long_option( self, token, tokens, fmt, lenient ): # type: (str, List[str], ArgsFormat, bool) -> None name = token[2:] pos = name.find("=") if pos != -1: self._add_long_option(name[:pos], name[pos + 1 :], tokens, fmt, lenient) else: if fmt.has_option(name) and fmt.get_option(name).accepts_value(): try: value = tokens.pop(0) except IndexError: value = None if value and value.startswith("-"): tokens.insert(0, value) value = None self._add_long_option(name, value, tokens, fmt, lenient) else: self._add_long_option(name, None, tokens, fmt, lenient)
Example #7
Source File: default_args_parser.py From clikit with MIT License | 6 votes |
def _parse_short_option( self, token, tokens, fmt, lenient ): # type: (str, List[str], ArgsFormat, bool) -> None name = token[1:] if len(name) > 1: if fmt.has_option(name[0]) and fmt.get_option(name[0]).accepts_value(): # an option with a value (with no space) self._add_short_option(name[0], name[1:], tokens, fmt, lenient) else: self._parse_short_option_set(name, tokens, fmt, lenient) else: if fmt.has_option(name[0]) and fmt.get_option(name[0]).accepts_value(): try: value = tokens.pop(0) except IndexError: value = None if value and value.startswith("-"): tokens.insert(0, value) value = None self._add_short_option(name, value, tokens, fmt, lenient) else: self._add_short_option(name, None, tokens, fmt, lenient)
Example #8
Source File: default_resolver.py From clikit with MIT License | 6 votes |
def get_options_to_test(self, tokens): # type: (Iterator[str]) -> List[str] options_to_test = [] token = next(tokens, None) while token: # "--" stops option parsing if token == "--": break if token[:1] and token[0] == "-": if token[:2] == "--" and len(token) > 2: options_to_test.append(token[2:]) elif len(token) == 2: options_to_test.append(token[1:]) token = next(tokens, None) return options_to_test
Example #9
Source File: default_args_parser.py From clikit with MIT License | 6 votes |
def _parse_short_option_set( self, name, tokens, fmt, lenient ): # type: (str, List[str], ArgsFormat, bool) -> None l = len(name) for i in range(0, l): if not fmt.has_option(name[i]): raise NoSuchOptionException(name[i]) option = fmt.get_option(name[i]) if option.accepts_value(): self._add_long_option( option.long_name, None if l - 1 == i else name[i + 1 :], tokens, fmt, lenient, ) break else: self._add_long_option(option.long_name, None, tokens, fmt, lenient)
Example #10
Source File: cell_wrapper.py From clikit with MIT License | 6 votes |
def _wrap_column( self, col, column_length, formatter ): # type: (int, List[int], Formatter) -> None for i, row in enumerate(self._wrapped_rows): cell = row[col] cell_length = self._cell_lengths[i][col] if cell_length > column_length: self._word_wraps = True if not self._word_cuts: min_length_without_cut = get_max_word_length(cell, formatter) if min_length_without_cut > column_length: self._word_cuts = True # TODO: use format aware wrapper wrapped_cell = "\n".join(textwrap.wrap(cell, column_length)) self._wrapped_rows[i][col] = wrapped_cell # Refresh cell length self._cell_lengths[i][col] = get_max_line_length( wrapped_cell, formatter )
Example #11
Source File: cli.py From mutatest with MIT License | 6 votes |
def selected_categories(whitelist: List[str], blacklist: List[str]) -> List[str]: """Create the selected categories from the whitelist/blacklist set to use in filtering. Args: whitelist: list of categories blacklist: list of categories Returns: Selection set of mutation categories """ all_mutations = {m.category for m in transformers.get_compatible_operation_sets()} w_set = set(whitelist) b_set = set(blacklist) if w_set: return list(w_set - b_set) return list(all_mutations - b_set)
Example #12
Source File: doc_parse.py From hydrus with MIT License | 5 votes |
def get_all_properties(classes: List[Dict[str, Any]]) -> Set[str]: """Get all the properties in the APIDocumentation.""" # properties = list() prop_names = set() # type: Set[str] for class_ in classes: for prop in class_["supportedProperty"]: if prop["title"] not in prop_names: prop_names.add(prop["title"]) # properties.append(prop) return set(prop_names)
Example #13
Source File: exceptions.py From hydrus with MIT License | 5 votes |
def __init__(self, params: List[str]) -> None: """Constructor.""" self.params = params
Example #14
Source File: operation.py From vergeml with MIT License | 5 votes |
def process(self, sample: Sample, ops=List['BaseOperation']) -> Generator[Sample, None, None]: """Complete a processing step in the pipeline and run the next one. :param sample: The sample to be processed :param ops: The next operations to run :return: A generator yielding samples The process function is expected to first transform the sample and then to call the next BaseOperation, yielding the resulting sample as a return value. """ raise NotImplementedError
Example #15
Source File: operation.py From vergeml with MIT License | 5 votes |
def process(self, sample: Sample, ops=List[BaseOperation]) -> Generator[Sample, None, None]: for s1 in self.transform_sample(sample): if not ops: yield s1 else: nextop, *rest = ops yield from nextop.process(s1, rest) # pylint: disable=E1101
Example #16
Source File: option.py From vergeml with MIT License | 5 votes |
def _has_type(type_, *types): for typ in types: if isinstance(typ, str): typ = typ.replace('@', 'TrainedModel') typ = eval(typ) # pylint: disable=W0123 if type_ == typ: return True if typ in (list, List) and getattr(type_, '__name__', None) == 'List': return True return False
Example #17
Source File: loader.py From vergeml with MIT License | 5 votes |
def read_samples(self, split: str, index: int, n_samples: int = 1) -> List[Sample]: samples = super().read_samples(split, index, n_samples) if not self.output: samples = [self.input.recover_raw_sample(sample) for sample in samples] return samples
Example #18
Source File: doc_parse.py From hydrus with MIT License | 5 votes |
def get_classes(apidoc: Dict[str, Any]) -> List[Dict[str, Any]]: """Get all the classes in the APIDocumentation.""" classes = list() for class_ in apidoc["supportedClass"]: if class_["@id"] not in ["http://www.w3.org/ns/hydra/core#Collection", "http://www.w3.org/ns/hydra/core#Resource", "vocab:EntryPoint"]: classes.append(class_) # print(classes) return classes
Example #19
Source File: argv_args.py From clikit with MIT License | 5 votes |
def option_tokens(self): # type: () -> List[str] return self._option_tokens
Example #20
Source File: token_parser.py From clikit with MIT License | 5 votes |
def _parse(self): # type: () -> List[str] tokens = [] while self._is_valid(): if self._current.isspace(): # Skip spaces self._next() continue if self._is_valid(): tokens.append(self._parse_token()) return tokens
Example #21
Source File: token_parser.py From clikit with MIT License | 5 votes |
def parse(self, string): # type: (str) -> List[str] self._string = string self._cursor = 0 self._current = None if len(string) > 0: self._current = string[0] self._next_ = None if len(string) > 1: self._next_ = string[1] tokens = self._parse() return tokens
Example #22
Source File: cell_wrapper.py From clikit with MIT License | 5 votes |
def add_cells(self, cells): # type: (List[str]) -> CellWrapper for cell in cells: self.add_cell(cell) return self
Example #23
Source File: cell_wrapper.py From clikit with MIT License | 5 votes |
def column_lengths(self): # type: () -> List[int] return self._column_lengths
Example #24
Source File: cell_wrapper.py From clikit with MIT License | 5 votes |
def wrapped_rows(self): # type: () -> List[List[str]] return self._wrapped_rows
Example #25
Source File: cell_wrapper.py From clikit with MIT License | 5 votes |
def cells(self): # type: () -> List[str] return self._cells
Example #26
Source File: border_util.py From clikit with MIT License | 5 votes |
def draw_bottom_border( cls, io, style, column_lengths, indentation=0 ): # type: (IO, BorderStyle, List[int], int) -> None cls.draw_border( io, column_lengths, indentation, style.line_hb_char, style.corner_bl_char, style.crossing_b_char, style.corner_br_char, style.style, )
Example #27
Source File: border_util.py From clikit with MIT License | 5 votes |
def draw_middle_border( cls, io, style, column_lengths, indentation=0 ): # type: (IO, BorderStyle, List[int], int) -> None cls.draw_border( io, column_lengths, indentation, style.line_hc_char, style.crossing_l_char, style.crossing_c_char, style.crossing_r_char, style.style, )
Example #28
Source File: border_util.py From clikit with MIT License | 5 votes |
def draw_top_border( cls, io, style, column_lengths, indentation=0 ): # type: (IO, BorderStyle, List[int], int) -> None cls.draw_border( io, column_lengths, indentation, style.line_ht_char, style.corner_tl_char, style.crossing_t_char, style.corner_tr_char, style.style, )
Example #29
Source File: table.py From clikit with MIT License | 5 votes |
def set_row(self, index, row): # type: (int, List[str]) -> Table if len(row) != self._nb_columns: raise ValueError( "Expected the row to contain {} cells, but got {}.".format( self._nb_columns, len(row) ) ) self._rows[index] = row return self
Example #30
Source File: table.py From clikit with MIT License | 5 votes |
def add_rows(self, rows): # type: (List[List[str]]) -> Table for row in rows: self.add_row(row) return self