Skip to content

STYLE place standard library imports at top of file #49647

Closed
@MarcoGorelli

Description

@MarcoGorelli

Imports should typically be placed at the top of files. Sometimes, imports are placed inside functions to:

  • avoid circular imports
  • avoid ImportError if it's an optional dependency

Standard library imports should really always be at the top of files.

Noticed in #49645 that this is often not the case

I've made a script to automate detecting when this is the case. So the task is:

git checkout -b standard-library-imports main
git pull [email protected]:MarcoGorelli/pandas.git standard-library-imports
git reset --hard FETCH_HEAD
pre-commit run stdlib-imports --all-files

Then, fixup any errors that are reported. Finally, stage your changes, commit them, push them to your fork, and open a pull request

Feel free to reach out if you into any issues along the way

If any wants to take this, it would be a nice and welcome clean up!


EDIT: after going through a PR, I'm not sure it's worth introducing a check for this - but we can still take some of the cleanups it found

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions