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

doctest test finder doesnt find line numbers of properties #61648

Closed
RonnyPfannschmidt mannequin opened this issue Mar 17, 2013 · 14 comments
Closed

doctest test finder doesnt find line numbers of properties #61648

RonnyPfannschmidt mannequin opened this issue Mar 17, 2013 · 14 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@RonnyPfannschmidt
Copy link
Mannequin

RonnyPfannschmidt mannequin commented Mar 17, 2013

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

    @RonnyPfannschmidt
    Copy link
    Mannequin Author

    RonnyPfannschmidt mannequin commented Mar 17, 2013

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

    class example(object):
      @property
      def me(self):
       """
       >>> 1/0
       """
       pass

    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Oct 1, 2014

    @ronny can you provide a patch for this?

    @BreamoreBoy BreamoreBoy mannequin added the type-bug An unexpected behavior, bug, or error label Oct 1, 2014
    @mscuthbert
    Copy link
    Mannequin

    mscuthbert mannequin commented Jan 31, 2016

    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).

    @timofurrer
    Copy link
    Mannequin

    timofurrer mannequin commented Feb 1, 2016

    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 :)

    @mscuthbert
    Copy link
    Mannequin

    mscuthbert mannequin commented Feb 5, 2016

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

    @Vgr255
    Copy link
    Mannequin

    Vgr255 mannequin commented Feb 5, 2016

    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.

    @timofurrer
    Copy link
    Mannequin

    timofurrer mannequin commented Feb 5, 2016

    Yes, I've tested it.

    @mscuthbert
    Copy link
    Mannequin

    mscuthbert mannequin commented Mar 8, 2016

    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!

    @mscuthbert
    Copy link
    Mannequin

    mscuthbert mannequin commented Mar 21, 2016

    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)
    

    @mscuthbert
    Copy link
    Mannequin

    mscuthbert mannequin commented May 16, 2017

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

    @mscuthbert mscuthbert mannequin added the 3.7 (EOL) end of life label May 16, 2017
    @mscuthbert
    Copy link
    Mannequin

    mscuthbert mannequin commented Oct 4, 2017

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

    @blueyed
    Copy link
    Mannequin

    blueyed mannequin commented Oct 28, 2019

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

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

    The code I contributed to 3.7 is still, I believe, the best path forward. Based on my experiences trying to contribute to cpython, I will not be continuing on this issue. It can be closed.

    @AA-Turner
    Copy link
    Member

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

    A

    @iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
    serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Dec 15, 2023
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 15, 2023
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Dec 15, 2023
    serhiy-storchaka added a commit that referenced this issue Dec 15, 2023
    serhiy-storchaka added a commit that referenced this issue Dec 15, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants