Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

global declaration in except has incorrect prior use #111123

Closed
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error
@15r10nk

Description

@15r10nk

Bug report

Bug description:

I think theglobal a has no prior use in this code (and pyright tells me the same). But I don't understand why cpython thinks it has a prior use.

a=5deff():try:passexcept:globalaelse:print(a)

output (Python 3.12.0):

File"/home/frank/projects/pysource-playground/pysource-codegen/bug.py",line8globala^^^^^^^^SyntaxError:name'a'isusedpriortoglobaldeclaration

the following code has no syntax error:

a=5deff():try:passexcept:globalaprint(a)

I can also reproduce this issue in 3.7.

I also don't know what the exact semantic of global/nonlocal inside statements like if/while/try/... is. I would like to know more about it because I'm currently writingpysource-codegen where I generate such cases.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp