Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
gh-125331: Allow the parser to activate future imports on the fly#125482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
nineteendo commentedOct 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Eh, not sure if this is desirable, maybe lock the future behind a repl compiler flag: # tmp.pyfrom __future__importbarry_as_FLUFL1!=2 $ gh-125331/python.exe tmp.py File"/Users/wannes/Documents/GitHub/cpython/tmp.py", line 2 1!= 2 ^^SyntaxError: with Barry as BDFL, use'<>' instead of'!=' This is great though: >>>from __future__importbarry_as_FLUFL...1<>2...True |
nineteendo commentedOct 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
This change isn't backwards compatible, although it only affects 14 files (Github search). |
JelleZijlstra commentedOct 14, 2024
I feel it should work like any other future import, so it can serve as an example.
I feel those people are asking for it; they're using an undocumented joke feature. We can limit this change to 3.14 though. |
pablogsal commentedOct 14, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The whole point of this is that it works everywhere, not just in the REPL
haha, we need to decide if is a bug or if is not. If we decide this should work everywhere the fact that those people are using isfixing the bug. In the issue I said I don't think this is a bug, but if we decide that it is, then it is not backwards incompatible: it's fixing a bug. Notice there is no documentation about how this is supposed to work and all observable behaviour is not protected for backwards compatibility. |
nineteendo commentedOct 15, 2024
cc@warsaw |
thatbirdguythatuknownot commentedOct 15, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
How about the multiple-name imports? from __future__importannotations,barry_as_FLUFLx:Aprint(__annotations__['x'])# Aprint(1<>2)# True If I'm looking at the code correctly, it only accepts single-name imports for now.. |
lysnikolaou left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'm generally okay with this, I think we do some similar hacky things elsewhere.
A couple of minor comments.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
pablogsal commentedOct 15, 2024
Yeah, the PR is only a draft for evaluating the idea, is still missing many things like tests, NEWs...etc |
Uh oh!
There was an error while loading.Please reload this page.
cd167c2 to8fb86b3Comparepablogsal commentedOct 29, 2024
@lysnikolaou can you take another look? |
Uh oh!
There was an error while loading.Please reload this page.
lysnikolaou left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM! 🎉 A couple of very nitty comments. Feel free to diregard.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issue-125331.quKQ7V.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issue-125331.quKQ7V.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
picnixz left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Thanks Pablo & Jelle for answering my questions!
Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issue-125331.quKQ7V.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
JelleZijlstra left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Someone alluded to it above, but this incorrectly picks up relative future imports:
>>> from .__future__ import barry_as_FLUFL; 1 <> 2Traceback (most recent call last): File "<python-input-4>", line 1, in <module> from .__future__ import barry_as_FLUFL; 1 <> 2 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ModuleNotFoundError: No module named '_pyrepl.__future__'True>>> from .__future__ import barry_as_FLUFLx; 1 <> 2 File "<python-input-5>", line 1 from .__future__ import barry_as_FLUFLx; 1 <> 2 ^^SyntaxError: invalid syntaxThe first one correctly throws ModuleNotFoundError, but it also allows1 <> 2. The second one throws a SyntaxError as expected.
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…e-125331.quKQ7V.rstCo-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Nice Zombies <nineteendo19d0@gmail.com>
…e-125331.quKQ7V.rstCo-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
…gh-issue-125331.quKQ7V.rst
pablogsal commentedFeb 13, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@JelleZijlstra I have fixed the relative imports, rebased and added a test, can you review it again? |
3bd3e09 intopython:mainUh oh!
There was an error while loading.Please reload this page.
Thanks@pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Thanks@pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…ly (pythonGH-125482)(cherry picked from commit3bd3e09)Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
GH-131062 is a backport of this pull request to the3.13 branch. |
…ly (pythonGH-125482)(cherry picked from commit3bd3e09)Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
GH-131063 is a backport of this pull request to the3.12 branch. |
Uh oh!
There was an error while loading.Please reload this page.
from __future__ import barry_as_FLUFLdoesn't work #125331