Skip to content
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

Fix broken python method #8821

Merged
merged 3 commits into from
Feb 5, 2019
Merged

Fix broken python method #8821

merged 3 commits into from
Feb 5, 2019

Conversation

RDIL
Copy link
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
Collaborator

iSazonov commented Feb 4, 2019

@RDIL Is this Python version related?

@RDIL
Copy link
Contributor Author

RDIL commented Feb 4, 2019

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

@iSazonov
Copy link
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
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
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

Copy link
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
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
Member

@iSazonov We may want to eventually have a doc page about interop with other languages, but we can keep this code here in this repo for now

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.

None yet

5 participants