Fix broken python method by RDIL · Pull Request #8821 · PowerShell/PowerShell · GitHub
Skip to content

Fix broken python method#8821

Merged
iSazonov merged 3 commits intoPowerShell:masterfrom
RDIL:patch-10
Feb 5, 2019
Merged

Fix broken python method#8821
iSazonov merged 3 commits intoPowerShell:masterfrom
RDIL:patch-10

Conversation

@RDIL
Copy link
Copy Markdown
Contributor

@RDIL RDIL commented Feb 3, 2019

PR Summary

this doesn’t work in python, the keyword is self.

PR Context

It needs to be fixed.

PR Checklist

@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Feb 4, 2019

@RDIL
Copy link
Copy Markdown
Contributor Author

RDIL commented Feb 4, 2019

@iSazonov what do you mean? I’m just fixing broken code in this PR.

@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Feb 4, 2019

I guess that the code worked on old Python version.
Perhaps we need to specify actual version in the doc.

@RDIL
Copy link
Copy Markdown
Contributor Author

RDIL commented Feb 4, 2019

The code clearly defines that the script should use a python 3.x.x version, but the this keyword hasn’t been a thing since the 2.5 series. I think it is time to update!

Copy link
Copy Markdown
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread demos/python/class1.py
Copy link
Copy Markdown
Collaborator

@rjmholt rjmholt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth noting that neither this nor self are keywords in Python; instance methods in Python pass the instance reference explicitly through the first parameter, and you can call that parameter whatever you like (you don't even need to be consistent):

class MyObject:
    def __init__(banana):
        banana.field = 10

    def get_field(truck):
         return truck.field

if __name__ == '__main__':
    print(MyObject().get_field()) # prints '10'

So this Python script would have run correctly using this.

However, self is the near-universal convention, and worth us aligning to that, especially in our examples. Thanks @RDIL!

@iSazonov iSazonov self-assigned this Feb 5, 2019
@iSazonov iSazonov added the CL-Docs Indicates that a PR should be marked as a documentation change in the Change Log label Feb 5, 2019
@iSazonov
Copy link
Copy Markdown
Collaborator

iSazonov commented Feb 5, 2019

@SteveL-MSFT Make sense to move this to Docs repo?

@iSazonov iSazonov merged commit bff73a3 into PowerShell:master Feb 5, 2019
@RDIL RDIL deleted the patch-10 branch February 5, 2019 12:32
@SteveL-MSFT
Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Docs Indicates that a PR should be marked as a documentation change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants