# HG changeset patch
# User Simon King <simon.king@unijena.de>
# Date 1346147394 7200
# Node ID 4e230c92400de3407a14ead563bc0c5e72868917
# Parent 618dd21098bc08985243ad1a6af36db262d63392
#13378: Do not try to construct a conversion/coercion on invalid input
diff git a/sage/structure/parent.pyx b/sage/structure/parent.pyx
a

b


190  190  from sage.structure.dynamic_class import dynamic_class 
191  191  Sets_parent_class = Sets().parent_class 
192  192  
 193  cdef inline bint good_as_coerce_domain(S): 
 194  """ 
 195  Determine whether the input can be the domain of a map. 
 196  
 197  NOTE: 
 198  
 199  This is the same as being an object in a category, or 
 200  being a type. Namely, in Sage, we do consider coercion maps 
 201  from the type ``<int>`` to, say, `ZZ`. 
 202  
 203  TESTS: 
 204  
 205  If an instance `S` is not suitable as domain of a map, then 
 206  the nonexistence of a coercion or conversion map from `S` 
 207  to some other parent is not cached, by :trac:`13378`:: 
 208  
 209  sage: P.<x,y> = QQ[] 
 210  sage: P.is_coercion_cached(x) 
 211  False 
 212  sage: P.coerce_map_from(x) 
 213  sage: P.is_coercion_cached(x) # indirect doctest 
 214  False 
 215  
 216  """ 
 217  return isinstance(S,CategoryObject) or isinstance(S,type) 
 218  
 219  cdef inline bint good_as_convert_domain(S): 
 220  return isinstance(S,SageObject) or isinstance(S,type) 
 221  
193  222  cdef class Parent(category_object.CategoryObject): 
194  223  """ 
195  224  Parents are the Sage/mathematical analogues of container objects 
… 
… 

1963  1992  To: Macdonald polynomials in the Ht basis over Fraction Field of Multivariate Polynomial Ring in q, t over Rational Field 
1964  1993  
1965  1994  """ 
 1995  if not good_as_coerce_domain(S): 
 1996  return None 
1966  1997  self._coercions_used = True 
1967  1998  cdef map.Map mor 
1968  1999  if S is self: 
… 
… 

2161  2192  sage: parent(m(35/7)) 
2162  2193  Integer Ring 
2163  2194  """ 
 2195  if not good_as_convert_domain(S): 
 2196  return None 
2164  2197  if self._convert_from_hash is None: # this is because parent.__init__() does not always get called 
2165  2198  self.init_coerce() 
2166  2199  try: 