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

__context__ for yields inside except clause #69869

Closed
1st1 opened this issue Nov 20, 2015 · 5 comments
Closed

__context__ for yields inside except clause #69869

1st1 opened this issue Nov 20, 2015 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@1st1
Copy link
Member

1st1 commented Nov 20, 2015

BPO 25683
Nosy @gvanrossum, @vstinner, @benjaminp, @njsmith, @cjerdonek, @1st1, @Vgr255

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-12-17.23:07:38.969>
created_at = <Date 2015-11-20.16:29:46.688>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = '__context__ for yields inside except clause'
updated_at = <Date 2017-12-01.06:25:21.619>
user = 'https://github.com/1st1'

bugs.python.org fields:

activity = <Date 2017-12-01.06:25:21.619>
actor = 'chris.jerdonek'
assignee = 'none'
closed = True
closed_date = <Date 2015-12-17.23:07:38.969>
closer = 'yselivanov'
components = ['Interpreter Core']
creation = <Date 2015-11-20.16:29:46.688>
creator = 'yselivanov'
dependencies = []
files = []
hgrepos = []
issue_num = 25683
keywords = []
message_count = 5.0
messages = ['254994', '255348', '255349', '256621', '287993']
nosy_count = 7.0
nosy_names = ['gvanrossum', 'vstinner', 'benjamin.peterson', 'njs', 'chris.jerdonek', 'yselivanov', 'abarry']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue25683'
versions = ['Python 3.3', 'Python 3.4', 'Python 3.5', 'Python 3.6']

@1st1
Copy link
Member Author

1st1 commented Nov 20, 2015

In the below snippet, SubError will propagate with __context__ set to None, instead of MainError. Maybe this isn't a bug?

    class MainError(Exception): pass
    class SubError(Exception): pass

    def main():
        try:
            raise MainError()
        except MainError:
            yield

    coro = main()
    coro.send(None)
    coro.throw(SubError())

@1st1 1st1 added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Nov 20, 2015
@Vgr255
Copy link
Mannequin

Vgr255 mannequin commented Nov 25, 2015

This is due to the fact that Python 3 added the ability to define only __eq__ and get a free __ne__ defined. If my memory serves me right, functools.total_ordering was added in 3.2 and then backported to 2.x - where the relationship with __eq__ and __ne__ is not present. total_ordering doesn't do anything to touch __ne__ as it expects Python itself to do so (which it doesn't in 2.x).

@Vgr255
Copy link
Mannequin

Vgr255 mannequin commented Nov 25, 2015

Oops, that was *completely* the wrong issue. I apologize for the noise.

@1st1
Copy link
Member Author

1st1 commented Dec 17, 2015

I now don't think this is a bug.

In the above example, SubError is instantiated outside of main generator. It's also thrown into main from the outside scope. And context should be set for exceptions that were originated by the code that was handling other exceptions.

Closing this issue with 'not a bug'.

@1st1 1st1 closed this as completed Dec 17, 2015
@1st1 1st1 added the invalid label Dec 17, 2015
@njsmith
Copy link
Contributor

njsmith commented Feb 17, 2017

I disagree with the stated reason for closing this, because in general, implicit context chaining doesn't care about where the exception was instantiated, only where it was raised. For example:

-----

err = ValueError()
try:
    raise KeyError
except Exception:
    raise err

Prints:

-----

Traceback (most recent call last):
  File "/tmp/bar.py", line 3, in <module>
    raise KeyError
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/bar.py", line 5, in <module>
    raise err
ValueError

I would expect 'gen.throw(OBJ)' to be equivalent to doing 'raise OBJ' inside the generator, and raise does set __context__.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants