Skip to content

__neg__: Should use class(self)(...) instead of Vector(...) #1

@Grazfather

Description

@Grazfather

In your solution to vector you use Vector:

    def __neg__(self):
        return Vector(-x for x in self)

You also hardcode Vector in __add__.

Above it, though, in __getitem__ you get the class by using class(self). This seems inconsistent, and probably incorrect. If you were to subclass Vector, for instance, it would break when negating an instance of the subclass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions