diff mbox series

prserv: remove dead code in exception handling

Message ID 20240306171144.1874798-1-michael.opdenacker@bootlin.com
State New
Headers show
Series prserv: remove dead code in exception handling | expand

Commit Message

Michael Opdenacker March 6, 2024, 5:11 p.m. UTC
From: Michael Opdenacker <michael.opdenacker@bootlin.com>

As explained in https://docs.python.org/3/reference/compound_stmts.html#else-clause,
the code after the "else" statement won't be run as there is a "return"
in the "try" block.

Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>

---

See the whole code on
https://git.openembedded.org/bitbake/tree/lib/prserv/serv.py#n38
---
 lib/prserv/serv.py | 2 --
 1 file changed, 2 deletions(-)

Comments

Joshua Watt March 6, 2024, 11:31 p.m. UTC | #1
On Wed, Mar 6, 2024 at 10:12 AM Michael Opdenacker via
lists.openembedded.org
<michael.opdenacker=bootlin.com@lists.openembedded.org> wrote:
>
> From: Michael Opdenacker <michael.opdenacker@bootlin.com>
>
> As explained in https://docs.python.org/3/reference/compound_stmts.html#else-clause,
> the code after the "else" statement won't be run as there is a "return"
> in the "try" block.
>
> Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
>
> ---
>
> See the whole code on
> https://git.openembedded.org/bitbake/tree/lib/prserv/serv.py#n38
> ---
>  lib/prserv/serv.py | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
> index 5fc8863f7..5032f7cd7 100644
> --- a/lib/prserv/serv.py
> +++ b/lib/prserv/serv.py
> @@ -40,8 +40,6 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection):
>          except:
>              self.table.sync()
>              raise
> -        else:
> -            self.table.sync_if_dirty()

It is correct this will not run, should self.table.sync() be in a
finally block instead to make sure the DB is always synced? (the
except can also be removed then)

>
>      async def handle_get_pr(self, request):
>          version = request['version']
> --
> 2.34.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#15990): https://lists.openembedded.org/g/bitbake-devel/message/15990
> Mute This Topic: https://lists.openembedded.org/mt/104770220/3616693
> Group Owner: bitbake-devel+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [JPEWhacker@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Michael Opdenacker March 8, 2024, 3:31 p.m. UTC | #2
Hi Joshua

On 3/7/24 at 00:31, Joshua Watt wrote:
> On Wed, Mar 6, 2024 at 10:12 AM Michael Opdenacker via
> lists.openembedded.org
> <michael.opdenacker=bootlin.com@lists.openembedded.org> wrote:
>> From: Michael Opdenacker <michael.opdenacker@bootlin.com>
>>
>> As explained in https://docs.python.org/3/reference/compound_stmts.html#else-clause,
>> the code after the "else" statement won't be run as there is a "return"
>> in the "try" block.
>>
>> Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
>>
>> ---
>>
>> See the whole code on
>> https://git.openembedded.org/bitbake/tree/lib/prserv/serv.py#n38
>> ---
>>   lib/prserv/serv.py | 2 --
>>   1 file changed, 2 deletions(-)
>>
>> diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
>> index 5fc8863f7..5032f7cd7 100644
>> --- a/lib/prserv/serv.py
>> +++ b/lib/prserv/serv.py
>> @@ -40,8 +40,6 @@ class PRServerClient(bb.asyncrpc.AsyncServerConnection):
>>           except:
>>               self.table.sync()
>>               raise
>> -        else:
>> -            self.table.sync_if_dirty()
> It is correct this will not run, should self.table.sync() be in a
> finally block instead to make sure the DB is always synced? (the
> except can also be removed then)

I've implemented this simplification, but it would cause to run 
"self.table.sync()" even when no exception is caught. That wasn't the 
case before. Is that what you were suggesting?

Happy to submit my change if you agree!
Cheers
Michael.
diff mbox series

Patch

diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py
index 5fc8863f7..5032f7cd7 100644
--- a/lib/prserv/serv.py
+++ b/lib/prserv/serv.py
@@ -40,8 +40,6 @@  class PRServerClient(bb.asyncrpc.AsyncServerConnection):
         except:
             self.table.sync()
             raise
-        else:
-            self.table.sync_if_dirty()
 
     async def handle_get_pr(self, request):
         version = request['version']