You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by ko...@apache.org on 2021/06/08 03:32:57 UTC

[avro] branch master updated: AVRO-2921: Typefix avro.tether.util (#1249)

This is an automated email from the ASF dual-hosted git repository.

kojiromike pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git


The following commit(s) were added to refs/heads/master by this push:
     new 4db2e32  AVRO-2921: Typefix avro.tether.util (#1249)
4db2e32 is described below

commit 4db2e32cbdf5577c62e9770e8387d1d312b2bfce
Author: Michael A. Smith <mi...@smith-li.com>
AuthorDate: Mon Jun 7 23:32:36 2021 -0400

    AVRO-2921: Typefix avro.tether.util (#1249)
    
    Add type hints to avro.tether.util
---
 lang/py/avro/tether/util.py | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/lang/py/avro/tether/util.py b/lang/py/avro/tether/util.py
index 05454d1..1c950d1 100644
--- a/lang/py/avro/tether/util.py
+++ b/lang/py/avro/tether/util.py
@@ -18,16 +18,12 @@
 # limitations under the License.
 
 import socket
+from typing import cast
 
 
-def find_port():
-    """
-    Return an unbound port
-    """
-    s = socket.socket()
-    s.bind(("127.0.0.1", 0))
-
-    port = s.getsockname()[1]
-    s.close()
-
-    return port
+def find_port() -> int:
+    """Return an unbound port"""
+    with socket.socket() as s:
+        s.bind(("127.0.0.1", 0))
+        port = s.getsockname()[1]
+    return cast(int, port)