Repository: sympy/sympy
Pull request: core/containers: no longer create Tuple's with lists as arguments.
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #22550

#### Brief description of what is fixed or changed
Several classes in SymPy use `sympify` on their arguments. In some cases, this leads to the creation of `Tuple` objects that have `lists` as their arguments. This PR solves those cases as far as they show up in the tests, by explicitly looping over iterables when a mix of `tuple` and `list` can be used for the input arguments.

#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
NO ENTRY
<!-- END RELEASE NOTES -->


Problem statement:
Tuple using sympify instead of _sympify incorrectly supports lists
Currently, `Tuple` supports the keyword `sympify` (`True` by default). However, this uses `sympify` rather than `_sympify`. As a result, `lists` appear to be supported as arguments to `Tuple` but this may result in unexpected behaviour since the resulting `Tuple` is now in principle mutable. Instead, I suggest to use `_sympify` over `sympify` and check for any `list` argument and convert those using `Tuple(*list_arg)`.

Hints from issue discussion:
Alternatively, since this is used very often, perhaps it is better to define a `TestBasic` class for the tests, which takes care of this in the class constructor
It is generally preferred to use `_sympify` rather than `sympify` but changing that everywhere would not be fully compatible. Is there a particular problem with Tuple and list arguments?
The issue is that it keeps them as lists, which are not `Basic`s 
```python
>>> from sympy import *
>>> type(Tuple([1]).args[0])
list
```
The proposed solution would give `Tuple([1]).args[0] == Tuple(S.One)`
My question is really: is that a behaviour that is depended upon somewhere and if so where?
The errors produced seem unrelated. I'm not sure if I made a mistake setting up the PR, or if the `TypeError` I am raising gets caught in try/except blocks
> The proposed solution would give `Tuple([1]).args[0]`

Maybe that's ok since we don't want a mutable as an argument so this is the only thing we can legitimately do with a list argument. But what if there is a nested list as in `Tuple([1, 2, [3, 4]])`? Or `Tuple([1,2],3)` -- raise an error? Note:
```python
>>> t=Tuple((1,2),3)
>>> type(t.args[0]) is Tuple
True
```

If any argument would be a `list`, it would be converted to `Tuple(*list)`, so that way it should be handled recursively, although I might be missing some case. I'll make sure to add tests such that `list` and `tuple` arguments are handled equivalently.

The linked PR now correctly hows where the issues are @oscarbenjamin 


