On Sat, 18 Jun 2022 at 13:42, Arthur Ryman <[email protected]> wrote: > > Oscar B, > > As a theme, how about making SymPy more mypy-friendly? I ran into one > problem, caused by the mypy folks not accepting certain syntax. You diagnosed > it: > > class A: > pass > > # B = A # <--- this is fine > B = C = A # <--- mypy chokes on this > > a: B = B() > > The error message is: > > $ mypy t.py > t.py:7: error: Variable "t.B" is not valid as a type > t.py:7: note: See > https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases > Found 1 error in 1 file (checked 1 source file) > > I need to create an issue for this (I've been distracted lately). > > Yes, this is a mypy bug and I'll also report it to the mypy project. However, > SymPy could avoid this bug simply by splitting the double type assignment for > Matrix into two single assignments.
I don't mind making that change because it's trivial so feel free to open a PR. I do want to see this opened as an issue with mypy in the first instance though. It's a very slippery slope if the expectation is to rewrite anything in downstream python libraries to be compatible with bugs in mypy. There needs to be pressure on the mypy developers to support perfectly valid code rather than pressure on everyone else to workaround their bugs. If you aren't going to open a bug report with mypy or they aren't prepared to fix bugs like this then I don't see why we should make any change to accomodate using sympy with mypy. > fyi, I had to roll back SymPy 1.10 to 1.9 since I rely on mypy. That seems a bit drastic. Several alternatives: 1. Use the actual class name which is MutableDenseMatrix. 2. Make your own alias Matrix = MutableDenseMatrix 3. Add type:ignore 4. And so on... -- Oscar -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxQ%2Bs-i8x02asQWY8%3Dh__zHX%3DybmkOotY%2B3O%3DZben4wZvA%40mail.gmail.com.
