@@ -146,11 +146,12 @@ def _to_rgba_no_colorcycle(c, alpha=None):
146146 If `alpha` is not `None`, it forces the alpha value.
147147 """
148148 orig_c = c
149- if isinstance (c , six .string_types ) and c .lower () == "none" :
150- return (0. , 0. , 0. , 0. )
151149 if isinstance (c , six .string_types ):
150+ if c .lower () == "none" :
151+ return (0. , 0. , 0. , 0. )
152152 # Named color.
153153 try :
154+ # This may turn c into a non-string, so we check again below.
154155 c = _colors_full_map [c .lower ()]
155156 except KeyError :
156157 pass
@@ -161,7 +162,6 @@ def _to_rgba_no_colorcycle(c, alpha=None):
161162 return (tuple (int (n , 16 ) / 255
162163 for n in [c [1 :3 ], c [3 :5 ], c [5 :7 ]])
163164 + (alpha if alpha is not None else 1. ,))
164- if isinstance (c , six .string_types ):
165165 # hex color with alpha.
166166 match = re .match (r"\A#[a-fA-F0-9]{8}\Z" , c )
167167 if match :
@@ -170,10 +170,9 @@ def _to_rgba_no_colorcycle(c, alpha=None):
170170 if alpha is not None :
171171 color [- 1 ] = alpha
172172 return tuple (color )
173- if isinstance (c , six .string_types ):
174173 # string gray.
175174 try :
176- return (float (c ),) * 3 + (1. ,)
175+ return (float (c ),) * 3 + (alpha if alpha is not None else 1. ,)
177176 except ValueError :
178177 pass
179178 raise ValueError ("Invalid RGBA argument: {!r}" .format (orig_c ))
0 commit comments