1 | | I have the feeling that `ForgetfulFunctor` does not work how it supposed to be, already on a deeper level. Right now, it calls the following code from `Functor`: |
2 | | |
3 | | {{{ |
4 | | #!python |
5 | | def _apply_functor(self, x): |
6 | | """ |
7 | | Apply the functor to an object of ``self``'s domain. |
8 | | |
9 | | NOTE: |
10 | | |
11 | | Each subclass of :class:`Functor` should overload this method. By default, |
12 | | this method coerces into the codomain, without checking whether the |
13 | | argument belongs to the domain. |
14 | | |
15 | | TESTS:: |
16 | | |
17 | | sage: from sage.categories.functor import Functor |
18 | | sage: F = Functor(FiniteFields(),Fields()) |
19 | | sage: F._apply_functor(ZZ) |
20 | | Rational Field |
21 | | |
22 | | """ |
23 | | return self.__codomain(x) |
24 | | }}} |
25 | | |
26 | | Here, `__codomain` should be the destination category. However, the call function of a category is treated as a coercion: |
27 | | |
28 | | {{{ |
29 | | #!python |
30 | | def __call__(self, x, *args, **opts): |
31 | | """ |
32 | | Construct an object in this category from the data in ``x``, |
33 | | or throw ``TypeError`` or ``NotImplementedError``. |
34 | | |
35 | | If ``x`` is readily in ``self`` it is returned unchanged. |
36 | | Categories wishing to extend this minimal behavior should |
37 | | implement :meth:`._call_`. |
38 | | |
39 | | EXAMPLES:: |
40 | | |
41 | | sage: Rings()(ZZ) |
42 | | Integer Ring |
43 | | """ |
44 | | if x in self: |
45 | | return x |
46 | | return self._call_(x, *args, **opts) |
47 | | }}} |
48 | | |
49 | | as the following note in `sage/categories/sets_cat.py` indicates, too: |
50 | | |
51 | | {{{ |
52 | | #!python |
53 | | def _call_(self, X, enumerated_set=False): |
54 | | r""" |
55 | | Construct an object in this category from the data ``X``. |
56 | | |
57 | | INPUT: |
58 | | |
59 | | - ``X`` -- an object to be converted into a set |
60 | | |
61 | | - ``enumerated_set`` -- if set to ``True`` and the input is either a |
62 | | Python tuple or a Python list then the output will be a finite |
63 | | enumerated set. |
64 | | |
65 | | EXAMPLES:: |
66 | | |
67 | | sage: Sets()(ZZ) |
68 | | Integer Ring |
69 | | sage: Sets()([1, 2, 3]) |
70 | | {1, 2, 3} |
71 | | |
72 | | sage: S = Sets()([1, 2, 3]); S.category() |
73 | | Category of finite sets |
74 | | sage: S = Sets()([1, 2, 3], enumerated_set=True); S.category() |
75 | | Category of facade finite enumerated sets |
76 | | |
77 | | .. NOTE:: |
78 | | |
79 | | Using ``Sets()(A)`` used to implement some sort of forgetful functor |
80 | | into the ``Sets()`` category. This feature has been removed, because |
81 | | it was not consistent with the semantic of :meth:`Category.__call__`. |
82 | | Proper forgetful functors will eventually be implemented, with |
83 | | another syntax. |
84 | | """ |
85 | | if enumerated_set and type(X) in (tuple, list, range): |
86 | | from sage.categories.enumerated_sets import EnumeratedSets |
87 | | return EnumeratedSets()(X) |
88 | | from sage.sets.set import Set |
89 | | return Set(X) |
90 | | }}} |
91 | | |
92 | | ''Proper forgetful functors will eventually be implemented, with another syntax.'' It seems, this hasn't been done so far. |
93 | | |
94 | | That's worth another ticket, isn't it? |
| 1 | The forgetful functor seems not to work properly anyway. Opened another ticket #31247. |