[issue43243] Strict ABC classes

2021-02-17 Thread Yurii Karabas


Yurii Karabas <1998uri...@gmail.com> added the comment:

Sorry about this, in a future I will use forum for such discussions.

--

___
Python tracker 

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



[issue43243] Strict ABC classes

2021-02-17 Thread Guido van Rossum


Change by Guido van Rossum :


--
nosy:  -gvanrossum

___
Python tracker 

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



[issue43243] Strict ABC classes

2021-02-17 Thread Guido van Rossum


Guido van Rossum  added the comment:

This discussion is not appropriate for the bug tracker. Try finding a user 
forum to discuss the pros and cons and history of the current functionality. It 
is clear that you have plenty of ways to discover the problem already.

--
resolution:  -> rejected
stage: patch review -> 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



[issue43243] Strict ABC classes

2021-02-17 Thread Yurii Karabas


Yurii Karabas <1998uri...@gmail.com> added the comment:

When I work with ABC classes usually I faced a problem -  I forget to implement 
one of the methods or make a typo in the method name. In such case I will know 
about it only when I will try to instantiate a class.

In case when a hierarchy is big you should go through classes and find the 
exact class where the problem is.

With this feature, in a case when a class inherits from strict ABC and doesn't 
implement all abstract methods of strict classes it will fail at class 
declaration rather than at instance creation as with regular ABC classes.

As an option, I can run mypy every time before start the python interpreter.

The perfect behavior for me is a case when ABC class will be strict by default, 
but it will break the existing code.

Examples to explain the idea:
```
from abc import ABC, abstractmethod

class Base(ABC):
@abstraabstractmethod
def foo(self):
 pass

class A(Base, ABC):  # totally okay, because class directly inherits from ABC
 pass

class B(Base):  # will fail, because class doesn't implement foo method
pass
```

Raymond, could you please explain why the current behavior is default.

--

___
Python tracker 

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



[issue43243] Strict ABC classes

2021-02-17 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Why is this needed?  Already, instantiation is blocked.

--
nosy: +gvanrossum, rhettinger

___
Python tracker 

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



[issue43243] Strict ABC classes

2021-02-17 Thread Yurii Karabas


Change by Yurii Karabas <1998uri...@gmail.com>:


--
keywords: +patch
pull_requests: +23339
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24558

___
Python tracker 

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



[issue43243] Strict ABC classes

2021-02-17 Thread Yurii Karabas


New submission from Yurii Karabas <1998uri...@gmail.com>:

Basically, the idea is to add the ability to mark abstract classes as strict.

What does this mean - in case when a class inherits from a strict abstract base 
class and doesn't implement all abstract methods then it will fail to create a 
class.

For instance:
>>> class Iterable(ABC, strict=True):
...   @abstractmethod
...   def __iter__(self):
...  pass

>>> class MyClass(Iterable):
...   pass
TypeError: Can't create class MyClass with unimplemented strict abstract method 
__iter__

That allows creating abc classes and be sure that class defines a required 
method, it will be perfrormed on a class declaration stage rather than class 
instance creation.

--
components: Library (Lib)
messages: 387169
nosy: uriyyo
priority: normal
severity: normal
status: open
title: Strict ABC classes
type: enhancement
versions: Python 3.10

___
Python tracker 

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