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

Type annotations break advertised support for older Python versions #49

Open
zahlman opened this issue Dec 4, 2024 · 0 comments
Open

Comments

@zahlman
Copy link

zahlman commented Dec 4, 2024

See investigation here: https://forums.linuxmint.com/viewtopic.php?p=2557029

Per the project metadata (trove classifiers and python_requires setting in setup.py), the project is supposed to support Python 3.7 and up, including in the current version.

However, it will in fact crash at import time in Python 3.7 through 3.9, due to how type annotations are used in lyrics.util, along the lines of:

  File "/path/to/lib/python3.8/site-packages/lyrics/util.py", line 33, in <module>
    def get_html(url, header=HEADER) -> str | Tuple[str, Exception]:
TypeError: unsupported operand type(s) for |: 'type' and '_GenericAlias'

In short, the | operator cannot be used with types in these older versions, as support for this was not added until 3.10:

A union object holds the value of the | (bitwise or) operation on multiple type objects. These types are intended primarily for type annotations. The union type expression enables cleaner type hinting syntax compared to typing.Union...
...
Added in version 3.10.

The simplest fix is to simply remove the type annotations from util.py, as the rest of the codebase doesn't appear to be using type annotations anyway (and there seems to be no good reason, yet, to drop support for older Python versions). Alternately, the long-form syntax using typing.Union is supported since 3.5 (when the typing standard library was added): Union[str, Tuple[str, Exception]], where the corresponding from typing import List, Tuple is modified to include Union as well.

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

No branches or pull requests

1 participant