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

await is valid in non async functions if PyCF_ALLOW_TOP_LEVEL_AWAIT is set #84146

Closed
pablogsal opened this issue Mar 15, 2020 · 4 comments
Closed
Labels
3.8 only security fixes 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@pablogsal
Copy link
Member

BPO 39965
Nosy @asvetlov, @1st1, @pablogsal, @miss-islington, @isidentical
PRs
  • bpo-39965: Correctly raise SyntaxError if await is used outside async functions when PyCF_ALLOW_TOP_LEVEL_AWAIT is set #19010
  • [3.8] bpo-39965: Correctly raise SyntaxError if await is used outside async functions when PyCF_ALLOW_TOP_LEVEL_AWAIT is set (GH-19010) #19011
  • 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 2020-03-15.04:30:29.958>
    created_at = <Date 2020-03-15.03:50:53.053>
    labels = ['type-bug', '3.8', '3.9', 'expert-asyncio']
    title = 'await is valid in non async functions if PyCF_ALLOW_TOP_LEVEL_AWAIT is set'
    updated_at = <Date 2020-03-15.06:00:32.857>
    user = 'https://github.com/pablogsal'

    bugs.python.org fields:

    activity = <Date 2020-03-15.06:00:32.857>
    actor = 'yselivanov'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-03-15.04:30:29.958>
    closer = 'pablogsal'
    components = ['asyncio']
    creation = <Date 2020-03-15.03:50:53.053>
    creator = 'pablogsal'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39965
    keywords = ['patch']
    message_count = 4.0
    messages = ['364216', '364217', '364218', '364221']
    nosy_count = 5.0
    nosy_names = ['asvetlov', 'yselivanov', 'pablogsal', 'miss-islington', 'BTaskaya']
    pr_nums = ['19010', '19011']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39965'
    versions = ['Python 3.8', 'Python 3.9']

    @pablogsal
    Copy link
    Member Author

    If PyCF_ALLOW_TOP_LEVEL_AWAIT is set this code is valid:

    def f():
       await foo

    And this should raise a "SyntaxError: 'await' outside async function". The reason is that the PyCF_ALLOW_TOP_LEVEL_AWAIT is global in the compiler and affects everything without checking if the current code being compiled is actually in the TOP level or not.

    @pablogsal pablogsal added 3.8 only security fixes 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error labels Mar 15, 2020
    @pablogsal
    Copy link
    Member Author

    New changeset 9023581 by Pablo Galindo in branch 'master':
    bpo-39965: Correctly raise SyntaxError if await is used outside async functions when PyCF_ALLOW_TOP_LEVEL_AWAIT is set (GH-19010)
    9023581

    @miss-islington
    Copy link
    Contributor

    New changeset f7e32fc by Miss Islington (bot) in branch '3.8':
    bpo-39965: Correctly raise SyntaxError if await is used outside async functions when PyCF_ALLOW_TOP_LEVEL_AWAIT is set (GH-19010)
    f7e32fc

    @1st1
    Copy link
    Member

    1st1 commented Mar 15, 2020

    Good catch & PR ;) Thanks

    @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
    3.8 only security fixes 3.9 only security fixes topic-asyncio type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants