On 7/4/2017 5:48 PM, David Mertz wrote:
If a method, why not a property?
Since the time to respond in human terms is trivial, I can imagine that
this might be accepted. I just did not think of that option.
On Jul 4, 2017 2:41 PM, "Terry Reedy"
<tjre...@udel.edu
<mailto:tjre...@udel.edu>> wrote:
On 7/4/2017 3:32 PM, David Mertz wrote:
I don't see the usefulness rich exception data as at all as
limited as this. Here's some toy code that shows a use:
----
# For some reason, imports might not be ready immediately
# Maybe flaky network drive, maybe need to install modules, etc
# The overall program can do things too make them available
lazy_import("foo", "bar", "baz", "blat")
while True:
try:
x = foo(1) * bar(2) + baz(3)**blat(4)
break
except NameError as err:
lazy_import(err.name <http://err.name> <http://err.name>)
sleep(1)
Alternate proposal: give the NameError class a .name instance method
that extracts the name from the message. This should not increase
the time to create an instance. You would then write 'err.name
<http://err.name>()' instead of 'err.name <http://err.name>'. For 3.6
def name(self):
msg = self.args[0]
return msg[6:msg.rindex("'")]
# current test
try: xyz
except NameError as e:
print(name(e) == 'xyz')
# Exceptions unittest to ensure that the method
# stays synchronized with future versions of instances
def test_nameerror_name(self):
try:
xyz
except NameError as e:
self.assertEqual(e.name <http://e.name>(), 'xyz')
Generalize to other exceptions.
Further only-partially baked idea: Since exceptions are (in cpython)
coded in C, I wonder if C data could be inexpensively attached to
the instance to be retrieved and converted to python objects by
methods when needed.
--
Terry Jan Reedy
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
<mailto:Python-ideas@python.org>
https://mail.python.org/mailman/listinfo/python-ideas
<https://mail.python.org/mailman/listinfo/python-ideas>
Code of Conduct: http://python.org/psf/codeofconduct/
<http://python.org/psf/codeofconduct/>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
--
Terry Jan Reedy
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/