Repository: sympy/sympy

Issue:
RR.parent returns CC
```python3
>>> from sympy import *
>>> from sympy.polys import *

>>> RR(2).parent()
CC
>>> CC(2).parent()
CC
```
Should `RR.parent` be returning `RR`?

Discussion:

Patch:
diff --git a/sympy/polys/domains/complexfield.py b/sympy/polys/domains/complexfield.py
index 8130c97f09..ee918d9399 100644
--- a/sympy/polys/domains/complexfield.py
+++ b/sympy/polys/domains/complexfield.py
@@ -43,7 +43,7 @@ def tolerance(self):
         return self._context.tolerance
 
     def __init__(self, prec=_default_precision, dps=None, tol=None):
-        context = MPContext(prec, dps, tol)
+        context = MPContext(prec, dps, tol, False)
         context._parent = self
         self._context = context
 
diff --git a/sympy/polys/domains/mpelements.py b/sympy/polys/domains/mpelements.py
index f2dfb6ff56..ad42edec8a 100644
--- a/sympy/polys/domains/mpelements.py
+++ b/sympy/polys/domains/mpelements.py
@@ -45,7 +45,7 @@ def parent(self):
 @public
 class MPContext(PythonMPContext):
 
-    def __init__(ctx, prec=53, dps=None, tol=None):
+    def __init__(ctx, prec=53, dps=None, tol=None, real=False):
         ctx._prec_rounding = [prec, round_nearest]
 
         if dps is None:
@@ -57,8 +57,12 @@ def __init__(ctx, prec=53, dps=None, tol=None):
         ctx.mpc = ComplexElement
         ctx.mpf._ctxdata = [ctx.mpf, new, ctx._prec_rounding]
         ctx.mpc._ctxdata = [ctx.mpc, new, ctx._prec_rounding]
-        ctx.mpf.context = ctx
-        ctx.mpc.context = ctx
+
+        if real:
+            ctx.mpf.context = ctx
+        else:
+            ctx.mpc.context = ctx
+
         ctx.constant = _constant
         ctx.constant._ctxdata = [ctx.mpf, new, ctx._prec_rounding]
         ctx.constant.context = ctx
diff --git a/sympy/polys/domains/realfield.py b/sympy/polys/domains/realfield.py
index f46036cc4a..2e076594b2 100644
--- a/sympy/polys/domains/realfield.py
+++ b/sympy/polys/domains/realfield.py
@@ -44,7 +44,7 @@ def tolerance(self):
         return self._context.tolerance
 
     def __init__(self, prec=_default_precision, dps=None, tol=None):
-        context = MPContext(prec, dps, tol)
+        context = MPContext(prec, dps, tol, True)
         context._parent = self
         self._context = context
 


Test patch:
diff --git a/sympy/polys/domains/tests/test_domains.py b/sympy/polys/domains/tests/test_domains.py
index 9e428fc031..87b9ecec67 100644
--- a/sympy/polys/domains/tests/test_domains.py
+++ b/sympy/polys/domains/tests/test_domains.py
@@ -781,3 +781,7 @@ def test_CC_double():
     assert CC(1e-15j).imag > 1e-50
     assert CC(1e-20j).imag > 1e-50
     assert CC(1e-40j).imag > 1e-50
+
+def test_issue_18278():
+    assert str(RR(2).parent()) == 'RR'
+    assert str(CC(2).parent()) == 'CC'