Skip to content
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

Added Scanner to re.pyi #3071

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions stdlib/3/re.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,11 @@ def escape(string: AnyStr) -> AnyStr: ...

def purge() -> None: ...
def template(pattern: Union[AnyStr, Pattern[AnyStr]], flags: _FlagsType = ...) -> Pattern[AnyStr]: ...

class Scanner:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add an undocumented flag. Also, this needs to be generic over AnyStr for the methods to have correct types:

Suggested change
class Scanner:
# undocumented
class Scanner(Generic[AnyStr]):

def __init__(
self,
lexicon: Sequence[Tuple[AnyStr, Callable[[Scanner, AnyStr], Any]]],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the action can be anything, not just a callable:

Suggested change
lexicon: Sequence[Tuple[AnyStr, Callable[[Scanner, AnyStr], Any]]],
lexicon: Sequence[Tuple[AnyStr, Any]],

Alternatively, another TypeVar for the return value might make sense, in which case this would be:

Suggested change
lexicon: Sequence[Tuple[AnyStr, Callable[[Scanner, AnyStr], Any]]],
lexicon: Sequence[Tuple[AnyStr, Union[None, _T, Callable[[Scanner, AnyStr], Optional[_T]]]],

flags: _FlagsType = ...,
) -> None: ...
def scan(self, string: AnyStr) -> Tuple[List[Any], AnyStr]: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of introducing another type var, List[Any] -> List[_T].