Skip to content

Allow subclasses of Symbol #124

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

Merged
merged 4 commits into from
Feb 28, 2017
Merged

Allow subclasses of Symbol #124

merged 4 commits into from
Feb 28, 2017

Conversation

isuruf
Copy link
Member

@isuruf isuruf commented Feb 20, 2017

Fixes #123.

@KristianJensen, you can do the following now

import symengine.sympy_compat as symengine

class Wrapper(symengine.Symbol):
    def __new__(cls, name, extra_attribute):
        return symengine.Symbol.__new__(cls, name)

    def __init__(self, name, extra_attribute):
        super(Wrapper, self).__init__(name)
        self.extra_attribute = extra_attribute

# Instantiate the subclass
x = Wrapper("x", extra_attribute=3)
assert x.extra_attribute == 3
two_x = 2 * x
# Check that after arithmetic, same subclass is returned
assert two_x.args[1] is x

@KristianJensen
Copy link

That's fantastic. Thank you!

@isuruf isuruf requested a review from certik February 24, 2017 15:39
@certik certik merged commit e2a348e into symengine:master Feb 28, 2017
@certik
Copy link
Contributor

certik commented Feb 28, 2017

Thanks @isuruf !

@isuruf isuruf deleted the subclass branch March 1, 2017 03:29
phantomas1234 added a commit to phantomas1234/python-symengine-feedstock that referenced this pull request Mar 20, 2017
isuruf added a commit to symengine/python-symengine-feedstock that referenced this pull request Mar 20, 2017
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

Successfully merging this pull request may close these issues.

3 participants