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

Special syntax error forelif afterelse #129858

Closed
Labels
@swfarnsworth

Description

@swfarnsworth

Feature or enhancement

Proposal:

I've implemented a special syntax error in the case that anelif follows anelse. Seehere.

ifi%3==0:print("divisible by 3")else:print("not divisible by 3")elifi%2==0:print("divisible by 2")# SyntaxError: elif not allowed after else

This is currently the extent of the new behavior. If possible, I would be interested to implement behavior like this:

ifisinstance(i,int):ifi%3==0:print("divisible by 3")else:print("not divisible by 3")elifisinstance(i,str):print("i is a string")# SyntaxError: elif not allowed after else. Perhaps the elif is at the wrong indentation level?

This would be even more informative for beginners, but I'm not sure if the parser supports that level of state. In particular, we wouldn't want the latter syntax error (the one that suggests that the indentation level is wrong) to be raised if the invalid elif were within a for block.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp