Skip to content

Commit f7cecfe

Browse files
committed
perf(core): make sympify faster for Basic subclasses.
The behaviour of sympify was changed in sympy#20128 so that sympifying a Basic subclass would be an error when strict=True. That change made the codepath for calling e.g. _sympify(Basic) slower as more checks would be done before returning. This commit adds an early raise for the case of calling _sympify(a) where a is a Basic subclass.
1 parent 99701a5 commit f7cecfe

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sympy/core/sympify.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,13 @@ def sympify(a, locals=None, convert_xor=True, strict=False, rational=False,
344344
#
345345
# https://github.com/sympy/sympy/issues/20124
346346
is_sympy = getattr(a, '__sympy__', None)
347-
if is_sympy is True or (is_sympy is not None and not strict):
347+
if is_sympy is True:
348348
return a
349+
elif is_sympy is not None:
350+
if not strict:
351+
return a
352+
else:
353+
raise SympifyError(a)
349354

350355
if isinstance(a, CantSympify):
351356
raise SympifyError(a)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy