This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: doctest test finder doesnt find line numbers of properties
Type: behavior Stage: patch review
Components: Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Ronny.Pfannschmidt, abarry, blueyed, mscuthbert, r.david.murray, tuxtimo
Priority: normal Keywords: patch

Created on 2013-03-17 16:08 by Ronny.Pfannschmidt, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
fix_issue_17446.patch tuxtimo, 2016-02-01 01:51 review
Pull Requests
URL Status Linked Edit
PR 3419 open mscuthbert, 2017-09-07 04:32
Messages (12)
msg184384 - (view) Author: Ronny Pfannschmidt (Ronny.Pfannschmidt) Date: 2013-03-17 16:08
examples that are found on a property dont detect the line number

class example(object):
  @property
  def me(self):
   """
   >>> 1/0
   """
   pass
msg228122 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-10-01 21:07
@Ronny can you provide a patch for this?
msg259300 - (view) Author: Michael Cuthbert (mscuthbert) * Date: 2016-01-31 18:51
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).
msg259306 - (view) Author: Timo Furrer (tuxtimo) * Date: 2016-02-01 01:51
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 :)
msg259618 - (view) Author: Michael Cuthbert (mscuthbert) * Date: 2016-02-05 02:24
The test looks great to me.  Does anyone on nosy know the proper way to request a patch review?
msg259620 - (view) Author: Anilyka Barry (abarry) * (Python triager) Date: 2016-02-05 02:30
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.
msg259621 - (view) Author: Timo Furrer (tuxtimo) * Date: 2016-02-05 02:41
Yes, I've tested it.
msg261372 - (view) Author: Michael Cuthbert (mscuthbert) * Date: 2016-03-08 19:48
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!
msg262146 - (view) Author: Michael Cuthbert (mscuthbert) * Date: 2016-03-21 20:24
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)
msg293747 - (view) Author: Michael Cuthbert (mscuthbert) * Date: 2017-05-16 03:30
just poking to see if this patch is worth trying to get into 3.7
msg303699 - (view) Author: Michael Cuthbert (mscuthbert) * Date: 2017-10-04 14:46
A pull request has been in for about a month -- is it possible to review or merge or comment?  Thanks!
msg355572 - (view) Author: daniel hahler (blueyed) * Date: 2019-10-28 17:25
The PR appears to need a better test according to https://github.com/python/cpython/pull/3419#issuecomment-350570083.
History
Date User Action Args
2022-04-11 14:57:42adminsetgithub: 61648
2019-10-28 17:25:43blueyedsetnosy: + blueyed
messages: + msg355572
2017-10-04 14:46:15mscuthbertsetmessages: + msg303699
2017-09-07 04:32:04mscuthbertsetpull_requests: + pull_request3416
2017-05-16 03:30:57mscuthbertsetmessages: + msg293747
versions: + Python 3.7, - Python 2.7, Python 3.4, Python 3.5
2016-03-21 20:24:24mscuthbertsetmessages: + msg262146
2016-03-08 19:48:53mscuthbertsetmessages: + msg261372
2016-02-05 02:41:56tuxtimosetmessages: + msg259621
2016-02-05 02:30:56abarrysetnosy: + abarry

messages: + msg259620
stage: patch review
2016-02-05 02:25:00mscuthbertsetmessages: + msg259618
2016-02-01 01:51:30tuxtimosetfiles: + fix_issue_17446.patch

nosy: + tuxtimo
messages: + msg259306

keywords: + patch
2016-02-01 01:23:15BreamoreBoysetnosy: - BreamoreBoy
2016-01-31 18:51:59mscuthbertsetnosy: + mscuthbert
messages: + msg259300
2014-10-01 21:07:32BreamoreBoysetversions: + Python 2.7, Python 3.4, Python 3.5
nosy: + BreamoreBoy

messages: + msg228122

type: behavior
2013-03-17 19:38:37r.david.murraysetnosy: + r.david.murray
2013-03-17 16:08:27Ronny.Pfannschmidtcreate