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

Symbol table incorrectly identifies code as a generator, when 'yield' occurs in an annotation #87003

Closed
markshannon opened this issue Jan 6, 2021 · 10 comments
Assignees

Comments

@markshannon
Copy link
Member

BPO 42837
Nosy @gvanrossum, @larryhastings, @markshannon, @serhiy-storchaka, @lysnikolaou, @pablogsal, @isidentical
PRs
  • bpo-42837: Account for deferred evaluation of yields in symbol tables. #24138
  • 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 = 'https://github.com/markshannon'
    closed_at = <Date 2021-08-13.08:34:19.370>
    created_at = <Date 2021-01-06.09:51:20.744>
    labels = []
    title = "Symbol table incorrectly identifies code as a generator, when 'yield' occurs in an annotation"
    updated_at = <Date 2021-08-13.08:52:25.527>
    user = 'https://github.com/markshannon'

    bugs.python.org fields:

    activity = <Date 2021-08-13.08:52:25.527>
    actor = 'BTaskaya'
    assignee = 'Mark.Shannon'
    closed = True
    closed_date = <Date 2021-08-13.08:34:19.370>
    closer = 'Mark.Shannon'
    components = []
    creation = <Date 2021-01-06.09:51:20.744>
    creator = 'Mark.Shannon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42837
    keywords = ['patch']
    message_count = 10.0
    messages = ['384479', '384480', '384482', '384484', '384489', '384491', '384495', '384612', '399504', '399508']
    nosy_count = 7.0
    nosy_names = ['gvanrossum', 'larry', 'Mark.Shannon', 'serhiy.storchaka', 'lys.nikolaou', 'pablogsal', 'BTaskaya']
    pr_nums = ['24138']
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue42837'
    versions = []

    @markshannon
    Copy link
    Member Author

    This is an internal inconsistency. I have not identified any surface level bugs, but it is a trap for future compiler work.

    @serhiy-storchaka
    Copy link
    Member

    This is a duplicate of bpo-42725.

    @markshannon
    Copy link
    Member Author

    No this is not a duplicate.
    This is about making the symbol table correct for current semantics.
    bpo-42725 is about changing the behavior

    @markshannon markshannon reopened this Jan 6, 2021
    @markshannon markshannon reopened this Jan 6, 2021
    @serhiy-storchaka
    Copy link
    Member

    Does not it change the current behavior? I do not see a difference with bpo-42725.

    >>> def f():
    ...     x: (yield)
    ... 
    >>> f()
    <generator object f at 0x7f971b45d950>

    @markshannon
    Copy link
    Member Author

    The aim is to change the behavior of the symbol table to match the compiler.
    The behavior has already changed at module scope.

    Python 3.9.0+
    >>> x:(yield None)
      File "<stdin>", line 1
    SyntaxError: 'yield' outside function
    >>> 
    
    
    Python 3.10.0a4+
    >>> x:(yield None)
    >>>

    @serhiy-storchaka
    Copy link
    Member

    Then why not fix the compiler?

    As I understand, it is not clear yet what behavior should be, and discussing it is the matter of bpo-42725. Any changes before the decision be made are preliminary.

    It is very likely that the decision will be in favor of ignoring annotations. In that case your PR or even more radical changes can be merged.

    @markshannon
    Copy link
    Member Author

    OK, I won't merge anything yet.

    @isidentical
    Copy link
    Sponsor Member

    Well even though I still don't understand 'how this issue is different than bpo-42725', I don't think you actually fix the symbol table;
    see this one: https://bugs.python.org/msg383659

    Annotations still have side effects on the symbol table (even though they shouldn't have). and I already had a fix but decided not to go for it until bpo-42737 is resolved since it would make the language inconsistent. Just FYI.

    @markshannon
    Copy link
    Member Author

    I guess this will be resolved when the great PEP 563/649 debate is concluded. No need for another issue.

    @isidentical
    Copy link
    Sponsor Member

    AFAIK this is already resolved on the main (https://bugs.python.org/issue42725)

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

    No branches or pull requests

    3 participants