Skip to content

[gyb] check isinstance(result, basestring) before string comparison #7324

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 10, 2017

Conversation

toffaletti
Copy link
Contributor

Guard against types that override __eq__ and do things like
raise TypeError when the types being compared don't match.

@CodaFi
Copy link
Contributor

CodaFi commented Feb 8, 2017

@swift-ci please python lint.

@toffaletti
Copy link
Contributor Author

@swift-ci Please smoke test

@toffaletti
Copy link
Contributor Author

PyLint failures unrelated to this change.

@hughbe
Copy link
Contributor

hughbe commented Feb 8, 2017

I'll open a PR fixing the python-lint issues by the way, just claiming that :D

@CodaFi
Copy link
Contributor

CodaFi commented Feb 8, 2017

@toffaletti Looks like you don't have your collaborator bit, so CI has to be done by somebody else

@swift-ci please smoke test

@@ -716,7 +716,8 @@ def execute(self, context):

# If we got a result, the code was an expression, so append
# its value
if result is not None and result != '':
if result is not None \
or (isinstance(result, basestring) and result != ''):
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work in Python 3. I think we try to make all the python code compatible with both.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm pretty sure gyb would require a lot of changes to work with python3, but do you have a preferred solution?

http://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiousity I just ran gyb.py --verbose-test with both python and python3. Both succeeded. Which is a bit surprising since doctests contain a lot of print x statements. Anyhow, this looks alright.

Copy link
Contributor Author

@toffaletti toffaletti Feb 10, 2017

Choose a reason for hiding this comment

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

Done. I'm surprised too, pleasantly. The utils/gyb file explicitly referencing python2.7 and discussion in #1535 threw me off. I guess I also expected to see unicode_literals imported if the code was trying to be Python 3 ready, and didn't really pay attention to the rest of the code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks!

Guard against types that override __eq__ and do things like
raise TypeError when the types being compared don't match.
@moiseev
Copy link
Contributor

moiseev commented Feb 10, 2017

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit aedf844 into swiftlang:master Feb 10, 2017
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.

5 participants