Trac #13394: Implement faster and safer WeakValueDictionary
# Sat Oct 19 11:50:04 2013 +0200

# Node ID f98c0b44c17dbb718c8449f3eabcbc7b8bdc825d
# Parent  2306f17ea8f3e40d1a3668c24695a50bfad34d1f
#10963: More functorial constructions
# Sun Oct 27 13:58:49 2013 +0100

# Node ID 70a11b0abddbee6bfbac4103147808fc1a792647
# Parent  df8fdfb31c4eca2d3761f268e3f41ceb9a6aeb81
trac #10963 doctests corrections
# Tue Oct 29 20:14:19 2013 +0100

# Node ID e374533eb4a23dfff21146ffe4834ae93ca70769
# Parent  599ab9a6bd8d8015fb6c6247fcfbd27912c9f0d3
#10963: More functorial constructions (fix graded modules with basis)
trac #15432: use a callback class object holding a weak reference for sage.misc.weak_dict.WeakValueDictionary
trac #15432: also equip iteration context with a weak reference
trac #15432: Code context manager in iterator via try/finally. This saves an entire class and some reference management.Z
merging sage/categories/category.py
Merge branch 'master' into 10963
duplication introduced in my own merge removed
typos and unused imports
trac 15506: ensure that WeakValueDictionary deletes entries via a list, so that we benefit from Python's trashcan
Merge branch 'ticket/15432' into ticket/15506
Trac #15506: Fix another "recursion depth exceeded" in memory deallocation for weak dictionaries

See: http://trac.sagemath.org/ticket/10963?replyto=174#comment:159 and
follow up for details

This is a follow up to #13394 #15069, and a blocker for #10963.

URL: http://trac.sagemath.org/15506
Reported by: nthiery
Ticket author(s):
Reviewer(s):
Trac #10963: More functorial constructions

This ticket implements:

- Support for full subcategories defined by an axiom (Finite,
  Infinite, Facade, Commutative, Associative, Unital,
  Inverse, NoZeroDivisors, Division, FiniteDimensional, Connected,
  WithBasis, Irreducible), and joins thereof:

{{{
    sage: Groups() & Sets().Finite()
    Category of finite groups
    sage: Algebras(QQ).Finite() & Monoids().Commutative()
    Join of Category of commutative algebras over Rational Field and
Category of finite monoids
    sage: Rings().Division() & Sets().Finite()
    Category of finite fields
}}}

- New categories:
  - AdditiveSemigroups, AdditiveMonoids, AdditiveGroups
  - DistributiveMagmasAndAdditiveMagmas
  - MagmaticAlgebras (will replace Algebras in #15043)
  - AssociativeAlgebras
  - UnitalAlgebras
  - Algebras of additive semigroups and monoids

- More mathematical rules:
  - A subquotient of a finite set is a finite set
  - The algebra of a finite set is finite dimensional
  - The algebra of a commutative magma is commutative
  - A finite division ring is a field
  - ...

- Documentation:
  - More documentation for IsomorphicObjects
  - Complete revamping of sage.categories.primer
  - Misc

- Use SubcategoryMethods to put the functorial constructions where
  they belong. E.g. DualObjects, TensorProducts, and Graded are now
  only defined for subcategories of Modules.

- More lazy imports, removed a bunch of unused imports, ...

Patch developed on:
http://combinat.sagemath.org/patches/file/tip/trac_10963
-more_functorial_constructions-nt.patch.

This ticket is dedicated to the town of Megantic where I was so warmly
welcomed and a good chunk of this ticket got implemented!

Apply:

* [attachment:trac_10963-more_functorial_constructions-nt.patch]
* [attachment:trac_10963_doctest_correction-fc.patch]
* [attachment:trac_10963-more_functorial_constructions-graded-modules-
fix-nt.patch]

URL: http://trac.sagemath.org/10963
Reported by: nthiery
Ticket author(s): Nicolas M. Thiéry
Reviewer(s): Simon King, Frédéric Chapoton