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

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

Closed
rzepeckit mannequin opened this issue Aug 12, 2021 · 7 comments
Closed

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

rzepeckit mannequin opened this issue Aug 12, 2021 · 7 comments
Labels
3.9 only security fixes 3.10 only security fixes 3.11 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@rzepeckit
Copy link
Mannequin

rzepeckit mannequin commented Aug 12, 2021

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']

    @rzepeckit
    Copy link
    Mannequin Author

    rzepeckit mannequin commented Aug 12, 2021

    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.

    @rzepeckit rzepeckit mannequin added 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Aug 12, 2021
    @AlexWaygood
    Copy link
    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__'

    @AlexWaygood AlexWaygood added 3.10 only security fixes 3.11 only security fixes labels Oct 9, 2021
    @AlexWaygood AlexWaygood changed the title Erroneous behaviour for abstract class properties Classmethod properties are erroneously "called" in multiple modules Oct 9, 2021
    @rhettinger
    Copy link
    Contributor

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

    @serhiy-storchaka
    Copy link
    Member

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

    @miss-islington
    Copy link
    Contributor

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

    @miss-islington
    Copy link
    Contributor

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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @SharpEdgeMarshall
    Copy link

    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
    Labels
    3.9 only security fixes 3.10 only security fixes 3.11 only security fixes type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants