Fix Python 3.10 compatibility in features module #167
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The features module had two Python 3.10 compatibility issues that caused import and syntax errors:
list[...],type[...],|) without thefrom __future__ import annotationsimport*unpackingsyntax in array subscriptsThese syntaxes are not supported in Python 3.10, causing the module to fail when collecting tests or importing:
Solution
Fix 1: Future Annotations Import
Added
from __future__ import annotationsto three files in the features module:list[tuple[str, Callable]],list[tuple[str, type[FeatureExtractor]]]list[str]and union types with|str | Pathandlist[int] | NoneThis import (PEP 563) defers evaluation of all type annotations, converting them to strings at module import time. This allows Python 3.10 to parse the modern syntax without runtime errors.
Fix 2: Array Subscript Unpacking Replacement
Replaced Python 3.11+
*unpackingsyntax with functionally equivalent Python 3.10 compatible indexing:In
eegdash/features/feature_bank/complexity.py:counts_m[*i, :]→counts_m[i + (slice(None),)]counts_mp1[*i, :]→counts_mp1[i + (slice(None),)]x_emb[*i, :, :]→x_emb[i + (slice(None), slice(None))]In
eegdash/features/feature_bank/dimensionality.py:x[*i, m:]→x[i + (slice(m, None),)]The replacement syntax uses tuple concatenation which is functionally identical but compatible with Python 3.10.
Fix 3: Test Coverage
Added
tests/test_features.pywith comprehensive import tests to:Impact
pyproject.toml)Fixes the issue where the features module would not work with Python 3.10 despite the project declaring support for it.
Warning
cluster0-shard-00-00.vz35p.mongodb.net/usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/ -v --tb=short(dns block)cluster0-shard-00-01.vz35p.mongodb.net/usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/ -v --tb=short(dns block)cluster0-shard-00-02.vz35p.mongodb.net/usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/ -v --tb=short(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Fixes #166
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.