Skip to content

Treat exceptions as normal variables properly - #150

Open
victorjzsun wants to merge 3 commits into
laike9m:masterfrom
victorjzsun:fix-exceptions
Open

victorjzsun wants to merge 3 commits into
laike9m:masterfrom
victorjzsun:fix-exceptions

Conversation

@victorjzsun

Copy link
Copy Markdown
Collaborator

Fixes #147

Use SymbolWithCustomValueStackItem class to allow exceptions to be treated as normal variables.

Comment thread cyberbrain/value_stack.py Outdated
try:
a = RuntimeError("A")
raise a
except b.__class__ as e:

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

it's not entirely clear to me what this part is for, mind elaborate?

@victorjzsun victorjzsun Feb 25, 2022

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's using a merge_stack_items on an actual error class from raise_args and a stack item containing b. Merging two SymbolWithCustomValue's (will be) done in simple test, this one tests merging a SymbolWithCustomValue with a CustomValue.

The second except is unnecessary since it's similar to the outer except.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Consider breaking this test down to smaller ones, ideally with one-except, and please add proper comments. In any case, I'd want to avoid tests from which readers cannot see the intent at first glance.

@@ -0,0 +1,84 @@
import pytest

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Can we add some tests in which exceptions have sources? e.g.

b = ...  # a string
a = ImportError(b)

@laike9m

laike9m commented Feb 24, 2022

Copy link
Copy Markdown
Owner

some test errors seem to be related to pdm. maybe try updating its version and try again?

class CustomException(Exception):
pass

a = ImportError("A")

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think ImportError("A") is equivalent to ImportError() in our case? In other words, "A" and "B" are merely distractions, I'd probably remove them from all tests.

Also, having print(a) doesn't seem very useful either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fails to treat variables of exception types, when they're not used in error handling

2 participants