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

TypeError: unsupported operand type(s) for |: 'type' and 'types.GenericAlias' #1049

Open
DucNgn opened this issue Nov 6, 2024 · 3 comments

Comments

@DucNgn
Copy link

DucNgn commented Nov 6, 2024

I'm encountering an error while trying to follow the quick start guide for the library. The error occurs when importing the Diagram class from the diagrams module.

Steps to Reproduce

  1. Install Graphviz (already done)
  2. Install diagrams using poetry: poetry add diagrams
  3. Create a Python file with the following content:
from diagrams import Cluster, Diagram
  1. Run the python file: poetry run python3 main.py
Traceback (most recent call last):
  File "/Users/duc.nguyen/docs/main.py", line 1, in <module>
    from diagrams import Cluster, Diagram
  File "/Users/duc.nguyen/docs/.venv/lib/python3.9/site-packages/diagrams/__init__.py", line 40, in <module>
    class Diagram:
  File "/Users/duc.nguyen/docs/.venv/lib/python3.9/site-packages/diagrams/__init__.py", line 85, in Diagram
    outformat: str | list[str] = "png",
TypeError: unsupported operand type(s) for |: 'type' and 'types.GenericAlias'
@mingrammer
Copy link
Owner

Sorry, I fixed this issue with #1052, and will release a new fixed version.

@mingrammer
Copy link
Owner

The fixed version (v0.24.1) is now released.

@HenryBao91
Copy link

HenryBao91 commented Dec 20, 2024

The fixed version (v0.24.1) is now released.

I installed this version, but here is a problem:

 henry@master  python -c "from diagrams import Diagram"                                        
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/henry/src/miniconda3/lib/python3.8/site-packages/diagrams/__init__.py", line 40, in <module>
    class Diagram:
  File "/Users/henry/src/miniconda3/lib/python3.8/site-packages/diagrams/__init__.py", line 85, in Diagram
    outformat: Union[str, list[str]] = "png",
TypeError: 'type' object is not subscriptable
image

@mingrammer And then, I fix it, and I fixed this with #1084

vim /Users/henry/src/miniconda3/lib/python3.8/site-packages/diagrams/__init__.py

class Diagram:
    # ...
    def __init__(
        self,
        name: str = "",
        filename: str = "",
        direction: str = "LR",
        curvestyle: str = "ortho",
        # outformat: Union[str, list[str]] = "png", 
        outformat: Union[str, List[str]] = "png",  #  Fix here
        autolabel: bool = False,
        show: bool = True,
        strict: bool = False,
        graph_attr: Optional[dict] = None,
        node_attr: Optional[dict] = None,
        edge_attr: Optional[dict] = None,
    ):
        ...

And then it run successfully.

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

3 participants