Skip to content

Classmethod properties are erroneously "called" in multiple modules #89067

Closed

Description

@rzepeckit
mannequin
BPO 44904
Nosy @tim-one, @rhettinger, @serhiy-storchaka, @miss-islington, @AlexWaygood
PRs
  • bpo-44904: Fix classmethod property bug in doctest module #28838
  • [3.10] bpo-44904: Fix classmethod property bug in doctest module (GH-28838) #29261
  • [3.9] bpo-44904: Fix classmethod property bug in doctest module (GH-28838) #29262
  • Superseder
  • bpo-45356: Calling help executes @classmethod @Property decorated methods
  • Files
  • bug_report.py: Example of the issue
  • classmethod_properties_bug.py: Short script demonstrating how a bug relating to classmethod properties causes doctest.py to crash
  • 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 = None
    closed_at = <Date 2021-10-10.22:18:34.456>
    created_at = <Date 2021-08-12.21:16:41.103>
    labels = ['type-bug', '3.9', '3.10', '3.11']
    title = 'Classmethod properties are erroneously "called" in multiple modules'
    updated_at = <Date 2021-10-28.08:13:53.897>
    user = 'https://bugs.python.org/rzepeckit'

    bugs.python.org fields:

    activity = <Date 2021-10-28.08:13:53.897>
    actor = 'miss-islington'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-10-10.22:18:34.456>
    closer = 'rhettinger'
    components = []
    creation = <Date 2021-08-12.21:16:41.103>
    creator = 'rzepecki.t'
    dependencies = []
    files = ['50212', '50218']
    hgrepos = []
    issue_num = 44904
    keywords = ['patch']
    message_count = 6.0
    messages = ['399482', '399622', '403612', '405154', '405156', '405157']
    nosy_count = 6.0
    nosy_names = ['tim.peters', 'rhettinger', 'serhiy.storchaka', 'miss-islington', 'AlexWaygood', 'rzepecki.t']
    pr_nums = ['28838', '29261', '29262']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '45356'
    type = 'behavior'
    url = 'https://bugs.python.org/issue44904'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. rzepeckit commented on Aug 12, 2021

      rzepeckitmannequin
      MannequinAuthor

      Subclassing an abc with an abstract class property yields to unexpected behaviour: the class property is called, and an abstract class may be erroneously considered concrete.

      See https://stackoverflow.com/a/68763572/4434666 for details.

    2. AlexWaygood commented on Aug 15, 2021

      @AlexWaygood
      Member

      This same bug (where classmethod properties are accidentally called by other parts of Python) is also present for non-abstract class properties, and has the side effect of causing doctest.py to crash with a fairly incomprehensible AttributeError:

      Script:

          class Untestable:
              """
              >>> Untestable.my_classmethod_property
              'Oh no!'
              """
      
              @classmethod
              @property
              def my_classmethod_property(cls):
                  return 'Oh no!'
      
      
          if __name__ == '__main__':
              import doctest
              doctest.testmod()

      Output:

          Traceback (most recent call last):
            File "C:/Users/Alex/classmethod_properties_bug.py", line 13, in <module>
              doctest.testmod()
            File "C:\Users\Alex\.conda\envs\WebGame39\lib\doctest.py", line 1955, in testmod
              for test in finder.find(m, name, globs=globs, extraglobs=extraglobs):
            File "C:\Users\Alex\.conda\envs\WebGame39\lib\doctest.py", line 939, in find
              self._find(tests, obj, name, module, source_lines, globs, {})
            File "C:\Users\Alex\.conda\envs\WebGame39\lib\doctest.py", line 1001, in _find
              self._find(tests, val, valname, module, source_lines,
            File "C:\Users\Alex\.conda\envs\WebGame39\lib\doctest.py", line 1028, in _find
              val = getattr(obj, valname).__func__
          AttributeError: 'str' object has no attribute '__func__'
    3. changed the title [-]Erroneous behaviour for abstract class properties[/-] [+]Classmethod properties are erroneously "called" in multiple modules[/+] on Oct 9, 2021
    4. rhettinger commented on Oct 10, 2021

      @rhettinger
      Contributor

      Moving this discussion to bpo-45356 because some of the discussion would need to be duplicated.

    5. serhiy-storchaka commented on Oct 28, 2021

      @serhiy-storchaka
      Member

      New changeset b1302ab by Alex Waygood in branch 'main':
      bpo-44904: Fix classmethod property bug in doctest module (GH-28838)
      b1302ab

    6. miss-islington commented on Oct 28, 2021

      @miss-islington
      Contributor

      New changeset 1f45cc0 by Miss Islington (bot) in branch '3.10':
      bpo-44904: Fix classmethod property bug in doctest module (GH-28838)
      1f45cc0

    7. miss-islington commented on Oct 28, 2021

      @miss-islington
      Contributor

      New changeset 8365a5b by Miss Islington (bot) in branch '3.9':
      bpo-44904: Fix classmethod property bug in doctest module (GH-28838)
      8365a5b

    8. transferred this issue fromon Apr 10, 2022
    9. SharpEdgeMarshall commented on Aug 29, 2022

      @SharpEdgeMarshall

      This is not fixed, you just fixed an issue on doctest module but the issue persist if you create an abstract class property

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of life3.11only security fixes3.9 (EOL)end of lifetype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions