Files
pytorch/torch/_numpy/__init__.py
Xuehai Pan 7837a12474 [BE] enforce style for empty lines in import segments (#129751)
This PR follows https://github.com/pytorch/pytorch/pull/129374#pullrequestreview-2136555775 cc @malfet:

> Lots of formatting changes unrelated to PR goal, please keep them as part of separate PR (and please add lint rule if you want to enforce those, or at least cite one)

`usort` allows empty lines within import segments. For example, `usort` do not change the following code:

```python
import torch.aaa
import torch.bbb
import torch.ccc

x = ...  # some code
```

```python
import torch.aaa

import torch.bbb
import torch.ccc

x = ...  # some code
```

```python
import torch.aaa

import torch.bbb

import torch.ccc

x = ...  # some code
```

This PR first sort imports via `isort`, then re-sort the file using `ufmt` (`usort` + `black`). This enforces the following import style:

1. no empty lines within segments.
2. single empty line between segments.
3. two spaces after import statements.

All the code snippets above will be formatted to:

```python
import torch.aaa
import torch.bbb
import torch.ccc

x = ...  # some code
```

which produces a consistent code style.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/129751
Approved by: https://github.com/malfet
2024-06-29 14:15:24 +00:00

32 lines
535 B
Python

# mypy: ignore-errors
from . import fft, linalg, random
from ._dtypes import * # noqa: F403
from ._funcs import * # noqa: F403
from ._getlimits import finfo, iinfo
from ._ndarray import (
array,
asarray,
ascontiguousarray,
can_cast,
from_dlpack,
ndarray,
newaxis,
result_type,
)
from ._ufuncs import * # noqa: F403
from ._util import AxisError, UFuncTypeError
from math import pi, e # usort: skip
alltrue = all
sometrue = any
inf = float("inf")
nan = float("nan")
False_ = False
True_ = True