88import logging
99import re
1010import string
11+ import sys
1112from collections import abc
1213from fractions import Fraction
1314from functools import singledispatch
1415from inspect import isfunction
15- from types import NoneType
1616from typing import TYPE_CHECKING , Any , cast
1717
1818import attrs
2525from qrules .topology import FrozenTransition , MutableTransition , Topology , Transition
2626from qrules .transition import ProblemSet , ReactionInfo , State
2727
28+ if sys .version_info >= (3 , 10 ):
29+ from types import NoneType
30+
31+
2832if TYPE_CHECKING :
2933 from collections .abc import Iterable
3034
@@ -299,19 +303,26 @@ def as_string(obj: Any) -> str:
299303 >>> as_string(10)
300304 'new int rendering'
301305 """
302- _LOGGER .warning (f"No DOT renderer implemented type { type (obj ).__name__ } " )
306+ if obj is not None :
307+ _LOGGER .warning (f"No DOT renderer implemented type { type (obj ).__name__ } " )
303308 return str (obj )
304309
305310
306- @as_string .register (NoneType )
307- @as_string .register (int )
311+ if sys .version_info >= (3 , 10 ):
312+
313+ @as_string .register (NoneType )
314+ def _ (obj : Any ) -> str :
315+ return str (obj )
316+
317+
318+ @as_string .register (int ) # type: ignore[no-redef]
308319@as_string .register (float )
309320@as_string .register (str )
310321def _ (obj : Any ) -> str :
311322 return str (obj )
312323
313324
314- @as_string .register (dict )
325+ @as_string .register (dict ) # type: ignore[no-redef]
315326def _ (obj : dict ) -> str :
316327 lines = []
317328 for key , value in obj .items ():
@@ -334,7 +345,7 @@ def __render_key_and_value(key: str, value: Any) -> str:
334345 return as_string (value )
335346
336347
337- @as_string .register (InteractionProperties )
348+ @as_string .register (InteractionProperties ) # type: ignore[no-redef]
338349def _ (obj : InteractionProperties ) -> str :
339350 lines = []
340351 if obj .l_magnitude is not None :
@@ -355,7 +366,7 @@ def _(obj: InteractionProperties) -> str:
355366 return "\n " .join (lines )
356367
357368
358- @as_string .register (EdgeSettings )
369+ @as_string .register (EdgeSettings ) # type: ignore[no-redef]
359370@as_string .register (NodeSettings )
360371def _ (settings : EdgeSettings | NodeSettings ) -> str :
361372 output = ""
@@ -418,7 +429,7 @@ def __render_domain(domain: list[Any], key: str) -> str:
418429 return "[" + ", " .join (domain_str ) + "]"
419430
420431
421- @as_string .register (Particle )
432+ @as_string .register (Particle ) # type: ignore[no-redef]
422433def _ (particle : Particle ) -> str :
423434 return particle .name
424435
@@ -437,7 +448,7 @@ def _state_to_str(state: State) -> str:
437448 return f"{ particle } [{ spin_projection } ]"
438449
439450
440- @as_string .register (tuple )
451+ @as_string .register (tuple ) # type: ignore[no-redef]
441452def _ (obj : tuple ) -> str :
442453 if len (obj ) == 2 :
443454 if isinstance (obj [0 ], Particle ) and isinstance (obj [1 ], (Fraction , float , int )):
0 commit comments