[issue47083] The __complex__ method is missing from the complex, float, and int built-in types

2022-03-31 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47083] The __complex__ method is missing from the complex, float, and int built-in types

2022-03-29 Thread Géry

Géry  added the comment:

> I think this may fine as-is.  In general, virtiual classes only promise that 
> an operation will work rather than promsing the presence of a particular 
> method.

Okay, I just wanted to make sure that the absence of the `__complex__` method 
was intended and not an oversight, since the built-in numeric types define 
*all* the other methods of the numbers ABCs.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47083] The __complex__ method is missing from the complex, float, and int built-in types

2022-03-27 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

I think this may fine as-is.  In general, virtiual classes only promise that an 
operation will work rather than promsing the presence of a particular method.

An object can be Iterable without defining __iter__ because iter() can use 
__getitem__ and __len__ to build a sequence iterator.  Likewise, an object can 
be a Container without defining __contains__ because the in-operator will work 
on any iterable.  An object can be Reversible without defining __reversed__ 
because reversed() will fall back to an implementation based on __getitem__ and 
__len__.

The docstring in numbers.Complex promises, "Complex defines the operations that 
work on the builtin complex type.  In short, those are: a conversion to 
complex, .real, .imag, +, -, *, /, **, abs(), .conjugate, ==, and !=."

In other words, the promise is that these work (which they do):

   >>> complex(0.0)
   0j
   >>> int(0.0)
   0

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47083] The __complex__ method is missing from the complex, float, and int built-in types

2022-03-24 Thread Dong-hee Na


Change by Dong-hee Na :


--
nosy: +corona10, mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47083] The __complex__ method is missing from the complex, float, and int built-in types

2022-03-21 Thread Géry

New submission from Géry :

## Expected outcome

```
>>> hasattr(complex(), '__complex__')
True
>>> hasattr(float(), '__complex__')
True
>>> hasattr(int(), '__complex__')
True
```

## Actual outcome

```
>>> hasattr(complex(), '__complex__')
False
>>> hasattr(float(), '__complex__')
False
>>> hasattr(int(), '__complex__')
False
```

## Rationale

The `numbers.Complex` abstract base class has a `__complex__` abstract method 
and the `numbers.Real` and `numbers.Integral` abstract base classes inherit 
from `numbers.Complex` 
(https://github.com/python/cpython/blob/v3.10.3/Lib/numbers.py#L45-L47):

```
@abstractmethod
def __complex__(self):
"""Return a builtin complex instance. Called for complex(self)."""
```

The `complex` built-in type is a virtual subclass (nominal subtype) of 
`numbers.Complex` 
(https://github.com/python/cpython/blob/v3.10.3/Lib/numbers.py#L144):

```
Complex.register(complex)
```

The `float` built-in type is a virtual subclass (nominal subtype) of 
`numbers.Real` 
(https://github.com/python/cpython/blob/v3.10.3/Lib/numbers.py#L264):

```
Real.register(float)
```

The `int` built-in type is a virtual subclass (nominal subtype) of 
`numbers.Integral` 
(https://github.com/python/cpython/blob/v3.10.3/Lib/numbers.py#L393):

```
Integral.register(int)
```

`__complex__` is the only method of the abstract base classes of `numbers` 
missing from `complex`, `float`, and `int`:

```
>>> import numbers
>>> for attr in dir(numbers.Complex):
... if not hasattr(complex(), attr): print(attr)
... 
__abstractmethods__
__complex__
__module__
__slots__
_abc_impl
>>> for attr in dir(numbers.Real):
... if not hasattr(float(), attr): print(attr)
... 
__abstractmethods__
__complex__
__module__
__slots__
_abc_impl
>>> for attr in dir(numbers.Integral):
... if not hasattr(int(), attr): print(attr)
... 
__abstractmethods__
__complex__
__module__
__slots__
_abc_impl
```

--
components: Interpreter Core
messages: 415689
nosy: maggyero
priority: normal
severity: normal
status: open
title: The __complex__ method is missing from the complex, float, and int 
built-in types
type: behavior
versions: Python 3.10, Python 3.11, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com