<p>I have a bunch of classes I want to rename.  Some of them have names that are small and that name is reused in other class names, where I don't want that name changed.  Most of this lives in Python code, but we also have some XML code that references class names.</p>

<p>Simple search and replace only gets me so far.  In my case, I want to rename AdminAction to AdminActionPlug and AdminActionLogger to AdminActionLoggerPlug, so the first one's search-and-replace would also hit the second, wrongly.</p>

<p>Does anyone have experience with Python refactoring tools ? Bonus points if they can fix class names in the XML documents too.</p>

[{'answer_id': 29770, 'author': 'Thomas Vander Stichele', 'author_id': 2900, 'author_profile': 'https://Stackoverflow.com/users/2900', 'pm_score': 7, 'selected': True, 'text': '<p>In the meantime, I\'ve tried it two tools that have some sort of integration with vim.</p>\n\n<p>The first is <a href="https://github.com/python-rope/rope" rel="noreferrer">Rope</a>, a python refactoring library that comes with a Vim (and emacs) plug-in.  I tried it for a few renames, and that definitely worked as expected.  It allowed me to preview the refactoring as a diff, which is nice.  It is a bit text-driven, but that\'s alright for me, just takes longer to learn.</p>\n\n<p>The second is <a href="http://bicyclerepair.sourceforge.net/" rel="noreferrer">Bicycle Repair Man</a> which I guess wins points on name.  Also plugs into vim and emacs.  Haven\'t played much with it yet, but I remember trying it a long time ago.</p>\n\n<p>Haven\'t played with both enough yet, or tried more types of refactoring, but I will do some more hacking with them.</p>\n'}, {'answer_id': 1813244, 'author': 'przemo_li', 'author_id': 218760, 'author_profile': 'https://Stackoverflow.com/users/218760', 'pm_score': 2, 'selected': False, 'text': '<p>Your IDE can support refactorings !!\nCheck it Eric, Eclipse, WingIDE have build in tools for refactorings (Rename including). And that are very safe refactorings - if something can go wrong IDE wont do ref.</p>\n\n<p>Also consider adding few unit test to ensure your code did not suffer during refactorings.</p>\n'}, {'answer_id': 4882243, 'author': 'Michael Kent', 'author_id': 566335, 'author_profile': 'https://Stackoverflow.com/users/566335', 'pm_score': 3, 'selected': False, 'text': "<p>WingIDE 4.0 (WingIDE is my python IDE of choice) will support a few refactorings, but I just tried out the latest beta, beta6, and... there's still work to be done.  Retract Method works nicely, but Rename Symbol does not.</p>\n\n<p>Update: The 4.0 release has fixed all of the refactoring tools.  They work great now.</p>\n"}, {'answer_id': 14046877, 'author': 'David Pokorny', 'author_id': 1822419, 'author_profile': 'https://Stackoverflow.com/users/1822419', 'pm_score': -1, 'selected': False, 'text': "<p>You can use sed to perform this. The trick is to recall that regular expressions can recognize word boundaries. This works on all platforms provided you get the tools, which on Windows is Cygwin, Mac OS may require installing the dev tools, I'm not sure, and Linux has this out of the box. So grep, xargs, and sed should do the trick, after 12 hours of reading man pages and trial and error ;)</p>\n"}, {'answer_id': 25765376, 'author': 'Benoit Blanchon', 'author_id': 1164966, 'author_profile': 'https://Stackoverflow.com/users/1164966', 'pm_score': 2, 'selected': False, 'text': '<p><a href="http://www.jetbrains.com/pycharm/features/" rel="nofollow">PyCharm</a> have some refactoring features.</p>\n\n<blockquote>\n  <h3>PYTHON REFACTORING</h3>\n  \n  <p><strong>Rename</strong> refactoring allows to perform global code changes safely and instantly. Local changes within a file are performed in-place. Refactorings work in plain Python and Django projects.</p>\n  \n  <p>Use <strong>Introduce Variable/Field/Constant</strong> and <strong>Inline Local</strong> for improving the code structure within a method, <strong>Extract Method</strong> to break up longer methods, <strong>Extract Superclass</strong>, <strong>Push Up</strong>, <strong>Pull Down</strong> and <strong>Move</strong> to move the methods and classes.</p>\n</blockquote>\n'}, {'answer_id': 26381548, 'author': 'Oliver Bestwalter', 'author_id': 2626627, 'author_profile': 'https://Stackoverflow.com/users/2626627', 'pm_score': 5, 'selected': False, 'text': '<p>I would strongly recommend <a href="https://www.jetbrains.com/pycharm/" rel="noreferrer">PyCharm</a> - not just for refactorings. Since the first PyCharm answer was posted here a few years ago the refactoring support in PyCharm has improved significantly.</p>\n\n<p><a href="https://www.jetbrains.com/pycharm/webhelp/refactoring-source-code.html" rel="noreferrer">Python Refactorings available in PyCharm</a> (last checked 2016/07/27 in PyCharm 2016.2)</p>\n\n<ul>\n<li>Change Signature</li>\n<li>Convert to Python Package/Module</li>\n<li>Copy</li>\n<li>Extract Refactorings</li>\n<li>Inline</li>\n<li>Invert Boolean</li>\n<li>Make Top-Level Function</li>\n<li>Move Refactorings</li>\n<li>Push Members down</li>\n<li>Pull Members up</li>\n<li>Rename Refactorings</li>\n<li>Safe Delete</li>\n</ul>\n\n<p>XML refactorings (I checked in context menu in an XML file):</p>\n\n<ul>\n<li>Rename</li>\n<li>Move</li>\n<li>Copy</li>\n<li>Extract Subquery as CTE</li>\n<li>Inline</li>\n</ul>\n\n<p>Javascript refactorings:</p>\n\n<ul>\n<li>Extract Parameter in JavaScript</li>\n<li>Change Signature in JavaScript</li>\n<li>Extract Variable in JavaScript</li>\n</ul>\n'}, {'answer_id': 52539363, 'author': 'qff', 'author_id': 118608, 'author_profile': 'https://Stackoverflow.com/users/118608', 'pm_score': 3, 'selected': False, 'text': '<p>I would take a look at <em>Bowler</em> (<a href="https://pybowler.io" rel="noreferrer">https://pybowler.io</a>).</p>\n\n<p>It\'s better suited for use directly from the command-line than rope and encourages scripting (one-off scripts).</p>\n'}]
['https://Stackoverflow.com/questions/28796', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2900/']