Skip to content

ListMultiplyViolation link is incorrect and explanation is misleading #2433

@niloatgoshare

Description

@niloatgoshare

Sorry for creating a blank ticket, but this is not a bug nor a new rule.

At the current version wemake_python_styleguide: 0.16.1 the documentation states, for rule WPS435, ListMultiplyViolation , the following:

When you multiply lists - it does not create new values, it creates references to the existing value. It is not what people mean in 99.9% of cases.

And that this block is wrong:

# Wrong:
my_list = [1, 2, 3] * 3

This explanation is incorrect. The example does create new values:

row = [1, 2, 3] 
mylist = row * 3
row[0] = 'X'
print(mylist)

This prints [1, 2, 3, 1, 2, 3, 1, 2, 3].

Moreover, the link with the explanation seems off.
Instead of
https://github.com/satwikkansal/wtfPython#-explanation-8

it seems like it should be:
https://github.com/satwikkansal/wtfPython#-a-tic-tac-toe-where-x-wins-in-the-first-attempt

I would suggest replacing the link and copying the example found there:

# Let's initialize a row
row = [""] * 3 #row i['', '', '']
# Let's make a board
board = [row] * 3
>>> board
[['', '', ''], ['', '', ''], ['', '', '']]
>>> board[0]
['', '', '']
>>> board[0][0]
''
>>> board[0][0] = "X"
>>> board
[['X', '', ''], ['X', '', ''], ['X', '', '']]

This would be a simple update in the documentation, maybe I could fix it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions