From 32548d7cd981e7dede903dfe45871076af705170 Mon Sep 17 00:00:00 2001 From: Matthias Bussonnier Date: Mon, 25 Dec 2023 12:20:13 +0100 Subject: [PATCH] Minor shuffle around and cleanup. This just makes #363 a bit easier to read. --- examples/numpy.toml | 62 +++++++++++++++++++++++---------------------- papyri/gen.py | 15 +---------- papyri/utils.py | 14 ++++++++++ 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/examples/numpy.toml b/examples/numpy.toml index 40935260..7cfe393b 100644 --- a/examples/numpy.toml +++ b/examples/numpy.toml @@ -3,39 +3,41 @@ module = 'numpy' exclude = [ -'numpy:tensordot', + 'numpy:tensordot', + # See https://github.com/jupyter/papyri/issues/361' + 'numpy.ma.core:MaskedArray.resize', ] execute_exclude_patterns = [ -'numpy._', -'numpy.testing._priv', -'numpy.errstate', -'numpy.seterr', -'numpy.bincount', -'numpy.core._multiarray_umath.bincount', -'numpy.core._multiarray_umath.datetime_as_string', -'numpy.core._multiarray_umath.normalize_axis_index', -'numpy.core._multiarray_umath.shares_memory', -'numpy.datetime_as_string', -'numpy.shares_memory', -'numpy.squeeze', -'numpy.average', -'numpy.ctypeslib', -'numpy.append', -'numpy.ma.core', -'numpy.core.umath_tests', -# try to create a pager that waits for input -'numpy.lookfor', -# write directly to stdout -'numpy.info', -# Misc -'numpy.distutils', -'numpy.char.multiply', -'numpy.polynomial.chebyshev.chebinterpolate', -'numpy.lib.npyio._read', -'numpy.polynomial._polybase:ABCPolyBase', -'numpy.distutils.misc_util:Configuration.__init__', -'numpy.ma.core:MaskedArray.resize', # First line of docstring is a directive; breaks parsing + 'numpy._', + 'numpy.testing._priv', + 'numpy.errstate', + 'numpy.seterr', + 'numpy.bincount', + 'numpy.core._multiarray_umath.bincount', + 'numpy.core._multiarray_umath.datetime_as_string', + 'numpy.core._multiarray_umath.normalize_axis_index', + 'numpy.core._multiarray_umath.shares_memory', + 'numpy.datetime_as_string', + 'numpy.shares_memory', + 'numpy.squeeze', + 'numpy.average', + 'numpy.ctypeslib', + 'numpy.append', + 'numpy.ma.core', + 'numpy.core.umath_tests', + # try to create a pager that waits for input + 'numpy.lookfor', + # write directly to stdout + 'numpy.info', + # Misc + 'numpy.distutils', + 'numpy.char.multiply', + 'numpy.polynomial.chebyshev.chebinterpolate', + 'numpy.lib.npyio._read', + 'numpy.polynomial._polybase:ABCPolyBase', + 'numpy.distutils.misc_util:Configuration.__init__', + 'numpy.ma.core:MaskedArray.resize', # First line of docstring is a directive; breaks parsing ] submodules = [ diff --git a/papyri/gen.py b/papyri/gen.py index cbbc95ba..e55c98a2 100644 --- a/papyri/gen.py +++ b/papyri/gen.py @@ -12,7 +12,6 @@ import dataclasses import datetime -import importlib import inspect import json import logging @@ -80,6 +79,7 @@ full_qual, pos_to_nl, progress, + obj_from_qualname, ) from .vref import NumpyDocString @@ -189,19 +189,6 @@ def _jedi_set_cache(text, value): _cache.write_text(json.dumps(value)) -def obj_from_qualname(name): - mod_name, sep, objs = name.partition(":") - module = importlib.import_module(mod_name) - if not sep: - return module - else: - obj = module - parts = objs.split(".") - for p in parts: - obj = getattr(obj, p) - return obj - - def parse_script( script: str, ns: Dict, prev, config, *, where=None ) -> Optional[List[Tuple[str, Optional[str]]]]: diff --git a/papyri/utils.py b/papyri/utils.py index 35280da4..19dc4391 100644 --- a/papyri/utils.py +++ b/papyri/utils.py @@ -2,6 +2,7 @@ import time import typing +import importlib from datetime import timedelta from textwrap import dedent from typing import Tuple, NewType @@ -226,3 +227,16 @@ def pos_to_nl(script: str, pos: int) -> Tuple[int, int]: else: return ln, rest raise RuntimeError + + +def obj_from_qualname(name): + mod_name, sep, objs = name.partition(":") + module = importlib.import_module(mod_name) + if not sep: + return module + else: + obj = module + parts = objs.split(".") + for p in parts: + obj = getattr(obj, p) + return obj