Skip to content

Commit eab6201

Browse files
eduralphclaude
authored andcommitted
lxml: use == not is when comparing os.name to a string literal
`lxml/lxmlGramplet.py:400` and `:758` both use: if os.name is 'nt': Python 3.12+ emits a SyntaxWarning on this idiom: SyntaxWarning: "is" with 'str' literal. Did you mean "=="? `is` checks object identity, not equality. The expression happens to evaluate as expected on CPython today only because short strings get interned during compilation, so `os.name` and the literal `'nt'` end up pointing at the same object — but that's an implementation detail of the interpreter and not guaranteed by the language. The right test is value equality. Two other call sites in the same file already use `==` for the same comparison (`lxmlGramplet.py:161` and `:181`), so this also brings the file's style into self-consistency. Verified via `python3 -W error::SyntaxWarning -m py_compile lxml/lxmlGramplet.py` (exits 0). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 42a4029 commit eab6201

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lxml/lxmlGramplet.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def read_xml(self, entry):
397397
os.system(f'xmllint')
398398

399399
try:
400-
if os.name is 'nt':
400+
if os.name == 'nt':
401401
os.system(f'xmllint --relaxng {rng} --noout {filename} {options}')
402402
LOG.debug('xmllint (relaxng) : %s' % filename)
403403
else:
@@ -755,7 +755,7 @@ def check_valid(self, filename):
755755

756756
dtd = os.path.join(USER_PLUGINS, 'lxml', 'grampsxml.dtd')
757757
try:
758-
if os.name is 'nt':
758+
if os.name == 'nt':
759759
os.system(f'xmllint --dtdvalid {dtd} {filename} {options}')
760760
else:
761761
os.system(f'xmllint --dtdvalid file://{dtd} {filename} {options}')

0 commit comments

Comments
 (0)