-
-
Notifications
You must be signed in to change notification settings - Fork 410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge .pyi files #926
Merged
Merged
Merge .pyi files #926
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8d0cdee
Start merging .pyi files
chanicpanic d7b819e
Continue merging .pyi files
chanicpanic 089bc2b
More .pyi merging
chanicpanic 433adee
Last batch of .pyi files
chanicpanic be76059
Merge the Literal types
chanicpanic bca7c79
Declare instance variable types at class level
chanicpanic 1c4af01
Update mypy workflow
chanicpanic 4bc9445
Corrections for PR and some mypy errors
chanicpanic 804114d
Remove default values on type declarations and mark ClassVars
chanicpanic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,10 +23,10 @@ class Pattern(Serialize, ABC): | |
|
||
value: str | ||
flags: Collection[str] | ||
raw: str = None | ||
type: str = None | ||
raw: Optional[str] = None | ||
type: Optional[str] = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not optional. It is also more of a |
||
|
||
def __init__(self, value: str, flags: Collection[str]=(), raw: str=None) -> None: | ||
def __init__(self, value: str, flags: Collection[str]=(), raw: Optional[str]=None) -> None: | ||
self.value = value | ||
self.flags = frozenset(flags) | ||
self.raw = raw | ||
|
@@ -81,7 +81,10 @@ def to_regexp(self) -> str: | |
@property | ||
def min_width(self) -> int: | ||
return len(self.value) | ||
max_width = min_width | ||
|
||
@property | ||
def max_width(self) -> int: | ||
return len(self.value) | ||
|
||
|
||
class PatternRE(Pattern): | ||
|
@@ -320,15 +323,36 @@ def _regexp_has_newline(r): | |
""" | ||
return '\n' in r or '\\n' in r or '\\s' in r or '[^' in r or ('(?s' in r and '.' in r) | ||
|
||
|
||
class LexerState(object): | ||
__slots__ = 'text', 'line_ctr', 'last_token' | ||
|
||
def __init__(self, text, line_ctr, last_token=None): | ||
self.text = text | ||
self.line_ctr = line_ctr | ||
self.last_token = last_token | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, LexerState): | ||
return NotImplemented | ||
|
||
return self.text is other.text and self.line_ctr == other.line_ctr and self.last_token == other.last_token | ||
|
||
def __copy__(self): | ||
return type(self)(self.text, copy(self.line_ctr), self.last_token) | ||
|
||
|
||
_Callback = Callable[[Token], Token] | ||
|
||
class Lexer(ABC): | ||
"""Lexer interface | ||
|
||
Method Signatures: | ||
lex(self, text) -> Iterator[Token] | ||
lex(self, lexer_state, parser_state) -> Iterator[Token] | ||
""" | ||
lex: Callable[..., Iterator[Token]] = NotImplemented | ||
@abstractmethod | ||
def lex(self, lexer_state: LexerState, parser_state: Any) -> Iterator[Token]: | ||
... | ||
|
||
def make_lexer_state(self, text): | ||
line_ctr = LineCounter(b'\n' if isinstance(text, bytes) else '\n') | ||
|
@@ -394,6 +418,7 @@ def _build(self) -> None: | |
def mres(self) -> List[Tuple[REPattern, Dict[int, str]]]: | ||
if self._mres is None: | ||
self._build() | ||
assert self._mres is not None | ||
return self._mres | ||
|
||
def match(self, text: str, pos: int) -> Optional[Tuple[str, str]]: | ||
|
@@ -402,12 +427,12 @@ def match(self, text: str, pos: int) -> Optional[Tuple[str, str]]: | |
if m: | ||
return m.group(0), type_from_index[m.lastindex] | ||
|
||
def lex(self, state: Any, parser_state: Any) -> Iterator[Token]: | ||
def lex(self, state: LexerState, parser_state: Any) -> Iterator[Token]: | ||
with suppress(EOFError): | ||
while True: | ||
yield self.next_token(state, parser_state) | ||
|
||
def next_token(self, lex_state: Any, parser_state: Any=None) -> Token: | ||
def next_token(self, lex_state: LexerState, parser_state: Any=None) -> Token: | ||
line_ctr = lex_state.line_ctr | ||
while line_ctr.char_pos < len(lex_state.text): | ||
res = self.match(lex_state.text, line_ctr.char_pos) | ||
|
@@ -443,24 +468,6 @@ def next_token(self, lex_state: Any, parser_state: Any=None) -> Token: | |
raise EOFError(self) | ||
|
||
|
||
class LexerState(object): | ||
__slots__ = 'text', 'line_ctr', 'last_token' | ||
|
||
def __init__(self, text, line_ctr, last_token=None): | ||
self.text = text | ||
self.line_ctr = line_ctr | ||
self.last_token = last_token | ||
|
||
def __eq__(self, other): | ||
if not isinstance(other, LexerState): | ||
return NotImplemented | ||
|
||
return self.text is other.text and self.line_ctr == other.line_ctr and self.last_token == other.last_token | ||
|
||
def __copy__(self): | ||
return type(self)(self.text, copy(self.line_ctr), self.last_token) | ||
|
||
|
||
class ContextualLexer(Lexer): | ||
|
||
lexers: Dict[str, TraditionalLexer] | ||
|
@@ -494,7 +501,7 @@ def __init__(self, conf: 'LexerConf', states: Dict[str, Collection[str]], always | |
def make_lexer_state(self, text): | ||
return self.root_lexer.make_lexer_state(text) | ||
|
||
def lex(self, lexer_state: Any, parser_state: Any) -> Iterator[Token]: | ||
def lex(self, lexer_state: LexerState, parser_state: Any) -> Iterator[Token]: | ||
try: | ||
while True: | ||
lexer = self.lexers[parser_state.position] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to provide values when annotation on classes?