0

I plan to remove a class from quite lengthy python project (its functionality is duplicated by other code). However, I wish to check that nothing is broken without testing everything. The code is quite messy and not fully covered by tests.

Is it possible to use some static code analyzers to find the places where this class is referenced?

This has nothing to do with type check.

Misha
  • 562
  • 6
  • 21
  • Should be quite straightforward with any IDE, like PyCharm: https://www.jetbrains.com/help/pycharm/finding-usages-in-project.html Any reason that's not good enough for you? – Random Davis Aug 20 '21 at 15:12
  • Other tools exist, but I use `mypy` and strongly recommend it. – Samwise Aug 20 '21 at 15:12
  • @Samwise could you briefly explain, how to use mypy for this purpose? Basically, the goal is to change the code where the class is referenced. – Misha Aug 20 '21 at 15:25
  • Remove the class, then run `mypy`. It will produce an error everyplace that class was used. Clean up all the errors, re-run static analysis. When it's error-free, you know you got all the references. Being able to refactor and know whether you broke anything (and exactly what, and how to fix it) is like 90% of the benefit of using static type analysis. You can use other tools for this, but all of them amount to some version of type checking (at the very least, you have to be able to distinguish between the types of "defined" and "not defined"). – Samwise Aug 20 '21 at 15:53

0 Answers0