pylance-release
pylance-release copied to clipboard
Can't access certain members errors
Environment data
- Language Server version: 2024.4.1
- OS and version: MacOS 14.4.1 (23E224)
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.2 (virtual environment)
Code Snippet
Repro Steps
Access things like Qt.DisplayRole or Qt.EditRole. Code works fine, but pylance can't find the members.
Logs
I tried to reproduce this from your screenshot + requirements.txt, but was unsuccessful. Please provide a complete, minimal code sample (as text!) that reproduces the behavior you are seeing. The screenshot you provided above is missing imports, etc.
Here's one where it can't find database in cantools. can_send.txt
Here is the log for that. language_server.txt
where can one finds DbcMessage? could you provide full code including import statements and what packages needed to be installed?
that said, for your can_send.txt, some function returned Union so code requires some kind of cast/narrow/typeguard to specify which type code assumes.
import can
import time
import cantools
import cantools.database
from cantools.database.can.database import Database
from cantools.database.can.message import Message
bus = None
def send_message(msg: Message):
signal_values = {}
signal_db = {}
for signal in msg.signals:
signal_values[signal.name] = signal.minimum
signal_db[signal.name] = {'minimum':signal.minimum, 'maximum':signal.maximum}
while True:
data = msg.encode(signal_values)
message = can.Message(arbitration_id=msg.frame_id, data=data, is_extended_id=True)
assert(bus is not None)
bus.send(message)
for key in signal_values:
signal_values[key] += 1
if signal_values[key] > signal_db[key]['maximum']:
signal_values[key] = signal_db[key]['minimum']
time.sleep(1) # Send a message every second
if __name__ == '__main__':
bus = can.Bus(interface='udp_multicast', channel='239.0.0.1', port=10000, receive_own_messages=False)
db = cantools.database.load_file('../envgo/dbc/xerotech_battery_j1939.dbc')
assert(isinstance(db, Database))
for msg in db.messages:
if 'VCU' not in msg.senders:
send_message(msg)
break
This issue has been closed automatically because it needs more information and has not had recent activity. If the issue still persists, please reopen with the information requested. Thanks.
Environment data
- Language Server version: 2024.6.1 (pyright version 1.1.364, commit 0618acc5)
- OS and version: Windows 11 23H2
- Python version (& distribution if applicable, e.g. Anaconda): 3.12.4
Code Snippet
from PySide6.QtCore import Qt
print(type(Qt.DisplayRole))
print(type(Qt.ItemDataRole.DisplayRole))
Repro Steps
- Try to use an enum contained in PySide6.QtCore.Qt
Expected behavior
Qt.DisplayRole should autocomplete and not show an error in PyLance
Actual behavior
Pylance can't find Qt.DisplayRole, and throws the error below. The code runs and works as expected.
Cannot access attribute "DisplayRole" for class "type[Qt]"
Attribute "DisplayRole" is unknown Pylance[reportAttributeAccessIssue](https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportAttributeAccessIssue)
Logs
Thanks for the additional info @fezboy, I created a new issue: https://github.com/microsoft/pylance-release/issues/6109
I believe the issue with your example is that Qt.DisplayRole is not in the stub that way so QtCore must be moving it up one level at runtime (it's dynamic behavior and not supported by Pylance).