From nobody Sun May 19 02:26:41 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1699056560962588.694550612411; Fri, 3 Nov 2023 17:09:20 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7BC4D18AA; Fri, 3 Nov 2023 20:09:19 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7D9D118A2; Fri, 3 Nov 2023 20:06:38 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3AF62189D; Fri, 3 Nov 2023 20:06:30 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id E717C187F for ; Fri, 3 Nov 2023 20:06:28 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-ua_Eukm3Pr2v3KXAzbKZEQ-1; Fri, 03 Nov 2023 20:06:27 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B40BE101A53B for ; Sat, 4 Nov 2023 00:06:26 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.32.79]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82A482166B26; Sat, 4 Nov 2023 00:06:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: ua_Eukm3Pr2v3KXAzbKZEQ-1 From: Laine Stump To: devel@lists.libvirt.org Subject: [libvirt PATCH] rpcgen: use proper operators when comparing types Date: Fri, 3 Nov 2023 20:04:13 -0400 Message-ID: <20231104000626.581451-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: SBPFPEOOXN3FKYTMUF7B6DVYO76NKGM7 X-Message-ID-Hash: SBPFPEOOXN3FKYTMUF7B6DVYO76NKGM7 X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Andrea Bolognani X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8"; x-default="true" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1699056561391100001 flake8 (run on all python scripts as a part of the syntax checks) version 6.1.0 (on macOS 14) issued many complaints like this on the new rpcgen python scripts: [...]libvirt/scripts/rpcgen/rpcgen/lexer.py:57:17: E721 do not compare type= s, for exact checks use `is` / `is not`, for instance checks use `isinstanc= e()` This patch changes all [type] =3D=3D [type] to use "is" instead of "=3D=3D", and similarly to use "is not" instead of "!=3D". (flake8 5.03, e.g. on Fedora 38, is just fine with using "=3D=3D" and "!=3D= ", but python on both likes "is" and "is not") Fixes: commit v9.9.0-24-g8ec79e5e14 Fixes: commit v9.9.0-22-gca3f025011 Fixes: commit v9.9.0-21-g031efb691f Fixes: commit v9.9.0-20-g8c8b97685b Signed-off-by: Laine Stump Reviewed-by: Daniel P. Berrang=C3=A9 --- scripts/rpcgen/rpcgen/ast.py | 4 +- scripts/rpcgen/rpcgen/generator.py | 26 ++++++------ scripts/rpcgen/rpcgen/lexer.py | 2 +- scripts/rpcgen/rpcgen/parser.py | 68 +++++++++++++++--------------- 4 files changed, 50 insertions(+), 50 deletions(-) diff --git a/scripts/rpcgen/rpcgen/ast.py b/scripts/rpcgen/rpcgen/ast.py index 3e3e089713..52d9c3ac46 100644 --- a/scripts/rpcgen/rpcgen/ast.py +++ b/scripts/rpcgen/rpcgen/ast.py @@ -185,9 +185,9 @@ class XDRTypeCustom(XDRType): self.definition =3D definition =20 def is_scalar(self): - if type(self.definition) =3D=3D XDRDefinitionEnum: + if type(self.definition) is XDRDefinitionEnum: return True - if type(self.definition) =3D=3D XDRDefinitionTypedef: + if type(self.definition) is XDRDefinitionTypedef: return self.definition.decl.typ.is_scalar() return False =20 diff --git a/scripts/rpcgen/rpcgen/generator.py b/scripts/rpcgen/rpcgen/gen= erator.py index 73731e1497..c6e210e7b0 100644 --- a/scripts/rpcgen/rpcgen/generator.py +++ b/scripts/rpcgen/rpcgen/generator.py @@ -81,7 +81,7 @@ class XDRTypeDeclarationGenerator(XDRVisitor): ) =20 def visit_declaration_variablearray(self, obj, indent, context): - if type(obj.typ) =3D=3D XDRTypeString: + if type(obj.typ) is XDRTypeString: return "%schar *%s" % (indent, obj.identifier) else: code =3D ( @@ -178,10 +178,10 @@ class XDRTypeDeclarationGenerator(XDRVisitor): + "%s union {\n" % indent ) for value in obj.cases: - if type(value.decl.typ) =3D=3D XDRTypeVoid: + if type(value.decl.typ) is XDRTypeVoid: continue code =3D code + self.visit_object(value, indent + " ") = + ";\n" - if obj.default is not None and type(obj.default.typ) !=3D XDRTypeV= oid: + if obj.default is not None and type(obj.default.typ) is not XDRTyp= eVoid: code =3D code + self.visit_object(obj.default, indent + " = ") + ";\n" code =3D code + "%s } %su;\n" % (indent, prefix) + "%s}" % inde= nt return code @@ -250,10 +250,10 @@ class XDRMarshallImplementationGenerator(XDRVisitor): return code =20 def generate_type_call(self, decl, field, typename, embedded=3DFalse, = indent=3D""): - if type(decl.typ) =3D=3D XDRTypeVoid: + if type(decl.typ) is XDRTypeVoid: return "" - if type(decl) =3D=3D XDRDeclarationFixedArray: - if type(decl.typ) =3D=3D XDRTypeOpaque: + if type(decl) is XDRDeclarationFixedArray: + if type(decl.typ) is XDRTypeOpaque: code =3D "%s if (!xdr_%s(xdrs, %s, %s))\n" % ( indent, self.visit_object(decl.typ, context=3D"func"), @@ -270,7 +270,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor): self.visit_object(decl.typ), self.visit_object(decl.typ, context=3D"func"), ) - elif type(decl) =3D=3D XDRDeclarationVariableArray: + elif type(decl) is XDRDeclarationVariableArray: fieldRef =3D "." pointerStr =3D "" if embedded: @@ -278,7 +278,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor): else: fieldRef =3D "->" =20 - if type(decl.typ) =3D=3D XDRTypeString: + if type(decl.typ) is XDRTypeString: code =3D "%s if (!xdr_%s(xdrs, %s%s, %s))\n" % ( indent, self.visit_object(decl.typ, context=3D"func"), @@ -286,7 +286,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor): field, decl.maxlength, ) - elif type(decl.typ) =3D=3D XDRTypeOpaque: + elif type(decl.typ) is XDRTypeOpaque: code =3D "%s if (!xdr_bytes(xdrs, (char **)&%s%s%s_val,= " % ( indent, field, @@ -311,7 +311,7 @@ class XDRMarshallImplementationGenerator(XDRVisitor): self.visit_object(decl.typ, context=3D"func"), ) ) - elif type(decl) =3D=3D XDRDeclarationPointer: + elif type(decl) is XDRDeclarationPointer: pointerStr =3D "" if embedded: pointerStr =3D "&" @@ -327,9 +327,9 @@ class XDRMarshallImplementationGenerator(XDRVisitor): else: pointerStr =3D "" isFixedArray =3D ( - type(decl.typ) =3D=3D XDRTypeCustom - and type(decl.typ.definition) =3D=3D XDRDefinitionTypedef - and type(decl.typ.definition.decl) =3D=3D XDRDeclarationFi= xedArray + type(decl.typ) is XDRTypeCustom + and type(decl.typ.definition) is XDRDefinitionTypedef + and type(decl.typ.definition.decl) is XDRDeclarationFixedA= rray ) =20 if embedded and not isFixedArray: diff --git a/scripts/rpcgen/rpcgen/lexer.py b/scripts/rpcgen/rpcgen/lexer.py index 989c2ae216..a27d7005b8 100644 --- a/scripts/rpcgen/rpcgen/lexer.py +++ b/scripts/rpcgen/rpcgen/lexer.py @@ -55,7 +55,7 @@ class XDRToken(abc.ABC): =20 def __eq__(self, other): return ( - type(self) =3D=3D type(other) + type(self) is type(other) and self.line =3D=3D other.line and self.column =3D=3D other.column and self.value =3D=3D other.value diff --git a/scripts/rpcgen/rpcgen/parser.py b/scripts/rpcgen/rpcgen/parser= .py index 7efbe5468e..c01ae56755 100644 --- a/scripts/rpcgen/rpcgen/parser.py +++ b/scripts/rpcgen/rpcgen/parser.py @@ -162,10 +162,10 @@ class XDRParser: if token is None: return None =20 - if type(token) =3D=3D XDRTokenCEscape: + if type(token) is XDRTokenCEscape: return XDRDefinitionCEscape(token.value[1:]) =20 - if type(token) !=3D XDRTokenIdentifier: + if type(token) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % token) =20 defs =3D { @@ -186,18 +186,18 @@ class XDRParser: definition =3D func() =20 semi =3D self.lexer.next() - if type(semi) !=3D XDRTokenPunctuation or semi.value !=3D ";": + if type(semi) is not XDRTokenPunctuation or semi.value !=3D ";": raise Exception("Expected ';', but got %s" % semi) =20 return definition =20 def parse_definition_const(self): ident =3D self.lexer.next() - if type(ident) !=3D XDRTokenIdentifier: + if type(ident) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % ident) =20 assign =3D self.lexer.next() - if type(assign) !=3D XDRTokenPunctuation or assign.value !=3D "=3D= ": + if type(assign) is not XDRTokenPunctuation or assign.value !=3D "= =3D": raise Exception("Expected '=3D', but got %s" % assign) =20 const =3D self.lexer.next() @@ -217,7 +217,7 @@ class XDRParser: =20 def parse_definition_enum(self): name =3D self.lexer.next() - if type(name) !=3D XDRTokenIdentifier: + if type(name) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % name) =20 body =3D self.parse_enum_body() @@ -231,7 +231,7 @@ class XDRParser: =20 def parse_definition_struct(self): name =3D self.lexer.next() - if type(name) !=3D XDRTokenIdentifier: + if type(name) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % name) =20 body =3D self.parse_struct_body() @@ -245,7 +245,7 @@ class XDRParser: =20 def parse_definition_union(self): name =3D self.lexer.next() - if type(name) !=3D XDRTokenIdentifier: + if type(name) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % name) =20 body =3D self.parse_union_body() @@ -260,23 +260,23 @@ class XDRParser: def parse_declaration(self): typ =3D self.parse_type() =20 - if type(typ) =3D=3D XDRTypeVoid: + if type(typ) is XDRTypeVoid: return XDRDeclarationScalar(typ, None) =20 ident =3D self.lexer.next() =20 pointer =3D False - if type(ident) =3D=3D XDRTokenPunctuation: + if type(ident) is XDRTokenPunctuation: if ident.value !=3D "*": raise Exception("Expected '*' or identifer, but got %s" % = ident) - if type(typ) =3D=3D XDRTypeString or type(typ) =3D=3D XDRTypeO= paque: + if type(typ) is XDRTypeString or type(typ) is XDRTypeOpaque: raise Exception("Pointer invalid for 'string' and 'opaque'= types") =20 pointer =3D True ident =3D self.lexer.next() =20 bracket =3D self.lexer.peek() - if type(bracket) =3D=3D XDRTokenPunctuation: + if type(bracket) is XDRTokenPunctuation: if bracket.value =3D=3D "[": _ =3D self.lexer.next() value =3D self.lexer.next() @@ -284,10 +284,10 @@ class XDRParser: raise Exception("Expected constant, but got %s" % valu= e) =20 close =3D self.lexer.next() - if type(close) !=3D XDRTokenPunctuation or close.value != =3D "]": + if type(close) is not XDRTokenPunctuation or close.value != =3D "]": raise Exception("Expected ']', but got %s" % value) =20 - if type(typ) =3D=3D XDRTypeString: + if type(typ) is XDRTypeString: raise Exception("Fixed array invalid for 'string' type= ") return XDRDeclarationFixedArray(typ, ident.value, value.va= lue) elif bracket.value =3D=3D "<": @@ -298,7 +298,7 @@ class XDRParser: value =3D self.lexer.next().value =20 close =3D self.lexer.next() - if type(close) !=3D XDRTokenPunctuation or close.value != =3D ">": + if type(close) is not XDRTokenPunctuation or close.value != =3D ">": raise Exception("Expected '>', but got %s" % close) =20 return XDRDeclarationVariableArray(typ, ident.value, value) @@ -310,12 +310,12 @@ class XDRParser: =20 def parse_type(self): typ =3D self.lexer.next() - if type(typ) !=3D XDRTokenIdentifier: + if type(typ) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % typ) =20 if typ.value =3D=3D "unsigned": typ =3D self.lexer.peek() - if type(typ) !=3D XDRTokenIdentifier: + if type(typ) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % typ) =20 if typ.value =3D=3D "char": @@ -366,25 +366,25 @@ class XDRParser: =20 def parse_enum_body(self): body =3D self.lexer.next() - if type(body) !=3D XDRTokenPunctuation or body.value !=3D "{": + if type(body) is not XDRTokenPunctuation or body.value !=3D "{": raise Exception("Expected '{', but got %s" % body) =20 values =3D [] while True: ident =3D self.lexer.next() - if type(ident) !=3D XDRTokenIdentifier: + if type(ident) is not XDRTokenIdentifier: raise Exception("Expected identifier, but got %s" % ident) =20 equal =3D self.lexer.next() - if type(equal) !=3D XDRTokenPunctuation or equal.value !=3D "= =3D": + if type(equal) is not XDRTokenPunctuation or equal.value !=3D = "=3D": raise Exception("Expected '=3D', but got %s" % ident) =20 value =3D self.lexer.next() - if type(value) !=3D XDRTokenConstant: + if type(value) is not XDRTokenConstant: raise Exception("Expected constant, but got %s" % ident) =20 separator =3D self.lexer.next() - if type(separator) !=3D XDRTokenPunctuation and separator.valu= e not in [ + if type(separator) is not XDRTokenPunctuation and separator.va= lue not in [ "}", ",", ]: @@ -403,7 +403,7 @@ class XDRParser: =20 def parse_struct_body(self): body =3D self.lexer.next() - if type(body) !=3D XDRTokenPunctuation or body.value !=3D "{": + if type(body) is not XDRTokenPunctuation or body.value !=3D "{": raise Exception("Expected '{', but got %s" % body) =20 fields =3D [] @@ -412,11 +412,11 @@ class XDRParser: fields.append(field) =20 separator =3D self.lexer.next() - if type(separator) !=3D XDRTokenPunctuation and separator.valu= e !=3D ";": + if type(separator) is not XDRTokenPunctuation and separator.va= lue !=3D ";": raise Exception("Expected ';', but got %s" % separator) =20 end =3D self.lexer.peek() - if type(end) =3D=3D XDRTokenPunctuation and end.value =3D=3D "= }": + if type(end) is XDRTokenPunctuation and end.value =3D=3D "}": break =20 # discard the '}' we peeked at to end the loop @@ -429,28 +429,28 @@ class XDRParser: =20 def parse_union_body(self): ident =3D self.lexer.next() - if type(ident) !=3D XDRTokenIdentifier or ident.value !=3D "switch= ": + if type(ident) is not XDRTokenIdentifier or ident.value !=3D "swit= ch": raise Exception("Expected 'switch', but got %s" % ident) =20 bracket =3D self.lexer.next() - if type(bracket) !=3D XDRTokenPunctuation or bracket.value !=3D "(= ": + if type(bracket) is not XDRTokenPunctuation or bracket.value !=3D = "(": raise Exception("Expected '(', but got %s" % bracket) =20 discriminator =3D self.parse_declaration() =20 bracket =3D self.lexer.next() - if type(bracket) !=3D XDRTokenPunctuation or bracket.value !=3D ")= ": + if type(bracket) is not XDRTokenPunctuation or bracket.value !=3D = ")": raise Exception("Expected ')', but got %s" % bracket) =20 bracket =3D self.lexer.next() - if type(bracket) !=3D XDRTokenPunctuation or bracket.value !=3D "{= ": + if type(bracket) is not XDRTokenPunctuation or bracket.value !=3D = "{": raise Exception("Expected '{', but got %s" % bracket) =20 default =3D None cases =3D [] while True: ident =3D self.lexer.next() - if type(ident) !=3D XDRTokenIdentifier or ident.value not in [ + if type(ident) is not XDRTokenIdentifier or ident.value not in= [ "default", "case", ]: @@ -463,7 +463,7 @@ class XDRParser: raise Exception("Expected constant, but got %s" % valu= e) =20 sep =3D self.lexer.next() - if type(sep) !=3D XDRTokenPunctuation or sep.value !=3D ":= ": + if type(sep) is not XDRTokenPunctuation or sep.value !=3D = ":": raise Exception("Expected ':', but got %s" % value) =20 decl =3D self.parse_declaration() @@ -475,17 +475,17 @@ class XDRParser: raise Exception("Duplicate 'default' clause") =20 sep =3D self.lexer.next() - if type(sep) !=3D XDRTokenPunctuation or sep.value !=3D ":= ": + if type(sep) is not XDRTokenPunctuation or sep.value !=3D = ":": raise Exception("Expected ':', but got %s" % value) =20 default =3D self.parse_declaration() =20 separator =3D self.lexer.next() - if type(separator) !=3D XDRTokenPunctuation and separator.valu= e !=3D ";": + if type(separator) is not XDRTokenPunctuation and separator.va= lue !=3D ";": raise Exception("Expected ';', but got %s" % bracket) =20 end =3D self.lexer.peek() - if type(end) =3D=3D XDRTokenPunctuation and end.value =3D=3D "= }": + if type(end) is XDRTokenPunctuation and end.value =3D=3D "}": break =20 # discard the '}' we peeked at to end the loop --=20 2.41.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org