Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 5, 2025

Problem

The features module had two Python 3.10 compatibility issues that caused import and syntax errors:

  1. Type Annotation Syntax: Using modern Python type hints (list[...], type[...], |) without the from __future__ import annotations import
  2. Array Subscript Unpacking: Using Python 3.11+ exclusive *unpacking syntax in array subscripts

These syntaxes are not supported in Python 3.10, causing the module to fail when collecting tests or importing:

# Issue 1: This would fail in Python 3.10
def get_all_features() -> list[tuple[str, Callable]]:
    ...

# Issue 2: This would fail in Python 3.10 (Python 3.11+ only)
counts_m[*i, :] = value

Solution

Fix 1: Future Annotations Import

Added from __future__ import annotations to three files in the features module:

  1. eegdash/features/inspect.py - Contains functions with return types like list[tuple[str, Callable]], list[tuple[str, type[FeatureExtractor]]]
  2. eegdash/features/extractors.py - Uses list[str] and union types with |
  3. eegdash/features/serialization.py - Uses str | Path and list[int] | None

This 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+ *unpacking syntax 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.py with comprehensive import tests to:

  • Verify the features module can be imported without syntax errors
  • Test all features submodules import correctly
  • Validate basic functionality of key functions
  • Prevent future Python 3.10 compatibility regressions

Impact

  • ✅ Fully compatible with Python 3.10, 3.11, and 3.12 (as specified in pyproject.toml)
  • ✅ All type hints preserved and functional
  • ✅ No breaking changes to existing functionality
  • ✅ All indexing operations produce identical results
  • ✅ Minimal changes: 6 files modified, 76 insertions(+), 4 deletions(-)
  • ✅ Test coverage added to catch future syntax issues

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

  • Triggering command: /usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/ -v --tb=short (dns block)
  • cluster0-shard-00-01.vz35p.mongodb.net
    • Triggering command: /usr/bin/python3 /home/REDACTED/.local/bin/pytest tests/ -v --tb=short (dns block)
  • cluster0-shard-00-02.vz35p.mongodb.net
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>[BUG] The feature module doesn't work with Python 3.10, but we support Python 3.10. It is mainly because of this type of attribution:</issue_title>
<issue_description>The feature module doesn't work with Python 3.10, but we support Python 3.10. It is mainly because of this type of attribution:

==================================== ERRORS ====================================
___________________ ERROR collecting tests/test_features.py ____________________
.venv/lib/python3.10/site-packages/_pytest/python.py:498: in importtestmodule
mod = import_path(
.venv/lib/python3.10/site-packages/_pytest/pathlib.py:587: in import_path
importlib.import_module(module_name)
../../../.local/share/uv/python/cpython-3.10.18-linux-x86_64-gnu/lib/python3.10/importlib/init.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
:1050: in _gcd_import
???
:1027: in _find_and_load
???
:1006: in _find_and_load_unlocked
???
:688: in _load_unlocked
???
.venv/lib/python3.10/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
exec(co, module.dict)
tests/test_features.py:4: in
from eegdash.features.datasets import FeaturesDataset, FeaturesConcatDataset
eegdash/features/init.py:17: in
from .feature_bank import ( # Complexity; Connectivity; CSP; Dimensionality; Signal; Spectral
eegdash/features/feature_bank/init.py:8: in
from .complexity import (
E File "/home/runner/work/EEGDash/EEGDash/eegdash/features/feature_bank/complexity.py", line 39
E counts_m[*i, :] = _channel_app_samp_entropy_counts(x[i], m, rr[i], l)
E ^
E SyntaxError: invalid syntax

Originally posted by @bruAristimunha in #164 (comment)
</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #166

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: bruAristimunha <42702466+bruAristimunha@users.noreply.github.com>
Copilot AI changed the title [WIP] [BUG] The feature module doesn't work with Python 3.10, but we support Python 3.10. It is mainly because of this type of attribution: Fix Python 3.10 compatibility in features module by adding future annotations Oct 5, 2025
Copilot AI requested a review from bruAristimunha October 5, 2025 01:15
Copilot finished work on behalf of bruAristimunha October 5, 2025 01:15
@bruAristimunha
Copy link
Collaborator

Okay, interesting start, but you need to fix this issue from my numba program style:

home/runner/work/EEGDash/EEGDash/eegdash/features/feature_bank/complexity.py", line 39
E counts_m[*i, :] = _channel_app_samp_entropy_counts(x[i], m, rr[i], l)

I would like you too create some shallow test just importing the EEGdash.feature module, just to capture the issue.

@bruAristimunha
Copy link
Collaborator

Please iterate more @copilot based on my feedback

Co-authored-by: bruAristimunha <42702466+bruAristimunha@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 5, 2025

Okay, interesting start, but you need to fix this issue from my numba program style:

home/runner/work/EEGDash/EEGDash/eegdash/features/feature_bank/complexity.py", line 39...

Fixed in commit 61a3f70.

The issue was Python 3.11+ exclusive syntax using *unpacking in array subscripts (e.g., counts_m[*i, :]). This syntax is not supported in Python 3.10.

Changes:

  • complexity.py: Replaced array[*i, :]array[i + (slice(None),)]
  • dimensionality.py: Replaced array[*i, m:]array[i + (slice(m, None),)]
  • Added tests/test_features.py with import tests to catch these issues

The fix maintains identical functionality while ensuring Python 3.10 compatibility.

Copilot AI changed the title Fix Python 3.10 compatibility in features module by adding future annotations Fix Python 3.10 compatibility in features module Oct 5, 2025
Copilot finished work on behalf of bruAristimunha October 5, 2025 02:27
@bruAristimunha bruAristimunha marked this pull request as ready for review October 5, 2025 17:06
@bruAristimunha bruAristimunha merged commit 47acae9 into develop Oct 5, 2025
8 checks passed
@bruAristimunha bruAristimunha deleted the copilot/fix-d7f0a9a7-e10b-4c4d-bef8-9d03c3f086f8 branch October 5, 2025 17:54
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.

[BUG] The feature module doesn't work with Python 3.10, but we support Python 3.10. It is mainly because of this type of attribution:

2 participants