Skip to content

pyright reports using private imports and attribute access errors on example code #461

@davefiddes

Description

@davefiddes

I have been using pyright for type checking of my project using canopen in preference top mypy as it seems to be the default in VS Code. As part of upgrading to 2.3.0 I found it reporting canopen.Network() as a private symbol.

I have been able to distill a minimal example of the problem using the example code from the readme and the following environment:

virtualenv venv
. venv/bin/activate
pip install canopen pyright

Running pyright then yields a lot of errors:

$ pyright
/tmp/pytest/canopen-example.py
  /tmp/pytest/canopen-example.py:4:19 - error: "Network" is not exported from module "canopen" (reportPrivateImportUsage)
  /tmp/pytest/canopen-example.py:7:16 - error: "RemoteNode" is not exported from module "canopen" (reportPrivateImportUsage)
  /tmp/pytest/canopen-example.py:22:52 - error: Cannot access attribute "raw" for class "SdoArray"
    Attribute "raw" is unknown (reportAttributeAccessIssue)
  /tmp/pytest/canopen-example.py:22:52 - error: Cannot access attribute "raw" for class "SdoRecord"
    Attribute "raw" is unknown (reportAttributeAccessIssue)
  /tmp/pytest/canopen-example.py:23:13 - error: "__getitem__" method not defined on type "SdoVariable" (reportIndexIssue)
  /tmp/pytest/canopen-example.py:26:37 - error: Cannot assign to attribute "raw" for class "SdoArray"
    Attribute "raw" is unknown (reportAttributeAccessIssue)
  /tmp/pytest/canopen-example.py:26:37 - error: Cannot assign to attribute "raw" for class "SdoRecord"
    Attribute "raw" is unknown (reportAttributeAccessIssue)
  /tmp/pytest/canopen-example.py:51:45 - error: Cannot access attribute "raw" for class "PdoMap"
    Attribute "raw" is unknown (reportAttributeAccessIssue)
8 errors, 0 warnings, 0 informations 

It seems that https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#library-interface describes the rules for module imports.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions