pytorch/test/jit
Meghan Lele 28c5d90b67 [JIT] Allow implicit boolean conversion of containers (#51683)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/51683

**Summary**
This commit enables implicit boolean conversion of lists, strings, and
dictionaries in conditional expressions. Like Python, empty lists,
strings and dictionaries evaluate to `False` and their non-empty
counterparts evaluate to `True`. This allows users to write code like

```
torch.jit.script
def fn(l: List[int]):
  if l:
    ...
  else:
    ...
```

This has been requested by some users and would be a good usability
improvement.

**Test Plan**
This commit adds unit tests to `TestList`, `TestDict` and
`test_jit_string.py` to test this new feature.

Test Plan: Imported from OSS

Reviewed By: pbelevich

Differential Revision: D26264410

Pulled By: SplitInfinity

fbshipit-source-id: b764c18fd766cfc128ea98a02b7c6c3fa49f8632
2021-02-05 00:34:35 -08:00
..
_imported_class_test remediation of S205607 2020-07-17 17:19:47 -07:00
fixtures Throws runtime error when torch.full would infer a float dtype from a bool or integral fill value (#40364) 2020-06-23 23:27:22 -07:00
__init__.py remediation of S205607 2020-07-17 17:19:47 -07:00
test_async.py Type annotations in test/jit (#50293) 2021-01-12 16:47:06 -08:00
test_autodiff_subgraph_slicing.py add RequiresGradCheck (#50392) 2021-01-15 16:50:42 -08:00
test_backends.py [JIT] Add selective backend lowering API (#43613) 2020-10-30 00:37:33 -07:00
test_builtins.py Type annotations in test/jit (#50293) 2021-01-12 16:47:06 -08:00
test_class_type.py Fix more JIT tests under Python-3.9 (#51182) 2021-01-27 10:57:03 -08:00
test_complex.py Add support for complex valued keys for dict in TS (#51472) 2021-02-01 22:40:01 -08:00
test_complexity.py [JIT] rename enable_profiling_mode to enable_profiling_mode_for_profiling_tests (#37825) 2020-05-06 11:30:02 -07:00
test_cuda.py Adding JIT support for cuda streams and events (#48020) 2020-12-29 20:24:57 -08:00
test_custom_operators.py Revert D18672405: Revert D18672405: Use codegen'ed unboxing wrappers (#36010) 2020-04-09 10:45:28 -07:00
test_data_parallel.py
test_enum.py [Usability] Tolerate torch.jit.script call to Enum classes (#51624) 2021-02-04 01:51:49 -08:00
test_export_modes.py
test_freezing.py [JIT] Print out CU address in ClassType::repr_str() (#50194) 2021-01-19 23:04:30 -08:00
test_functional_blocks.py [JIT] move remove mutation to its own test file (#41502) 2020-07-20 12:03:28 -07:00
test_fuser_common.py JIT: guard DifferentiableGraph node (#49433) 2021-01-08 20:01:27 -08:00
test_hash.py Support hashing of various data types by implementing generic hashing for IValues (#46441) 2020-10-23 21:26:01 -07:00
test_hooks_modules.py [WIP] JIT Static Hooks: python tests (#49546) 2021-01-20 09:12:53 -08:00
test_hooks.py [JIT] Enable saving modules with hooks in FBCODE (#51241) 2021-02-01 17:01:44 -08:00
test_isinstance.py [JIT] adding missing test cases for test_isinstance.py (#47396) 2020-11-30 09:10:15 -08:00
test_list_dict.py [JIT] Allow implicit boolean conversion of containers (#51683) 2021-02-05 00:34:35 -08:00
test_logging.py
test_models.py Improving ModuleList indexing error msg (#43361) 2020-09-09 16:22:57 -07:00
test_module_containers.py [JIT] Provide more info when attribute fails to convert (#50870) 2021-01-27 20:37:10 -08:00
test_module_interface.py Workaround Python3.9 limitations in test_jit_py3 (#51088) 2021-01-26 12:49:35 -08:00
test_onnx_export.py Linear autodiff revert revert (#51613) 2021-02-04 16:32:05 -08:00
test_peephole.py Peephole Optimize out conv(x).dim(), which prevents BN fusion (#50221) 2021-01-12 11:39:09 -08:00
test_profiler.py JIT: guard DifferentiableGraph node (#49433) 2021-01-08 20:01:27 -08:00
test_python_bindings.py Graceful invalidation of Python Node/Value/Block when C++ object is deleted (#50326) 2021-02-04 01:34:46 -08:00
test_python_ir.py Fix naming of "strides" method in TensorType (#36727) 2020-04-16 17:07:27 -07:00
test_recursive_script.py Type annotations in test/jit (#50293) 2021-01-12 16:47:06 -08:00
test_remove_mutation.py Linear autodiff revert revert (#51613) 2021-02-04 16:32:05 -08:00
test_save_load.py Type annotations in test/jit (#50293) 2021-01-12 16:47:06 -08:00
test_slice.py Support Python Slice class in TorchScript (#44335) 2020-09-17 00:41:53 -07:00
test_string_formatting.py Support %-based string formatting (#45976) 2020-10-20 16:13:36 -07:00
test_torchbind.py [JIT] Add __prepare_scriptable__ duck typing to allow replacing nn.modules with scriptable preparations (#45645) (#49242) 2021-01-05 14:18:15 -08:00
test_tracer.py [Bug] fix for module_has_exports (#50680) 2021-01-27 16:03:24 -08:00
test_type_sharing.py [JIT] Add API for ignoring arbitrary module attributes (#45262) 2020-10-06 18:02:06 -07:00
test_unsupported_ops.py Unify TensorOptions signatures (#39611) 2020-07-08 17:00:33 -07:00
test_warn.py Make sure each warnings.warn only executes once inside TorchScript. (#45382) 2020-10-02 14:55:10 -07:00
test_with.py Fix more JIT tests under Python-3.9 (#51182) 2021-01-27 10:57:03 -08:00