Skip to content

Public API symbols not re-exported from package __init__.py files, causing reportPrivateImportUsage errors in Pylance/Pyright #225

Description

@adamarnesen

Package version: nisystemlink-clients 2.32.1

Description

Every public class and model in the nisystemlink.clients.* packages triggers a reportPrivateImportUsage diagnostic in Pylance/Pyright, even though the symbols are accessible at runtime. For example:

"QuerySystemsRequest" is not exported from module "nisystemlink.clients.systems.models"
  Import from "nisystemlink.clients.systems.models._query_systems_request" instead

"SystemsClient" is not exported from module "nisystemlink.clients.systems"
  Import from "nisystemlink.clients.systems._systems_client" instead

"HttpConfiguration" is not exported from module "nisystemlink.clients.core"
  Import from "nisystemlink.clients.core._http_configuration" instead

This affects all sub-packages: assetmanagement, core, product, systems, work_item, etc.

Root cause

The __init__.py files in each sub-package import from private _module files but do not re-export the symbols explicitly. PEP 484 and the Pylance/Pyright type checkers require that symbols be either defined directly in __init__.py or explicitly re-exported (e.g. from ._systems_client import SystemsClient as SystemsClient, or via __all__). Without this, type checkers treat the symbols as private even though they are publicly accessible at runtime.

Expected behavior

from nisystemlink.clients.systems import SystemsClient            # no warning
from nisystemlink.clients.systems.models import QuerySystemsRequest   # no warning

Workaround

Add reportPrivateImportUsage = "none" to pyproject.toml under [tool.pyright], which suppresses the warning project-wide at the cost of losing legitimate private-import detection elsewhere.

Fix

In each sub-package __init__.py, use explicit re-export syntax for all public symbols:

# Before
from ._systems_client import SystemsClient

# After
from ._systems_client import SystemsClient as SystemsClient  # re-exported

Or add an __all__ list. Either approach tells Pylance/Pyright that the symbol is intentionally public.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions