Oscar, I opened two issues:
* mypy - https://github.com/python/mypy/issues/12995 * sympy - https://github.com/sympy/sympy/issues/23647 I agree that the best way to fix this is in the mypy code. Let's see how they respond. Splitting the Matrix chained type alias assignment in the sympy code base is a pragmatic workaround and not too unnatural. I haven't contributed a PR to sympy yet so I'll need to spend some time understanding the contribution guidelines and doing whatever setup is required to run tests, etc. I'm glad you are supportive of this workaround. I'll also try overriding the Matrix type alias with a local definition. -- Arthur On Sat, Jun 18, 2022 at 9:58 AM Oscar Benjamin <oscar.j.benja...@gmail.com> wrote: > On Sat, 18 Jun 2022 at 13:42, Arthur Ryman <arthur.ry...@gmail.com> 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 sympy+unsubscr...@googlegroups.com. > 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 > . > -- 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 sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAApBiOk5X8FonL3_fGQUSnph-C%2BkBhc%2Bdc3a2UvQvfgg0UFrGQ%40mail.gmail.com.