Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix super call in list comprehension #5393

Merged
merged 1 commit into from Feb 3, 2024
Merged

Conversation

r04922101
Copy link
Contributor

@r04922101 r04922101 commented Jan 26, 2024

python doc super()

The zero argument form only works inside a class definition, as the compiler fills in the necessary details to correctly retrieve the class being defined, as well as accessing the current instance for ordinary methods.

List comprehension works in a separate scope, where doesn't have class information. Zero argument super call doesn't work in such a scope.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@davidism davidism added this to the 3.0.2 milestone Feb 3, 2024
@davidism
Copy link
Member

davidism commented Feb 3, 2024

Ah, this was because in Python 3.12, list comprehensions no longer execute in a separate hidden function scope. So no-arg super() became valid, which is what I saw when cleaning up things locally, but still didn't work on older Python versions.

Thanks for adding a test, that's why it wasn't caught last time.

I've reverted the change that caused this, with a further note not to modify it until 3.12 is the minimum supported version.

@davidism davidism merged commit d7209a9 into pallets:3.0.x Feb 3, 2024
13 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants