Skip to content

Remove confusing instance variable example in cheat sheet#15441

Merged
hauntsaninja merged 1 commit intopython:masterfrom
atallahade:fix_cheat_sheet
Jun 15, 2023
Merged

Remove confusing instance variable example in cheat sheet#15441
hauntsaninja merged 1 commit intopython:masterfrom
atallahade:fix_cheat_sheet

Conversation

@atallahade
Copy link
Copy Markdown
Contributor

The mypy cheat sheet documentation provides an example on how to type instance and class attributes. However, it shows that an attribute with a default value in the class body is an instance variable, and I don't think this is correct. I understand that strings are immutable, which makes the example valid in the end, but I don't believe this is a great practice to define instance variables with a value outside of the init method.

Please let me know if you disagree or would prefer to change the comment rather than deleting the example.

@ikonst
Copy link
Copy Markdown
Contributor

ikonst commented Jun 15, 2023

LGTM. I don't see any value in that example, and agree it's a dubious practice especially when people then carry it into mutable types.

@hauntsaninja hauntsaninja merged commit cfec717 into python:master Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants