Re: [libvirt] [PATCH 2/2] Added syntax-check rule for return with parentheses
On 03/23/2012 07:21 AM, Osier Yang wrote: On 03/22/2012 07:33 PM, Martin Kletzander wrote: After cleanup introduced with previous commit, there is a need for syntax-check rule taking care of return(). Regexp used in 'prohibit' parameter is taken from the cleanup commit and modified so it fits 'grep -E' format. Semicolon at the end is needed, otherwise the regexp could match return with cast. No exception is needed thanks to files excused by default. The exception is not even needed for python files because 1) when returning a tuple, you can still omit parentheses around (unless there is only one value inside, but that's very unusual case), 2) return in python doesn't need semicolon at the end of statement when there is no statement following (and statement following 'return' doesn't make sense). This forces the Python coding style actually, prohibiting one writes Python codes like: def test(): return (1); def test1(): return (1,2,3); regardless of whether coding like this is good or bad, usual or unsual, they are legal in Python, and we don't say they are not allowed in HACKING or somewhere else. Not sure if we should allow this, even we will allow that, we need to document it somewhere, or more clear and specific for .py files in halt message. You're right. I feel inclined to the version where we don't force this for python code. My initial concern was about python-generated C code, but that's a small portion of the code and it's fixed already. Instead of creating some internal python code style, I'll send v2 with the exception in a minute. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 2/2] Added syntax-check rule for return with parentheses
After cleanup introduced with previous commit, there is a need for syntax-check rule taking care of return(). Regexp used in 'prohibit' parameter is taken from the cleanup commit and modified so it fits 'grep -E' format. Semicolon at the end is needed, otherwise the regexp could match return with cast. No exception is needed thanks to files excused by default. The exception is not even needed for python files because 1) when returning a tuple, you can still omit parentheses around (unless there is only one value inside, but that's very unusual case), 2) return in python doesn't need semicolon at the end of statement when there is no statement following (and statement following 'return' doesn't make sense). --- cfg.mk |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/cfg.mk b/cfg.mk index 24e6a69..59b07ef 100644 --- a/cfg.mk +++ b/cfg.mk @@ -469,6 +469,12 @@ sc_prohibit_xmlURI: halt='use virURI(Parse|Format), not xml(ParseURI|SaveUri)' \ $(_sc_search_regexp) +# we don't want old old-style return with parentheses around argument +sc_prohibit_return_as_function: + @prohibit='\return *\(([^()]*(\([^()]*\)[^()]*)*)\) *;'\ + halt='avoid extra () with return statements'\ + $(_sc_search_regexp) + # ATTRIBUTE_UNUSED should only be applied in implementations, not # header declarations sc_avoid_attribute_unused_in_header: -- 1.7.3.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/2] Added syntax-check rule for return with parentheses
On 03/22/2012 07:33 PM, Martin Kletzander wrote: After cleanup introduced with previous commit, there is a need for syntax-check rule taking care of return(). Regexp used in 'prohibit' parameter is taken from the cleanup commit and modified so it fits 'grep -E' format. Semicolon at the end is needed, otherwise the regexp could match return with cast. No exception is needed thanks to files excused by default. The exception is not even needed for python files because 1) when returning a tuple, you can still omit parentheses around (unless there is only one value inside, but that's very unusual case), 2) return in python doesn't need semicolon at the end of statement when there is no statement following (and statement following 'return' doesn't make sense). This forces the Python coding style actually, prohibiting one writes Python codes like: def test(): return (1); def test1(): return (1,2,3); regardless of whether coding like this is good or bad, usual or unsual, they are legal in Python, and we don't say they are not allowed in HACKING or somewhere else. Not sure if we should allow this, even we will allow that, we need to document it somewhere, or more clear and specific for .py files in halt message. --- cfg.mk |6 ++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/cfg.mk b/cfg.mk index 24e6a69..59b07ef 100644 --- a/cfg.mk +++ b/cfg.mk @@ -469,6 +469,12 @@ sc_prohibit_xmlURI: halt='use virURI(Parse|Format), not xml(ParseURI|SaveUri)' \ $(_sc_search_regexp) +# we don't want old old-style return with parentheses around argument +sc_prohibit_return_as_function: + @prohibit='\return *\(([^()]*(\([^()]*\)[^()]*)*)\) *;'\ + halt='avoid extra () with return statements'\ + $(_sc_search_regexp) + # ATTRIBUTE_UNUSED should only be applied in implementations, not # header declarations sc_avoid_attribute_unused_in_header: -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list