From b7b9813e52f7488026d102ad180e246bcd9d6de9 Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Fri, 20 Dec 2024 09:15:08 -0800 Subject: [PATCH 1/4] Fix python 3.13 deprecation of typing.re In python 3.13, `typing.re` was removed (deprecated since Python 3.8). See https://github.com/python/cpython/issues/92871 This pr refactors to support python 3.13 which currently throws ```python ImportError: cannot import name 're' from 'typing' ``` --- linkml_runtime/utils/slot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/linkml_runtime/utils/slot.py b/linkml_runtime/utils/slot.py index bdc0b309..f8d44d23 100644 --- a/linkml_runtime/utils/slot.py +++ b/linkml_runtime/utils/slot.py @@ -1,5 +1,6 @@ from dataclasses import dataclass -from typing import Type, List, Optional, Any, re +import re +from typing import Type, List, Optional, Any from rdflib import URIRef From f51d51e7963c148e63564055fe62a0894d1b6aeb Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Fri, 20 Dec 2024 12:14:08 -0800 Subject: [PATCH 2/4] rf: support re typing for python 3.9 - 3.13+ --- linkml_runtime/utils/slot.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/linkml_runtime/utils/slot.py b/linkml_runtime/utils/slot.py index f8d44d23..460444ae 100644 --- a/linkml_runtime/utils/slot.py +++ b/linkml_runtime/utils/slot.py @@ -1,9 +1,12 @@ from dataclasses import dataclass -import re -from typing import Type, List, Optional, Any - from rdflib import URIRef - +from typing import Type, List, Optional, Any +try: + # Python 3.8, 3.9, 3.10 + from typing import re +except: + # Python 3.11+ + import re @dataclass class Slot: From c28679aca552e748ad5b449e09c306b64213426b Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Fri, 20 Dec 2024 12:19:59 -0800 Subject: [PATCH 3/4] rf: simpler approach using specific re classes --- linkml_runtime/utils/slot.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/linkml_runtime/utils/slot.py b/linkml_runtime/utils/slot.py index 460444ae..c83fe393 100644 --- a/linkml_runtime/utils/slot.py +++ b/linkml_runtime/utils/slot.py @@ -1,12 +1,7 @@ from dataclasses import dataclass from rdflib import URIRef +from re import Pattern, Match from typing import Type, List, Optional, Any -try: - # Python 3.8, 3.9, 3.10 - from typing import re -except: - # Python 3.11+ - import re @dataclass class Slot: From 0b60c452148f06201964895571af0492a1005dce Mon Sep 17 00:00:00 2001 From: Nolan Nichols Date: Fri, 20 Dec 2024 14:23:32 -0800 Subject: [PATCH 4/4] add: Pattern and Match to type def --- linkml_runtime/utils/slot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linkml_runtime/utils/slot.py b/linkml_runtime/utils/slot.py index c83fe393..b2b991ab 100644 --- a/linkml_runtime/utils/slot.py +++ b/linkml_runtime/utils/slot.py @@ -1,7 +1,7 @@ from dataclasses import dataclass from rdflib import URIRef from re import Pattern, Match -from typing import Type, List, Optional, Any +from typing import Type, List, Optional, Any, Union @dataclass class Slot: @@ -14,4 +14,4 @@ class Slot: domain: Optional[Type] range: Any mappings: Optional[List[URIRef]] = None - pattern: Optional[re] = None + pattern: Optional[Union[Pattern, Match]] = None