pylance-release icon indicating copy to clipboard operation
pylance-release copied to clipboard

Can't access certain members errors

Open jmailloux opened this issue 1 year ago • 4 comments
trafficstars

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

Screenshot 2024-04-29 at 11 05 28 PM

Repro Steps

Access things like Qt.DisplayRole or Qt.EditRole. Code works fine, but pylance can't find the members.

Logs

pylance_issues.log

requirements.txt

jmailloux avatar Apr 30 '24 03:04 jmailloux

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.

debonte avatar Apr 30 '24 17:04 debonte

Here's one where it can't find database in cantools. can_send.txt

jmailloux avatar Apr 30 '24 21:04 jmailloux

Here is the log for that. language_server.txt

jmailloux avatar Apr 30 '24 21:04 jmailloux

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

heejaechang avatar May 01 '24 00:05 heejaechang

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.

github-actions[bot] avatar Jun 01 '24 11:06 github-actions[bot]

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))

requirements.txt

Repro Steps

  1. 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)

image

Logs

log.txt

fezboy avatar Jul 08 '24 22:07 fezboy

Thanks for the additional info @fezboy, I created a new issue: https://github.com/microsoft/pylance-release/issues/6109

rchiodo avatar Jul 08 '24 22:07 rchiodo

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).

rchiodo avatar Jul 08 '24 23:07 rchiodo