# A Pyrefly configuration for PyTorch
# Based on https://github.com/pytorch/pytorch/blob/main/mypy.ini
python-version = "3.12"

project-includes = [
    "torch_npu",
    "torchnpugen",
    "test",
    "caffe2",
    "test/test_bundled_images.py",
    "test/test_bundled_inputs.py",
    "test/test_complex.py",
    "test/test_datapipe.py",
    "test/test_futures.py",
    "test/test_numpy_interop.py",
    # We exclude test_torch.py because it is full of errors, but most functions lack type signatures,
    # and mypy.ini specifies `check_untyped_defs = False` for this file.
    # If you check even the unannotated stuff mypy produces 322 errors.
    # "test/test_torch.py",
    "test/test_type_hints.py",
    "test/test_type_info.py",
    "test/test_utils.py",
]
project-excludes = [
  "tools/**",
  "torch_npu/_inductor/runtime/triton_heuristics.py",
  "torch_npu/_inductor/runtime/triton_helpers.py",
  "torch_npu/_inductor/runtime/halide_helpers.py",
  "torch_npu/utils/data/typing.ipynb",
  "torch_npu/utils/data/dataframes_pipes.ipynb",
  "torch_npu/utils/data/standard_pipes.ipynb",
  "torch_npu/onnx/_internal/exporter/_torchlib/ops/nn.py",
  "torch_npu/include/**",
  "torch_npu/csrc/**",
  "torch_npu/distributed/elastic/agent/server/api.py",
  "torch_npu/testing/_internal/**",
  "torch_npu/distributed/fsdp/fully_sharded_data_parallel.py",
  "torch_npu/ao/quantization/pt2e/_affine_quantization.py",
  "torch_npu/nn/modules/pooling.py",
  "torch_npu/nn/parallel/_functions.py",
  "torch_npu/_appdirs.py",
  "torch_npu/multiprocessing/pool.py",
  "torch_npu/overrides.py",
  "*/__pycache__/**",
  "*/.*",
  "torch_npu/_inductor/kernel/vendored_templates/cutedsl/kernels/**",
  "torch_npu/_inductor/kernel/vendored_templates/cutedsl/dense_blockscaled_gemm_persistent.py",
]
ignore-missing-imports = [
    # XPU memory symbols not present for builds without XPU support
    "torch_npu._C._xpu_beginAllocateCurrentThreadToPool",
    "torch_npu._C._xpu_endAllocateToPool",
    "torch_npu._C._xpu_releasePool",
    "torch_npu._C._xpu_XPUAllocator",
    "torch_npu._C._XPUMemPool",
    "torch_npu._C._StaticXpuLauncher",
    "torch_npu._C._jit_tree_views.*",
    "torch_npu.for_onnx.onnx.*",
    "torch_npu.ao.quantization.experimental.apot_utils.*",
    "torch_npu.ao.quantization.experimental.quantizer.*",
    "torch_npu.ao.quantization.experimental.observer.*",
    "torch_npu.ao.quantization.experimental.APoT_tensor.*",
    "torch_npu.ao.quantization.experimental.fake_quantize_function.*",
    "torch_npu.ao.quantization.experimental.fake_quantize.*",
    "triton.*",
    "tensorflow.*",
    "tensorboard.*",
    "matplotlib.*",
    "numpy.*",
    "sympy.*",
    "hypothesis.*",
    "tqdm.*",
    "multiprocessing.*",
    "setuptools.*",
    "distutils.*",
    "nvd3.*",
    "future.utils.*",
    "past.builtins.*",
    "numba.*",
    "nvMatmulHeuristics",
    "PIL.*",
    "moviepy.*",
    "cv2.*",
    "torchvision.*",
    "pycuda.*",
    "tensorrt.*",
    "tornado.*",
    "pydot.*",
    "networkx.*",
    "scipy.*",
    "IPython.*",
    "google.protobuf.textformat.*",
    "lmdb.*",
    "mpi4py.*",
    "skimage.*",
    "librosa.*",
    "mypy.*",
    "xml.*",
    "boto3.*",
    "dill.*",
    "usort.*",
    "cutlass.*",
    "cutlass_library.*",
    "cutlass_api.*",
    "deeplearning.*",
    "einops.*",
    "libfb.*",
    "torch_npu.fb.*",
    "torch_npu.*.fb.*",
    "torch_xla.*",
    "onnx.*",
    "onnxruntime.*",
    "onnxscript.*",
    "redis.*",
]
# By default, mypy does not check untyped definitions.
# However, mypy has a configuration called check_untyped_defs which is used
# to typecheck the interior of untyped functions.
untyped-def-behavior = "check-and-infer-return-any"
# In lots of places they define their attributes in `_init` or similar.
# https://github.com/pytorch/pytorch/blob/75f3e5a88df60caef27fd9c9df3fd51161378fcc/torch/fx/experimental/symbolic_shapes.py#L3632C1-L3633C1
errors.implicitly-defined-attribute = false
errors.missing-import = false
# In many methods that are overridden, parameters are renamed.
# We can come up with a codemod for this in the future
errors.bad-param-name-override = false
# Mypy doesn't require that imports are explicitly imported, so be compatible with that.
# Might be a good idea to turn this on in future.
errors.implicit-import = false
errors.deprecated = false # re-enable after we've fix import formatting

permissive-ignores = true
replace-imports-with-any = ["!sympy.printing.*", "sympy.*", "onnxscript.onnx_opset.*", "networkx.*"]
search-path = ["tools/experimental"]

# Dynamo sub-config - note, we experiment with stricter typing here
[[sub-config]]
matches = "torch_npu/_dynamo/**"
[sub-config.errors]
implicit-import = false
implicit-any = true
# TODO: Turn on in later version
# unannotated-attribute=true
# unannotated-parameter=true
# unannotated-return=true

[[sub-config]]
matches = "torch_npu/_dispatch/**"
[sub-config.errors]
implicit-import = false
implicit-any = true

[[sub-config]]
matches = "torch_npu/_subclasses/**"
[sub-config.errors]
implicit-import = false
implicit-any = true

[[sub-config]]
matches = "torch_npu/_functorch/**"
[sub-config.errors]
implicit-import = false
implicit-any = true