fix text get item for lines

This commit is contained in:
Nathan Page 2021-05-09 15:20:01 -07:00
parent 18b780eeb3
commit fe87227c55
2 changed files with 6 additions and 5 deletions

View File

@ -81,11 +81,11 @@ class Lines:
...
@overload
def __getitem__(self, index: slice) -> "Lines":
def __getitem__(self, index: slice) -> List["Text"]:
...
def __getitem__(self, index: Union[slice, int]) -> Union["Text", "Lines"]:
return self._lines[index] # type: ignore
def __getitem__(self, index: Union[slice, int]) -> Union["Text", List["Text"]]:
return self._lines[index]
def __setitem__(self, index: int, value: "Text") -> "Lines":
self._lines[index] = value

View File

@ -1,8 +1,9 @@
import os.path
import platform
from rich.containers import Lines
import textwrap
from abc import ABC, abstractmethod
from typing import Any, Dict, Iterable, Optional, Set, Tuple, Type, Union
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple, Type, Union
from pygments.lexers import get_lexer_by_name, guess_lexer_for_filename
from pygments.style import Style as PygmentsStyle
@ -540,7 +541,7 @@ class Syntax(JupyterMixin):
yield from syntax_line
return
lines = text.split("\n", allow_blank=ends_on_nl)
lines: Union[List[Text], Lines] = text.split("\n", allow_blank=ends_on_nl)
if self.line_range:
lines = lines[line_offset:end_line]