From 40ee32e0659714a7711b65c168c75a82c00bef8b Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Tue, 23 May 2023 01:30:46 +0200 Subject: [PATCH] refactor: use `None` for `dict` default values (#831) --- diagrams/__init__.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/diagrams/__init__.py b/diagrams/__init__.py index 6e282d9..6fe2a80 100644 --- a/diagrams/__init__.py +++ b/diagrams/__init__.py @@ -2,7 +2,7 @@ import contextvars import os import uuid from pathlib import Path -from typing import List, Union, Dict +from typing import Dict, List, Optional, Union from graphviz import Digraph @@ -86,9 +86,9 @@ class Diagram: autolabel: bool = False, show: bool = True, strict: bool = False, - graph_attr: dict = {}, - node_attr: dict = {}, - edge_attr: dict = {}, + graph_attr: Optional[dict] = None, + node_attr: Optional[dict] = None, + edge_attr: Optional[dict] = None, ): """Diagram represents a global diagrams context. @@ -105,6 +105,12 @@ class Diagram: :param edge_attr: Provide edge_attr dot config attributes. :param strict: Rendering should merge multi-edges. """ + if graph_attr is None: + graph_attr = {} + if node_attr is None: + node_attr = {} + if edge_attr is None: + edge_attr = {} self.name = name if not name and not filename: filename = "diagrams_image" @@ -215,7 +221,7 @@ class Cluster: self, label: str = "cluster", direction: str = "LR", - graph_attr: dict = {}, + graph_attr: Optional[dict] = None, ): """Cluster represents a cluster context. @@ -223,6 +229,8 @@ class Cluster: :param direction: Data flow direction. Default is 'left to right'. :param graph_attr: Provide graph_attr dot config attributes. """ + if graph_attr is None: + graph_attr = {} self.label = label self.name = "cluster_" + self.label