Skip to content

Expand I001 documentation #27232

Closed
Closed

Description

@r-heimann

Summary

Hi, after updating to 0.16.0 i noticed that I001 is failing with any import, even if everything is properly configured. Example (AWS Lambda Python code):

import json

def lambda_handler(event, context):

  test = json("test")
  print(test)

gives the error

Import block is un-sorted or un-formatted

help: Organize importsRuffI001

Version

0.16.0

Activity

  1. calumy commented on Jul 28, 2026

    @calumy
    Contributor

    This can be fixed by adding an extra blank line below import json. See playground.

  2. r-heimann commented on Jul 28, 2026

    @r-heimann
    Author

    This can be fixed by adding an extra blank line below import json. See playground.

    Thank you, i was able to verify that it is fixed - but the Ruff documentation didn't mention anything about spaces? I also noticed that Ruff isn't explaining what exacly is wrong with this configuration:

    import json
    import logging
    import boto3
    
    
    def lambda_handler(event, context):
        print(boto3, logging, json)

    After talking to a LLM i saw that 3rd party modules should be separated by an extra space:

    import json
    import logging
    
    import boto3
    
    
    def lambda_handler(event, context):
        print(boto3, logging, json)

    The new rule set doesn't seem to properly explain these kinds of issues.

  3. r-heimann commented on Jul 28, 2026

    @r-heimann
    Author

    I also just noticed that doing this ignores the 2 spaces at the end of the imports:

    import json
    import logging
    
    import boto3
    
    test = "test"
    
    def lambda_handler(event, context):
        print(boto3, logging, json)

    Incredibly confusing, but i am not a Python Expert - so i may be stumbling upon something that is already known.

  4. ntBre commented on Jul 28, 2026

    @ntBre
    Contributor

    Thanks for the report! I see how this is confusing. As @calumy said, isort and Ruff's I001 rule require additional blank lines between imports and function and class definitions. The single blank line is allowed between imports and other kinds of statements. You can adjust this with the lines-after-imports setting.

    Looking at this today, I was a bit surprised that our docs for I001 are so short. I think it would be a good idea to expand them, especially now that the rule is enabled by default.

  5. changed the title [-]0.16.0: I001 - Fails with any import[/-] [+]I001 - Fails with any import[/+] on Jul 28, 2026
  6. added
    documentation
    isort
    on Jul 28, 2026
  7. roian6 commented on Jul 28, 2026

    @roian6

    Thanks! I’d be happy to work on this as a documentation-only change.

    I’ll expand the I001 rule documentation to explain import sections and the blank-line requirements after an import block, with links to the relevant lines-after-imports and import-classification settings.

  8. jonathandung commented on Jul 31, 2026

    @jonathandung
    Contributor

    Maybe change the issue title?

  9. changed the title [-]I001 - Fails with any import[/-] [+]Expand `I001` documentation[/+] on Jul 31, 2026
  10. halcyon-past commented on Oct 30, 2026

    @halcyon-past

    I'd like to work on this issue!

  11. added a commit that references this issue on Nov 3, 2026
    1bc8eab
  12. added a commit that references this issue on Nov 3, 2026
    d7f77cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationisort

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions