Drop Python 2.7 and 3.4 support, add mypy to tests

110 views
Skip to first unread message

Francesco Bonazzi

unread,
Dec 22, 2019, 11:16:42 AM12/22/19
to sympy
The typing module adds support for type annotations of various kinds to Python. Using mypy in Travis would enforce type-checking.

Type declarations would be beneficial to:
  • analyze the code and find potential bugs
  • serve as a first step before translating the code to C++

Oscar Benjamin

unread,
Dec 22, 2019, 7:32:05 PM12/22/19
to sympy
I think it would be good to use mypy but it will be a lot of work just
to get working on a small part of the codebase because so much of
SymPy is inconsistent about types right now. Ultimately it's not just
a case of "using mypy" but actually fixing the inconsistencies which
is a big task. Perhaps this could be suggested as an idea for a GSOC
proposal...
> --
> 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+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c7640d2a-802a-4ec9-890f-66a18d202395%40googlegroups.com.

Aaron Meurer

unread,
Dec 22, 2019, 7:53:58 PM12/22/19
to sympy
We already dropped 3.4 support after the 1.4 release. See
https://github.com/sympy/sympy/wiki/Release-Notes-for-1.4 and
https://github.com/sympy/sympy/wiki/Python-version-support-policy.

I agree that mypy will not be easy. I also suspect there would be
issues getting mypy to work with the SymPy type system. I'm not sure
how well they support custom types. It would be a good GSoC project or
if an existing dev wants to work on it, a good proposal for a NumFOCUS
small development grant.

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxTH0JiGDmemOmC-nEFzJTKdPkkAC5d06rRVQydg%3DgyZtg%40mail.gmail.com.

Francesco Bonazzi

unread,
Dec 24, 2019, 7:44:31 AM12/24/19
to sympy
It looks like the codegen module is really causing troubles to mypy. The module is a real mess, we'll have to review it one day.
> > To unsubscribe from this group and stop receiving emails from it, send an email to sy...@googlegroups.com.
> > To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/c7640d2a-802a-4ec9-890f-66a18d202395%40googlegroups.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 sy...@googlegroups.com.

Aaron Meurer

unread,
Dec 24, 2019, 12:46:40 PM12/24/19
to sy...@googlegroups.com
What sort of troubles?

Aaron Meurer 

To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/54220440-0069-4481-89f5-99a5a48728c5%40googlegroups.com.

Oscar Benjamin

unread,
Dec 24, 2019, 12:49:13 PM12/24/19
to sympy
I had a bit of trouble with codegen here:
https://github.com/sympy/sympy/pull/18116

The CodegenArrayContraction class is non-Expr but is used in Mul.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6Jcf%3Dh0kJmLgAfsM3X7RDpghb3XLbicj6utzK3My-Fm5g%40mail.gmail.com.

Francesco Bonazzi

unread,
Dec 26, 2019, 5:25:01 AM12/26/19
to sympy


On Tuesday, 24 December 2019 18:46:40 UTC+1, Aaron Meurer wrote:
What sort of troubles?
 
Aaron Meurer 

On Tue, Dec 24, 2019 at 5:44 AM Francesco Bonazzi <franz....@gmail.com> wrote:
It looks like the codegen module is really causing troubles to mypy. The module is a real mess, we'll have to review it one day.


Last time I had a look at the codegen module, I remember noticing extensive usage of class inheritance, followed by monkey-patching the incorrectly-inherited methods.

I get a lot of errors from the code printer if I run mymy -m sympy/, but I didn't check it deeply, so I'm not sure how much it is related to the class-inheritance problem.

Oscar Benjamin

unread,
Jan 18, 2020, 11:00:52 AM1/18/20
to sympy
I've just merged a PR that fixes the 1000 or so mypy errors on sympy's
master branch:
https://github.com/sympy/sympy/pull/18244

This means it is now possible to try out using mypy without seeing
lots of unrelated errors. The next step is to add type hints in key
places. They don't need to be everywhere: the hints are inherited by
subclasses so adding hints on Basic/Expr will propagate down. I guess
that key functions like sympify will need to be hinted as well for it
to work effectively.

There are a few places where I used type: ignore. One thing that
neither mypy or flake8 likes is multipledispatch where the same
function/method name is used repeatedly. Hopefully we can find a
better solution for that than type:ignore.
https://github.com/sympy/sympy/issues/17795

The other side effect of that PR is that it is now possible to have
Python 3 only syntax in master (previously the tests would have
failed).
Reply all
Reply to author
Forward
0 new messages