Skip to content

Conversation

@trimbo
Copy link
Contributor

@trimbo trimbo commented Aug 26, 2019

We need to use portions of the runtime as part of the migration. Splitting out into a separate changelist should help expedite the work.

We need to use portions of the runtime as part of the migration.
Splitting out into a separate changelist shouold expedite the work.
@trimbo trimbo requested a review from nicksay August 26, 2019 22:33
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from third_party import six
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from third_party import six

# 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):
Copy link
Contributor

@nicksay nicksay Aug 28, 2019

Choose a reason for hiding this comment

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

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):

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
f_func = import_module_symbol(f_name)
f_func = import_module_symbol(template_fucntion_map[tname])

import logging
import weakref

from third_party.six.moves import builtins
Copy link
Contributor

@nicksay nicksay Aug 28, 2019

Choose a reason for hiding this comment

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

Suggested change
from third_party.six.moves import builtins
# Python3 moved "__builtin__" to "builtins".
try:
import builtins
except ImportError:
import __builtin__ as builtins

# a few helpful filter functions

import functools
import types
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import types
import sys
import types


from spitfire import runtime
from spitfire.runtime import udn
from third_party import six
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from third_party import six

"""Replace special characters '&', '<' and '>' by SGML entities."""
value = simple_str_filter(value)
if isinstance(value, basestring):
if isinstance(value, six.string_types):
Copy link
Contributor

Choose a reason for hiding this comment

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

simple_str_filter always calls str()

Suggested change
if isinstance(value, six.string_types):
if isinstance(value, str):

from spitfire.runtime import udn
from third_party import six


Copy link
Contributor

Choose a reason for hiding this comment

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

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)

"""Deprecated - use simple_str_filter instead."""
if isinstance(value, (str, unicode, int, long, float,
runtime.UndefinedPlaceholder)):
if isinstance(value, (str, six.text_type, float,
Copy link
Contributor

Choose a reason for hiding this comment

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

See above

Suggested change
if isinstance(value, (str, six.text_type, float,
if isinstance(value, SAFE_VALUE_TYPES):

if isinstance(value, (str, unicode, int, long, float,
runtime.UndefinedPlaceholder)):
if isinstance(value, (str, six.text_type, float,
runtime.UndefinedPlaceholder) + six.integer_types):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
runtime.UndefinedPlaceholder) + six.integer_types):

"""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,
Copy link
Contributor

Choose a reason for hiding this comment

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

See above

Suggested change
if isinstance(value, (str, unicode, float,
if isinstance(value, SAFE_VALUE_TYPES):

if isinstance(value, (str, unicode, int, long, float,
runtime.UndefinedPlaceholder)):
if isinstance(value, (str, unicode, float,
runtime.UndefinedPlaceholder) + six.integer_types):
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
runtime.UndefinedPlaceholder) + six.integer_types):

Copy link
Contributor

@nicksay nicksay left a comment

Choose a reason for hiding this comment

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

Suggestions to avoid needing six.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants