compress python code
Дилян Палаузов
dilyan.palauzov@aegee.org
Thu Jan 3 20:36:00 GMT 2019
Hello Simon,
in a former project I worked for, applied diverse regular expressions to rewrite the python code shorter, like
- X if X else Y â X or Y
- no else after return (unfold instead the code after return)
and applied the searches at that time to GDB (a year ago).
Regards
ÐилÑн
-------
Compress Python code
-- replace
if x:
return True
return False
with
return x
where x is boolean expression
-- replace âif len(x) > 0â¦â with âif xâ¦â
-- replace âif len(x) != 0â¦â with âif xâ¦â
-- replace âif len(x) == 0â¦â with âif not xâ¦â
-- replace âif x not in y.keys():
y[x] = set()â with ây.setdefault(x, set())â
-- remove âreturnâ after âraiseâ (unreachable code)
-- replace âif hasattr(x, 'y'):
return x.y
return True" with âreturn getattr(x, y, True)â
diff --git a/etc/ChangeLog b/etc/ChangeLog
--- a/etc/ChangeLog
+++ b/etc/ChangeLog
@@ -1,3 +1,7 @@
+2019-01-13 ÐилÑн ÐалаÑзов <dilyan.palauzov@aegee.org>
+
+ * update-copyright.py: compress
+
2018-06-19 Simon Marchi <simon.marchi@ericsson.com>
* configure.in: Remove AC_PREREQ.
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2019-01-03 ÐилÑн ÐалаÑзов <dilyan.palauzov@aegee.org>
+
+ * contrib/cleanup_check.py: compress
+ * contrib/test_pubnames_and_indexes.py: compress
+ * python/lib/gdb/FrameDecorator.py: compress
+ * python/lib/gdb/command/explore.py: compress
+ * python/lib/gdb/command/frame_filters.py: compress
+ * python/lib/gdb/command/pretty_printers.py: compress
+ * python/lib/gdb/frames.py: compress
+ * system-gdbinit/elinos.py: compress
+
2019-01-03 Jim Wilson <jimw@sifive.com>
* riscv-tdep.c (riscv_freg_feature): Drop s0 name from f8.
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-03 ÐилÑн ÐалаÑзов <dilyan.palauzov@aegee.org>
+
+ * analyze-racy-logs.py: compress
+ * gdb.perf/lib/perftest/reporter.py: compress
+
2018-12-28 Tom Tromey <tom@tromey.com>
Simon Marchi <simark@simark.ca>
On Thu, 2019-01-03 at 11:50 -0500, Simon Marchi wrote:
> On 2019-01-03 08:00, ÐилÑн ÐалаÑзов wrote:
> > Some rewritings on python code, that make it shorter
>
> Hi Dilyan,
>
> Thanks for the patch. I am fine with these changes, which use more
> idiomatic Python constructs. Did you hunt these occurrences by hand, or
> did you use a static analysis tool/linter (if so, which one)?
>
> In the commit log can you make a summary of the classes of changes you
> do? For example:
>
> - Change "len(string) < 1" to "not string"
> - Change
>
> if string:
> return False
> return True
>
> to
>
> return not string
> - ...
>
>
> Finally, please include a corresponding ChangeLog entry, see [1] for
> reference. If it's not totally clear how to write it, do what you can
> and I'll help you fix it after.
>
> Simon
>
> [1]
> https://sourceware.org/gdb/wiki/ContributionChecklist#Properly_Formatted_GNU_ChangeLog
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gdb-python-compress.patch
Type: text/x-patch
Size: 12451 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20190103/68eeeda9/attachment.bin>
More information about the Gdb-patches
mailing list