Skip to content

Drop Python 2/3 compatibility shim from util.py - #122

Merged
urschrei merged 1 commit into
masterfrom
shugel/push-npvlokzskzsk
May 19, 2026
Merged

Drop Python 2/3 compatibility shim from util.py#122
urschrei merged 1 commit into
masterfrom
shugel/push-npvlokzskzsk

Conversation

@urschrei

Copy link
Copy Markdown
Owner

Replace the version_info-gated import of subprocess.check_output / getoutput (and the py3 / spop / branched fpath usage) with a direct import of subprocess.getoutput. Also defines fpath unconditionally at module level so the manylinux1 fallback no longer references an undefined name on macOS/Windows.

Gate numpy .astype path with isinstance check in _FFIArray

The duck-typed try/except (TypeError, AttributeError) around seq.astype(np.float64) caught two distinct conditions:

  1. numpy arrays whose buffer wasn't writable (TypeError from from_buffer) -- handled by retrying with from_buffer_copy.
  2. array.array / list / tuple inputs that lack .astype entirely (AttributeError) -- handled by falling through to array_type.from_buffer(array("d", seq)).

Make the numpy vs non-numpy branch explicit with isinstance(seq, np.ndarray) so the .astype call lives on a known-numpy path. Resolves the ty 'possibly-missing-attribute' diagnostic on .astype without changing runtime behaviour for any input type.

The two .astype calls carry # ty: ignore[no-matching-overload] because ty's current numpy stubs can't unify any dtype argument form (np.float64, "float64", np.dtype(...)) against the overloaded signature -- a stubs limitation rather than a real type error.

Replace the version_info-gated import of subprocess.check_output /
getoutput (and the py3 / spop / branched fpath usage) with a direct
import of subprocess.getoutput. Also defines fpath unconditionally at
module level so the manylinux1 fallback no longer references an
undefined name on macOS/Windows.

Gate numpy .astype path with isinstance check in _FFIArray

The duck-typed try/except (TypeError, AttributeError) around
seq.astype(np.float64) caught two distinct conditions:

1. numpy arrays whose buffer wasn't writable (TypeError from
   from_buffer) -- handled by retrying with from_buffer_copy.
2. array.array / list / tuple inputs that lack .astype entirely
   (AttributeError) -- handled by falling through to
   array_type.from_buffer(array("d", seq)).

Make the numpy vs non-numpy branch explicit with isinstance(seq,
np.ndarray) so the .astype call lives on a known-numpy path. Resolves
the ty 'possibly-missing-attribute' diagnostic on .astype without
changing runtime behaviour for any input type.

The two .astype calls carry # ty: ignore[no-matching-overload]
because ty's current numpy stubs can't unify any dtype argument form
(np.float64, "float64", np.dtype(...)) against the overloaded
signature -- a stubs limitation rather than a real type error.


Signed-off-by: Stephan Hügel <shugel@tcd.ie>
@urschrei
urschrei merged commit c027609 into master May 19, 2026
8 checks passed
@urschrei
urschrei deleted the shugel/push-npvlokzskzsk branch May 19, 2026 10:52
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.

1 participant