11# mypy: ignore-errors
22
3- from __future__ import unicode_literals
3+ from __future__ import annotations
44
55import logging
6+ from typing import Dict , List , Tuple
67
78import pygments .styles
89from pygments .token import string_to_tokentype , Token
910from pygments .style import Style as PygmentsStyle
1011from pygments .util import ClassNotFound
1112from prompt_toolkit .styles .pygments import style_from_pygments_cls
1213from prompt_toolkit .styles import merge_styles , Style
14+ from prompt_toolkit .styles .style import _MergedStyle
1315
1416logger = logging .getLogger (__name__ )
1517
1618# map Pygments tokens (ptk 1.0) to class names (ptk 2.0).
17- TOKEN_TO_PROMPT_STYLE = {
19+ TOKEN_TO_PROMPT_STYLE : Dict [ Token , str ] = {
1820 Token .Menu .Completions .Completion .Current : "completion-menu.completion.current" ,
1921 Token .Menu .Completions .Completion : "completion-menu.completion" ,
2022 Token .Menu .Completions .Meta .Current : "completion-menu.meta.completion.current" ,
4345}
4446
4547# reverse dict for cli_helpers, because they still expect Pygments tokens.
46- PROMPT_STYLE_TO_TOKEN = {v : k for k , v in TOKEN_TO_PROMPT_STYLE .items ()}
48+ PROMPT_STYLE_TO_TOKEN : Dict [ str , Token ] = {v : k for k , v in TOKEN_TO_PROMPT_STYLE .items ()}
4749
4850
49- def parse_pygments_style (token_name , style_object , style_dict ) :
51+ def parse_pygments_style (token_name : str , style_object , style_dict : Dict [ str , str ]) -> Tuple [ Token , str ] :
5052 """Parse token type and style string.
5153
5254 :param token_name: str name of Pygments token. Example: "Token.String"
@@ -62,13 +64,13 @@ def parse_pygments_style(token_name, style_object, style_dict):
6264 return token_type , style_dict [token_name ]
6365
6466
65- def style_factory (name , cli_style ) :
67+ def style_factory (name : str , cli_style : Dict [ str , str ]) -> _MergedStyle :
6668 try :
6769 style = pygments .styles .get_style_by_name (name )
6870 except ClassNotFound :
6971 style = pygments .styles .get_style_by_name ("native" )
7072
71- prompt_styles = []
73+ prompt_styles : List [ Tuple [ str , str ]] = []
7274 # prompt-toolkit used pygments tokens for styling before, switched to style
7375 # names in 2.0. Convert old token types to new style names, for backwards compatibility.
7476 for token in cli_style :
@@ -86,11 +88,11 @@ def style_factory(name, cli_style):
8688 # https://github.com/jonathanslenders/python-prompt-toolkit/blob/master/prompt_toolkit/styles/defaults.py
8789 prompt_styles .append ((token , cli_style [token ]))
8890
89- override_style = Style ([("bottom-toolbar" , "noreverse" )])
91+ override_style : Style = Style ([("bottom-toolbar" , "noreverse" )])
9092 return merge_styles ([style_from_pygments_cls (style ), override_style , Style (prompt_styles )])
9193
9294
93- def style_factory_output (name , cli_style ):
95+ def style_factory_output (name : str , cli_style : Dict [ str , str ] ):
9496 try :
9597 style = pygments .styles .get_style_by_name (name ).styles
9698 except ClassNotFound :
0 commit comments