Tracking changes in python source files?

I am learning python and got into a situation where I need to change a function of a function. I am originally a Java programmer, so in the Java world, a change in function would allow Eclipse to show that many Java source files have errors. That way, I can find out which files need to be changed. But how could one do this in python, given that there are no types ?! I am using TextMate2 for python coding.

I am currently doing brute force. We open each python script file and check where I use this function, and then modify it. But I am sure that this is not a way to cope with large projects.

Edit: as an example. I am defining a class named Graphin the python script file. Graphhas two object variables. I created many objects (each with a different name !!!) of this class in many script files, and then decided that I want to change the name of the object variables! Now I look at each file and read my code again to change the names again :(. PLEASE help!

Example: A file Ahas x,y,zclass objects C. The file Bhas xx,yy,zzclass objects C. The class Chas two instance variable names that should be changed Footo Pooand Foo1to Poo1. Also consider the many files of type Aand B. What would you do to solve this problem? You can open each file and search for x, y, z, xx, yy, zz, and then change the names separately? !!!

+4
source share
5 answers

Hey, slow down. The encoding process that you described is not scalable. How exactly did you change the behavior of the function? Give specifics, please.

UPDATE: , , - , OO- Python. , / . 10 , - . , .

(, , .)

, .

+1

, IDE!

, .

  • .

  • , grep

, , . .

grep, grep -R 'my_function_name' src src.

, : Unix IDE.

+1

. , , . "Goto Anything" (Ctrl + P), Multiple Selections/Multi Edit .

, IDE, JetBrains pycharm , , , .

Python Tools Visual Studio (. install, VS) Refactoring REPL .

. , pycharm , , PT4VS .

, python , IDE . , , Java # IDE. , Java, , , JetBrains IntelliJ, PyCharm .

, , , #, , python. , . . IDE , . , , .

0

, , . Python IDE , , .

:

  • grep . ( , Java, .)

  • , .

  • , , , , , , .

0

:

  • , , . :

    class MyClass(object):
        def __init__(self):
            self.t = time.time()
        # creating new names
        def new_foo(self, arg):
            return 'new_foo', arg
        def new_bar(self, arg):
            return 'new_bar', arg
        # now creating functions aliases
        foo = new_foo
        bar = new_bar
    
  • , , . / .

0

Source: https://habr.com/ru/post/1532430/


All Articles