Skip to content

Using type() - fix examples to work, and demonstrate the principle. #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2020

Conversation

NickSto
Copy link
Contributor

@NickSto NickSto commented Dec 28, 2019

The existing example doesn't actually function as intended, and it doesn't really demonstrate the idea very well.

The reason stated for using isinstance() instead of comparing type()s is that isinstance() handles inheritance. So I'm not sure why the second example uses two unrelated classes Rectangle and Circle. The obvious choice is to use Rectangle and Square, as in this fix.

And I'm not sure what the idea was with the third example, either. The Rectangle object is not a ListType, and I'm not sure why one would think it is. So I changed it to be a repeat of the worst practice example, except using the best practice to compare.

@adewes adewes merged commit 0d6b417 into quantifiedcode:master Feb 28, 2020
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.

2 participants