Skip to content

__future__ imports allow dots before them #118216

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

Closed
thatbirdguythatuknownot opened this issue Apr 24, 2024 · 2 comments
Closed

__future__ imports allow dots before them #118216

thatbirdguythatuknownot opened this issue Apr 24, 2024 · 2 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@thatbirdguythatuknownot
Copy link
Contributor

thatbirdguythatuknownot commented Apr 24, 2024

Bug report

Bug description:

__future__ imports don't check the amount of dots while checking from-import nodes for the module name, so they are still valid even if dots are put before the module name.

>>> from .__future__ import barry_as_FLUFL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
    from .__future__ import barry_as_FLUFL
ImportError: attempted relative import with no known parent package
>>> 1 <> 2
True

Is this intended? Allowing dots before the module name seems improper considering __future__ is supposed to be part of the stdlib.

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Windows

Linked PRs

@thatbirdguythatuknownot thatbirdguythatuknownot added the type-bug An unexpected behavior, bug, or error label Apr 24, 2024
@terryjreedy terryjreedy added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Apr 24, 2024
@terryjreedy
Copy link
Member

What is weird is both raising an error and doing the pseudoimport anyway.

@JelleZijlstra
Copy link
Member

Thanks @thatbirdguythatuknownot!

I merged the fix into main (3.13), so I'm closing this.

Arguably this is a bug that could also be fixed in 3.12, but I'd prefer to leave 3.12 unchanged, as the bug is rather harmless in practice and I feel core language behavior shouldn't change in a bugfix release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants