Fixed Python flake8 offenses
diff --git a/test/crossrunner/run.py b/test/crossrunner/run.py
index c401172..23b00a2 100644
--- a/test/crossrunner/run.py
+++ b/test/crossrunner/run.py
@@ -306,7 +306,7 @@
         return port if ok else self._get_domain_port()
 
     def alloc_port(self, socket_type):
-        if socket_type in ('domain', 'abstract','domain-socketactivated'):
+        if socket_type in ('domain', 'abstract', 'domain-socketactivated'):
             return self._get_domain_port()
         else:
             return self._get_tcp_port()
@@ -323,7 +323,7 @@
         self._log.debug('free_port')
         self._lock.acquire()
         try:
-            if socket_type in ['domain','domain-socketactivated']:
+            if socket_type in ['domain', 'domain-socketactivated']:
                 self._dom_ports.remove(port)
                 path = domain_socket_path(port)
                 if os.path.exists(path):
diff --git a/test/py/FastbinaryTest.py b/test/py/FastbinaryTest.py
old mode 100755
new mode 100644
index f680357..80a4932
--- a/test/py/FastbinaryTest.py
+++ b/test/py/FastbinaryTest.py
@@ -26,8 +26,6 @@
 # TODO(dreiss): Test error cases.  Check for memory leaks.
 
 import math
-import os
-import sys
 import timeit
 
 from copy import deepcopy
diff --git a/test/py/RunClientServer.py b/test/py/RunClientServer.py
index 809c93b..ffde6e8 100755
--- a/test/py/RunClientServer.py
+++ b/test/py/RunClientServer.py
@@ -315,7 +315,7 @@
 
     generated_dirs = []
     for gp_dir in options.genpydirs.split(','):
-        if gp_dir == 'type_hints' and (sys.version_info < (3,7)):
+        if gp_dir == 'type_hints' and (sys.version_info < (3, 7)):
             print('Skipping \'type_hints\' test since python 3.7 or later is required')
             continue
         generated_dirs.append('gen-py-%s' % (gp_dir))
diff --git a/test/py/SerializationTest.py b/test/py/SerializationTest.py
old mode 100755
new mode 100644
index a2b348f..2bda829
--- a/test/py/SerializationTest.py
+++ b/test/py/SerializationTest.py
@@ -44,7 +44,6 @@
 from thrift.transport import TTransport
 from thrift.protocol import TBinaryProtocol, TCompactProtocol, TJSONProtocol
 from thrift.TSerialization import serialize, deserialize
-import sys
 import unittest
 
 
diff --git a/test/py/TestClient.py b/test/py/TestClient.py
index 9971e42..f608e4e 100755
--- a/test/py/TestClient.py
+++ b/test/py/TestClient.py
@@ -244,7 +244,7 @@
         try:
             self.client.testException('TException')
             self.fail("should have gotten exception")
-        except TException as x:
+        except TException:
             pass
 
         # Should not throw
@@ -320,6 +320,7 @@
     Wraps any protocol with sequence ID checking: looks for outbound
     uniqueness as well as request/response alignment.
     """
+
     def __init__(self, protocol):
         # TProtocolDecorator.__new__ does all the heavy lifting
         pass
@@ -335,7 +336,6 @@
             name, type, seqid)
 
     def readMessageBegin(self):
-        global LAST_SEQID
         (name, type, seqid) =\
             super(TPedanticSequenceIdProtocolWrapper, self).readMessageBegin()
         if LAST_SEQID != seqid:
diff --git a/test/py/TestServer.py b/test/py/TestServer.py
index 3b93841..0108c98 100755
--- a/test/py/TestServer.py
+++ b/test/py/TestServer.py
@@ -206,6 +206,7 @@
     Wraps any protocol with sequence ID checking: looks for outbound
     uniqueness as well as request/response alignment.
     """
+
     def __init__(self, protocol):
         # TProtocolDecorator.__new__ does all the heavy lifting
         pass
@@ -422,7 +423,6 @@
     sys.path.insert(0, os.path.join(SCRIPT_DIR, options.genpydir))
 
     from ThriftTest import ThriftTest, SecondService
-    from thrift.Thrift import TException
     from thrift.TMultiplexedProcessor import TMultiplexedProcessor
     from thrift.transport import THeaderTransport
     from thrift.transport import TTransport
diff --git a/test/py/TestTypes.py b/test/py/TestTypes.py
index f578f42..bb1bc35 100644
--- a/test/py/TestTypes.py
+++ b/test/py/TestTypes.py
@@ -23,11 +23,14 @@
 
 import unittest
 
-# only run this test if the string 'options string: py:type_hints' esxists in the file 
+# only run this test if the string 'options string: py:type_hints' esxists in the file
+
+
 def has_type_hints_option():
     with open(ThriftTest.__file__) as f:
         return 'options string: py:type_hints' in f.read()
 
+
 @unittest.skipUnless(has_type_hints_option(), "type hints not enabled")
 class TypeAnnotationsTest(unittest.TestCase):
 
@@ -57,7 +60,7 @@
 
     def test_map(self):
         self.assertEqual(Client.testMap.__annotations__, {'return': dict[int, int], 'thing': dict[int, int]})
-    
+
     def test_list(self):
         self.assertEqual(Client.testList.__annotations__, {'return': list[int], 'thing': list[int]})
 
diff --git a/test/py/explicit_module/EnumSerializationTest.py b/test/py/explicit_module/EnumSerializationTest.py
index 8d82708..5f6944f 100644
--- a/test/py/explicit_module/EnumSerializationTest.py
+++ b/test/py/explicit_module/EnumSerializationTest.py
@@ -27,13 +27,15 @@
 from thrift.protocol import TBinaryProtocol
 from thrift.transport import TTransport
 
+
 def deserialize_immutable(base,
-                buf,
-                protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
+                          buf,
+                          protocol_factory=TBinaryProtocol.TBinaryProtocolFactory()):
     transport = TTransport.TMemoryBuffer(buf)
     protocol = protocol_factory.getProtocol(transport)
     return base.read(protocol)
 
+
 def serialization_deserialization_struct_enum_test():
     test_obj = TestStruct(param1="test_string", param2=TestEnum.TestEnum1, param3=SharedEnum.SharedEnum1)
     test_obj_serialized = serialize(test_obj)
@@ -42,6 +44,7 @@
     assert test_obj.param2 == test_obj2.param2
     assert test_obj.param3 == test_obj2.param3
 
+
 def serialization_deserialization_struct_enum_as_string_test():
     test_obj = TestStruct(param1="test_string", param2=TestEnum.TestEnum1.name, param3=SharedEnum.SharedEnum1.name)
     test_obj_serialized = serialize(test_obj)
@@ -50,6 +53,7 @@
     assert test_obj.param2 == test_obj2.param2
     assert test_obj.param3 == test_obj2.param3
 
+
 def serialization_deserialization_exception_enum_as_string_test():
     test_obj = TestException(whatOp=0, why=SharedEnum.SharedEnum0.name, who=TestEnum.TestEnum0.name)
     test_obj_serialized = serialize(test_obj)
@@ -58,6 +62,7 @@
     assert test_obj.why == test_obj2.why
     assert test_obj.who == test_obj2.who
 
+
 def serialization_deserialization_exception_enum_test():
     test_obj = TestException(whatOp=0, why=SharedEnum.SharedEnum0, who=TestEnum.TestEnum0)
     test_obj_serialized = serialize(test_obj)
@@ -67,7 +72,6 @@
     assert test_obj.who == test_obj2.who
 
 
-
 if __name__ == "__main__":
     args = sys.argv[1:]
     if args:
@@ -77,4 +81,4 @@
     serialization_deserialization_struct_enum_test()
     serialization_deserialization_struct_enum_as_string_test()
     serialization_deserialization_exception_enum_as_string_test()
-    serialization_deserialization_exception_enum_test()
\ No newline at end of file
+    serialization_deserialization_exception_enum_test()