Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Implement support for uuid.UUID #443

Merged
merged 4 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ The following things are supported:
* IPv4Address, IPv6Address
* typing.Any
* typing.NewType
* uuid.UUID

Unions
------
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
typedload (2.28-1) UNRELEASED; urgency=low

* New upstream release

-- Salvo 'LtWorf' Tomaselli <[email protected]> Tue, 23 Apr 2024 14:53:56 +0200

typedload (2.27-1) unstable; urgency=low

* New upstream release
Expand Down
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2.28
====
* Add support for uuid.UUID

2.27
====
* Add support for re.Patterns
Expand Down
4 changes: 4 additions & 0 deletions docs/supported_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ Loads a string as a `Path`; when dumping it goes back to being a string.
* `ipaddress.IPv4Interface`
* `ipaddress.IPv6Interface`

### uuid.UUID

* `uuid.UUID`

```python
In : typedload.load('10.1.1.3', IPv4Address)
Out: IPv4Address('10.1.1.3')
Expand Down
4 changes: 4 additions & 0 deletions tests/test_datadumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import re
from typing import Dict, List, NamedTuple, Optional, Set, Tuple, Union
import unittest
from uuid import UUID

from typedload import datadumper, dump, load

Expand Down Expand Up @@ -159,6 +160,9 @@ def test_ipaddress(self):
assert dump(IPv6Network('fe80::/64')) == 'fe80::/64'
assert dump(IPv6Interface('fe80::123/64')) == 'fe80::123/64'

def test_uuid(self):
assert dump(UUID('631b09cb-016e-11ef-97ce-000000000001')) == '631b09cb-016e-11ef-97ce-000000000001'

def test_pattern(self):
assert dump(re.compile(r'[bc](at|ot)\d+')) == r'[bc](at|ot)\d+'
assert dump(re.compile(br'[bc](at|ot)\d+')) == br'[bc](at|ot)\d+'
9 changes: 9 additions & 0 deletions tests/test_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import typing
from typing import Dict, List, NamedTuple, Optional, Set, Tuple, Union, Any, NewType, FrozenSet
import unittest
from uuid import UUID

from typedload import dataloader, load, exceptions

Expand Down Expand Up @@ -522,6 +523,14 @@ def test_pattern(self):
with self.assertRaises(exceptions.TypedloadTypeError) as e:
assert loader.load(None, typing.Pattern)

def test_uuid(self):
loader = dataloader.Loader()
assert loader.load('631b09cb-016e-11ef-97ce-000000000001', UUID) == UUID('631b09cb-016e-11ef-97ce-000000000001')

# Invalid UUID
with self.assertRaises(ValueError):
loader.load('631b09cb-016e-11ef-97ce-00000000000', UUID)

def test_ipaddress(self):
loader = dataloader.Loader()
assert loader.load('10.10.10.1', IPv4Address) == IPv4Address('10.10.10.1')
Expand Down
2 changes: 2 additions & 0 deletions typedload/datadumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import pathlib
import re
from typing import *
import uuid

from .exceptions import TypedloadValueError
from .typechecks import is_attrs, NONETYPE
Expand Down Expand Up @@ -135,6 +136,7 @@ def __init__(self, **kwargs) -> None:
ipaddress.IPv6Network,
ipaddress.IPv4Interface,
ipaddress.IPv6Interface,
uuid.UUID,
}

self.handlers = [
Expand Down
4 changes: 3 additions & 1 deletion typedload/dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from pathlib import Path
import re
from typing import *
import uuid

from .exceptions import *
from .typechecks import *
Expand Down Expand Up @@ -198,7 +199,8 @@ def __init__(self, **kwargs) -> None:
ipaddress.IPv4Network,
ipaddress.IPv6Network,
ipaddress.IPv4Interface,
ipaddress.IPv6Interface
ipaddress.IPv6Interface,
uuid.UUID,
}

# Bah
Expand Down
Loading