Package: typeshed-client
This project provides a way to retrieve information fromtypeshedand fromPEP 561stub packages.Example use cases:Find the path to the stub file for a particular module.Find the names defined in a stub.Find the AST node that defines a particular name in a stub.Projects for whichtypeshed_clientcould be useful include:Static analyzers that want to access typeshed annotations.Tools that check stubs for correctness.Tools that use typeshed for runtime introspection.Installationtypeshed_clientworks on all supported versions of Python. To install it, runpython3-mpip install typeshed_client.Finding stubsThetypeshed_client.findermodule provides functions for finding stub files
given a module name.Functions provided:get_search_context(*,typeshed: Optional[Path] = None, search_path: Optional[Sequence[Path]] = None, python_executable: Optional[str] = None, version: Optional[PythonVersion] = None, platform: str = sys.platform)->SearchContext:
Returns aSearchContexttypeshed_client.get_stub_file(module_name: str, *, search_context: Optional[SearchContext] = None)->Optional[Path]: Returns
the path to a module’s stub in typeshed. For example,get_stub_file('typing',search_context=get_search_context(version=(2,7)))may returnPath('/path/to/typeshed/stdlib/@python2/typing.pyi'). If there is no stub for the
module, returns None.typeshed_client.get_stub_asthas the same interface, but returns an AST
object (parsed using the standard libraryastmodule).Collecting names from stubstypeshed_client.parsercollects the names defined in a stub. It provides:typeshed_client.get_stub_names(module_name: str, *, search_context: Optional[SearchContext] = None)->Optional[NameDict]collects the names
defined in a module, using the given Python version and platform. It
returns aNameDict, a dictionary mapping object names defined in the module
toNameInforecords.typeshed_client.NameInfois a namedtuple defined as:classNameInfo(NamedTuple):name:stris_exported:boolast:Union[ast3.AST,ImportedName,OverloadedName]child_nodes:Optional[NameDict]=Nonenameis the object’s name.is_exportedindicates whether the name is a
part of the stub’s public interface.astis the AST node defining the name,
or a different structure if the name is imported from another module or is
overloaded. For classes,child_nodesis a dictionary containing the names
defined within the class.Resolving names to their definitionsThe third component of this package,typeshed_client.resolver, maps names to
their definitions, even if those names are defined in other stubs.To use the resolver, you need to instantiate thetypeshed_client.Resolverclass. For example, given aresolver = typeshed_client.Resolver(), you can
callresolver.get_fully_qualified_name('collections.Set')to retrieve theNameInfocontaining the AST node definingcollections.Setin typeshed.ChangelogVersion 2.5.1 (February 25, 2024)Fix packaging metadata that still incorrectly declared support for Python 3.7Version 2.5.0 (February 25, 2024)Update bundled typeshedDrop support for Python 3.7typeshed_client.finder.get_search_path()is now deprecated, as it is no longer usefulVersion 2.4.0 (September 29, 2023)Update bundled typeshedDeclare support for Python 3.12Version 2.3.0 (April 30, 2023)Update bundled typeshedSupport__all__.appendand__all__.extendVersion 2.2.0 (January 24, 2023)Update bundled typeshedFix crash on stubs that useif MYPYFix incorrect handling ofimport *in stubsDrop support for Python 3.6 (thanks to Alex Waygood)Version 2.1.0 (November 5, 2022)Update bundled typeshedDeclare support for Python 3.11Addtypeshed_client.resolver.Module.get_dunder_allto get the contents of__all__Add support for__all__ +=syntaxType check the code using mypy (thanks to Nicolas)Version 2.0.5 (April 17, 2022)Update bundled typeshedVersion 2.0.4 (March 10, 2022)Update bundled typeshedVersion 2.0.3 (February 2, 2022)Update bundled typeshedVersion 2.0.2 (January 28, 2022)Update bundled typeshedVersion 2.0.1 (January 14, 2022)Update bundled typeshedVersion 2.0.0 (December 22, 2021)Breaking change: Useastinstead oftyped_astfor parsingVersion 1.2.3 (December 12, 2021)Update bundled typeshedRemove noisy warning if a name is imported multiple timesFixget_all_stub_files()in Python 3 for modules that also exist in Python 2Version 1.2.2 (December 9, 2021)Further fix relative import resolutionVersion 1.2.1 (December 9, 2021)Fix bug with resolution of relative importsUpdate bundled typeshedVersion 1.2.0 (December 6, 2021)Support overloaded methodsUpdate bundled typeshedVersion 1.1.4 (December 6, 2021)Updated bundled typeshedVersion 1.1.3 (November 14, 2021)Update bundled typeshedDeclare support for Python 3.10Fix undeclared dependency onmypy_extensionsVersion 1.1.2 (November 5, 2021)Update bundled typeshedVersion 1.1.1 (July 31, 2021)Update bundled typeshedImprove error message when encountering a duplicate nameVersion 1.1.0 (June 24, 2021)Update bundled typeshedHandle missing@python2directoryAllow comments in VERSIONS fileVersion 1.0.2 (May 5, 2021)Handle version ranges in typeshed VERSIONS fileUpdate bundled typeshedVersion 1.0.1 (April 24, 2021)Update bundled typeshedVersion 1.0.0 (April 11, 2021)Improve docstringsVersion 1.0.0rc1 (April 11, 2021)Support new typeshed layoutSupport PEP 561 packagesBundle typeshed directly instead of relying on mypyVersion 0.4 (December 2, 2019)Performance improvementCode quality improvementsVersion 0.3 (November 23, 2019)Update location of typeshed for newer mypy versionsVersion 0.2 (May 25, 2017)Support using a custom typeshed directoryAddget_all_stub_files()Handlefrom module import *Bug fixesVersion 0.1 (May 4, 2017)Initial release