pxt icon indicating copy to clipboard operation
pxt copied to clipboard

Help text for Python seems to be incorrect?

Open jaydeetay opened this issue 4 years ago • 0 comments

Python Help Text

Describe the bug https://github.com/microsoft/pxt/blob/master/common-docs/python/classes.md

seems to have a few inaccuracies. I original filed a PR to fix them, but alas I have to withdraw it as my company doesn't allow me to sign the CLA - sorry about that!

I'm no Python expert, so let me know if I have this wrong, but...

  • Several classes have members defined like greeting = "". These are static members, so they're actually not getting used by the constructor and the greet method. They can be removed.
  • The discussion on public/private/protected isn't quite right. There's nothing stopping you accessing any of the members in Python. The only thing is that prepending __ causes the name to be mangled so you have to do __ClassName__method. The use of _ for protected and __ for private is just a convention. The error message in the comment # Error: 'name' is private isn't right. Firstly it should be Animal("Cat").__name and secondly the error will be "object has no attribute __name" or something similar.
  • The section on structural typing isn't right I think. As as far as I know there's no reason why you can't assign the value of employee to animal. It's just a reference and is dynamically typed. [Or have I misunderstood and is Microbit Python a little 'non-standard' due to it needing to convert to/from JS? I've tried to test out the code in MakeCode but have been running into issues like https://github.com/microsoft/pxt-microbit/issues/4201]

To Reproduce N/A

Expected behavior N/A Screenshots image

Desktop (please complete the following information): N/A

Smartphone (please complete the following information): N/A

Additional context N/A

jaydeetay avatar Jun 18 '21 16:06 jaydeetay