Skip to content

Document re.Scanner #106338

Closed
Closed

Description

@JosephSBoyle

Documentation

re.Scanner is currently marked as "experimental" but was added to the standard library 24 years ago[0].
People seem to think this is an interesting feature[1][2] and a github code search for re.Scanner( gives >500 hits[3],
suggesting people have found practical uses for the class.

Proposal

I suggest we add a few lines to the docs describing what it is and perhaps a short docstring with an example.

Some previously collated discussions:
#91308 (comment)

[0].

# experimental stuff (see python-dev discussions for details)

[1]. https://news.ycombinator.com/item?id=36517749
[2]. https://www.reddit.com/r/ProgrammerTIL/comments/4tpt03/python_til_about_rescanner_which_is_useful_for/
[3]. https://github.com/search?q=re.Scanner%28+language%3APython&type=code

Linked PRs

Activity

  1. AlexWaygood commented on Jul 2, 2023

    @AlexWaygood
    Member

    @vstinner put together a list of places where this has previously been discussed here: #91308 (comment)

    Cc. @serhiy-storchaka as well, for interest

  2. rhettinger commented on Jul 3, 2023

    @rhettinger
    Contributor

    I believe that Scanner was intentionally left undocumented and only left in because someone might have found it and relied on it. The tool was deemed to be a dead end.

  3. serhiy-storchaka commented on Jul 3, 2023

    @serhiy-storchaka
    Member

    One of problems is that it may conflict with the name of internal class _sre.SRE_Scanner if we make it public like we did with _sre.SRE_Pattern and _sre.SRE_Match (now exposed as re.Pattern and re.Match for documentation purposes). _sre.SRE_Scanner is used in implementation of re.Pattern.finditer(), but it also the type of the result of undocumented re.Pattern.scanner(). If we decide to document re.Pattern.scanner(), we will have a problem.

  4. encukou commented on Sep 8, 2026

    @encukou
    Member

    Any new code is better off starting with the example tokenizer in the docs, which doesn't include re.Scanner's quirks (like the if callable() or skipping None), but lets you add any quirks you need. It also adds line/column information to tokens, for better error messages.

    I think we should link these docs from re.Scanner source, and leave it at that.

  5. fry69 commented on Oct 19, 2026

    @fry69
    Contributor

    Any new code is better off starting with the example tokenizer in the docs,

    FYI: That link got mangled (you need explicit https:// for outside links in Markdown, or it get prefixed with the current domain).

    Here is where it wants to point to -> https://docs.python.org/3/library/re.html#writing-a-tokenizer

  6. zeyadrabie commented on Nov 5, 2026

    @zeyadrabie
    Contributor

    Hey. Can I be assigned to this? What I would do is what @encukou suggested: add a comment on re.Scanner in Lib/re/__init__.py that links to https://docs.python.org/3/library/re.html#writing-a-tokenizer, and stop there, so Scanner itself stays undocumented.

  7. encukou commented on Nov 5, 2026

    @encukou
    Member

    You can't be assigned (GitHub's UI doesn't allow it), but it looks like no one else is working on this, feel free to send the PR.

  8. added a commit that references this issue on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions