-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ABC documentation needs more details on usage #132
Comments
Could you provide a bit more detail on what areas of the docs you are looking at?
I'm sorry but I'm not clear on what you are asking here.
I'm sorry but I'm not clear on what you are asking here. |
I am looking at the module: https://docs.python.org/3/library/abc.html#module-abc
It is apparently possible to make methods and attributes mandatory by using the NotInplemented exception, but there are no examples. The user has to be aware of this possibility.
If a Iterator is being used in an Abstract Base Class, the Iterator is not passed down to the child class. What should the user do to make the Iterator work? These are just random two examples. But what I am generally asking if someone can look at the documentation and write more practical examples/instructions so that it makes more sense on the why and how to use the module for the more "advanced" usage, because the source code itself is not giving any information what is and isn't possible. |
Hmm you should use decorate the function with However I agree that we need to provide clearer explanation and instructions overall.
Sorry I still don't fully understand this. Do you perhaps have code snippet of how you defined the iterator on your ABC and the child class? |
“Hmm you should use decorate the function with @AbstractMethod which will raise exception if the child class doesn't implement it.”
But what if I have a series of variables. Some are mandatory and the others aren’t. How should I then define them? I would like to see these possibilities in the documentation.
“Sorry I still don't fully understand this. Do you perhaps have code snippet of how you defined the iterator on your ABC and the child class?”
Here you can find a full working test code: https://github.com/cdorsman/snippets/blob/e401c5a1da9eebfb5aa3ad2ff9c329f13fc8191d/mvc/mvc.py
I had to define ABC Iterator like so to iterate and get the values because the childclasses cannot not inherit the Iterator from the Abstract Base Class.
class Model(ABC, Iterable):
_instances = []
@AbstractMethod
def __iter__(self):
return iter(getattr(self, '_instances', []))
While I expected that the Iterator would be passed downstream.
…________________________________
From: Mariatta ***@***.***>
Sent: Monday, September 16, 2024 5:04 PM
To: python/docs-community ***@***.***>
Cc: Chris Dorsman ***@***.***>; Author ***@***.***>
Subject: Re: [python/docs-community] ABC documentation needs more details on usage (Issue #132)
It is apparently possible to make methods and attributes mandatory by using the NotInplemented exception, but there are no examples
Hmm you should use decorate the function with @AbstractMethod which will raise exception if the child class doesn't implement it.
However I agree that we need to provide clearer explanation and instructions overall.
If a Iterator is being used in an Abstract Base Class, the Iterator is not passed down to the child class. What should the user do to make the Iterator work?
Sorry I still don't fully understand this. Do you perhaps have code snippet of how you defined the iterator on your ABC and the child class?
—
Reply to this email directly, view it on GitHub<#132 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AJMU4APL44GWNI4Q7KMJ4CDZW3XPJAVCNFSM6AAAAABOEU4H6KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJTGE4DGOJVGY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
I am trying to use Abstract Base Classes. But I find the documentation lacking on several points that makes the matter too 'abstract'.
For example. There is no explanation on making abstract objects mandatory by using exceptions
Or how to implement Iterable abstract bsse class that can be inherited from and still be usable.
Can someone shed more light onto this so that the documentation is more accessible?
The text was updated successfully, but these errors were encountered: