Skip to content

Commit 37fc3be

Browse files
committed
fixes #593
1 parent 6055877 commit 37fc3be

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

fastcore/_modidx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@
201201
'fastcore.basics.uniqueify': ('basics.html#uniqueify', 'fastcore/basics.py'),
202202
'fastcore.basics.using_attr': ('basics.html#using_attr', 'fastcore/basics.py'),
203203
'fastcore.basics.val2idx': ('basics.html#val2idx', 'fastcore/basics.py'),
204+
'fastcore.basics.ver2tuple': ('basics.html#ver2tuple', 'fastcore/basics.py'),
204205
'fastcore.basics.with_cast': ('basics.html#with_cast', 'fastcore/basics.py'),
205206
'fastcore.basics.wrap_class': ('basics.html#wrap_class', 'fastcore/basics.py'),
206207
'fastcore.basics.zip_cycle': ('basics.html#zip_cycle', 'fastcore/basics.py')},

fastcore/basics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# %% auto 0
44
__all__ = ['defaults', 'null', 'num_methods', 'rnum_methods', 'inum_methods', 'arg0', 'arg1', 'arg2', 'arg3', 'arg4', 'Self',
55
'ifnone', 'maybe_attr', 'basic_repr', 'is_array', 'listify', 'tuplify', 'true', 'NullType', 'tonull',
6-
'get_class', 'mk_class', 'wrap_class', 'ignore_exceptions', 'exec_local', 'risinstance', 'Inf', 'in_',
7-
'ret_true', 'ret_false', 'stop', 'gen', 'chunked', 'otherwise', 'custom_dir', 'AttrDict', 'NS',
6+
'get_class', 'mk_class', 'wrap_class', 'ignore_exceptions', 'exec_local', 'risinstance', 'ver2tuple', 'Inf',
7+
'in_', 'ret_true', 'ret_false', 'stop', 'gen', 'chunked', 'otherwise', 'custom_dir', 'AttrDict', 'NS',
88
'get_annotations_ex', 'eval_type', 'type_hints', 'annotations', 'anno_ret', 'signature_ex', 'union2tuple',
99
'argnames', 'with_cast', 'store_attr', 'attrdict', 'properties', 'camel2words', 'camel2snake', 'snake2camel',
1010
'class2attr', 'getcallable', 'getattrs', 'hasattrs', 'setattrs', 'try_attrs', 'GetAttrBase', 'GetAttr',
@@ -163,6 +163,10 @@ def risinstance(types, obj=None):
163163
return any(t.__name__ in types for t in type(obj).__mro__)
164164
return isinstance(obj, types)
165165

166+
# %% ../nbs/01_basics.ipynb
167+
def ver2tuple(v:str)->tuple:
168+
return tuple(int(o or 0) for o in re.search(r'(\d+)(?:\.(\d+))?(?:\.(\d+))?', v).groups())
169+
166170
# %% ../nbs/01_basics.ipynb
167171
class _InfMeta(type):
168172
@property

nbs/01_basics.ipynb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,29 @@
891891
"assert not risinstance('int', 'a')"
892892
]
893893
},
894+
{
895+
"cell_type": "code",
896+
"execution_count": null,
897+
"metadata": {},
898+
"outputs": [],
899+
"source": [
900+
"#| export\n",
901+
"def ver2tuple(v:str)->tuple:\n",
902+
" return tuple(int(o or 0) for o in re.search(r'(\\d+)(?:\\.(\\d+))?(?:\\.(\\d+))?', v).groups())"
903+
]
904+
},
905+
{
906+
"cell_type": "code",
907+
"execution_count": null,
908+
"metadata": {},
909+
"outputs": [],
910+
"source": [
911+
"test_eq(ver2tuple('3.8.1'), (3,8,1))\n",
912+
"test_eq(ver2tuple('3.1'), (3,1,0))\n",
913+
"test_eq(ver2tuple('3.'), (3,0,0))\n",
914+
"test_eq(ver2tuple('3'), (3,0,0))"
915+
]
916+
},
894917
{
895918
"cell_type": "markdown",
896919
"metadata": {},

0 commit comments

Comments
 (0)