I guess part of the problem is the fact that `sympify` (as opposed to `_sympify` also handles lists so is not guaranteed to return Basic but many places that should use `_sympify` use `sympify` instead.
The problem with `Tuple` specifically is not that it isn't guaranteed to have `Basic`s, but there are actually examples that are ran during the tests that have this happening.
<details>
<summary> errors found when not allowing `list` in `Tuple` </summary>

```
________________________________________________________________________________
____________ sympy/core/tests/test_diff.py:test_diff_nth_derivative ____________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/core/tests/test_diff.py", line 152, in test_diff_nth_derivative
    assert (cos(x)*sin(y)).diff([[x, y, z]]) == NDimArray([
  File "/home/runner/work/sympy/sympy/sympy/core/expr.py", line 3544, in diff
    return _derivative_dispatch(self, *symbols, **assumptions)
  File "/home/runner/work/sympy/sympy/sympy/core/function.py", line 1920, in _derivative_dispatch
    return ArrayDerivative(expr, *variables, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/tensor/array/array_derivatives.py", line 19, in __new__
    obj = super().__new__(cls, expr, *variables, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/core/function.py", line 1273, in __new__
    variables = list(sympify(variables))
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [[x, y, z]]
________________________________________________________________________________
___________ sympy/core/tests/test_function.py:test_Derivative__new__ ___________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/core/tests/test_function.py", line 1334, in test_Derivative__new__
    assert f(x, y).diff([(x, y), 0]) == f(x, y)
  File "/home/runner/work/sympy/sympy/sympy/core/expr.py", line 3544, in diff
    return _derivative_dispatch(self, *symbols, **assumptions)
  File "/home/runner/work/sympy/sympy/sympy/core/function.py", line 1920, in _derivative_dispatch
    return ArrayDerivative(expr, *variables, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/tensor/array/array_derivatives.py", line 19, in __new__
    obj = super().__new__(cls, expr, *variables, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/core/function.py", line 1273, in __new__
    variables = list(sympify(variables))
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [(x, y), 0]
________________________________________________________________________________
__________ sympy/matrices/tests/test_matrices.py:test_diff_by_matrix ___________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/matrices/tests/test_matrices.py", line 1977, in test_diff_by_matrix
    dB = B.diff([[a, b]])
  File "/home/runner/work/sympy/sympy/sympy/matrices/matrices.py", line 470, in diff
    deriv = ArrayDerivative(self, *args, evaluate=True)
  File "/home/runner/work/sympy/sympy/sympy/tensor/array/array_derivatives.py", line 19, in __new__
    obj = super().__new__(cls, expr, *variables, **kwargs)
  File "/home/runner/work/sympy/sympy/sympy/core/function.py", line 1273, in __new__
    variables = list(sympify(variables))
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [[a, b]]
________________________________________________________________________________
______________ sympy/printing/tests/test_julia.py:test_containers ______________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/printing/tests/test_julia.py", line 215, in test_containers
    assert julia_code((1, eye(3), Matrix(0, 0, []), [])) == "(1, [1 0 0;\n0 1 0;\n0 0 1], zeros(0, 0), Any[])"
  File "/home/runner/work/sympy/sympy/sympy/printing/julia.py", line 626, in julia_code
    return JuliaCodePrinter(settings).doprint(expr, assign_to)
  File "/home/runner/work/sympy/sympy/sympy/printing/codeprinter.py", line 137, in doprint
    expr = _handle_assign_to(expr, assign_to)
  File "/home/runner/work/sympy/sympy/sympy/printing/codeprinter.py", line 122, in _handle_assign_to
    return sympify(expr)
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: []
________________________________________________________________________________
______________ sympy/printing/tests/test_maple.py:test_containers ______________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/printing/tests/test_maple.py", line 237, in test_containers
    assert maple_code((1, eye(3), Matrix(0, 0, []), [])) == \
  File "/home/runner/work/sympy/sympy/sympy/printing/maple.py", line 295, in maple_code
    return MapleCodePrinter(settings).doprint(expr, assign_to)
  File "/home/runner/work/sympy/sympy/sympy/printing/codeprinter.py", line 137, in doprint
    expr = _handle_assign_to(expr, assign_to)
  File "/home/runner/work/sympy/sympy/sympy/printing/codeprinter.py", line 122, in _handle_assign_to
    return sympify(expr)
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: []
________________________________________________________________________________
_____________ sympy/printing/tests/test_octave.py:test_containers ______________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/printing/tests/test_octave.py", line 284, in test_containers
    assert mcode((1, eye(3), Matrix(0, 0, []), [])) == "{1, [1 0 0; 0 1 0; 0 0 1], [], {}}"
  File "/home/runner/work/sympy/sympy/sympy/printing/octave.py", line 709, in octave_code
    return OctaveCodePrinter(settings).doprint(expr, assign_to)
  File "/home/runner/work/sympy/sympy/sympy/printing/codeprinter.py", line 137, in doprint
    expr = _handle_assign_to(expr, assign_to)
  File "/home/runner/work/sympy/sympy/sympy/printing/codeprinter.py", line 122, in _handle_assign_to
    return sympify(expr)
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: []
________________________________________________________________________________
____________ sympy/printing/tests/test_tableform.py:test_TableForm _____________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/printing/tests/test_tableform.py", line 13, in test_TableForm
    s = str(TableForm([["a", "b"], ["c", "d"], ["e", 0]],
  File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
    _lines = Tuple(*data)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [a, b]
________________________________________________________________________________
_________ sympy/printing/tests/test_tableform.py:test_TableForm_latex __________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/printing/tests/test_tableform.py", line 104, in test_TableForm_latex
    s = latex(TableForm([[0, x**3], ["c", S.One/4], [sqrt(x), sin(x**2)]],
  File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
    _lines = Tuple(*data)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [0, x**3]
________________________________________________________________________________
________________ sympy/simplify/tests/test_cse.py:test_cse_list ________________
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/simplify/tests/test_cse.py", line 588, in test_cse_list
    assert _cse(c(it)) == ([], c(it))
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [x]
________________________________________________________________________________
____ sympy/stats/tests/test_stochastic_process.py:test_DiscreteMarkovChain _____
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/stats/tests/test_stochastic_process.py", line 140, in test_DiscreteMarkovChain
    assert Y3.fundamental_matrix() == ImmutableMatrix([[176, 81, -132], [36, 141, -52], [-44, -39, 208]])/125
  File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1110, in fundamental_matrix
    _, _, _, Q = self.decompose()
  File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1351, in decompose
    classes = self.communication_classes()
  File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1096, in communication_classes
    return sympify(list(zip(classes, recurrence, periods)))
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in sympify
    return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in <listcomp>
    return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [0, 1, 2]
________________________________________________________________________________
 sympy/tensor/array/tests/test_array_comprehension.py:test_array_comprehension _
Traceback (most recent call last):
  File "/home/runner/work/sympy/sympy/sympy/tensor/array/tests/test_array_comprehension.py", line 44, in test_array_comprehension
    raises(TypeError, lambda: ArrayComprehension(i*j, (i, 1, 3), (j, 2, [1, 3, 2])))
  File "/home/runner/work/sympy/sympy/sympy/testing/pytest.py", line 110, in raises
    code()
  File "/home/runner/work/sympy/sympy/sympy/tensor/array/tests/test_array_comprehension.py", line 44, in <lambda>
    raises(TypeError, lambda: ArrayComprehension(i*j, (i, 1, 3), (j, 2, [1, 3, 2])))
  File "/home/runner/work/sympy/sympy/sympy/tensor/array/array_comprehension.py", line 41, in __new__
    arglist.extend(cls._check_limits_validity(function, symbols))
  File "/home/runner/work/sympy/sympy/sympy/tensor/array/array_comprehension.py", line 228, in _check_limits_validity
    limits = sympify(limits)
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 53, in __new__
    args = tuple((sympify(arg) for arg in args))
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 53, in <genexpr>
    args = tuple((sympify(arg) for arg in args))
  File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
    return conv(a)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
    converter[tuple] = lambda tup: Tuple(*tup)
  File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
    warnings.warn( DeprecationWarning(msg))
DeprecationWarning: Tuple should not contain list as arguments: [1, 3, 2]
```
```
 ________________________________________________________________________________
_________________ sympy.printing.tableform.TableForm._sympystr _________________
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 250, in sympy.printing.tableform.TableForm._sympystr
Failed example:
    t = TableForm([[5, 7], [4, 2], [10, 3]])
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm._sympystr[1]>", line 1, in <module>
        t = TableForm([[5, 7], [4, 2], [10, 3]])
      File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
        _lines = Tuple(*data)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [5, 7]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 251, in sympy.printing.tableform.TableForm._sympystr
Failed example:
    s = t.as_str()
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm._sympystr[2]>", line 1, in <module>
        s = t.as_str()
    NameError: name 't' is not defined
________________________________________________________________________________
_________________ sympy.printing.tableform.TableForm.as_matrix _________________
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 218, in sympy.printing.tableform.TableForm.as_matrix
Failed example:
    t = TableForm([[5, 7], [4, 2], [10, 3]], headings='automatic')
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm.as_matrix[1]>", line 1, in <module>
        t = TableForm([[5, 7], [4, 2], [10, 3]], headings='automatic')
      File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
        _lines = Tuple(*data)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [5, 7]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 219, in sympy.printing.tableform.TableForm.as_matrix
Failed example:
    t
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm.as_matrix[2]>", line 1, in <module>
        t
    NameError: name 't' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 225, in sympy.printing.tableform.TableForm.as_matrix
Failed example:
    t.as_matrix()
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm.as_matrix[3]>", line 1, in <module>
        t.as_matrix()
    NameError: name 't' is not defined
________________________________________________________________________________
_________________ sympy.printing.tableform.TableForm.__init__ __________________
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 101, in sympy.printing.tableform.TableForm.__init__
Failed example:
    TableForm([[5, 7], [4, 2], [10, 3]])
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm.__init__[1]>", line 1, in <module>
        TableForm([[5, 7], [4, 2], [10, 3]])
      File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
        _lines = Tuple(*data)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [5, 7]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 105, in sympy.printing.tableform.TableForm.__init__
Failed example:
    TableForm([list('.'*i) for i in range(1, 4)], headings='automatic')
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm.__init__[2]>", line 1, in <module>
        TableForm([list('.'*i) for i in range(1, 4)], headings='automatic')
      File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
        _lines = Tuple(*data)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [.,  ,  ]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 111, in sympy.printing.tableform.TableForm.__init__
Failed example:
    TableForm([[Symbol('.'*(j if not i%2 else 1)) for i in range(3)]
               for j in range(4)], alignments='rcl')
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm.__init__[3]>", line 1, in <module>
        TableForm([[Symbol('.'*(j if not i%2 else 1)) for i in range(3)]
      File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
        _lines = Tuple(*data)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [, ., ]
________________________________________________________________________________
______________________ sympy.printing.tableform.TableForm ______________________
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 17, in sympy.printing.tableform.TableForm
Failed example:
    t = TableForm([[5, 7], [4, 2], [10, 3]])
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm[1]>", line 1, in <module>
        t = TableForm([[5, 7], [4, 2], [10, 3]])
      File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
        _lines = Tuple(*data)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [5, 7]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 18, in sympy.printing.tableform.TableForm
Failed example:
    print(t)
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm[2]>", line 1, in <module>
        print(t)
    NameError: name 't' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 26, in sympy.printing.tableform.TableForm
Failed example:
    print(t.as_latex())
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.printing.tableform.TableForm[3]>", line 1, in <module>
        print(t.as_latex())
    NameError: name 't' is not defined
________________________________________________________________________________
________________________ sympy.utilities.misc.rawlines _________________________
File "/home/runner/work/sympy/sympy/sympy/utilities/misc.py", line 104, in sympy.utilities.misc.rawlines
Failed example:
    s = str(TableForm([[1, 10]], headings=(None, ['a', 'bee'])))
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.utilities.misc.rawlines[2]>", line 1, in <module>
        s = str(TableForm([[1, 10]], headings=(None, ['a', 'bee'])))
      File "/home/runner/work/sympy/sympy/sympy/printing/tableform.py", line 147, in __init__
        _lines = Tuple(*data)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [1, 10]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/utilities/misc.py", line 105, in sympy.utilities.misc.rawlines
Failed example:
    print(rawlines(s))
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.utilities.misc.rawlines[3]>", line 1, in <module>
        print(rawlines(s))
    NameError: name 's' is not defined
________________________________________________________________________________
___ sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form ____
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1406, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    states, new_matrix = X.canonical_form()
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[4]>", line 1, in <module>
        states, new_matrix = X.canonical_form()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1468, in canonical_form
        states, A, B, C = self.decompose()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1351, in decompose
        classes = self.communication_classes()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1096, in communication_classes
        return sympify(list(zip(classes, recurrence, periods)))
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in sympify
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in <listcomp>
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
        return conv(a)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
        converter[tuple] = lambda tup: Tuple(*tup)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [3]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1407, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    states
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[5]>", line 1, in <module>
        states
    NameError: name 'states' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1410, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    new_matrix
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[6]>", line 1, in <module>
        new_matrix
    NameError: name 'new_matrix' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1423, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    X = DiscreteMarkovChain('X', states, new_matrix)
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[7]>", line 1, in <module>
        X = DiscreteMarkovChain('X', states, new_matrix)
    NameError: name 'states' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1424, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    states, new_matrix = X.canonical_form()
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[8]>", line 1, in <module>
        states, new_matrix = X.canonical_form()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1468, in canonical_form
        states, A, B, C = self.decompose()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1351, in decompose
        classes = self.communication_classes()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1096, in communication_classes
        return sympify(list(zip(classes, recurrence, periods)))
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in sympify
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in <listcomp>
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
        return conv(a)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
        converter[tuple] = lambda tup: Tuple(*tup)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [3]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1425, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    states
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[9]>", line 1, in <module>
        states
    NameError: name 'states' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1428, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    new_matrix
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[10]>", line 1, in <module>
        new_matrix
    NameError: name 'new_matrix' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1444, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    states, new_matrix = X.canonical_form()
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[13]>", line 1, in <module>
        states, new_matrix = X.canonical_form()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1468, in canonical_form
        states, A, B, C = self.decompose()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1351, in decompose
        classes = self.communication_classes()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1096, in communication_classes
        return sympify(list(zip(classes, recurrence, periods)))
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in sympify
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in <listcomp>
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
        return conv(a)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
        converter[tuple] = lambda tup: Tuple(*tup)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [1, 3]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1445, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    states
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[14]>", line 1, in <module>
        states
    NameError: name 'states' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1448, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form
Failed example:
    new_matrix
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.canonical_form[15]>", line 1, in <module>
        new_matrix
    NameError: name 'new_matrix' is not defined
________________________________________________________________________________
______ sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose ______
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1310, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose
Failed example:
    states, A, B, C = X.decompose()
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose[4]>", line 1, in <module>
        states, A, B, C = X.decompose()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1351, in decompose
        classes = self.communication_classes()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1096, in communication_classes
        return sympify(list(zip(classes, recurrence, periods)))
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in sympify
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in <listcomp>
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
        return conv(a)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
        converter[tuple] = lambda tup: Tuple(*tup)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [2]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1311, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose
Failed example:
    states
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose[5]>", line 1, in <module>
        states
    NameError: name 'states' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1314, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose
Failed example:
    A   # recurrent to recurrent
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose[6]>", line 1, in <module>
        A   # recurrent to recurrent
    NameError: name 'A' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1317, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose
Failed example:
    B  # transient to recurrent
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose[7]>", line 1, in <module>
        B  # transient to recurrent
    NameError: name 'B' is not defined
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1324, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose
Failed example:
    C  # transient to transient
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.decompose[8]>", line 1, in <module>
        C  # transient to transient
    NameError: name 'C' is not defined
________________________________________________________________________________
 sympy.stats.stochastic_process_types.DiscreteMarkovChain.communication_classes 
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 995, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.communication_classes
Failed example:
    classes = X.communication_classes()
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.communication_classes[4]>", line 1, in <module>
        classes = X.communication_classes()
      File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 1096, in communication_classes
        return sympify(list(zip(classes, recurrence, periods)))
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in sympify
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 442, in <listcomp>
        return type(a)([sympify(x, locals=locals, convert_xor=convert_xor,
      File "/home/runner/work/sympy/sympy/sympy/core/sympify.py", line 366, in sympify
        return conv(a)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 152, in <lambda>
        converter[tuple] = lambda tup: Tuple(*tup)
      File "/home/runner/work/sympy/sympy/sympy/core/containers.py", line 57, in __new__
        warnings.warn( DeprecationWarning(msg))
    DeprecationWarning: Tuple should not contain list as arguments: [1, 2]
**********************************************************************
File "/home/runner/work/sympy/sympy/sympy/stats/stochastic_process_types.py", line 996, in sympy.stats.stochastic_process_types.DiscreteMarkovChain.communication_classes
Failed example:
    for states, is_recurrent, period in classes:
        states, is_recurrent, period
Exception raised:
    Traceback (most recent call last):
      File "/opt/hostedtoolcache/Python/3.9.9/x64/lib/python3.9/doctest.py", line 1334, in __run
        exec(compile(example.source, filename, "single",
      File "<doctest sympy.stats.stochastic_process_types.DiscreteMarkovChain.communication_classes[5]>", line 1, in <module>
        for states, is_recurrent, period in classes:
    NameError: name 'classes' is not defined

```
</summary>

Commit message: removed misuses of sympify that would create Tuples with non-Basic argument

Patch to review:
diff --git a/sympy/core/containers.py b/sympy/core/containers.py
index 2c6a7721b09c..f3f8a89662ca 100644
--- a/sympy/core/containers.py
+++ b/sympy/core/containers.py
@@ -14,7 +14,7 @@
 from .sympify import _sympify, sympify, converter, SympifyError
 from sympy.utilities.iterables import iterable
 from sympy.utilities.misc import as_int
-
+import warnings
 
 class Tuple(Basic):
     """
@@ -50,6 +50,12 @@ class Tuple(Basic):
     def __new__(cls, *args, **kwargs):
         if kwargs.get('sympify', True):
             args = (sympify(arg) for arg in args)
+        #if kwargs.get('denest_lists', False):
+        #    args = (Tuple(*arg) if isinstance(arg, list) else arg for arg in args)
+        args = tuple(args)
+        for arg in args:
+            if isinstance(arg, list):
+                warnings.warn(DeprecationWarning('Tuple',arg))
         obj = Basic.__new__(cls, *args)
         return obj
 
diff --git a/sympy/core/function.py b/sympy/core/function.py
index bb4ae3a6e06a..01dc55eb4944 100644
--- a/sympy/core/function.py
+++ b/sympy/core/function.py
@@ -1270,7 +1270,7 @@ def __new__(cls, expr, *variables, **kwargs):
                         must be supplied to differentiate %s''' % expr))
 
         # Standardize the variables by sympifying them:
-        variables = list(sympify(variables))
+        #variables = sympify(list(variables))
 
         # Split the list of variables into a list of the variables we are diff
         # wrt, where each element of the list has the form (s, count) where
@@ -1278,11 +1278,12 @@ def __new__(cls, expr, *variables, **kwargs):
         # derivative.
         variable_count = []
         array_likes = (tuple, list, Tuple)
+        integer_likes = (int, Integer)
 
         from sympy.tensor.array import Array, NDimArray
 
         for i, v in enumerate(variables):
-            if isinstance(v, Integer):
+            if isinstance(v, integer_likes):
                 if i == 0:
                     raise ValueError("First variable cannot be a number: %i" % v)
                 count = v
diff --git a/sympy/core/tests/test_containers.py b/sympy/core/tests/test_containers.py
index c598af7eda0f..a8070251e32e 100644
--- a/sympy/core/tests/test_containers.py
+++ b/sympy/core/tests/test_containers.py
@@ -42,6 +42,10 @@ def test_Tuple():
     assert Tuple.fromiter(x for x in range(4)) == Tuple(0, 1, 2, 3)
     assert st2.fromiter(st2.args) == st2
 
+    #see issue 22550
+    assert Tuple([1, 2, [3, 4]]) == Tuple(Tuple(1, 2, Tuple(3, 4)))
+    assert Tuple([1, 2], 3) == Tuple(Tuple(1, 2), 3)
+
 
 def test_Tuple_contains():
     t1, t2 = Tuple(1), Tuple(2)
diff --git a/sympy/printing/tableform.py b/sympy/printing/tableform.py
index c102ffe7f556..8d39285a4758 100644
--- a/sympy/printing/tableform.py
+++ b/sympy/printing/tableform.py
@@ -144,7 +144,7 @@ def __init__(self, data, **kwarg):
                         lj = Symbol(str(lj))
                 line[j] = lj
             data[i] = line
-        _lines = Tuple(*data)
+        _lines = Tuple(*[Tuple(*d) for d in data])
 
         headings = kwarg.get("headings", [None, None])
         if headings == "automatic":
diff --git a/sympy/printing/tests/test_julia.py b/sympy/printing/tests/test_julia.py
index e0e13f9257d7..c9a39151fc16 100644
--- a/sympy/printing/tests/test_julia.py
+++ b/sympy/printing/tests/test_julia.py
@@ -212,7 +212,8 @@ def test_containers():
     assert julia_code(Tuple(*[1, 2, 3])) == "(1, 2, 3)"
     assert julia_code((1, x*y, (3, x**2))) == "(1, x.*y, (3, x.^2))"
     # scalar, matrix, empty matrix and empty list
-    assert julia_code((1, eye(3), Matrix(0, 0, []), [])) == "(1, [1 0 0;\n0 1 0;\n0 0 1], zeros(0, 0), Any[])"
+    from sympy.codegen.pynodes import List
+    assert julia_code((1, eye(3), Matrix(0, 0, []), List())) == "(1, [1 0 0;\n0 1 0;\n0 0 1], zeros(0, 0), Any[])"
 
 
 def test_julia_noninline():
diff --git a/sympy/printing/tests/test_maple.py b/sympy/printing/tests/test_maple.py
index 337a6320930d..9435cab91e7b 100644
--- a/sympy/printing/tests/test_maple.py
+++ b/sympy/printing/tests/test_maple.py
@@ -233,8 +233,8 @@ def test_containers():
     assert maple_code(Tuple(*[1, 2, 3])) == "[1, 2, 3]"
     assert maple_code((1, x * y, (3, x ** 2))) == "[1, x*y, [3, x^2]]"
     # scalar, matrix, empty matrix and empty list
-
-    assert maple_code((1, eye(3), Matrix(0, 0, []), [])) == \
+    from sympy.codegen.pynodes import List
+    assert maple_code((1, eye(3), Matrix(0, 0, []), List(*[]))) == \
            "[1, Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]], storage = rectangular), Matrix([], storage = rectangular), []]"
 
 
diff --git a/sympy/printing/tests/test_octave.py b/sympy/printing/tests/test_octave.py
index e0762b7580db..d1969ec9abf1 100644
--- a/sympy/printing/tests/test_octave.py
+++ b/sympy/printing/tests/test_octave.py
@@ -281,7 +281,8 @@ def test_containers():
     assert mcode(Tuple(*[1, 2, 3])) == "{1, 2, 3}"
     assert mcode((1, x*y, (3, x**2))) == "{1, x.*y, {3, x.^2}}"
     # scalar, matrix, empty matrix and empty list
-    assert mcode((1, eye(3), Matrix(0, 0, []), [])) == "{1, [1 0 0; 0 1 0; 0 0 1], [], {}}"
+    from sympy.codegen.pynodes import List
+    assert mcode((1, eye(3), Matrix(0, 0, []), List(*[]))) == "{1, [1 0 0; 0 1 0; 0 0 1], [], {}}"
 
 
 def test_octave_noninline():
diff --git a/sympy/simplify/tests/test_cse.py b/sympy/simplify/tests/test_cse.py
index efb39bc2d3ea..eb9cc231316b 100644
--- a/sympy/simplify/tests/test_cse.py
+++ b/sympy/simplify/tests/test_cse.py
@@ -584,8 +584,10 @@ def test_cse_list():
     assert _cse(x) == ([], x)
     assert _cse('x') == ([], 'x')
     it = [x]
-    for c in (list, tuple, set, Tuple):
+    for c in (list, tuple, set):
         assert _cse(c(it)) == ([], c(it))
+    #Tuple works different from tuple:
+    assert _cse(Tuple(*it)) == ([], Tuple(*it))
     d = {x: 1}
     assert _cse(d) == ([], d)
 
diff --git a/sympy/stats/stochastic_process_types.py b/sympy/stats/stochastic_process_types.py
index ab5f934d0d61..5ea0bd658437 100644
--- a/sympy/stats/stochastic_process_types.py
+++ b/sympy/stats/stochastic_process_types.py
@@ -995,8 +995,8 @@ def communication_classes(self) -> tList[tTuple[tList[Basic], Boolean, Integer]]
         >>> classes = X.communication_classes()
         >>> for states, is_recurrent, period in classes:
         ...     states, is_recurrent, period
-        ([1, 2], True, 2)
-        ([3], False, 1)
+        ((1, 2), True, 2)
+        ((3,), False, 1)
 
         From this we can see that states ``1`` and ``2``
         communicate, are recurrent and have a period
@@ -1091,9 +1091,8 @@ def communication_classes(self) -> tList[tTuple[tList[Basic], Boolean, Integer]]
             # end breadth-first search
 
         # convert back to the user's state names
-        classes = [[self._state_index[i] for i in class_] for class_ in classes]
-
-        return sympify(list(zip(classes, recurrence, periods)))
+        classes = [[_sympify(self._state_index[i]) for i in class_] for class_ in classes]
+        return list(zip(classes, recurrence, map(Integer,periods)))
 
     def fundamental_matrix(self):
         """
diff --git a/sympy/tensor/array/array_comprehension.py b/sympy/tensor/array/array_comprehension.py
index 9498ea7f9f07..cd960c7c37ea 100644
--- a/sympy/tensor/array/array_comprehension.py
+++ b/sympy/tensor/array/array_comprehension.py
@@ -1,7 +1,7 @@
 import functools, itertools
-from sympy.core.sympify import sympify
+from sympy.core.sympify import _sympify, sympify
 from sympy.core.expr import Expr
-from sympy.core import Basic
+from sympy.core import Basic, Tuple
 from sympy.tensor.array import ImmutableDenseNDimArray
 from sympy.core.symbol import Symbol
 from sympy.core.numbers import Integer
@@ -225,8 +225,18 @@ def __len__(self):
 
     @classmethod
     def _check_limits_validity(cls, function, limits):
-        limits = sympify(limits)
+        #limits = sympify(limits)
+        new_limits = []
         for var, inf, sup in limits:
+            var = _sympify(var)
+            inf = _sympify(inf)
+            #since this is stored as an argument, it should be
+            #a Tuple
+            if isinstance(sup, list):
+                sup = Tuple(*sup)
+            else:
+                sup = _sympify(sup)                
+            new_limits.append(Tuple(var, inf, sup))
             if any((not isinstance(i, Expr)) or i.atoms(Symbol, Integer) != i.atoms()
                                                                 for i in [inf, sup]):
                 raise TypeError('Bounds should be an Expression(combination of Integer and Symbol)')
@@ -234,7 +244,7 @@ def _check_limits_validity(cls, function, limits):
                 raise ValueError('Lower bound should be inferior to upper bound')
             if var in inf.free_symbols or var in sup.free_symbols:
                 raise ValueError('Variable should not be part of its bounds')
-        return limits
+        return new_limits
 
     @classmethod
     def _calculate_shape_from_limits(cls, limits):


Code review comments:
diff_hunk: @@ -1270,19 +1270,20 @@ def __new__(cls, expr, *variables, **kwargs):
                         must be supplied to differentiate %s''' % expr))
 
         # Standardize the variables by sympifying them:
-        variables = list(sympify(variables))
+        #variables = sympify(list(variables))
path: sympy/core/function.py
text: @author:
This is actually not needed here since all variables are eventually stored in `Tuple` (or `Array` which again stores it in `Tuple`) where `sympify` is also used.

@user1:
Maybe this should just be deleted.