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

make namespace module flake8-compliant, change exceptions in that mod… #711

Merged
merged 2 commits into from
Feb 8, 2017

Conversation

adamhadani
Copy link
Contributor

@adamhadani adamhadani commented Feb 6, 2017

  • Updates Exceptions raised in this module to specific ones so possible to catch them without a "except Exception" catch-all in application code that uses this library
  • Some formatting updates to make this module flake8 compliant!
  • Mention doctest-ignore-unicode dependency in run_tests.py docs for running tests, update it to suggest using pip (without sudo - use virtualenv!)

I Opted to use built in exception types that seemed most appropriate, ideally we should define our own custom error hierarchy, but for now this seems a good start.

@adamhadani
Copy link
Contributor Author

ping @gromgull for your kind consideration

@adamhadani adamhadani added cleanup enhancement New feature or request labels Feb 7, 2017
@@ -120,7 +120,7 @@ def __getattr__(self, name):
return self.term(name)

def __repr__(self):
return "Namespace(%s)"%text_type.__repr__(self)
return "Namespace(%s)" % text_type.__repr__(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we just replace this with "Namespace(%r)" % text_type(self)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joernhees there's a lot of code here that looks suspicious to me :) as first pass at this module I just took care of some flake8 style fixes which are ancillary to main purpose of this PR (making exception types raised here more specific). I think we should have a separate effort around standardizing code a bit more (switch to use .format() rather than % for string interpolation, etc. etc.). Probably not in scope for this PR though

@@ -150,8 +150,7 @@ def format(self, *args, **kwargs):
return URIRef(text_type.format(self, *args, **kwargs))

def __repr__(self):
return "URIPattern(%r)"%text_type.__repr__(self)

return "URIPattern(%r)" % text_type.__repr__(self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is double repr, should probably be "URIPattern(%r)" % text_type(self)

@joernhees joernhees added this to the rdflib 5.0.0 milestone Feb 7, 2017
namespace, name = split_uri(uri)
namespace = URIRef(namespace)
prefix = self.store.prefix(namespace)
if prefix is None:
if not generate:
raise Exception(
"No known prefix for %s and generate=False")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was a great exception :D

@joernhees
Copy link
Member

joernhees commented Feb 8, 2017

ok, i just overrode the very weird stuff (wrt. repr and str)... if anything goes wrong, i'm to blame ;)

wrt. % vs. .format() cleanup... i'm not decided about this... format was meant to be the future, but then somehow got stuck... i think initially (py 3.0 or so) % was deprecated, but the current docs don't deprecate it anymore... the logging module still heavily relies on it (logging.debug('foo %r bar', huge_list) won't actually do any formatting for non debug log-levels, etc.). I guess the smartest thing we can do there is wait and allow both for now ;)

@joernhees joernhees merged commit f7c7be3 into RDFLib:master Feb 8, 2017
@joernhees
Copy link
Member

merged... thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants