sympy / sympy.github.com

SymPy's web page (sympy.org)
https://sympy.org/
179 stars 106 forks source link

Don't use import * #177

Open jfpuget opened 2 years ago

jfpuget commented 2 years ago

The startup code loaded by default for the SymPy shell has an import * statement. This is very very bad practice and should not be used

oscarbenjamin commented 2 years ago

Why is it bad practice in the particular context of the sympy interactive shell to use a star import?

certik commented 2 years ago

Right, I always thought the import * should not be used in Python source files, but it can be used in interactive shells (that is what is was meant for).

asmeurer commented 2 years ago

import * is just fine for interactive use. What would you suggest we use instead? If we were to replace it with an explicit import the import would be huge. sympy contains over 900 names.

oscarbenjamin commented 2 years ago

sympy contains over 900 names.

I guess you could argue that maybe it isn't necessary to import all 900 of them.

jfpuget commented 2 years ago

If import * is just fine in your shell then I can break it with one line. Just run this as first command

from math import # import is just fine

Then, this example from right pane no longer works:

sin(x).series(x, 0, 7) # one of the examples on the right pane

In general, import * is bad practice (I hope there is no disagreement here). If people see you use it, then they are likely to use it later on when writing python programs. And there it could be real bad.

sylee957 commented 1 year ago

I think that it was design flaw that sympy made exceptions for CamelCase for sin, cos even if they were really classes. The choice that they made everything look like math library like some 'magic' before, rather starts to confuse the users, and make conflicts for contributors, and not sure if it is helpful for learning curve.

oscarbenjamin commented 1 year ago

The real design flaw is the fact that there isn't a single sin function that can work with all types. Hence we have math.sin, 'cmath.sin', numpy.sin, sympy.sin etc. If there was a single dispatch sin function (like in Julia) then there would be no confusion about which to use.

Anshika91 commented 1 year ago

hey i can solve it please assign this issue to me

oscarbenjamin commented 1 year ago

I don't think that we want to change anything here. The online shell is designed for conveniently using sympy interactively.