Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/doc/en/thematic_tutorials/tutorial-programming-python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ The *standard types* are :class:`bool`, :class:`int`, :class:`list`,
sage: set([ [1], [2] ])
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...

* A *dictionary* is an association table, which associates values to
keys. Keys must be hashable. One creates dictionaries using the
Expand Down Expand Up @@ -765,7 +765,7 @@ appear once and must be immutable::
sage: d = {[1,2,3] : 12}
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...

Another way to add items to a dictionary is with the ``update()`` method which
updates the dictionary from another dictionary::
Expand Down
2 changes: 1 addition & 1 deletion src/sage/combinat/diagram_algebras.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def check(self):
sage: pd2 = da.AbstractPartitionDiagram(pd, [[[1,2],[-1,-2]]]) # indirect doctest
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...
"""
if self._base_diagram:
tst = frozenset(e for B in self._base_diagram for e in B)
Expand Down
6 changes: 3 additions & 3 deletions src/sage/combinat/finite_state_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ class FSMState(SageObject):
sage: A.determinisation()
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...
sage: A.state(0).color = ()
sage: A.determinisation()
Automaton with 1 state
Expand Down Expand Up @@ -6554,7 +6554,7 @@ def add_from_transition_function(self, function, initial_states=None,
sage: Transducer(transition, input_alphabet=[0], initial_states=[0])
Traceback (most recent call last):
...
TypeError: mutable vectors are unhashable
TypeError: ...mutable vectors are unhashable...
"""
if self.input_alphabet is None:
raise ValueError("No input alphabet is given. "
Expand Down Expand Up @@ -10951,7 +10951,7 @@ def determinisation(self):
sage: A.determinisation()
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...
sage: A.state(0).color = ()
sage: A.determinisation()
Automaton with 1 state
Expand Down
36 changes: 20 additions & 16 deletions src/sage/combinat/words/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,11 @@ class InfiniteWord_iter_with_caching(WordDatatype_iter_with_caching, InfiniteWor

Pickle is not supported for infinite word defined by an iterator::

sage: dumps(w)
Traceback (most recent call last):
...
TypeError: can...t...pickle...generator...object...
sage: try:
....: dumps(w)
....: except TypeError as e:
....: "pickle" in str(e) and "generator" in str(e)
True
"""
pass

Expand Down Expand Up @@ -557,10 +558,11 @@ class InfiniteWord_iter(WordDatatype_iter, InfiniteWord_class):

Pickle is not supported for infinite word defined by an iterator::

sage: dumps(w)
Traceback (most recent call last):
...
TypeError: can...t...pickle...generator...object...
sage: try:
....: dumps(w)
....: except TypeError as e:
....: "pickle" in str(e) and "generator" in str(e)
True
"""
pass

Expand Down Expand Up @@ -659,10 +661,11 @@ class Word_iter_with_caching(WordDatatype_iter_with_caching, Word_class):

Pickle is not supported for word of unknown length defined by an iterator::

sage: dumps(w)
Traceback (most recent call last):
...
TypeError: can...t...pickle...generator...object...
sage: try:
....: dumps(w)
....: except TypeError as e:
....: "pickle" in str(e) and "generator" in str(e)
True
"""
pass

Expand Down Expand Up @@ -696,10 +699,11 @@ class Word_iter(WordDatatype_iter, Word_class):

Pickle is not supported for word of unknown length defined by an iterator::

sage: dumps(w)
Traceback (most recent call last):
...
TypeError: can...t...pickle...generator...object...
sage: try:
....: dumps(w)
....: except TypeError as e:
....: "pickle" in str(e) and "generator" in str(e)
True
"""
pass

Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/base4.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def hasse_diagram(self):
sage: Q.hasse_diagram()
Traceback (most recent call last):
...
TypeError: mutable polyhedra are unhashable
TypeError: ...mutable polyhedra are unhashable...
sage: C = Q.combinatorial_polyhedron()
sage: D = C.hasse_diagram()
sage: set(D.vertices(sort=False)) == set(range(20))
Expand Down
2 changes: 1 addition & 1 deletion src/sage/geometry/polyhedron/base_mutable.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __hash__(self):
sage: set([p])
Traceback (most recent call last):
...
TypeError: mutable polyhedra are unhashable
TypeError: ...mutable polyhedra are unhashable...
sage: p.set_immutable()
sage: set([p])
{A 0-dimensional polyhedron in ZZ^2 defined as the convex hull of 1 vertex}
Expand Down
4 changes: 2 additions & 2 deletions src/sage/graphs/base/c_graph.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ cdef class CGraphBackend(GenericGraphBackend):
sage: D.add_vertex([])
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...

::

Expand All @@ -1720,7 +1720,7 @@ cdef class CGraphBackend(GenericGraphBackend):
sage: S.add_vertex([])
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...
"""
retval = None
if name is None:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/graphs/bipartite_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ def __hash__(self):
sage: B.__hash__()
Traceback (most recent call last):
...
TypeError: unhashable type: 'dict'
TypeError: ...unhashable type: 'dict'...
"""
if self.is_immutable():
# Determine whether to hash edge labels
Expand Down
3 changes: 1 addition & 2 deletions src/sage/graphs/generic_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -678,8 +678,7 @@ def __hash__(self):
sage: {G: 1}[G]
Traceback (most recent call last):
...
TypeError: This graph is mutable, and thus not hashable. Create
an immutable copy by `g.copy(immutable=True)`
TypeError: ...This graph is mutable, and thus not hashable...
sage: G_imm = Graph(G, data_structure='static_sparse')
sage: G_imm == G
True
Expand Down
8 changes: 3 additions & 5 deletions src/sage/graphs/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
sage: G = Graph({ 0 : { M : None } }) # needs sage.modules
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...

However, if one wants to define a dictionary, with the same keys and arbitrary
objects for entries, one can make that association::
Expand Down Expand Up @@ -391,8 +391,7 @@
sage: {G:1}[G]
Traceback (most recent call last):
...
TypeError: This graph is mutable, and thus not hashable.
Create an immutable copy by `g.copy(immutable=True)`
TypeError: ...This graph is mutable, and thus not hashable...
sage: G_immutable = Graph(G, immutable=True)
sage: G_immutable == G
True
Expand Down Expand Up @@ -868,8 +867,7 @@ class Graph(GenericGraph):
sage: {G:1}[G]
Traceback (most recent call last):
...
TypeError: This graph is mutable, and thus not hashable.
Create an immutable copy by `g.copy(immutable=True)`
TypeError: ...This graph is mutable, and thus not hashable...

When providing the optional arguments ``data_structure="static_sparse"`` or
``immutable=True`` (both mean the same), then an immutable graph results::
Expand Down
4 changes: 2 additions & 2 deletions src/sage/matrix/matrix0.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -471,11 +471,11 @@ cdef class Matrix(sage.structure.element.Matrix):
sage: hash(A)
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...
sage: v = {A:1}
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...

If we make A immutable it suddenly is hashable.

Expand Down
2 changes: 1 addition & 1 deletion src/sage/misc/cachefunc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ in caches. This can be achieved by defining an appropriate method
sage: hash(b)
Traceback (most recent call last):
...
TypeError: unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement'
TypeError: ...unhashable type: 'sage.rings.padics.qadic_flint_CR.qAdicCappedRelativeElement'...
sage: from sage.misc.cachefunc import cached_method
sage: @cached_method
....: def f(x): return x == a
Expand Down
19 changes: 9 additions & 10 deletions src/sage/misc/lazy_list.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -534,16 +534,15 @@ cdef class lazy_list_generic():
EXAMPLES::
sage: from itertools import count
sage: from sage.misc.lazy_list import lazy_list
sage: m = lazy_list(count())
sage: m = lazy_list(iter([0, 1, 4, 9, 16, 25, 36, 49, 64, 81]))
sage: x = loads(dumps(m))
sage: y = iter(x)
sage: print("{} {} {}".format(next(y), next(y), next(y)))
0 1 2
0 1 4
sage: m2 = m[3::2]
sage: loads(dumps(m2))
lazy list [3, 5, 7, ...]
lazy list [9, 25, 49, ...]
"""
if self.master is None:
raise NotImplementedError
Expand Down Expand Up @@ -916,8 +915,9 @@ cdef class lazy_list_from_iterator(lazy_list_generic):
[0, 1, 2]
sage: [next(x), next(y)]
[3, 3]
sage: loads(dumps(m))
lazy list [0, 1, 2, ...]
sage: m2 = lazy_list(iter([0, 1, 4, 9, 16]))
sage: loads(dumps(m2))
lazy list [0, 1, 4, ...]
"""

def __init__(self, iterator, cache=None, stop=None):
Expand Down Expand Up @@ -986,10 +986,9 @@ cdef class lazy_list_from_iterator(lazy_list_generic):
TESTS::
sage: from sage.misc.lazy_list import lazy_list_from_iterator
sage: from itertools import count
sage: loads(dumps(lazy_list_from_iterator(count())))
lazy list [0, 1, 2, ...]
sage: loads(dumps(lazy_list_from_iterator(count(), ['a'])))
sage: loads(dumps(lazy_list_from_iterator(iter([0, 1, 4, 9, 16]))))
lazy list [0, 1, 4, ...]
sage: loads(dumps(lazy_list_from_iterator(iter([0, 1, 4, 9, 16]), ['a'])))
lazy list ['a', 0, 1, ...]
"""
return lazy_list_from_iterator, (self.iterator, self.cache, self.stop)
Expand Down
25 changes: 11 additions & 14 deletions src/sage/misc/sage_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def run(self, category=None, skip=[], catch=True, raise_on_failure=False,
....: def _test_b(self, tester): tester.fail()
....: def _test_c(self, tester): pass
....: def _test_d(self, tester): tester.fail()
....: def _test_pickling(self, tester):
....: from _pickle import PicklingError
....: from sage.misc.persist import dumps
....: try:
....: dumps(self)
....: tester.fail("Expected PicklingError")
....: except PicklingError:
....: pass

sage: TestSuite(Blah()).run()
Failure in _test_b:
Expand All @@ -229,13 +237,7 @@ def run(self, category=None, skip=[], catch=True, raise_on_failure=False,
...
AssertionError: None
------------------------------------------------------------
Failure in _test_pickling:
Traceback (most recent call last):
...
...PicklingError: Can't pickle <class '__main__.Blah'>: attribute
lookup ...Blah... failed
------------------------------------------------------------
The following tests failed: _test_b, _test_d, _test_pickling
The following tests failed: _test_b, _test_d

sage: TestSuite(Blah()).run(verbose = True)
running ._test_a() . . . pass
Expand All @@ -253,13 +255,8 @@ def run(self, category=None, skip=[], catch=True, raise_on_failure=False,
------------------------------------------------------------
running ._test_new() . . . pass
running ._test_not_implemented_methods() . . . pass
running ._test_pickling() . . . fail
Traceback (most recent call last):
...
...PicklingError: Can't pickle <class '__main__.Blah'>: attribute
lookup ...Blah... failed
------------------------------------------------------------
The following tests failed: _test_b, _test_d, _test_pickling
running ._test_pickling() . . . pass
The following tests failed: _test_b, _test_d

File "/opt/sage/local/lib/python/site-packages/sage/misc/sage_unittest.py", line 183, in run
test_method(tester = tester)
Expand Down
12 changes: 6 additions & 6 deletions src/sage/misc/weak_dict.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ cdef class WeakValueDictionary(dict):
sage: D.setdefault(matrix([]), ZZ) # needs sage.modules
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...
"""
cdef PyObject* wr = PyDict_GetItemWithError(self, k)
if wr != NULL:
Expand Down Expand Up @@ -539,7 +539,7 @@ cdef class WeakValueDictionary(dict):
sage: D[matrix([])] = ZZ # needs sage.modules
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...
"""
self._set_item(k, v)

Expand Down Expand Up @@ -585,7 +585,7 @@ cdef class WeakValueDictionary(dict):
sage: D.pop(matrix([])) # needs sage.modules
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...
"""
cdef PyObject* wr = PyDict_GetItemWithError(self, k)
if wr == NULL:
Expand Down Expand Up @@ -662,7 +662,7 @@ cdef class WeakValueDictionary(dict):
sage: D.get(matrix([])) # needs sage.modules
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...
"""
cdef PyObject * wr = PyDict_GetItemWithError(self, k)
if wr == NULL:
Expand Down Expand Up @@ -701,7 +701,7 @@ cdef class WeakValueDictionary(dict):
sage: D[matrix([])] # needs sage.modules
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...
"""
cdef PyObject* wr = PyDict_GetItemWithError(self, k)
if wr == NULL:
Expand Down Expand Up @@ -744,7 +744,7 @@ cdef class WeakValueDictionary(dict):
sage: matrix([]) in D # needs sage.modules
Traceback (most recent call last):
...
TypeError: mutable matrices are unhashable
TypeError: ...mutable matrices are unhashable...
"""
cdef PyObject* wr = PyDict_GetItemWithError(self, k)
return (wr != NULL) and (PyWeakref_GetObject(wr) != Py_None)
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/tutorial_free_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
sage: F = CombinatorialFreeModule(ZZ, ([1],[2],[3])); F.an_element()
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...

sage: F = CombinatorialFreeModule(ZZ, ((1,), (2,), (3,))); F.an_element()
2*B[(1,)] + 2*B[(2,)] + 3*B[(3,)]
Expand Down
2 changes: 1 addition & 1 deletion src/sage/modules/with_basis/indexed_element.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ cdef class IndexedFreeModuleElement(ModuleElement):
sage: a[[2,1]]
Traceback (most recent call last):
...
TypeError: unhashable type: 'list'
TypeError: ...unhashable type: 'list'...
"""
res = self._monomial_coefficients.get(m)
if res is None:
Expand Down
2 changes: 1 addition & 1 deletion src/sage/plot/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ def __truediv__(self, right):
sage: Color('black') / 0.0
Traceback (most recent call last):
...
ZeroDivisionError: float division by zero
ZeroDivisionError: ...division by zero

sage: papayawhip / yellow
Traceback (most recent call last):
Expand Down
Loading
Loading