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

Raise a more specific Exception when lang isn't valid #1497

Merged
merged 1 commit into from
Dec 15, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion rdflib/term.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def __new__(cls, lexical_or_value, lang=None, datatype=None, normalize=None):
)

if lang and not _is_valid_langtag(lang):
raise Exception("'%s' is not a valid language tag!" % lang)
raise ValueError("'%s' is not a valid language tag!" % lang)

if datatype:
datatype = URIRef(datatype)
Expand Down
5 changes: 5 additions & 0 deletions test/test_literal.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def testCantPassLangAndDatatype(self):
TypeError, Literal, "foo", lang="en", datatype=URIRef("http://example.com/")
)

def testCantPassInvalidLang(self):
self.assertRaises(
ValueError, Literal, "foo", lang="999"
)

def testFromOtherLiteral(self):
l = Literal(1)
l2 = Literal(l)
Expand Down