Skip to content

Do not cache the non-existence of coerce/convert map too often, and do not pretend that there is a conversion where it doesn't make sense at all #13378

@simon-king-jena

Description

@simon-king-jena

Sorry for the long ticket title.

About the first part of the title:

sage: P.<x,y> = QQ[]
sage: P.is_coercion_cached(x)
False
sage: P.coerce_map_from(x)
sage: P.is_coercion_cached(x)
True

Hence, there is a reference to x in the coercion cache for P. OK, by #715 and friends, the reference is weak --- unless x does not allow weak references, in which case the reference will be strong, and x would not be collectable. Hence, a potential memory leak.

About the second part:

sage: ZZ.convert_map_from(1)
Conversion map:
  From: Set of Python objects of 
  To:   Integer Ring

or

sage: P.convert_map_from(x)
Traceback (most recent call last):
...
TypeError: Cannot convert sage.rings.polynomial.multi_polynomial_libsingular.MPolynomial_libsingular to sage.structure.parent.Parent

I think it is not good that the error occurs. The answer of ZZ.convert_map_from(1) seems strange, but apparently those things actually occur, namely conversions from the category of sequences.

CC: @nbruin @jpflori

Component: coercion

Keywords: coercion conversion object cache

Author: Simon King

Reviewer: Nils Bruin

Merged: sage-5.7.beta0

Issue created by migration from https://trac.sagemath.org/ticket/13378

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions