Skip to content

Add a zero_instance method to avoid casting math operations #35

@philippeitis

Description

@philippeitis

Returning a ZeroPolynomial could be problematic, as you might expect that the following would work:

p = Polynomial(1, 2, 3) * Polynomial(0)
p.a = 5
>>> AttributeError: ...

But it does not, as a ZeroPolynomial is returned and p.a can not be set. Instead, we should define a mutable version of a zero_instance that does not restrict behaviour.

An issue with this would be when we might want to modify a Trinomial / Binomial / other class that enforces restrictions on degree behaviour - these don't really support a zero_instance, as there is no guarantee that they'll become valid class instances - so this change would mostly apply for the Polynomial & Monomial classes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions