MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / cast_to_value

Function cast_to_value

src/ifctester/ifctester/facet.py:36–50  ·  view source on GitHub ↗
(from_value, to_value)

Source from the content-addressed store, hash-verified

34
35
36def cast_to_value(from_value, to_value):
37 try:
38 target_type = type(to_value).__name__
39 if target_type == "int":
40 # Casting str -> float means that notation like '1e3' is preserved
41 # We do not cast to int because 42.0 == 42 and 42.3 != 42
42 return float(from_value)
43 elif target_type == "bool":
44 if from_value in ("true", "1"):
45 return True
46 elif from_value in ("false", "0"):
47 return False
48 return builtins.__dict__[target_type](from_value)
49 except ValueError:
50 pass
51
52
53# See bug 4716.

Callers 3

__call__Method · 0.85
__call__Method · 0.85
__eq__Method · 0.85

Calls 1

typeFunction · 0.50

Tested by

no test coverage detected