Skip to content

pyrefly report: (re-)exports #3104

@jorenham

Description

@jorenham

Typestats only considers public symbols for the stats. The way it determines whether a symbol is public, is by following all (re-)exports (__all__, or all non-private names if there's no __all__, and import a as a), and marking those as public.

For example:

# pkg/a.py
from ._b import _f
__all__ = ("_f",)

def g(): ...

Here, pkg._b._f is marked as public, but g is only marked public iff. it's publically re-exported in another public module.
With "public module" I mean one that's explicitly exported as public module, is called __init__ or __main__ and lives within a public package, or is a submodule of a public package with and has a non-private name (i.e. the module name does not start with _).

pyrefly report currently reports all symbols, and does not distinguish between public/private. AFAIK that's perfectly fine.
However, for typestats, I'll have to detemrine when it's public. And for that I need to know the export graph, which I can't determine by looking at the pyrefly report at the moment. To be precise, for each module, I need to know which symbols it exports. I can figure that out if I know:

  • the statically evaluated __all__ names (so after "flattening" operations like += and .append)
  • the import {name} as {name} implicit re-exports (also if there's an __all__)

If there is no __all__, then I can piece together the public names by looking at the namesof the module in the report json.
Note that I need to be able to distinguish between a module with an __all__ = () and a module that has no __all__.

Would that be possible to include in pyrefly report?

It's not part of typestats report, but that's because those reports already only show the public symbols.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions