Skip to content

Commit

Permalink
Fix sphinx including unexpected items in public API.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa committed Aug 22, 2023
1 parent 06e1b9b commit 5798fe3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
13 changes: 9 additions & 4 deletions jsonargparse/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
import os
import pathlib
import re
from enum import Enum
from typing import Any, Callable, Dict, List, Optional, Pattern, Tuple, Type, Union

from ._common import is_final_class, is_subclass
from ._common import is_final_class
from ._optionals import final, pydantic_support
from ._util import Path, get_import_path, get_private_kwargs, import_object

Expand Down Expand Up @@ -444,11 +443,17 @@ def range_deserializer(value):

pydantic_types: Tuple[type, ...] = tuple()
if pydantic_support:
from enum import Enum as _Enum

import pydantic

from ._common import is_subclass as _is_subclass

for module in [pydantic.types, pydantic.networks]:
pydantic_types += tuple(
v for k, v in vars(module).items() if inspect.isclass(v) and k in module.__all__ and not issubclass(v, Enum)
v
for k, v in vars(module).items()
if inspect.isclass(v) and k in module.__all__ and not issubclass(v, _Enum)
)


Expand All @@ -475,7 +480,7 @@ def pydantic_serializer(type_class):


def is_pydantic_type(type_class):
return pydantic_support and is_subclass(type_class, pydantic_types)
return pydantic_support and _is_subclass(type_class, pydantic_types)


def register_pydantic_type(type_class):
Expand Down
15 changes: 15 additions & 0 deletions jsonargparse_tests/test_typing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import inspect
import pickle
import random
import uuid
Expand Down Expand Up @@ -29,6 +30,20 @@
)
from jsonargparse_tests.conftest import get_parser_help


def test_public_api():
import jsonargparse.typing

names = {
n
for n, v in vars(jsonargparse.typing).items()
if n[0] != "_"
and getattr(v, "__module__", "").split(".")[0] not in {"jsonargparse", "typing"}
and (inspect.isclass(v) or inspect.isfunction(v))
}
assert set() == names - set(jsonargparse.typing.__all__)


# restricted number tests


Expand Down

0 comments on commit 5798fe3

Please sign in to comment.