GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-125331: Allow the parser to activate future imports on the fly by pablogsal · Pull Request #125482 · python/cpython

Conversation

@pablogsal

@pablogsal pablogsal commented Oct 14, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: from __future__ import barry_as_FLUFL doesn't work #125331

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

wimglenn reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@bedevere-app bedevere-app Bot mentioned this pull request Oct 14, 2024
from __future__ import barry_as_FLUFL doesn't work #125331
Closed
@nineteendo

nineteendo commented Oct 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Eh, not sure if this is desirable, maybe lock the future behind a repl compiler flag:

# tmp.py
from __future__ import barry_as_FLUFL
1 != 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__ import barry_as_FLUFL
... 1 <> 2
... 
True
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nineteendo

nineteendo commented Oct 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

This change isn't backwards compatible, although it only affects 14 files (Github search).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Oct 14, 2024

Copy link
Copy Markdown
Member

Eh, not sure if this is desirable, maybe lock the future behind a repl compiler flag

I feel it should work like any other future import, so it can serve as an example.

This change isn't backwards compatible, although it only affects 14 files (Github search).

I feel those people are asking for it; they're using an undocumented joke feature. We can limit this change to 3.14 though.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Oct 14, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Eh, not sure if this is desirable, maybe lock the future behind a repl compiler flag:

The whole point of this is that it works everywhere, not just in the REPL

This change isn't backwards compatible, although it only affects 14 files (Github search).

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 is fixing 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.

lysnikolaou and wimglenn reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@nineteendo

nineteendo commented Oct 15, 2024

Copy link
Copy Markdown
Contributor

cc @warsaw

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@thatbirdguythatuknownot

thatbirdguythatuknownot commented Oct 15, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

How about the multiple-name imports?

from __future__ import annotations, barry_as_FLUFL
x: A
print(__annotations__['x'])  # A
print(1 <> 2)  # True

If I'm looking at the code correctly, it only accepts single-name imports for now..

nineteendo reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou
lysnikolaou reviewed Oct 15, 2024
View reviewed changes

@lysnikolaou lysnikolaou left a comment

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Grammar/python.gram Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Parser/action_helpers.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

nineteendo
nineteendo reviewed Oct 15, 2024
View reviewed changes
Comment thread Parser/action_helpers.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal

pablogsal commented Oct 15, 2024

Copy link
Copy Markdown
Member Author

How about the multiple-name imports?

from __future__ import annotations, barry_as_FLUFL
x: A
print(__annotations__['x'])  # A
print(1 <> 2)  # True

If I'm looking at the code correctly, it only accepts single-name imports for now..

Yeah, the PR is only a draft for evaluating the idea, is still missing many things like tests, NEWs...etc

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal commented Oct 15, 2024
View reviewed changes
Comment thread Grammar/python.gram Resolved

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal force-pushed the gh-125331 branch 3 times, most recently from cd167c2 to 8fb86b3 Compare October 29, 2024 23:33
@pablogsal

pablogsal commented Oct 29, 2024

Copy link
Copy Markdown
Member Author

@lysnikolaou can you take another look?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal marked this pull request as ready for review October 29, 2024 23:47
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 29, 2024
nineteendo
nineteendo reviewed Oct 30, 2024
View reviewed changes
Comment thread Lib/test/test_grammar.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

lysnikolaou
lysnikolaou approved these changes Oct 30, 2024
View reviewed changes

@lysnikolaou lysnikolaou left a comment

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Parser/action_helpers.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issue-125331.quKQ7V.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Oct 30, 2024
picnixz
picnixz reviewed Oct 30, 2024
View reviewed changes
Comment thread Parser/action_helpers.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Oct 30, 2024
View reviewed changes
Comment thread Lib/test/test_flufl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal commented Oct 30, 2024
View reviewed changes
Comment thread Lib/test/test_flufl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

