Skip to content

[docs] add more info to allow_redefinition #11951

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

Merged
merged 3 commits into from
Jan 27, 2022

Conversation

KotlinIsland
Copy link
Contributor

I noticed the docs don't mention a rule of allow_redefinition

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! IIRC the exact condition is "if the variable has not been used since it was assigned to", e.g. the following is allowed:

def process(items: list[str]) -> None:
    # 'items' has type list[str]
    items = [item.split() for item in items]
    # 'items' now has type list[list[str]]
    print(items)
    items = "mypy"

(I haven't read that part of the code in a while, so I might be mistaken)

@JelleZijlstra JelleZijlstra merged commit e285203 into python:master Jan 27, 2022
@KotlinIsland KotlinIsland deleted the docs/allow_redefinition branch January 27, 2022 13:19
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

Successfully merging this pull request may close these issues.

3 participants