Pip: Update %-format call to use str.format

Created on 4 Sep 2019  路  17Comments  路  Source: pypa/pip

What's the problem this feature will solve?

Currently in src/pip/_internal/operations/prepare.py, we use %-style string formatting.

Describe the solution you'd like

We should use the .format method for consistency with the rest of the code base.

We should also consider doing the same for the rest of the code base. Whoever takes care of this specific issue should make a general issue for that!

_Posted in its original form by @pradyunsg in #6968 (comment)_


This issue is a good starting point for anyone who wants to help out with pip's development -- it's simple and the process of fixing this should be a good introduction to pip's development workflow.

awaiting PR auto-locked maintenance

Most helpful comment

I do wonder if there's some way to make the format strings for logging calls to use the new-style formatting

The style parameter documented here allows this. But it's Python 3 only. Can we stop supporting Python 2 now, please? 馃檪

All 17 comments

I like simple.

As long as you are not expecting this yesterday, I'll be happy to take this.

馃憢 submitting PR now

is there a general issue? happy to do that too

All yours then @dyspop

FYI, to catch %-style string formatting in the code consider flake8-printf-formatting plugin for flake8.

Usage:

$ pip install flake8 flake8-printf-formatting
$ flake8 src/pip/_internal/operations/prepare.py --select=MOD
src/pip/_internal/operations/prepare.py:111:13: MOD001 do not use printf-style string formatting
src/pip/_internal/operations/prepare.py:147:21: MOD001 do not use printf-style string formatting
src/pip/_internal/operations/prepare.py:217:21: MOD001 do not use printf-style string formatting
src/pip/_internal/operations/prepare.py:249:21: MOD001 do not use printf-style string formatting
src/pip/_internal/operations/prepare.py:277:13: MOD001 do not use printf-style string formatting

following the https://github.com/pypa/pip/pull/6763#discussion_r321961775
/cc @pradyunsg

One clarification / caveat: we probably want to exclude logging calls from this change. I can provide reasons if desired.

@cjerdonek I agree -- https://github.com/pypa/pip/pull/6968#discussion_r320098782.

I do wonder if there's some way to make the format strings for logging calls to use the new-style formatting. Let's discuss in a new issue.

I do wonder if there's some way to make the format strings for logging calls to use the new-style formatting

The style parameter documented here allows this. But it's Python 3 only. Can we stop supporting Python 2 now, please? 馃檪

@pfmoore I wish. :(

I guess we could write a Formatter that would do this handling for us. It shouldn't be too difficult. Anyway, I opened #7009 for discussing this further.

Reopened since there's still more references of this.

Are there any reasons not to use f-strings ?

f-strings are not compatible with python 2.7 and 3.5.

Working on it.

I've done some work on this issue in the bugfix/6973-format-method branch. In that patch, I've also patched addressed two regressions introduced in the earlier work. I'm taking a break because this translation is a lot of work.

I've removed the good first issue label. Someone coming new to this issue has a lot of history to contend with.

Thanks everyone who's worked on this! ^>^

Could be related to this issue. I see now these logs on pip install ...:

Collecting pytest==3.8.2
  Downloading pytest-3.8.2-py2.py3-none-any.whl (209 kB)
     |鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅鈻堚枅| {downloaded} {download_speed} {pretty_eta}
Was this page helpful?
0 / 5 - 0 ratings