Skip to content
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

Instance variable reference #16

Open
navyad opened this issue Aug 19, 2016 · 2 comments
Open

Instance variable reference #16

navyad opened this issue Aug 19, 2016 · 2 comments

Comments

@navyad
Copy link
Contributor

navyad commented Aug 19, 2016

class Attachment(object):

    def to_dict(self):
        return {
            'type': self.attachment_type,
            'payload': self.payload
        }

The above class does not have the attachment_type and payload attributes, I guess you have kept this to be used by child classes, which make sense.

Although creating the instance of Attachment is not the idea, But instance can be created. And in that case
to_dict() will break, since the attachment_type and payload attributes are not there.

There are two solution of the problem:
Solution 1: allows instantiation of Attachment and add attributes to the class. Will not recommend it since the idea is not to allow the instantiation of this class.

Solution 2: Does not allow instance of class while maintaining the inheritance of the attributes.

@geeknam
Copy link
Owner

geeknam commented Aug 19, 2016

The proper way is to use python's abc, felt like it wasn't worth the effort.

@navyad
Copy link
Contributor Author

navyad commented Aug 20, 2016

@geeknam thanks for suggesting, abc module provides elegant way to handle such scenario.

related change is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants