You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
doctest test finder doesnt find line numbers of properties #61648
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=Noneclosed_at=Nonecreated_at=<Date2013-03-17.16:08:27.046>labels= ['type-bug', '3.7']
title='doctest test finder doesnt find line numbers of properties'updated_at=<Date2019-10-28.17:25:43.144>user='https://github.com/RonnyPfannschmidt'
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 commented on Feb 1, 2016
timofurrermannequin
Mannequin
More actions
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 commented on Feb 5, 2016
mscuthbertmannequin
Mannequin
More actions
The test looks great to me. Does anyone on nosy know the proper way to request a patch review?
Vgr255 commented on Feb 5, 2016
Vgr255mannequin
Mannequin
More actions
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 commented on Feb 5, 2016
timofurrermannequin
Mannequin
More actions
Yes, I've tested it.
mscuthbert commented on Mar 8, 2016
mscuthbertmannequin
Mannequin
More actions
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 commented on Mar 21, 2016
mscuthbertmannequin
Mannequin
More actions
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 commented on May 16, 2017
mscuthbertmannequin
Mannequin
More actions
just poking to see if this patch is worth trying to get into 3.7
Activity
RonnyPfannschmidt commentedon Mar 17, 2013
examples that are found on a property dont detect the line number
BreamoreBoy commentedon Oct 1, 2014
@ronny can you provide a patch for this?
mscuthbert commentedon 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:
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 commentedon 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 commentedon Feb 5, 2016
The test looks great to me. Does anyone on nosy know the proper way to request a patch review?
Vgr255 commentedon 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 commentedon Feb 5, 2016
Yes, I've tested it.
mscuthbert commentedon 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 commentedon 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:
mscuthbert commentedon May 16, 2017
just poking to see if this patch is worth trying to get into 3.7
mscuthbert commentedon Oct 4, 2017
A pull request has been in for about a month -- is it possible to review or merge or comment? Thanks!
blueyed commentedon Oct 28, 2019
The PR appears to need a better test according to #3419 (comment).
1 remaining item
AA-Turner commentedon Jun 7, 2022
The linked PR (#3419) seems to have been closed with no discussion, I'm reopening.
A
pythongh-61648: Detect line numbers of properties in doctests
gh-61648: Detect line numbers of properties in doctests (GH-113161)
pythongh-61648: Detect line numbers of properties in doctests (python…
pythongh-61648: Detect line numbers of properties in doctests (python…
[3.11] gh-61648: Detect line numbers of properties in doctests (GH-11…
[3.12] gh-61648: Detect line numbers of properties in doctests (GH-11…
pythongh-61648: Detect line numbers of properties in doctests (python…
pythongh-61648: Detect line numbers of properties in doctests (python…
pythongh-61648: Detect line numbers of properties in doctests (python…
Keep the doctest `_find_lineno` workaround covered in CI
Keep the doctest `_find_lineno` workaround covered in CI
Keep the doctest `_find_lineno` workaround covered in CI