sagemath/sage

Move Set_PythonType to a separate file

jdemeyer opened this issue · 7 comments

This is done mainly to avoid cyclic imports when enabling binding=True (#22747).

I'm also removing this pointless implementation of cardinality():

    def cardinality(self):
        from sage.rings.integer import Integer
        two = Integer(2)
        if self._type is bool:
            return two
        elif self._type is int:
            import sys
            return two * sys.maxsize + 2
        elif self._type is float:
            return 2 * two**52 * (two**11 - 1) + 3 # all NaN's are the same from Python's point of view
        else:
            # probably
            import sage.rings.infinity
            return sage.rings.infinity.infinity

Somebody probably found this clever, but it's just silly... who cares how many different int instances there exist? Besides, it's wrong in Python 3.

CC: @tscrim

Component: coercion

Author: Jeroen Demeyer

Branch/Commit: 8005a7b

Reviewer: Travis Scrimshaw

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

Description changed:

--- 
+++ 
@@ -1 +1,21 @@
 This is done mainly to avoid cyclic imports when enabling `binding=True` (#22747).
+
+I'm also removing this pointless implementation of `cardinality()`:
+
+```
+    def cardinality(self):
+        from sage.rings.integer import Integer
+        two = Integer(2)
+        if self._type is bool:
+            return two
+        elif self._type is int:
+            import sys
+            return two * sys.maxsize + 2
+        elif self._type is float:
+            return 2 * two**52 * (two**11 - 1) + 3 # all NaN's are the same from Python's point of view
+        else:
+            # probably
+            import sage.rings.infinity
+            return sage.rings.infinity.infinity
+```
+Somebody probably found this clever, but it's just silly... who cares how many different `int` instances there exist? Besides, it's wrong in Python 3.

Commit: 8005a7b

New commits:

8005a7bMove Set_PythonType to a new file
comment:4

Green bot => positive review.

Reviewer: Travis Scrimshaw

Changed branch from u/jdemeyer/ticket/25845 to 8005a7b