Commit Graph

10 Commits

Author SHA1 Message Date
Edward Z. Yang
9bce208dfb Replace follow_imports = silent with normal (#118414)
This is a lot of files changed! Don't panic! Here's how it works:

* Previously, we set `follow_imports = silent` for our mypy.ini configuration. Per https://mypy.readthedocs.io/en/stable/running_mypy.html#follow-imports, what this does is whenever we have an import to a module which is not listed as a file to be typechecked in mypy, we typecheck it as normal but suppress all errors that occurred in that file.
* When mypy is run inside lintrunner, the list of files is precisely the files covered by the glob in lintrunner.toml, but with files in excludes excluded.
* The top-level directive `# mypy: ignore-errors` instructs mypy to typecheck the file as normal, but ignore all errors.
* Therefore, it should be equivalent to set `follow_imports = normal`, if we put `# mypy: ignore-errors` on all files that were previously excluded from the file list.
* Having done this, we can remove the exclude list from .lintrunner.toml, since excluding a file from typechecking is baked into the files themselves.
* torch/_dynamo and torch/_inductor were previously in the exclude list, because they were covered by MYPYINDUCTOR. It is not OK to mark these as `# mypy: ignore-errors` as this will impede typechecking on the alternate configuration. So they are temporarily being checked twice, but I am suppressing the errors in these files as the configurations are not quite the same. I plan to unify the configurations so this is only a temporary state.
* There were some straggler type errors after these changes somehow, so I fixed them as needed. There weren't that many.

In the future, to start type checking a file, just remove the ignore-errors directive from the top of the file.

The codemod was done with this script authored by GPT-4:

```
import glob

exclude_patterns = [
    ...
]

for pattern in exclude_patterns:
    for filepath in glob.glob(pattern, recursive=True):
        if filepath.endswith('.py'):
            with open(filepath, 'r+') as f:
                content = f.read()
                f.seek(0, 0)
                f.write('# mypy: ignore-errors\n\n' + content)
```

Signed-off-by: Edward Z. Yang <ezyang@meta.com>

Pull Request resolved: https://github.com/pytorch/pytorch/pull/118414
Approved by: https://github.com/thiagocrepaldi, https://github.com/albanD
2024-01-27 02:44:11 +00:00
Justin Chu
4cc1745b13 [BE] f-stringify torch/ and scripts (#105538)
This PR is a follow up on the pyupgrade series to convert more strings to use f-strings using `flynt`.

- https://docs.python.org/3/reference/lexical_analysis.html#f-strings
- https://pypi.org/project/flynt/

Command used:

```
flynt torch/ -ll 120
flynt scripts/ -ll 120
flynt tools/ -ll 120
```

and excluded `collect_env.py`

Pull Request resolved: https://github.com/pytorch/pytorch/pull/105538
Approved by: https://github.com/ezyang, https://github.com/malfet
2023-07-21 19:35:24 +00:00
Peter Bell
454361435c Implement correction argument in torch.masked.{std,var} (#87118)
This makes the signature of `torch.masked.std` and `var` more consistent with the global namespace variant and also updates the sample inputs to repurpose the existing `sample_inputs_std_var` inputs which fully exercise the `correction` argument.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/87118
Approved by: https://github.com/cpuhrsch
2022-12-08 15:59:09 +00:00
mantaionut
7c0bb61291 Force numpy prod to use 64 bit integers on Windows in some tests (#88089)
This fixes some prod and masked.prod tests on Windows.

np.prod uses int32 on Windows so it overflows.

On Linux it uses by default int64.

Fixes #77305
Fixes #77320
Fixes #77334
Fixes #77335
Fixes #77336
Fixes #77337

Pull Request resolved: https://github.com/pytorch/pytorch/pull/88089
Approved by: https://github.com/mruberry
2022-11-22 18:37:14 +00:00
Peter Bell
91eb1b9bb9 Move _masked opinfos to opinfo/definitions/_masked.py (#83763)
Ref #82518
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83763
Approved by: https://github.com/albanD
2022-08-22 19:08:41 +00:00
Peter Bell
7656ef73f1 Move torch.special OpInfos into opinfo/definitions/special.py (#83762)
Ref #82518

As with `linalg` this doesn't include ops with an alias in special,
only the ones where `special.foo` is the actual name of the opinfo.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83762
Approved by: https://github.com/albanD
2022-08-22 19:08:41 +00:00
Peter Bell
ae68e455be Enable formatting in all of testing/_internal/opinfo (#83559)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83559
Approved by: https://github.com/albanD
2022-08-19 12:25:57 +00:00
PyTorch MergeBot
61b2cde527 Revert "Enable formatting in all of testing/_internal/opinfo (#83559)"
This reverts commit a7e6196909.

Reverted https://github.com/pytorch/pytorch/pull/83559 on behalf of https://github.com/peterbell10 due to Stack broke lint
2022-08-19 02:27:03 +00:00
Peter Bell
a7e6196909 Enable formatting in all of testing/_internal/opinfo (#83559)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/83559
Approved by: https://github.com/albanD
2022-08-19 01:49:45 +00:00
Peter Bell
4d405517e4 Move OpInfo class into new opinfo folder (#82540)
Ref #82518

Starting small to minimize merge conflicts, this moves the top-level
class definitions and some helper functions into the `opinfos` folder.
It also brings `common_methods_invocations.py` to just below 1MB.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/82540
Approved by: https://github.com/albanD
2022-08-05 15:10:17 +00:00