Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
pablogsal merged 10 commits intopython:mainfrompablogsal:gh-125331
Feb 14, 2025

Conversation

@pablogsal
Copy link
Member

@pablogsalpablogsal commentedOct 14, 2024
edited by bedevere-appbot
Loading

wimglenn reacted with rocket emoji
@nineteendo
Copy link
Contributor

nineteendo commentedOct 14, 2024
edited
Loading

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
Copy link
Contributor

nineteendo commentedOct 14, 2024
edited
Loading

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

@JelleZijlstra
Copy link
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.

@pablogsal
Copy link
MemberAuthor

pablogsal commentedOct 14, 2024
edited
Loading

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

lysnikolaou and wimglenn reacted with thumbs up emoji

@nineteendo
Copy link
Contributor

cc@warsaw

@thatbirdguythatuknownot
Copy link
Contributor

thatbirdguythatuknownot commentedOct 15, 2024
edited
Loading

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

nineteendo reacted with thumbs up emoji

Copy link
Member

@lysnikolaoulysnikolaou left a 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.

@pablogsal
Copy link
MemberAuthor

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

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

@pablogsalpablogsalforce-pushed thegh-125331 branch 3 times, most recently fromcd167c2 to8fb86b3CompareOctober 29, 2024 23:33
@pablogsal
Copy link
MemberAuthor

@lysnikolaou can you take another look?

@pablogsalpablogsal marked this pull request as ready for reviewOctober 29, 2024 23:47
Copy link
Member

@lysnikolaoulysnikolaou left a 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.

Copy link
Member

@picnixzpicnixz left a 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!

Copy link
Member

@JelleZijlstraJelleZijlstra left a 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 syntax

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

nineteendo and pablogsal reacted with thumbs up emoji
pablogsaland others added9 commitsFebruary 13, 2025 00:45
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>
@pablogsal
Copy link
MemberAuthor

pablogsal commentedFeb 13, 2025
edited
Loading

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

@pablogsalpablogsalenabled auto-merge (squash)February 13, 2025 00:51
@pablogsalpablogsal merged commit3bd3e09 intopython:mainFeb 14, 2025
45 of 46 checks passed
@pablogsalpablogsal deleted the gh-125331 branchFebruary 14, 2025 04:54
@pablogsalpablogsal added needs backport to 3.12only security fixes needs backport to 3.13bugs and security fixes labelsMar 10, 2025
@miss-islington-app
Copy link

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

@miss-islington-app
Copy link

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 10, 2025
…ly (pythonGH-125482)(cherry picked from commit3bd3e09)Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@bedevere-app
Copy link

GH-131062 is a backport of this pull request to the3.13 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.13bugs and security fixes labelMar 10, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestMar 10, 2025
…ly (pythonGH-125482)(cherry picked from commit3bd3e09)Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
@bedevere-app
Copy link

GH-131063 is a backport of this pull request to the3.12 branch.

@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelMar 10, 2025
pablogsal added a commit that referenced this pull requestMar 10, 2025
…fly (GH-125482) (#131063)gh-125331: Allow the parser to activate future imports on the fly (GH-125482)(cherry picked from commit3bd3e09)Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
pablogsal added a commit that referenced this pull requestMar 10, 2025
…fly (GH-125482) (#131062)gh-125331: Allow the parser to activate future imports on the fly (GH-125482)(cherry picked from commit3bd3e09)Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@picnixzpicnixzpicnixz approved these changes

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

@lysnikolaoulysnikolaoulysnikolaou approved these changes

+1 more reviewer

@nineteendonineteendonineteendo left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

6 participants

@pablogsal@nineteendo@JelleZijlstra@thatbirdguythatuknownot@picnixz@lysnikolaou

[8]ページ先頭

©2009-2025 Movatter.jp