typedparser 0.31.3__tar.gz → 0.32.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typedparser
3
- Version: 0.31.3
3
+ Version: 0.32.2
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
@@ -1,11 +1,11 @@
1
- from ._typedattr import definenumpy, attrs_from_dict, NamedTupleMixin
1
+ from ._typedattr import NamedTupleMixin, attrs_from_dict, definenumpy
2
2
  from ._typedparser import (
3
- add_argument,
3
+ TaskSplitterArgs,
4
4
  TypedParser,
5
5
  VerboseQuietArgs,
6
- TaskSplitterArgs,
7
- split_list_given_task_splitter_args,
6
+ add_argument,
8
7
  split_list_for_processing,
8
+ split_list_given_task_splitter_args,
9
9
  )
10
10
  from .custom_format import CustomArgparseFmt
11
11
  from .objects import get_attr_names
@@ -25,4 +25,4 @@ __all__ = [
25
25
  ]
26
26
 
27
27
 
28
- __version__ = "0.31.3"
28
+ __version__ = "0.32.2"
@@ -5,33 +5,33 @@ from functools import partial
5
5
  from inspect import isclass
6
6
  from pathlib import Path
7
7
  from typing import (
8
- Tuple,
9
- Union,
10
- Dict,
11
8
  AbstractSet,
12
- Iterable,
13
- Mapping,
14
- Collection,
15
- Type,
16
9
  Any,
10
+ Callable,
11
+ Collection,
12
+ Dict,
13
+ Iterable,
17
14
  List,
15
+ Mapping,
18
16
  Optional,
17
+ Tuple,
18
+ Type,
19
+ Union,
19
20
  get_type_hints,
20
- Callable,
21
21
  )
22
22
 
23
23
  import attrs
24
- from attr import has, AttrsInstance
25
- from attrs import define, fields_dict, fields, Attribute
24
+ from attr import AttrsInstance, has
25
+ from attrs import Attribute, define, fields, fields_dict
26
26
 
27
- from .objects import check_object_equality, RecursorInterface, StrictRecursor, AttrsClass
27
+ from .objects import AttrsClass, RecursorInterface, StrictRecursor, check_object_equality
28
28
 
29
29
  try:
30
30
  from types import UnionType
31
31
  except ImportError:
32
32
  UnionType = None
33
33
 
34
- from typing import get_origin, get_args
34
+ from typing import get_args, get_origin
35
35
 
36
36
  # default conversions allow to convert instead of raising errors in case of matching types
37
37
  # e.g. create Path given str, or create float given int
@@ -1,13 +1,14 @@
1
1
  # from __future__ import annotations # do not use here, it breaks everything
2
2
 
3
3
  import argparse
4
- from attr import field, define
5
4
  from dataclasses import dataclass
6
- from typing import Optional, Type, Any
5
+ from typing import Any, Optional, Type
6
+
7
+ from attr import define, field
7
8
 
8
9
  from ._typedattr import AttrsClass
9
10
  from .custom_format import CustomArgparseFmt
10
- from .funcs import parse_typed_args, add_typed_args
11
+ from .funcs import add_typed_args, parse_typed_args
11
12
 
12
13
 
13
14
  @dataclass
@@ -2,7 +2,7 @@ import argparse
2
2
  from typing import Any, Dict
3
3
 
4
4
  from attr import AttrsInstance
5
- from attrs import has, fields_dict
5
+ from attrs import fields_dict, has
6
6
 
7
7
  from ._typedattr import attrs_from_dict
8
8
  from .objects import get_attr_names
@@ -7,12 +7,12 @@ from __future__ import annotations
7
7
  import inspect
8
8
  from abc import ABCMeta, abstractmethod
9
9
  from collections import defaultdict
10
- from collections.abc import Mapping, Iterable
10
+ from collections.abc import Iterable, Mapping
11
11
  from copy import deepcopy
12
12
  from functools import partial
13
- from typing import Type, List, Any, Callable
13
+ from typing import Any, Callable, List, Type
14
14
 
15
- from attr import has, AttrsInstance
15
+ from attr import AttrsInstance, has
16
16
  from attrs import fields
17
17
 
18
18
  AttrsClass = Type[AttrsInstance]
@@ -105,6 +105,7 @@ def modify_nested_object(
105
105
  modifier_fn: Callable,
106
106
  return_copy: bool = False,
107
107
  parser_class: Type[RecursorInterface] = StrictRecursor,
108
+ tuple_to_list: bool = False,
108
109
  ) -> Any:
109
110
  """
110
111
  Traverse a python object and apply a modifier function to all leaves.
@@ -116,6 +117,7 @@ def modify_nested_object(
116
117
  modifier_fn: modifier function to apply to all leaves
117
118
  return_copy: whether to copy the object before modifying it
118
119
  parser_class: which parser to use for iterable and mapping checks
120
+ tuple_to_list: if True, convert tuples to lists
119
121
 
120
122
  Examples:
121
123
  >>> e_dict = {'a': 1, 'b': {'c': 2, 'd': 3}}
@@ -126,16 +128,17 @@ def modify_nested_object(
126
128
 
127
129
  """
128
130
  parser = parser_class()
131
+ tuple_type = list if tuple_to_list else tuple
132
+ if return_copy:
133
+ d = deepcopy(d)
129
134
 
130
135
  def _modify_nested_object(d_inner: Any, depth: int = 0) -> Any:
131
136
  recursive_fn = partial(_modify_nested_object, depth=depth + 1)
132
- if return_copy:
133
- d_inner = deepcopy(d_inner)
134
137
  if parser.is_mapping_fn(d_inner):
135
138
  for k, v in d_inner.items():
136
139
  d_inner[k] = recursive_fn(v)
137
140
  elif isinstance(d_inner, tuple): # tuple does not support in-place modification
138
- d_inner = tuple(recursive_fn(v) for v in d_inner)
141
+ d_inner = tuple_type(recursive_fn(v) for v in d_inner)
139
142
  elif isinstance(d_inner, set): # set does not support in-place modification
140
143
  d_inner = set(recursive_fn(v) for v in d_inner)
141
144
  elif parser.is_iterable_fn(d_inner):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typedparser
3
- Version: 0.31.3
3
+ Version: 0.32.2
4
4
  Summary: Extension for python argparse with typehints and typechecks.
5
5
  Author: simon-ging
6
6
  License: Apache-2.0
File without changes
File without changes
File without changes