@@ -503,6 +503,67 @@ cdef class Parent(category_object.CategoryObject):
503
503
print ' hash of {0} changed in Parent._refine_category_ during refinement' \
504
504
.format(str (self .__class__))
505
505
506
+ def _unset_category (self ):
507
+ """
508
+ Remove the information on ``self``'s category.
509
+
510
+ NOTE:
511
+
512
+ This may change ``self``'s class!
513
+
514
+ EXAMPLES:
515
+
516
+ Let us create a parent in the category of rings::
517
+
518
+ sage: class MyParent(Parent):
519
+ ....: def __init__(self):
520
+ ....: Parent.__init__(self, category=Rings())
521
+ ....:
522
+ sage: P = MyParent()
523
+ sage: P.category()
524
+ Category of rings
525
+
526
+ Of course, its category is initialised::
527
+
528
+ sage: P._is_category_initialized()
529
+ True
530
+
531
+ We may now refine the category to the category of fields.
532
+ Note that this changes the class::
533
+
534
+ sage: C = type(P)
535
+ sage: C == MyParent
536
+ False
537
+ sage: P._refine_category_(Fields())
538
+ sage: P.category()
539
+ Category of fields
540
+ sage: C == type(P)
541
+ False
542
+
543
+ Now we may have noticed that the category refinement was a
544
+ mistake. We do not need to worry, because we can undo category
545
+ initialisation totally::
546
+
547
+ sage: P._unset_category()
548
+ sage: P._is_category_initialized()
549
+ False
550
+ sage: type(P) == MyParent
551
+ True
552
+
553
+ Hence, we can now initialise the parent again in the original
554
+ category, i.e., the category of rings. We find that not only
555
+ the category, but also theclass of the parent is brought back
556
+ to what it was after the original category initialisation::
557
+
558
+ sage: P._init_category_(Rings())
559
+ sage: type(P) == C
560
+ True
561
+
562
+ """
563
+ self ._category = None
564
+ if not is_extension_type(self .__class__):
565
+ while issubclass (self .__class__, Sets_parent_class):
566
+ self .__class__ = self .__class__.__base__
506
567
507
568
# This probably should go into Sets().Parent
508
569
@lazy_attribute
0 commit comments