Skip to content

Conversation

@Sachaa-Thanasius
Copy link
Contributor

@Sachaa-Thanasius Sachaa-Thanasius commented Sep 26, 2025

I think it's more accurate, given CPython bytecode often seems to pass None to fromlist instead of an empty tuple.

Rationale

PowerShell 7.5.3
PS C:\Users\Tushaar> py -3.9 -m dis
import abc
^Z
  1           0 LOAD_CONST               0 (0)
              2 LOAD_CONST               1 (None)
              4 IMPORT_NAME              0 (abc)
              6 STORE_NAME               0 (abc)
              8 LOAD_CONST               1 (None)
             10 RETURN_VALUE
PS C:\Users\name> py -3.10 -m dis
import abc
^Z
  1           0 LOAD_CONST               0 (0)
              2 LOAD_CONST               1 (None)
              4 IMPORT_NAME              0 (abc)
              6 STORE_NAME               0 (abc)
              8 LOAD_CONST               1 (None)
             10 RETURN_VALUE
PS C:\Users\name> py -3.11 -m dis
import abc
^Z
  0           0 RESUME                   0

  1           2 LOAD_CONST               0 (0)
              4 LOAD_CONST               1 (None)
              6 IMPORT_NAME              0 (abc)
              8 STORE_NAME               0 (abc)
             10 LOAD_CONST               1 (None)
             12 RETURN_VALUE
PS C:\Users\name> py -3.12 -m dis
import abc
^Z
  0           0 RESUME                   0

  1           2 LOAD_CONST               0 (0)
              4 LOAD_CONST               1 (None)
              6 IMPORT_NAME              0 (abc)
              8 STORE_NAME               0 (abc)
             10 RETURN_CONST             1 (None)
PS C:\Users\name> py -3.13 -m dis
import abc
^Z
  0           RESUME                   0

  1           LOAD_CONST               0 (0)
              LOAD_CONST               1 (None)
              IMPORT_NAME              0 (abc)
              STORE_NAME               0 (abc)
              RETURN_CONST             1 (None)

https://docs.python.org/3/library/dis.html#opcode-IMPORT_NAME

STACK[-1] and STACK[-2] are popped and provide the fromlist and level arguments of __import__().

Ergo, the LOAD_CONST (None) is being passed as the fromlist parameter, and has been passed since at least CPython 3.9 (maybe even earlier). I'm only showing a test via the dis cli and importing a single module, but the result should be replicable in other conditions.

Plus, the implementation of __import__ in importlib only checks truthiness of fromlist before treating it as populated, so None seems like a valid input when looking there too.

CPython bytecode often passes None as the fromlist.
@github-actions

This comment has been minimized.

CPython bytecode often passes None as the fromlist.
@Sachaa-Thanasius Sachaa-Thanasius force-pushed the more-permissive-import-signature branch from c488d3f to 84e690b Compare September 26, 2025 14:48
@Sachaa-Thanasius Sachaa-Thanasius marked this pull request as ready for review September 26, 2025 14:49
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 16c4e13 into python:main Sep 30, 2025
63 checks passed
@Sachaa-Thanasius Sachaa-Thanasius deleted the more-permissive-import-signature branch September 30, 2025 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants