Skip to content

Conversation

shoaniki
Copy link
Contributor

In CPython, from __future__ import print_function works both in scripts and interactive interpreters; in the latter it can be enabled at any time and will apply to the parsing of all subsequent inputs. The same is true of unicode_literals.

Jython implements this correctly in scripts, but it has never worked in interactive interpreters. This was reported early in Jython 2.7 development (https://bugs.jython.org/issue2007), but apparently today is the first time it's been sufficiently annoying for someone to dig into Jython guts and fix it ;)

The cause is that each input is handled by a new PythonParser, and PythonParser currently only enables future features if it sees the import statement itself. Fortunately the feature flags are also recorded in PythonInterpreter.cflags, and this is already passed to the ParserFacade that creates the parser instances, so it is straightforward to add the missing step and initialize the parser correctly.

@shoaniki shoaniki changed the base branch from master to main April 24, 2021 10:10
@shoaniki shoaniki force-pushed the master branch 2 times, most recently from 3c951f0 to 1c5da28 Compare April 24, 2021 10:16
@shoaniki shoaniki changed the base branch from main to master April 24, 2021 10:16
@jeff5 jeff5 added this to the Jython 2.7.3 milestone May 8, 2022
@jeff5 jeff5 self-assigned this May 8, 2022
@jeff5
Copy link
Member

jeff5 commented May 8, 2022

@shoaniki : It's taken a while to get to this, but I really appreciate you digging into the guts to fix this. Let's see if we can get it in the next release.

I'll ask you to sign the Python Contributor Agreement before we can merge this, but meanwhile, I'll pull it down for review.

Copy link
Member

@jeff5 jeff5 left a comment

Choose a reason for hiding this comment

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

This is good! I traced through the un-patched version and it's really difficult to spot where the necessary transfer of options isn't happening, so well done for finding what's missing.

No actual code changes are needed.

I'd like to merge this on condition only that you sign the Python Contributor Agreement. Let us know it's happened on the PR -- the PSF process is changing we're not properly joined up yet.

@jeff5
Copy link
Member

jeff5 commented May 14, 2022

I'll push a few change sets onto the PR to bring it up to the current head, so the squash-merge works, and add you to the acknowledgments file. Is your GitHub name @shoaniki all you want to appear?

Unfortunately, this will make a mess of your clone of our repo. (The clean way was to create a new branch and PR from there. We use essentially the same process as for CPython with the C-specific things adjusted.)

And a bit of formatting of the test to project standard.
@shoaniki
Copy link
Contributor Author

shoaniki commented Jul 5, 2022

Whoops, I completely forgot about this too, until just now when I was wondering why print_function wasn't working and came looking to see if anyone had run into the problem before 😅

I have now signed the CLA.

Re acknowledgements, yes, just my Github handle is fine thank you.

@jeff5
Copy link
Member

jeff5 commented Jul 6, 2022

That was close. I built a 2.7.3b1 last night, but will call it a dry-run.

I assumed GitHub would ping you about the "change required" -- just the CLA, in practice -- and was disappointed not to be able to include this, so thanks for signing, @shoaniki.

You'll see some more pushes onto your repo to deconflict the merge.

@jeff5 jeff5 merged commit 87f92b8 into jython:master Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants