Skip to content

module-import-not-at-top-of-file ignore after os.environ #10059

@Pastells

Description

@Pastells

Sometimes you need to set an environment variable before importing a package, for example:

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "4" 
os.environ["WORLD_SIZE"] = "1"
import torch

See: https://discuss.pytorch.org/t/runtimeerror-device-0-device-num-gpus-internal-assert-failed/178118/6

My suggestion is to ignore E402 module-import-not-at-top-of-file if it comes after a os.environ statement, similar to #9047

Metadata

Metadata

Assignees

Labels

ruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions