Skip to content

Commit 51c326a

Browse files
d-w-mooretrel
authored andcommitted
[#372] eliminate SyntaxWarning ("is" operator being used with a literal)
In the no-argument form of the call to function irods.message.ET (which the client executes quite often), the comparison against a literal 0 was only being used to test whether an call parameter was allowed to default; but the first-ever such call (just after the production of the .pyc containing the Python3 byte-code) was then emitting the disconcerting SyntaxWarning. Here, we change the parameter's default value to an empty tuple and then use a == comparison instead to suppress the SyntaxWarning and, with that, better conform to Python3's expectations in terms of restricted uses of the 'is' operator.
1 parent 95b6f40 commit 51c326a

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

irods/message/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def XML_entities_active():
116116

117117
# ET() [no-args form] will just fetch the current thread's XML parser settings
118118

119-
def ET(xml_type = 0, server_version = None):
119+
def ET(xml_type = (), server_version = None):
120120
"""
121121
Return the module used to parse XML from iRODS protocol messages text.
122122
@@ -126,13 +126,15 @@ def ET(xml_type = 0, server_version = None):
126126
* QUASI_XML is custom parser designed to be more compatible with the use of
127127
non-printable characters in object names.
128128
* STANDARD_XML uses the standard module, xml.etree.ElementTree.
129+
* an empty tuple is the default argument for `xml_type', imparting the same
130+
semantics as for the argumentless form ET(), ie., short-circuit any parser change.
129131
130132
`server_version', if given, should be a list or tuple specifying the version of the connected iRODS server.
131133
132134
"""
133-
if xml_type is not 0:
134-
_thrlocal.xml_type = default_XML_parser() if xml_type in (None, XML_Parser_Type(0)) \
135-
else XML_Parser_Type(xml_type)
135+
if xml_type != ():
136+
_thrlocal.xml_type = (default_XML_parser() if xml_type in (None, XML_Parser_Type(0))
137+
else XML_Parser_Type(xml_type))
136138
if isinstance(server_version, _TUPLE_LIKE_TYPES):
137139
_thrlocal.irods_server_version = tuple(server_version) # A default server version for Quasi-XML parsing is set (from the environment) and
138140
return _XML_parsers[current_XML_parser()] # applies to all threads in which ET() has not been called to update the value.

0 commit comments

Comments
 (0)