pablogsal
pablogsal commented Oct 30, 2024
View reviewed changes
Comment thread Lib/test/test_flufl.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Oct 30, 2024
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issue-125331.quKQ7V.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Parser/action_helpers.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Parser/action_helpers.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Parser/action_helpers.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz approved these changes Oct 30, 2024
View reviewed changes

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
JelleZijlstra
JelleZijlstra reviewed Oct 30, 2024
View reviewed changes
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issue-125331.quKQ7V.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra
JelleZijlstra requested changes Oct 30, 2024
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

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 <> 2
Traceback (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 syntax

The first one correctly throws ModuleNotFoundError, but it also allows 1 <> 2. The second one throws a SyntaxError as expected.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

nineteendo and pablogsal reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 30, 2024
pablogsal and others added 9 commits February 13, 2025 00:45
@pablogsal @lysnikolaou @nineteendo
Apply suggestions from code review
4ef188c
Co-authored-by: Lysandros Nikolaou <[email protected]>
Co-authored-by: Nice Zombies <[email protected]>
Signed-off-by: Pablo Galindo <[email protected]>
@pablogsal
Fix whitespace
c316541
@pablogsal @lysnikolaou @picnixz
Apply suggestions from code review
d12081a
Co-authored-by: Lysandros Nikolaou <[email protected]>
Co-authored-by: Bénédikt Tran <[email protected]>
@pablogsal
Update Lib/test/test_flufl.py
68b29e4
@pablogsal
Update Lib/test/test_flufl.py
53a237e
@pablogsal @picnixz
Update Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issu…
941d2ed
…e-125331.quKQ7V.rst

Co-authored-by: Bénédikt Tran <[email protected]>
@pablogsal @nineteendo
Update action_helpers.c
f377291
Co-authored-by: Nice Zombies <[email protected]>
@pablogsal @JelleZijlstra
Update Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.gh-issu…
babe18b
…e-125331.quKQ7V.rst

Co-authored-by: Jelle Zijlstra <[email protected]>
@pablogsal
fixup! Update Misc/NEWS.d/next/Core_and_Builtins/2024-10-29-23-30-35.…
76d8c9f
…gh-issue-125331.quKQ7V.rst
@pablogsal
pablogsal force-pushed the gh-125331 branch from 387e67f to 76d8c9f Compare February 13, 2025 00:50
@pablogsal

pablogsal commented Feb 13, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

@JelleZijlstra I have fixed the relative imports, rebased and added a test, can you review it again?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pablogsal
pablogsal enabled auto-merge (squash) February 13, 2025 00:51
JelleZijlstra
JelleZijlstra approved these changes Feb 14, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting changes labels Feb 14, 2025
@pablogsal
pablogsal merged commit 3bd3e09 into python:main Feb 14, 2025
@pablogsal
pablogsal deleted the gh-125331 branch February 14, 2025 04:54
@bedevere-app bedevere-app Bot removed the awaiting merge label Feb 14, 2025
@pablogsal pablogsal added needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Mar 10, 2025
@miss-islington-app

miss-islington-app Bot commented Mar 10, 2025

Copy link
Copy Markdown

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented Mar 10, 2025

Copy link
Copy Markdown

Thanks @pablogsal for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 10, 2025
@pablogsal @miss-islington
pythongh-125331: Allow the parser to activate future imports on the f…
98f0c71
…ly (pythonGH-125482)

(cherry picked from commit 3bd3e09)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
@bedevere-app

bedevere-app Bot commented Mar 10, 2025

Copy link
Copy Markdown

GH-131062 is a backport of this pull request to the 3.13 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label Mar 10, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 10, 2025
@pablogsal @miss-islington
pythongh-125331: Allow the parser to activate future imports on the f…
f0889aa
…ly (pythonGH-125482)

(cherry picked from commit 3bd3e09)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
@bedevere-app

bedevere-app Bot commented Mar 10, 2025

Copy link
Copy Markdown

GH-131063 is a backport of this pull request to the 3.12 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label Mar 10, 2025
pablogsal added a commit that referenced this pull request Mar 10, 2025
@miss-islington @pablogsal
[3.12] gh-125331: Allow the parser to activate future imports on the …
fcf1f57
…fly (GH-125482) (#131063)

gh-125331: Allow the parser to activate future imports on the fly (GH-125482)
(cherry picked from commit 3bd3e09)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
pablogsal added a commit that referenced this pull request Mar 10, 2025
@miss-islington @pablogsal
[3.13] gh-125331: Allow the parser to activate future imports on the …
ebd2ed7
…fly (GH-125482) (#131062)

gh-125331: Allow the parser to activate future imports on the fly (GH-125482)
(cherry picked from commit 3bd3e09)

Co-authored-by: Pablo Galindo Salgado <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@picnixz picnixz picnixz approved these changes
@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes
@lysnikolaou lysnikolaou lysnikolaou approved these changes
+1 more reviewer
@nineteendo nineteendo nineteendo left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@pablogsal @nineteendo @JelleZijlstra @thatbirdguythatuknownot @picnixz @lysnikolaou
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.