Skip to content

doctest test finder doesnt find line numbers of properties #61648

Closed

Description

@RonnyPfannschmidt
BPO 17446
Nosy @blueyed, @bitdancer, @RonnyPfannschmidt, @Vgr255, @mscuthbert, @timofurrer
PRs
  • bpo-17446: Get line numbers of properties in doctest #3419
  • Files
  • fix_issue_17446.patch
  • 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 = None
    created_at = <Date 2013-03-17.16:08:27.046>
    labels = ['type-bug', '3.7']
    title = 'doctest test finder doesnt find line numbers of properties'
    updated_at = <Date 2019-10-28.17:25:43.144>
    user = 'https://github.com/RonnyPfannschmidt'

    bugs.python.org fields:

    activity = <Date 2019-10-28.17:25:43.144>
    actor = 'blueyed'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2013-03-17.16:08:27.046>
    creator = 'Ronny.Pfannschmidt'
    dependencies = []
    files = ['41769']
    hgrepos = []
    issue_num = 17446
    keywords = ['patch']
    message_count = 12.0
    messages = ['184384', '228122', '259300', '259306', '259618', '259620', '259621', '261372', '262146', '293747', '303699', '355572']
    nosy_count = 6.0
    nosy_names = ['blueyed', 'r.david.murray', 'Ronny.Pfannschmidt', 'abarry', 'mscuthbert', 'tuxtimo']
    pr_nums = ['3419']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue17446'
    versions = ['Python 3.7']

    Linked PRs

    Activity

    1. RonnyPfannschmidt commented on Mar 17, 2013

      RonnyPfannschmidtmannequin
      MannequinAuthor

      examples that are found on a property dont detect the line number

      class example(object):
        @property
        def me(self):
         """
         >>> 1/0
         """
         pass
    2. BreamoreBoy commented on Oct 1, 2014

      BreamoreBoymannequin
      Mannequin

      @ronny can you provide a patch for this?

    3. mscuthbert commented on Jan 31, 2016

      mscuthbertmannequin
      Mannequin

      this is my first contribution to Python core so I really have no idea how to do this, but I have found a solution (works in Py3.4, 2.7):

      in doctest.py after line 1087 ("lineno = getattr(obj, 'co_firstlineno', None)-1") add these lines:

          if lineno is None and isinstance(obj, property) and \
                  obj.fget is not None:
              obj = obj.fget.__code__
              lineno = getattr(obj, 'co_firstlineno', None) 
              # no need for -1 because of decorator. 
      

      I can try to make a patch file for this, but just want to be sure I'm on the right track for contributing first. I know how to do a Git pull, but not hg/patch.

      (p.s., I think the current code "lineno = getattr(obj, 'co_firstlineno', None)-1" has an error; if the getattr does not find 'co_firstlineno', it will return None and then subtract 1 from None which is a TypeError).

    4. timofurrer commented on Feb 1, 2016

      timofurrermannequin
      Mannequin

      I took the ideas from @Michael.Cuthbert and wrote a proper test. It's my first patch so I hope everything's fine with it. If not I'm happy for feedback :)

    5. mscuthbert commented on Feb 5, 2016

      mscuthbertmannequin
      Mannequin

      The test looks great to me. Does anyone on nosy know the proper way to request a patch review?

    6. Vgr255 commented on Feb 5, 2016

      Vgr255mannequin
      Mannequin

      Left a comment on Rietveld. I don't have time right now to check the test, but I suspect you tested it before submitting the patch, so it should probably be fine.

    7. timofurrer commented on Feb 5, 2016

      timofurrermannequin
      Mannequin

      Yes, I've tested it.

    8. mscuthbert commented on Mar 8, 2016

      mscuthbertmannequin
      Mannequin

      looks like we're stuck on a style change (backslash to parens; ironic: I chose backslash to match surrounding code; I never use them myself). tuxtimo - could you fix this? (or I'll do once the move to github is done). Thanks!

    9. mscuthbert commented on Mar 21, 2016

      mscuthbertmannequin
      Mannequin

      Here's a rather obscure bug that I was able to catch before we put this into action: doctests inside the __doc__ for namedtuples (and perhaps all namedtuples?) are instances of property, have .fget, but do not have .fget.__code__. Thus one more check is needed:

          if (lineno is None and 
                  isinstance(obj, property) and
                  obj.fget is not None and 
                  hasattr(obj.fget, '__code__')):
              obj = obj.fget.__code__
              lineno = getattr(obj, 'co_firstlineno', None)
      
    10. mscuthbert commented on May 16, 2017

      mscuthbertmannequin
      Mannequin

      just poking to see if this patch is worth trying to get into 3.7

    11. mscuthbert commented on Oct 4, 2017

      mscuthbertmannequin
      Mannequin

      A pull request has been in for about a month -- is it possible to review or merge or comment? Thanks!

    12. blueyed commented on Oct 28, 2019

      blueyedmannequin
      Mannequin

      The PR appears to need a better test according to #3419 (comment).

    13. transferred this issue fromon Apr 10, 2022
    14. 1 remaining item

    15. AA-Turner commented on Jun 7, 2022

      @AA-Turner
      Member

      The linked PR (#3419) seems to have been closed with no discussion, I'm reopening.

      A

    16. added
      stdlibStandard Library Python modules in the Lib/ directory
      on Nov 23, 2023
    17. added 2 commits that reference this issue on Dec 15, 2023
    18. added 2 commits that reference this issue on Dec 15, 2023
    19. added 2 commits that reference this issue on Dec 15, 2023
    20. added a commit that references this issue on Dec 15, 2023
    21. added a commit that references this issue on Feb 11, 2024
    22. added a commit that references this issue on Sep 2, 2024
    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.7 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions