weaveworks / grafanalib

Python library for building Grafana dashboards
Apache License 2.0
1.87k stars 311 forks source link

grafanalib 0.7.1 trips with `ImportError: cannot import name 'Literal' from 'typing'` #650

Closed amotl closed 5 months ago

amotl commented 7 months ago

Hi there,

first things first: Thanks a stack for conceiving and maintaining grafanalib.

Looking at our CI run #7525555866, it trips like this:

ImportError while loading conftest '/home/runner/work/grafana-wtf/grafana-wtf/tests/conftest.py'.
tests/conftest.py:9: in <module>
    import grafanalib.core
.venv/lib/python3.7/site-packages/grafanalib/core.py:15: in <module>
    from typing import Literal
E   ImportError: cannot import name 'Literal' from 'typing' (/opt/hostedtoolcache/Python/3.7.17/x64/lib/python3.7/typing.py)
make: *** [Makefile:33: test] Error 4

We did not investigate about the root cause yet, just wanted to report here for a start.

With kind regards, Andreas.

amotl commented 7 months ago

Most probably, Python 3.7 became unsupported without bumping to 0.8.0. That would be the easiest and most straight-forward explanation. We can't find anything in the changelog about it, though, and setup.py still lists Python 3.7. Is it true?

davaffy commented 7 months ago

The reason is because of commit #622 which added the Literal import from typing. That is not available in 3.7 thus given error.

The changelog says:

However, it breaks py37 functionality. Is it not possible to upgrade to 3.8, which has it (since 3.7 is EOL) ?

It's my opinion that either the Literal has to be changed in order to make it back compliant with 3.7 ( by using typing_extensions) or 3.7 should be removed as supported version and you will need to upgrade.

Ideally it should be the second one in my opinion

amotl commented 7 months ago

Dear @davaffy,

thanks for your quick reply.

[...] or 3.7 should be removed as supported version and you will need to upgrade.

Yeah, I think it will be fine to remove the compatibility definition in project metadata.

https://github.com/weaveworks/grafanalib/blob/b312693fc2d5548e57c23a8bd9503ed8d15603fc/setup.py#L36

With kind regards, Andreas.

amotl commented 6 months ago

Hi again,

on our downstream project grafana-wtf, we removed support for Python 3.7, and upgraded to grafanalib 0.7.1. Thanks!

On matters of grafanalib itself, we submitted a corresponding patch to fix the project metadata.

With kind regards, Andreas.