Permalink
Browse files

In Morphism, define __new__ to allow keyword arguments.

Since Morphism derives from Basic, and Basic.__new__ does not accept
keyword arguments, Morphism could not be constructed with keyword
arguments.  While this is all right for simple constructors like those
of Object and Category, the constructor of Morphism will quickly become
awkward to use if the user will be required to supply all arguments in
order.
  • Loading branch information...
scolobb committed Jun 6, 2012
1 parent 462a5e1 commit c9b027b113ec57d8ecdb9ae88f88bee19b6e969b
Showing with 9 additions and 5 deletions.
  1. +9 −5 sympy/categories/baseclasses.py
@@ -93,12 +93,16 @@ class Morphism(Basic):
Morphism(Object("A"), Object("B"), "f")
"""
- def __init__(self, domain, codomain, name=""):
- self.domain = domain
- self.codomain = codomain
- self.name = name
+ def __new__(cls, domain, codomain, name=""):
+ new_morphism = Basic.__new__(cls, domain, codomain, name)
+
+ new_morphism.domain = domain
+ new_morphism.codomain = codomain
+ new_morphism.name = name
+
+ new_morphism.components = [new_morphism]
- self.components = [self]
+ return new_morphism
def compose(self, g, new_name=""):
"""

0 comments on commit c9b027b

Please sign in to comment.