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.

Author nedbat
Recipients nedbat
Date 2018-06-03.11:11:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528024309.59.0.592728768989.issue33745@psf.upfronthosting.co.za>
In-reply-to
Content
I'm not sure if this is a regression or an intentional change.  I know that the behavior has changed.

If a function has a docstring but no other body, Python 3.7b5 assigns the line number of the docstring to the implicit "return None".  Previous versions (including 3.7b4) used the line number of the "def".

Demonstration:

$ cat /tmp/empty.py
def empty():
    pass

def empty_with_docstring():
    '''Docstring'''

def docstring():
    '''Docstring'''
    return 1

import dis, sys

print(sys.version)

for fn in [empty, empty_with_docstring, docstring]:
    print(fn.__name__)
    dis.dis(fn)

$ /usr/local/pythonz/pythons/CPython-2.7.14/bin/python2.7 /tmp/empty.py
2.7.14 (default, Oct  4 2017, 09:45:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
empty
  2           0 LOAD_CONST               0 (None)
              3 RETURN_VALUE
empty_with_docstring
  4           0 LOAD_CONST               1 (None)
              3 RETURN_VALUE
docstring
  9           0 LOAD_CONST               1 (1)
              3 RETURN_VALUE

$ /usr/local/pythonz/pythons/CPython-3.6.4/bin/python3.6 /tmp/empty.py
3.6.4 (default, Dec 19 2017, 08:11:42)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
empty
  2           0 LOAD_CONST               0 (None)
              2 RETURN_VALUE
empty_with_docstring
  4           0 LOAD_CONST               1 (None)
              2 RETURN_VALUE
docstring
  9           0 LOAD_CONST               1 (1)
              2 RETURN_VALUE

$ /usr/local/pythonz/pythons/CPython-3.7.0b4/bin/python3.7 /tmp/empty.py
3.7.0b4 (default, May  2 2018, 21:07:21)
[Clang 9.0.0 (clang-900.0.39.2)]
empty
  2           0 LOAD_CONST               0 (None)
              2 RETURN_VALUE
empty_with_docstring
  4           0 LOAD_CONST               1 (None)
              2 RETURN_VALUE
docstring
  9           0 LOAD_CONST               1 (1)
              2 RETURN_VALUE

$ /usr/local/pythonz/pythons/CPython-3.7.0b5/bin/python3.7 /tmp/empty.py
3.7.0b5 (default, Jun  2 2018, 11:27:19)
[Clang 9.1.0 (clang-902.0.39.2)]
empty
  2           0 LOAD_CONST               0 (None)
              2 RETURN_VALUE
empty_with_docstring
  5           0 LOAD_CONST               1 (None)
              2 RETURN_VALUE
docstring
  9           0 LOAD_CONST               1 (1)
              2 RETURN_VALUE
History
Date User Action Args
2018-06-03 11:11:49nedbatsetrecipients: + nedbat
2018-06-03 11:11:49nedbatsetmessageid: <1528024309.59.0.592728768989.issue33745@psf.upfronthosting.co.za>
2018-06-03 11:11:49nedbatlinkissue33745 messages
2018-06-03 11:11:49nedbatcreate