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.
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__, andimport a as a), and marking those as public.For example:
Here,
pkg._b._fis marked as public, butgis 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 reportcurrently 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 reportat the moment. To be precise, for each module, I need to know which symbols it exports. I can figure that out if I know:__all__names (so after "flattening" operations like+=and.append)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 thenamesof 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.