I like to compare Python sources with diff util and I have seen that git diff shows me the function name (for some files, but also not for Python) in the hunk or chunk? header. Thats why I searched to do the same with normal diff.
Then I found that there is a -p, --show-c-function param, which don't work well with Python files (I only get the class name). So I also found in the man page the param: -F, --show-function-line=RE
Now I searched for a nice RE to match python functions to include them in my diff output without luck.
I know we have def myname(): or async def myname(): ... and maybe more?
Has someone a good RegEx for it?
I found this one, but it don't work with diff util (the output has no function names):
diff -Nru -F '(?P<function>\w+)\s?\((?P<arg>(?P<args>\w+(,\s?)?)+)\)' modules/websocket/__init__.py.old modules/websocket/__init__.py
Regards, Thomas
git log -p, which uses the same diff asgit diff, on my Python repo, and it's finding the class or function quite reliably for me, except for code that's outside those. What version of Git are you using? I've got 2.25.1 where I just tested this.diff, not ingit diff. For what it's worth, if thegit diffoutput happened to be what you liked better, you can dogit diff path1 path2to invokegit diffon files outside a repo context, or ignoring the repo they're in.git diff file1 file2will also work outside a Git repo -- all you need is the Git software installed. But if it doesn't output what you want, then nevermind!