stamixthereal commented on code in PR #28675:
URL: https://github.com/apache/airflow/pull/28675#discussion_r1062154743


##########
airflow/providers/mongo/hooks/mongo.py:
##########
@@ -74,12 +68,13 @@ def __exit__(
         exc_val: BaseException | None,
         exc_tb: TracebackType | None,
     ) -> None:
-        if self.client is not None:
-            self.close_conn()
+        if self.client:
+            self.client.close()
+            self.client = None
 
     def get_conn(self) -> MongoClient:
         """Fetches PyMongo Client"""
-        if self.client is not None:
+        if self.client:

Review Comment:
   In general, `if self.client` will be faster than `if self.client is not 
None`. This is because the `is not` operator requires evaluating the object on 
the right hand side, while the `if` statement only checks the truthiness of the 
object on the left-hand side.
   
   The interpreter only needs to check the truthiness of `self.client`. This 
means that `if self.client` will be faster if `self.client` is often `True`, 
while `if self.client is not None` will be faster `if self.client` is often 
None.
   
   It's worth noting that the difference in performance will likely be very 
small, and in most cases, it is more important to write code that is easy to 
read and understand.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to