Skip to content

HTMLParser: undocumented not implemented method #76025

Description

@srittau
mannequin
BPO 31844
Nosy @srittau, @ezio-melotti, @berkerpeksag, @csabella
PRs
  • bpo-31844: Remove _markupbase.ParserBase.error() #8562
  • bpo-31844: Move whatsnew note to 3.10.rst #21504
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/ezio-melotti'
    closed_at = <Date 2020-07-16.06:39:25.857>
    created_at = <Date 2017-10-23.08:27:23.318>
    labels = ['type-bug', 'library', '3.10']
    title = 'HTMLParser: undocumented not implemented method'
    updated_at = <Date 2020-07-16.06:39:25.857>
    user = 'https://github.com/srittau'

    bugs.python.org fields:

    activity = <Date 2020-07-16.06:39:25.857>
    actor = 'berker.peksag'
    assignee = 'ezio.melotti'
    closed = True
    closed_date = <Date 2020-07-16.06:39:25.857>
    closer = 'berker.peksag'
    components = ['Library (Lib)']
    creation = <Date 2017-10-23.08:27:23.318>
    creator = 'srittau'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31844
    keywords = ['patch']
    message_count = 10.0
    messages = ['304782', '304783', '305303', '305306', '322662', '322672', '323968', '371500', '373745', '373746']
    nosy_count = 5.0
    nosy_names = ['srittau', 'ezio.melotti', 'berker.peksag', 'cheryl.sabella', 'William Ayd']
    pr_nums = ['8562', '21504']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31844'
    versions = ['Python 3.10']

    Activity

    1. srittau commented on Oct 23, 2017

      srittaumannequin
      MannequinAuthor

      HTMLParser derives from _markupbase.ParserBase, which has the following method:

      class HTMLParser:
      ...
      
          def error(self, message):
              raise NotImplementedError(
                  "subclasses of ParserBase must override error()")

      HTMLParser does not implement this method and the documentation for HTMLParser (https://docs.python.org/3.6/library/html.parser.html) does not mention that its sub-classes need to override it.

      I am not sure whether this is a documentation omission, whether HTMLParser should provide an (empty?) implementation, or whether ParserBase should not raise a NotImplementedError (to make linters happy).

    2. srittau commented on Oct 23, 2017

      srittaumannequin
      MannequinAuthor

      The quoted code above should have used ParserBase:

      class ParserBase:
      ...
      
          def error(self, message):
              raise NotImplementedError(
                  "subclasses of ParserBase must override error()")
    3. WilliamAyd commented on Oct 31, 2017

      WilliamAydmannequin
      Mannequin

      Would we be open to setting the meta class of the ParserBase to ABCMeta and setting error as an abstract method? That at the very least would make the expectation clearer for subclasses.

      I haven’t contributed to Python before but am open to this as a first attempt if the direction makes sense.

    4. WilliamAyd commented on Oct 31, 2017

      WilliamAydmannequin
      Mannequin

      And assuming that subclass requirement is intentional we could add an optional keyword argument to the HTMLParser that indicates what to do with errors, much like how encoding issues are handled within codecs. For backwards compatibility it can default to ignore, but fail and warn could be two alternate approaches that the error method could account for

    5. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on Oct 31, 2017
    6. berkerpeksag commented on Jul 30, 2018

      @berkerpeksag
      Member

      HTMLParser.error() method was deprecated in Python 3.4 (88ebfb1#diff-1a7486df8279dbac7f20abd487947845R157) and removed in Python 3.5 (73a4359#diff-1a7486df8279dbac7f20abd487947845L171)

      _markupbase is a private and undocumented module and its only user is HTMLParser (sgmllib was removed from the stdlib in 2008) Since we already have removed HTMLParser.error(), I think we can just remove _markupbase.ParserBase.error() without a deprecation period.

    7. srittau commented on Jul 30, 2018

      srittaumannequin
      MannequinAuthor

      Good call. Maybe it's actually time to retire _markupbase and merge ParserBase into HTMLParser.

    8. berkerpeksag commented on Aug 23, 2018

      @berkerpeksag
      Member

      After triaging bpo-34480, I realized that we can't simply remove the error() method because the _markupbase.ParserBase() class still uses it. I've just closed PR 8562.

    9. self-assigned this
      on Aug 25, 2018
    10. csabella commented on Jun 14, 2020

      @csabella
      Contributor

      @berker.peksag's last comment was he closed the PR on 23 August 2018. However, he reopened it on 6 January 2020 as @ezio.melotti mentioned that they are both needed.

      The PR for this issue is waiting to be re-reviewed by Ezio.

    11. berkerpeksag commented on Jul 16, 2020

      @berkerpeksag
      Member

      New changeset e34bbfd by Berker Peksag in branch 'master':
      bpo-31844: Remove _markupbase.ParserBase.error() (GH-8562)
      e34bbfd

    12. berkerpeksag commented on Jul 16, 2020

      @berkerpeksag
      Member

      New changeset d4d127f by Berker Peksag in branch 'master':
      bpo-31844: Move whatsnew note to 3.10.rst (GH-21504)
      d4d127f

    13. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions