[issue42116] Inspect library ignore comments at the end of a function (inspect.getsource)

Irit Katriel report at bugs.python.org
Thu Dec 3 10:12:06 EST 2020


Irit Katriel <iritkatriel at yahoo.com> added the comment:

1. For a comment line, the tokenizer emits a COMMENT token followed by an NL token for the newline. The inspect.BlockFinder.tokeneater increments its "last" field to the last line it identified as belonging to the code block. Currently it increments it when it sees a NEWLINE token, but not for an NL token.

2. For a comment line, the tokenizer does not emit an INDENT/DEDENT token, so the indentation level when it is processes is assumed to be equal to that of the previous line.

PR 23630 aims to include comment lines in the block if their start column is after the start column of the opening line of the block:

   def f():
      return 42

     # this is a part of f
   # this is not a part of f

----------
nosy: +taleinat
versions: +Python 3.10, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42116>
_______________________________________


More information about the Python-bugs-list mailing list