A trait for complex numbers.
| 2830 | |
| 2831 | |
| 2832 | class Complex(TraitType[complex, t.Union[complex, float, int]]): |
| 2833 | """A trait for complex numbers.""" |
| 2834 | |
| 2835 | default_value = 0.0 + 0.0j |
| 2836 | info_text = "a complex number" |
| 2837 | |
| 2838 | def validate(self, obj: t.Any, value: t.Any) -> complex | None: |
| 2839 | if isinstance(value, complex): |
| 2840 | return value |
| 2841 | if isinstance(value, (float, int)): |
| 2842 | return complex(value) |
| 2843 | self.error(obj, value) |
| 2844 | |
| 2845 | def from_string(self, s: str) -> complex | None: |
| 2846 | if self.allow_none and s == "None": |
| 2847 | return None |
| 2848 | return complex(s) |
| 2849 | |
| 2850 | def subclass_init(self, cls: type[t.Any]) -> None: |
| 2851 | pass # fully opt out of instance_init |
| 2852 | |
| 2853 | |
| 2854 | class CComplex(Complex, TraitType[complex, t.Any]): |
no outgoing calls
no test coverage detected
searching dependent graphs…