pylint
pylint copied to clipboard
Wave_write object from wave library confused with Wave_read object #603
Bug description
"""Demonstrate pylint bug with wave module."""
import wave
import struct
if __name__ == "__main__":
# Create a 2-second blank WAV file
with wave.open("blank_audio.wav", "wb") as wav_file:
# Set parameters for a mono 16-bit 44.1kHz WAV file
wav_file.setnchannels(1) # Mono
wav_file.setsampwidth(2) # 16-bit
wav_file.setframerate(44100) # 44.1kHz
wav_file.setnframes(88200) # 2 seconds * 44100 Hz
wav_file.setcomptype("NONE", "not compressed")
# Create silent frame (0 for 16-bit)
silent_frame = struct.pack("<h", 0)
# Write all frames at once
wav_file.writeframes(silent_frame * 88200)
print("Successfully created blank_audio.wav")
Configuration
Command used
pylint test_bug.py
Pylint output
************* Module test_bug
test_bug.py:10:8: E1101: Instance of 'Wave_read' has no 'setnchannels' member; maybe 'getnchannels'? (no-member)
test_bug.py:11:8: E1101: Instance of 'Wave_read' has no 'setsampwidth' member; maybe 'getsampwidth'? (no-member)
test_bug.py:12:8: E1101: Instance of 'Wave_read' has no 'setframerate' member; maybe 'getframerate'? (no-member)
test_bug.py:13:8: E1101: Instance of 'Wave_read' has no 'setnframes' member; maybe 'getnframes'? (no-member)
test_bug.py:14:8: E1101: Instance of 'Wave_read' has no 'setcomptype' member; maybe 'getcomptype'? (no-member)
test_bug.py:20:8: E1101: Instance of 'Wave_read' has no 'writeframes' member (no-member)
------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)
Expected behavior
pylint should see that the wav_file object is a Wave_write and not a Wave_read object.
As specified in https://docs.python.org/3/library/wave.html, with the open call:
A mode of 'rb' returns a Wave_read object, while a mode of 'wb' returns a Wave_write object. If mode is omitted and a file-like object is passed as file, file.mode is used as the default value for mode.
Pylint version
pylint 3.3.6
astroid 3.3.9
Python 3.12.9 (main, Mar 17 2025, 21:36:21) [Clang 20.1.0 ]
OS / Environment
macOS 15.3.2 (24D81) Codename: Sequoia
Additional dependencies