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

"yield" causes strange behaviour #45203

Closed
tebeka mannequin opened this issue Jul 15, 2007 · 3 comments
Closed

"yield" causes strange behaviour #45203

tebeka mannequin opened this issue Jul 15, 2007 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs)

Comments

@tebeka
Copy link
Mannequin

tebeka mannequin commented Jul 15, 2007

BPO 1754456
Nosy @rhettinger, @tebeka
Files
  • yield.py: yield.py
  • 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 2007-07-16.13:05:22.000>
    created_at = <Date 2007-07-15.21:17:25.000>
    labels = ['interpreter-core']
    title = '"yield" causes strange behaviour'
    updated_at = <Date 2007-07-16.13:05:22.000>
    user = 'https://github.com/tebeka'

    bugs.python.org fields:

    activity = <Date 2007-07-16.13:05:22.000>
    actor = 'tebeka'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Interpreter Core']
    creation = <Date 2007-07-15.21:17:25.000>
    creator = 'tebeka'
    dependencies = []
    files = ['2422']
    hgrepos = []
    issue_num = 1754456
    keywords = []
    message_count = 3.0
    messages = ['32512', '32513', '32514']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'tebeka']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1754456'
    versions = ['Python 2.5']

    @tebeka
    Copy link
    Mannequin Author

    tebeka mannequin commented Jul 15, 2007

    Running the attached files produces:
    ONE PASS

    However if you uncomment line 46 and run the file again, you don't get any output.

    A pdb session of the file produces:
    [mtebeka@lakshmi:python-bug - 14:14] $pdb yield.py

    /home/mtebeka/work/python-bug/yield.py(3)<module>()
    -> from imaplib import IMAP4
    (Pdb) b 72
    Breakpoint 1 at /home/mtebeka/work/python-bug/yield.py:72
    (Pdb) c
    /home/mtebeka/work/python-bug/yield.py(72)main()
    -> one_pass()
    (Pdb) s
    --Call--
    /usr/local/lib/python2.5/bdb.py:318: RuntimeWarning: tp_compare didn't return -1 or -2 for exception
    i = max(0, len(stack) - 1)
    The program finished and will be restarted
    /home/mtebeka/work/python-bug/yield.py(3)<module>()
    -> from imaplib import IMAP4
    (Pdb) q
    [mtebeka@lakshmi:python-bug - 14:15] $

    (Sorry for the length of the example, this is the smaller version that still reproduces the bug)

    @tebeka tebeka mannequin closed this as completed Jul 15, 2007
    @tebeka tebeka mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jul 15, 2007
    @tebeka tebeka mannequin closed this as completed Jul 15, 2007
    @tebeka tebeka mannequin added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Jul 15, 2007
    @rhettinger
    Copy link
    Contributor

    Miki, I don't see a bug here. The presence of "yield" is significant during compilation not just when the line is executed. When the yield appears anywhere in a function body, it is not a function anymore, it is a generator. So, when the "yield" is uncommented, the call to one_pass returns a generator which doesn't start running until its next() method is called. In contrast, when the "yield" is commented, you have a function that starts running immediately when one_pass() is called.

    Here is a simplified comparison of the generator versus function:

    >>> def one_pass():
    ...     print 'running'
    ...     yield 1
    ...
    >>> g = one_pass()
    >>> g.next()
    running
    1
    >>> def one_pass():
    ...     print 'running'
    ...     # yield 1
    ...
    >>> one_pass()
    running

    If you still see a bug, please elaborate. If not, please close this report.

    @tebeka
    Copy link
    Mannequin Author

    tebeka mannequin commented Jul 16, 2007

    OUCH, forgot about that sorry.

    Closing.

    @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)
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant