Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add str concat for pydantic_core.Url #46

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions hsmodels/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pydantic_core import Url


def __add__(self, other):
return str(self) + other


def __radd__(self, other):
return other + str(self)
devincowan marked this conversation as resolved.
Show resolved Hide resolved


# monkey patch string concatentation until pydantic implements Url as an extension of str again
# https://github.com/pydantic/pydantic-core/pull/1126

Url.__add__ = __add__
Url.__radd__ = __radd__
2 changes: 1 addition & 1 deletion hsmodels/schemas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from enum import Enum

from pydantic import BaseModel
from pydantic_core import Url
from rdflib import Graph, Literal, URIRef

from hsmodels import Url
from hsmodels.namespaces import DC, HSTERMS, ORE, RDF, RDFS1
from hsmodels.schemas.aggregations import (
FileSetMetadata,
Expand Down
3 changes: 1 addition & 2 deletions hsmodels/schemas/rdf/validators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from pydantic_core import Url

from hsmodels import Url
from hsmodels.schemas.enums import CoverageType, DateType
from hsmodels.schemas.languages_iso import languages

Expand Down
2 changes: 1 addition & 1 deletion hsmodels/schemas/root_validators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic_core import Url
from rdflib import URIRef

from hsmodels import Url
from hsmodels.schemas.enums import CoverageType, DateType, ModelProgramFileType, RelationType, UserIdentifierType
from hsmodels.utils import to_coverage_dict

Expand Down
6 changes: 6 additions & 0 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,9 @@ def test_resource_metadata(res_md):
res_md.publisher.name == "Consortium of Universities for the Advancement of Hydrologic Science, Inc. (CUAHSI)"
)
assert str(res_md.publisher.url) == "https://www.cuahsi.org/"


def test_resource_metadata_url_str_concat(res_md):
assert (
"concat test " + res_md.url == "concat test http://www.hydroshare.org/resource/84805fd615a04d63b4eada65644a1e20"
devincowan marked this conversation as resolved.
Show resolved Hide resolved
)
Loading