8
8
import logging
9
9
import re
10
10
import string
11
+ import sys
11
12
from collections import abc
12
13
from fractions import Fraction
13
14
from functools import singledispatch
14
15
from inspect import isfunction
15
- from types import NoneType
16
16
from typing import TYPE_CHECKING , Any , cast
17
17
18
18
import attrs
25
25
from qrules .topology import FrozenTransition , MutableTransition , Topology , Transition
26
26
from qrules .transition import ProblemSet , ReactionInfo , State
27
27
28
+ if sys .version_info >= (3 , 10 ):
29
+ from types import NoneType
30
+
31
+
28
32
if TYPE_CHECKING :
29
33
from collections .abc import Iterable
30
34
@@ -299,19 +303,26 @@ def as_string(obj: Any) -> str:
299
303
>>> as_string(10)
300
304
'new int rendering'
301
305
"""
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__ } " )
303
308
return str (obj )
304
309
305
310
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]
308
319
@as_string .register (float )
309
320
@as_string .register (str )
310
321
def _ (obj : Any ) -> str :
311
322
return str (obj )
312
323
313
324
314
- @as_string .register (dict )
325
+ @as_string .register (dict ) # type: ignore[no-redef]
315
326
def _ (obj : dict ) -> str :
316
327
lines = []
317
328
for key , value in obj .items ():
@@ -334,7 +345,7 @@ def __render_key_and_value(key: str, value: Any) -> str:
334
345
return as_string (value )
335
346
336
347
337
- @as_string .register (InteractionProperties )
348
+ @as_string .register (InteractionProperties ) # type: ignore[no-redef]
338
349
def _ (obj : InteractionProperties ) -> str :
339
350
lines = []
340
351
if obj .l_magnitude is not None :
@@ -355,7 +366,7 @@ def _(obj: InteractionProperties) -> str:
355
366
return "\n " .join (lines )
356
367
357
368
358
- @as_string .register (EdgeSettings )
369
+ @as_string .register (EdgeSettings ) # type: ignore[no-redef]
359
370
@as_string .register (NodeSettings )
360
371
def _ (settings : EdgeSettings | NodeSettings ) -> str :
361
372
output = ""
@@ -418,7 +429,7 @@ def __render_domain(domain: list[Any], key: str) -> str:
418
429
return "[" + ", " .join (domain_str ) + "]"
419
430
420
431
421
- @as_string .register (Particle )
432
+ @as_string .register (Particle ) # type: ignore[no-redef]
422
433
def _ (particle : Particle ) -> str :
423
434
return particle .name
424
435
@@ -437,7 +448,7 @@ def _state_to_str(state: State) -> str:
437
448
return f"{ particle } [{ spin_projection } ]"
438
449
439
450
440
- @as_string .register (tuple )
451
+ @as_string .register (tuple ) # type: ignore[no-redef]
441
452
def _ (obj : tuple ) -> str :
442
453
if len (obj ) == 2 :
443
454
if isinstance (obj [0 ], Particle ) and isinstance (obj [1 ], (Fraction , float , int )):
0 commit comments