Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SyntaxError: invalid syntax (import SourceType.GPS) #243

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

pdcastro
Copy link
Contributor

@pdcastro pdcastro commented Feb 6, 2024

Following PR #238, my home assistant logs started showing this stack trace:

2024-02-06 16:25:29.728 ERROR (MainThread) [homeassistant.loader] Unexpected exception importing platform custom_components.volkswagen_we_connect_id.device_tracker
Traceback (most recent call last):
  File "/home/vscode/env/lib/python3.12/site-packages/homeassistant/loader.py", line 842, in get_platform
    cache[full_name] = self._import_platform(platform_name)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vscode/env/lib/python3.12/site-packages/homeassistant/loader.py", line 859, in _import_platform
    return importlib.import_module(f"{self.pkg_path}.{platform_name}")
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 990, in exec_module
  File "<frozen importlib._bootstrap_external>", line 1128, in get_code
  File "<frozen importlib._bootstrap_external>", line 1058, in source_to_code
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/vscode/.homeassistant/custom_components/volkswagen_we_connect_id/device_tracker.py", line 8
    from homeassistant.components.device_tracker import SourceType.GPS
                                                                  ^
SyntaxError: invalid syntax

Indeed:

Before this PR (after PR #238):

$ python
Python 3.11.7 (main, Feb  6 2024, 18:04:56) [GCC 12.2.0] on linux

>>> import sys
>>> sys.path.append('custom_components')
>>> from volkswagen_we_connect_id.device_tracker import VolkswagenIDSensor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/workspaces/volkswagen_we_connect_id/custom_components/volkswagen_we_connect_id/device_tracker.py", line 8
    from homeassistant.components.device_tracker import SourceType.GPS
                                                                  ^
SyntaxError: invalid syntax

After this PR:

$ python
Python 3.11.7 (main, Feb  6 2024, 18:04:56) [GCC 12.2.0] on linux

>>> import sys
>>> sys.path.append('custom_components')
>>> from volkswagen_we_connect_id.device_tracker import VolkswagenIDSensor
>>> from unittest.mock import MagicMock
>>> s = VolkswagenIDSensor(MagicMock(), MagicMock(), 0)
>>> s.source_type
<SourceType.GPS: 'gps'>

Tested with both Python 3.11 and 3.12 — same results.

@pdcastro
Copy link
Contributor Author

pdcastro commented Feb 6, 2024

Tested with Home Assistant version 2024.1.6.

@pdcastro
Copy link
Contributor Author

pdcastro commented Feb 9, 2024

Also, if contributors used pylint...

$ pylint custom_components/volkswagen_we_connect_id/device_tracker.py 
************* Module volkswagen_we_connect_id.device_tracker
custom_components/volkswagen_we_connect_id/device_tracker.py:8:63: E0001: Parsing failed: 'invalid syntax (<unknown>, line 8)' (syntax-error)

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.

None yet

2 participants