There's a new mode in emacs29, `python-base-mode`, which `python-mode` and `python-ts-mode` both derive from, and importmagic ought to test against that.