Navigation Menu

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

Convert iteritems() to items() #10105

Merged
merged 13 commits into from Jan 6, 2017
Merged

Convert iteritems() to items() #10105

merged 13 commits into from Jan 6, 2017

Conversation

srinivasreddy
Copy link
Contributor

No description provided.

@@ -172,9 +172,6 @@ def isidentifier(s, dotted=False):
return all(isidentifier(a) for a in s.split("."))
return s.isidentifier()

xrange = range
def iteritems(d): return iter(d.items())
def itervalues(d): return iter(d.values())
Copy link
Member

Choose a reason for hiding this comment

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

Be careful removing stuff, even if it's not used anywhere in IPython; we've had a couple of times before when we've removed things from IPython and then found that we're still using them in another module, like ipykernel.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a ton. Then i will keep this file as is. Will gradually change all projects references of module py3compat.py to py3 function calls, then i think about remove it.

@takluyver
Copy link
Member

Thanks! This is now quite a bit to review, so please hold any more changes for future PRs.

@srinivasreddy
Copy link
Contributor Author

Okay

@srinivasreddy
Copy link
Contributor Author

srinivasreddy commented Jan 3, 2017

@takluyver If you want me to divide this PR into smaller ones, please let me know. I will cherry-pick one after another. 😄

@@ -26,7 +26,7 @@ def get_pasted_lines(sentinel, l_input=py3compat.input, quiet=False):
prompt = ""
while True:
try:
l = py3compat.str_to_unicode(l_input(prompt))
Copy link
Member

Choose a reason for hiding this comment

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

str_to_unicode is a no-op on Python 3, and should be replaced with no call at all, rather than casting str to str.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -193,8 +192,8 @@ def log_write(self, data, kind='input'):
write = self.logfile.write
if kind=='input':
if self.timestamp:
write(str_to_unicode(time.strftime('# %a, %d %b %Y %H:%M:%S\n',
time.localtime())))
write(str(time.strftime('# %a, %d %b %Y %H:%M:%S\n',
Copy link
Member

Choose a reason for hiding this comment

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

The str here shouldn't be necessary, I think. str_to_unicode is a no-op on Python 3, because str is unicode.

@@ -138,7 +137,7 @@ def logstart(self, parameter_s=''):
for n in range(1,len(input_hist)-1):
log_write(input_hist[n].rstrip() + u'\n')
if n in output_hist:
log_write(str_to_unicode(repr(output_hist[n])),'output')
log_write(str(repr(output_hist[n])),'output')
Copy link
Member

Choose a reason for hiding this comment

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

Again, we shouldn't need the call to str.

vstr = unicode_type(var).encode(DEFAULT_ENCODING,
'backslashreplace')
vstr = var.encode(DEFAULT_ENCODING,
'backslashreplace')
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this except block can't happen any more under Python 3, but leave it for now; I'll double check that and work out if anything else is needed instead.

@@ -20,7 +20,7 @@ def __str__(self):
return str(self())

def __unicode__(self):
return py3compat.unicode_type(self())
return self.__str__()
Copy link
Member

Choose a reason for hiding this comment

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

The __unicode__ magic method is no longer used on Python 3, so we can get rid of it.

@@ -121,7 +121,7 @@ def test_list_profiles_in():
# No need to remove these directories and files, as they will get nuked in
# the module-level teardown.
td = tempfile.mkdtemp(dir=TMP_TEST_DIR)
td = py3compat.str_to_unicode(td)
td = str(td)
Copy link
Member

Choose a reason for hiding this comment

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

Again, we don't need to call str(). Here, we don't need the line at all.

@@ -87,7 +87,7 @@ def unquote_filename(name, win32=(sys.platform=='win32')):
def compress_user(path):
"""Reverse of :func:`os.path.expanduser`
"""
path = py3compat.unicode_to_str(path, sys.getfilesystemencoding())
path = str(path)
Copy link
Member

Choose a reason for hiding this comment

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

Same again.

@takluyver
Copy link
Member

I've looked through all the changes now; once the specific bits I pointed out are fixed, I think this will be ready. Thanks!

@takluyver takluyver added this to the 6.0 milestone Jan 6, 2017
@srinivasreddy
Copy link
Contributor Author

srinivasreddy commented Jan 6, 2017

@takluyver Done. Please feel free to squash, since some of the commit messages are not that helpful.

@takluyver
Copy link
Member

Thanks. I don't generally bother squashing unless someone has added/deleted a whole load of stuff and then undone it in a later commit.

@takluyver takluyver merged commit 748d707 into ipython:master Jan 6, 2017
@srinivasreddy srinivasreddy deleted the dead_code branch January 6, 2017 13:40
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.

None yet

3 participants