MCPcopy
hub / github.com/hylang/hy / __new__

Method __new__

hy/models.py:383–397  ·  view source on GitHub ↗
(cls, real, imag=0, *args, **kwargs)

Source from the content-addressed store, hash-verified

381 __match_args__ = ("real", "imag")
382
383 def __new__(cls, real, imag=0, *args, **kwargs):
384 if isinstance(real, str):
385 value = super().__new__(cls, strip_digit_separators(real))
386 p1, _, p2 = real.lstrip("+-").replace("-", "+").partition("+")
387 check_inf_nan_cap(p1, value.imag if "j" in p1.lower() else value.real)
388 if p2:
389 check_inf_nan_cap(p2, value.imag)
390 return value
391 if isinstance(imag, complex):
392 raise TypeError("`imag` must be real")
393 if isinstance(real, complex):
394 # This is deprecated by Python 3.14's `complex`, so
395 # extract the imaginary part before passing through.
396 real, imag = real.real, imag + real.imag
397 return super().__new__(cls, real, imag)
398
399
400_wrappers[complex] = Complex

Callers

nothing calls this directly

Calls 4

strip_digit_separatorsFunction · 0.85
check_inf_nan_capFunction · 0.85
__new__Method · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected