Skip to content
Prev Previous commit
Next Next commit
fixup! fixup! gh-105069: Add a readline-like callable to the tokenize…
…r to consume input iteratively
  • Loading branch information
pablogsal committed May 30, 2023
commit d3700879709cedf193b4d190663c66ec22f21452
2 changes: 1 addition & 1 deletion Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -2203,7 +2203,7 @@ def _signature_strip_non_python_syntax(signature):
add(string)
if (string == ','):
add(' ')
clean_signature = ''.join(text).strip()
Copy link
Copy Markdown
Member Author

@pablogsal pablogsal May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is because for some reason the inspect module is relying on the fact that if lines yielded by the generator do not end in \n then they are concatenated together, which is wrong because the contract says "should yield one line at a time" so if the line doesn't end in newline we add one always.

clean_signature = ''.join(text).strip().replace("\n", "")
return clean_signature, self_parameter


Expand Down
2 changes: 1 addition & 1 deletion Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ tok_underflow_file(struct tok_state *tok, int use_readline) {
tok->done = E_EOF;
return 0;
}
if (tok->readline == NULL && tok->inp[-1] != '\n') {
if (tok->inp[-1] != '\n') {
assert(tok->inp + 1 < tok->end);
/* Last line does not end in \n, fake one */
*tok->inp++ = '\n';
Expand Down