Migrate some essential runtime files to Python 3#80
Open
trimbo wants to merge 1 commit intoyoutube:masterfrom
Open
Migrate some essential runtime files to Python 3#80trimbo wants to merge 1 commit intoyoutube:masterfrom
trimbo wants to merge 1 commit intoyoutube:masterfrom
Conversation
We need to use portions of the runtime as part of the migration. Splitting out into a separate changelist shouold expedite the work.
nicksay
reviewed
Aug 28, 2019
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
| from third_party import six |
Contributor
There was a problem hiding this comment.
Suggested change
| from third_party import six |
nicksay
reviewed
Aug 28, 2019
| # inject them into a module so they run as globals | ||
| def register_functions(module, template_function_map): | ||
| for t_name, f_name in template_function_map.iteritems(): | ||
| for t_name, f_name in six.iteritems(template_function_map): |
Contributor
There was a problem hiding this comment.
We can use the python2/python3 compatible iter(<map_value>) approach here (combined with next suggestion).
Suggested change
| for t_name, f_name in six.iteritems(template_function_map): | |
| for t_name in iter(template_function_map): |
nicksay
reviewed
Aug 28, 2019
| def register_functions(module, template_function_map): | ||
| for t_name, f_name in template_function_map.iteritems(): | ||
| for t_name, f_name in six.iteritems(template_function_map): | ||
| f_func = import_module_symbol(f_name) |
Contributor
There was a problem hiding this comment.
Suggested change
| f_func = import_module_symbol(f_name) | |
| f_func = import_module_symbol(template_fucntion_map[tname]) |
nicksay
reviewed
Aug 28, 2019
| import logging | ||
| import weakref | ||
|
|
||
| from third_party.six.moves import builtins |
Contributor
There was a problem hiding this comment.
Suggested change
| from third_party.six.moves import builtins | |
| # Python3 moved "__builtin__" to "builtins". | |
| try: | |
| import builtins | |
| except ImportError: | |
| import __builtin__ as builtins | |
nicksay
reviewed
Aug 28, 2019
| @@ -7,8 +7,10 @@ | |||
|
|
|||
| import functools | |||
| import types | |||
Contributor
There was a problem hiding this comment.
Suggested change
| import types | |
| import sys | |
| import types |
nicksay
reviewed
Aug 28, 2019
|
|
||
| from spitfire import runtime | ||
| from spitfire.runtime import udn | ||
| from third_party import six |
Contributor
There was a problem hiding this comment.
Suggested change
| from third_party import six |
nicksay
reviewed
Aug 28, 2019
| """Replace special characters '&', '<' and '>' by SGML entities.""" | ||
| value = simple_str_filter(value) | ||
| if isinstance(value, basestring): | ||
| if isinstance(value, six.string_types): |
Contributor
There was a problem hiding this comment.
simple_str_filter always calls str()
Suggested change
| if isinstance(value, six.string_types): | |
| if isinstance(value, str): |
nicksay
reviewed
Aug 28, 2019
| from spitfire.runtime import udn | ||
| from third_party import six | ||
|
|
||
|
|
Contributor
There was a problem hiding this comment.
Suggested change
| if sys.version_info[0] == 2 | |
| SAFE_VALUE_TYPES = (str, unicode, int, long, float, | |
| runtime.UndefinedPlaceholder) | |
| else: | |
| SAFE_VALUE_TYPES = (str, int, float, runtime.UndefinedPlaceholder) | |
nicksay
reviewed
Aug 28, 2019
| """Deprecated - use simple_str_filter instead.""" | ||
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, six.text_type, float, |
Contributor
There was a problem hiding this comment.
See above
Suggested change
| if isinstance(value, (str, six.text_type, float, | |
| if isinstance(value, SAFE_VALUE_TYPES): |
nicksay
reviewed
Aug 28, 2019
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, six.text_type, float, | ||
| runtime.UndefinedPlaceholder) + six.integer_types): |
Contributor
There was a problem hiding this comment.
Suggested change
| runtime.UndefinedPlaceholder) + six.integer_types): |
nicksay
reviewed
Aug 28, 2019
| """Return a string if the input type is something primitive.""" | ||
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, unicode, float, |
Contributor
There was a problem hiding this comment.
See above
Suggested change
| if isinstance(value, (str, unicode, float, | |
| if isinstance(value, SAFE_VALUE_TYPES): |
nicksay
reviewed
Aug 28, 2019
| if isinstance(value, (str, unicode, int, long, float, | ||
| runtime.UndefinedPlaceholder)): | ||
| if isinstance(value, (str, unicode, float, | ||
| runtime.UndefinedPlaceholder) + six.integer_types): |
Contributor
There was a problem hiding this comment.
Suggested change
| runtime.UndefinedPlaceholder) + six.integer_types): |
nicksay
suggested changes
Aug 28, 2019
Contributor
nicksay
left a comment
There was a problem hiding this comment.
Suggestions to avoid needing six.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We need to use portions of the runtime as part of the migration. Splitting out into a separate changelist should help expedite the work.