當前位置: 首頁>>代碼示例>>Python>>正文


Python typing.List方法代碼示例

本文整理匯總了Python中typing.List方法的典型用法代碼示例。如果您正苦於以下問題:Python typing.List方法的具體用法?Python typing.List怎麽用?Python typing.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typing的用法示例。


在下文中一共展示了typing.List方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_listeners

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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 
開發者ID:sdispater,項目名稱:clikit,代碼行數:19,代碼來源:event_dispatcher.py

示例2: selected_categories

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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) 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:20,代碼來源:cli.py

示例3: write_cov_file

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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
#################################################################################################### 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:27,代碼來源:conftest.py

示例4: __init__

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
def __init__(
        self, long_name, short_name=None, aliases=None, flags=0, description=None
    ):  # type: (str, Optional[str], Optional[List[str]], int, Optional[str]) -> None
        super(CommandOption, self).__init__(long_name, short_name, flags, description)

        if aliases is None:
            aliases = []

        self._long_aliases = []
        self._short_aliases = []

        for alias in aliases:
            alias = self._remove_dash_prefix(alias)

            if len(alias) == 1:
                self._validate_short_alias(alias)
                self._short_aliases.append(alias)
            else:
                self._validate_long_alias(alias)
                self._long_aliases.append(alias) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:22,代碼來源:command_option.py

示例5: _create_builder_for_elements

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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 
開發者ID:sdispater,項目名稱:clikit,代碼行數:20,代碼來源:args_format.py

示例6: _wrap_column

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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
                ) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:27,代碼來源:cell_wrapper.py

示例7: _parse_long_option

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:23,代碼來源:default_args_parser.py

示例8: _parse_short_option

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:26,代碼來源:default_args_parser.py

示例9: _parse_short_option_set

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:23,代碼來源:default_args_parser.py

示例10: process_arguments

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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) 
開發者ID:sdispater,項目名稱:clikit,代碼行數:22,代碼來源:default_resolver.py

示例11: get_options_to_test

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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 
開發者ID:sdispater,項目名稱:clikit,代碼行數:20,代碼來源:default_resolver.py

示例12: scan

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
def scan(self, path, exclude=[]) -> List[str]:
        """Scan path for matching files.

        :param path: the path to scan
        :param exclude: a list of directories to exclude

        :return: a list of sorted filenames
        """
        res = []
        path = path.rstrip("/").rstrip("\\")
        for pat in self.input_patterns:
            res.extend(glob.glob(path + os.sep + pat, recursive=True))

        res = list(filter(lambda p: os.path.isfile(p), res))

        if exclude:
            def excluded(path):
                for e in exclude:
                    if path.startswith(e):
                        return True
                return False

            res = list(filter(lambda p: not excluded(p), res))

        return sorted(res) 
開發者ID:mme,項目名稱:vergeml,代碼行數:27,代碼來源:io.py

示例13: get_reported_results

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
def get_reported_results(trial_results: List[MutantTrialResult], status: str) -> ReportedMutants:
    """Utility function to create filtered lists of mutants based on status.

    Args:
        trial_results: list of mutant trial results
        status: the status to filter by

    Returns:
        The reported mutants as a ``ReportedMutants`` container.
    """
    mutants = [t.mutant for t in trial_results if t.status == status]
    return ReportedMutants(status, mutants) 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:14,代碼來源:report.py

示例14: get_status_summary

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
def get_status_summary(trial_results: List[MutantTrialResult]) -> Dict[str, Union[str, int]]:
    """Create a status summary dictionary for later formatting.

    Args:
        trial_results: list of mutant trials

    Returns:
        Dictionary with keys for formatting in the report
    """
    status: Dict[str, Union[str, int]] = dict(Counter([t.status for t in trial_results]))
    status["TOTAL RUNS"] = len(trial_results)
    status["RUN DATETIME"] = str(datetime.now())

    return status 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:16,代碼來源:report.py

示例15: clean_trial

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import List [as 別名]
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
#################################################################################################### 
開發者ID:EvanKepner,項目名稱:mutatest,代碼行數:36,代碼來源:run.py


注:本文中的typing.List方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。