Repository: sympy/sympy

Issue:
BUG: sympy 1.10rc2 breaks unyt
Minimal Reproducer:
```
python3.8 -m venv .env
source .env/bin/activate/
pip install -U pip
pip install --pre sympy
pip install unyt

python -c "import unyt"
```
output
```
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/.env/lib/python3.8/site-packages/unyt/__init__.py", line 75, in <module>
    from unyt import unit_symbols
  File "/private/tmp/.env/lib/python3.8/site-packages/unyt/unit_symbols.py", line 33, in <module>
    _namespace[_alt_name] = _Unit(_canonical_name, registry=_registry)
  File "/private/tmp/.env/lib/python3.8/site-packages/unyt/unit_object.py", line 227, in __new__
    raise UnitParseError(
unyt.exceptions.UnitParseError: Unit representation must be a string or sympy Expr. 'Min' has type '<class 'sympy.core.function.FunctionClass'>'.
```

Discussion:

Patch:
diff --git a/sympy/parsing/sympy_parser.py b/sympy/parsing/sympy_parser.py
index ae79514670..671b78c6e2 100644
--- a/sympy/parsing/sympy_parser.py
+++ b/sympy/parsing/sympy_parser.py
@@ -1054,6 +1054,14 @@ def parse_expr(s, local_dict=None, transformations=standard_transformations,
     if global_dict is None:
         global_dict = {}
         exec('from sympy import *', global_dict)
+
+        builtins_dict = vars(builtins)
+        for name, obj in builtins_dict.items():
+            if isinstance(obj, types.BuiltinFunctionType):
+                global_dict[name] = obj
+        global_dict['max'] = Max
+        global_dict['min'] = Min
+
     elif not isinstance(global_dict, dict):
         raise TypeError('expecting global_dict to be a dict')
 
@@ -1079,13 +1087,6 @@ def parse_expr(s, local_dict=None, transformations=standard_transformations,
                     a transformation should be function that
                     takes 3 arguments'''))
 
-    builtins_dict = vars(builtins)
-    for name, obj in builtins_dict.items():
-        if isinstance(obj, types.BuiltinFunctionType):
-            global_dict[name] = obj
-    global_dict['max'] = Max
-    global_dict['min'] = Min
-
     code = stringify_expr(s, local_dict, global_dict, transformations)
 
     if not evaluate:


Test patch:
diff --git a/sympy/parsing/tests/test_sympy_parser.py b/sympy/parsing/tests/test_sympy_parser.py
index a03dd73952..826ffe815e 100644
--- a/sympy/parsing/tests/test_sympy_parser.py
+++ b/sympy/parsing/tests/test_sympy_parser.py
@@ -2,10 +2,12 @@
 
 
 import sys
+import builtins
+import types
 
 from sympy.assumptions import Q
 from sympy.core import Symbol, Function, Float, Rational, Integer, I, Mul, Pow, Eq
-from sympy.functions import exp, factorial, factorial2, sin
+from sympy.functions import exp, factorial, factorial2, sin, Min, Max
 from sympy.logic import And
 from sympy.series import Limit
 from sympy.testing.pytest import raises, skip
@@ -148,6 +150,27 @@ def test_global_dict():
         assert parse_expr(text, global_dict=global_dict) == result
 
 
+def test_no_globals():
+
+    # Replicate creating the default global_dict:
+    default_globals = {}
+    exec('from sympy import *', default_globals)
+    builtins_dict = vars(builtins)
+    for name, obj in builtins_dict.items():
+        if isinstance(obj, types.BuiltinFunctionType):
+            default_globals[name] = obj
+    default_globals['max'] = Max
+    default_globals['min'] = Min
+
+    # Need to include Symbol or parse_expr will not work:
+    default_globals.pop('Symbol')
+    global_dict = {'Symbol':Symbol}
+
+    for name in default_globals:
+        obj = parse_expr(name, global_dict=global_dict)
+        assert obj == Symbol(name)
+
+
 def test_issue_2515():
     raises(TokenError, lambda: parse_expr('(()'))
     raises(TokenError, lambda: parse_expr('"""'))