Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: omni-us/jsonargparse
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.10.0
Choose a base ref
...
head repository: omni-us/jsonargparse
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.10.1
Choose a head ref
  • 5 commits
  • 9 files changed
  • 1 contributor

Commits on Apr 21, 2021

  1. Copy the full SHA
    6842c7c View commit details

Commits on Apr 23, 2021

  1. - fail_untyped now adds untyped parameters as type Any and if no defa…

    …ult then default set to None.
    mauvilsa committed Apr 23, 2021
    Copy the full SHA
    2a46c70 View commit details

Commits on Apr 24, 2021

  1. Copy the full SHA
    e4bea70 View commit details
  2. Prepare for v3.10.1

    mauvilsa committed Apr 24, 2021
    Copy the full SHA
    d77ead2 View commit details
  3. Copy the full SHA
    6655e41 View commit details
Showing with 52 additions and 10 deletions.
  1. +1 −1 .bumpversion.cfg
  2. +1 −1 .sonarcloud.properties
  3. +14 −0 CHANGELOG.rst
  4. +1 −1 jsonargparse/__init__.py
  5. +8 −2 jsonargparse/signatures.py
  6. +5 −3 jsonargparse/typehints.py
  7. +11 −0 jsonargparse_tests/signatures_tests.py
  8. +10 −1 jsonargparse_tests/typehints_tests.py
  9. +1 −1 setup.cfg
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 3.10.0
current_version = 3.10.1
commit = True
tag = True
tag_name = v{new_version}
2 changes: 1 addition & 1 deletion .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sonar.sources=jsonargparse
sonar.projectVersion=3.10.0
sonar.projectVersion=3.10.1
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -10,6 +10,20 @@ only be introduced in major versions with advance notice in the **Deprecated**
section of releases.


v3.10.1 (2021-04-24)
--------------------

Changed
^^^^^^^
- fail_untyped now adds untyped parameters as type Any and if no default
then default set to None.

Fixed
^^^^^
- --*.help option being added for non-subclass types.
- Iterable and Sequence types not working for python>=3.7 #53.

v3.10.0 (2021-04-19)
--------------------

2 changes: 1 addition & 1 deletion jsonargparse/__init__.py
Original file line number Diff line number Diff line change
@@ -22,4 +22,4 @@
from .util import *


__version__ = '3.10.0'
__version__ = '3.10.1'
10 changes: 8 additions & 2 deletions jsonargparse/signatures.py
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import inspect
import re
from typing import Callable, Container, Optional, Type, Union
from typing import Any, Callable, Container, Optional, Type, Union

from .actions import _ActionConfigLoad, _ActionHelpClassPath
from .typehints import ActionTypeHint, is_optional
@@ -230,8 +230,12 @@ def update_has_args_kwargs(base, has_args=True, has_kwargs=True):
default = param.default
is_required = default == inspect._empty # type: ignore
skip_message = 'Skipping parameter "'+name+'" from "'+obj.__name__+'" because of: '
if not fail_untyped and annotation == inspect._empty: # type: ignore
annotation = Any
default = None if is_required else default
is_required = False
if kind in {kinds.VAR_POSITIONAL, kinds.VAR_KEYWORD} or \
(is_required and skip_first and num == 0) or \
(skip_first and num == 0) or \
(not is_required and name[0] == '_') or \
(annotation == inspect._empty and not is_required and default is None): # type: ignore
continue
@@ -274,6 +278,8 @@ def update_has_args_kwargs(base, has_args=True, has_kwargs=True):
opt_str = dest if is_required and as_positional else '--'+dest
if is_subclass_typehint:
group.add_argument('--'+dest+'.help', action=_ActionHelpClassPath(baseclass=annotation))
if opt_str in group._option_string_actions:
continue # temporal
group.add_argument(opt_str, **kwargs)
added_args.add(dest)
elif is_required and fail_untyped:
8 changes: 5 additions & 3 deletions jsonargparse/typehints.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
import re
import yaml
from argparse import Action
from collections.abc import Iterable as abcIterable
from collections.abc import Sequence as abcSequence
from enum import Enum
from typing import Any, Dict, Iterable, List, Sequence, Set, Tuple, Type, Union

@@ -40,7 +42,7 @@
Any,
Literal,
Union,
List, list, Iterable, Sequence,
List, list, Iterable, Sequence, abcIterable, abcSequence,
Tuple, tuple,
Set, set,
Dict, dict,
@@ -112,7 +114,7 @@ def is_supported_typehint(typehint, full=False):
def is_subclass_typehint(typehint):
if isinstance(typehint, Action):
typehint = getattr(typehint, '_typehint', None)
return inspect.isclass(typehint) and typehint not in leaf_types
return inspect.isclass(typehint) and typehint not in leaf_types.union(root_types)


@staticmethod
@@ -274,7 +276,7 @@ def adapt_typehints(val, typehint, serialize=False, instantiate_classes=False):
val = tuple(val) if typehint_origin in {Tuple, tuple} else set(val)

# List, Iterable or Sequence
elif typehint_origin in {List, list, Iterable, Sequence}:
elif typehint_origin in {List, list, Iterable, Sequence, abcIterable, abcSequence}:
if not isinstance(val, list):
raise ValueError('Expected a List but got "'+str(val)+'"')
if subtypehints is not None:
11 changes: 11 additions & 0 deletions jsonargparse_tests/signatures_tests.py
Original file line number Diff line number Diff line change
@@ -432,6 +432,17 @@ def func(a1: int = None):
self.assertIsNone(parser.parse_args(['--a1=null']).a1)


def test_fail_untyped_false(self):

def func(a1):
return a1

parser = ArgumentParser(error_handler=None)
parser.add_function_arguments(func, fail_untyped=False)

self.assertEqual(Namespace(a1=None), parser.parse_args([]))


@unittest.skipIf(not docstring_parser_support, 'docstring-parser package is required')
def test_docstring_parse_fail(self):

11 changes: 10 additions & 1 deletion jsonargparse_tests/typehints_tests.py
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
from calendar import Calendar
from datetime import datetime
from enum import Enum
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Union
from jsonargparse_tests.base import *
from jsonargparse.typehints import is_optional, Literal

@@ -70,6 +70,15 @@ def test_no_str_strip(self):
self.assertIsNone(parser.parse_args(['--op=null']).op)


def test_list(self):
for list_type in [Iterable, List, Sequence]:
with self.subTest(str(list_type)):
parser = ArgumentParser()
parser.add_argument('--list', type=list_type[int])
cfg = parser.parse_args(['--list=[1, 2]'])
self.assertEqual([1, 2], cfg.list)


def test_list_path(self):
parser = ArgumentParser()
parser.add_argument('--paths', type=List[Path_fc])
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ doc =

[metadata]
name = jsonargparse
version = 3.10.0
version = 3.10.1
description = Parsing of command line options, yaml/jsonnet config files and/or environment variables based on argparse.
long_description_content_type = text/x-rst
author = Mauricio Villegas