fix: replace deprecated pkg_resources with importlib.resources#792
Conversation
Updated BrainFlow EEG files: - emulator/: cyton_windows.py, freeeeg32_windows.py, knightboard_windows.py - python_package/brainflow/: board_shim.py, data_filter.py, ml_model.py ✅ Eliminates pkg_resources deprecation warnings
| except (TypeError, AttributeError): | ||
| import pkg_resources | ||
| return pkg_resources.resource_filename(__name__, os.path.join('com0com', 'setup_com0com_W7_x64_signed.exe')) |
There was a problem hiding this comment.
What are these except blocks trying to accomplish? Are they for backwards compatibility with older versions of python? If so, I'd suggest adding a comment to indicate that they exist for that reason, and I'd like to note that importlib has existed in python since 3.1. If not, you should definitely add a comment explaining why. Regardless, it's probably also worth emitting a warning.
There was a problem hiding this comment.
@Pandapip1 Thank you for the detailed review and suggestion.
Yes, exactly- except (TypeError, AttributeError) blocks provide backward compatibility.
The TypeError catches cases where importlib.resources.files() returns something unexpected, and AttributeError catches when the method doesn't exist (Python < 3.9).
While importlib.resources has existed since Python 3.1, the files() API wasn't introduced until Python 3.9. This is the modern, recommended way to access package resources.
I have added comment.
|
Looks good to me, thanks |
Updated BrainFlow EEG files:
emulator/: cyton_windows.py, freeeeg32_windows.py, knightboard_windows.py
python_package/brainflow/: board_shim.py, data_filter.py, ml_model.py
Eliminates pkg_resources deprecation warnings