This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Don't use builtins as variable names in urllib.request
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: bbrazil, eric.araujo, martin.panter, michael.foord, orsenthil, r.david.murray, terry.reedy
Priority: normal Keywords: patch

Created on 2012-07-07 15:33 by bbrazil, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
urllib-request-cleanup-builtin-names.patch bbrazil, 2012-07-07 15:33 review
Messages (8)
msg164874 - (view) Author: Brian Brazil (bbrazil) * Date: 2012-07-07 15:33
See attached patch, there's still self.type in places. I also converted one map to a list comprehension.
msg165442 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-07-14 12:34
We don’t do code cleanups for their own sake, but rather as part of a bug fix or feature addition.  Please see #15137 for a longer explanation.
msg165444 - (view) Author: Brian Brazil (bbrazil) * Date: 2012-07-14 12:46
This patch is a result of frustration encountered when debugging #15002.
Not being able to use 'type' directly is rather annoying, so after figuring
that bug out I set some time aside to make it easier for the next person.

This could be considered a bug that urllib is hard to debug and breaks
vim's syntax highlighting.
msg165461 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-07-14 17:58
> Not being able to use 'type' directly is rather annoying, so after figuring that bug out I set
> some time aside to make it easier for the next person.
If you make a patch for #15002 then by all means rename “type” to “filetype” so that you can use the type function without jumping through hoops.  Or see if using isinstance can avoid the need for type.

Note that Python lets you override a built-in name, it’s only a PEP 8 convention that recommends to avoid doing so.  In many cases it makes a lot of sense to name something “type” (typically a class attribute), “file” (like in the print function in 3.x) or “open” (see tarfile, gzip, tokenize, etc.).

> This could be considered a bug that urllib is hard to debug
I don’t think so; we prefer keeping the code similar between branches so that patches are easier to port.

> and breaks vim's syntax highlighting.
I am a Vim user and think there are great things (like the fact that string delimiters are not highlighted as string contents) and debatable things (like the special color for self and built-in functions).

Your help with fixing bugs is very appreciated, but I think this patch will be rejected.
msg171430 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2012-09-28 10:36
Code cleanups for their own sake sound like a good thing, *iff* the cleanup is worthwhile (for example it makes debugging easier). i.e. the cleanup isn't "gratuitous" but worthwhile. 

This seems to be the case here and the rejected patch in issue #15137 had other (better) reasons to reject it as it stood.

Not accepting cleanups greatly limits the opportunity for our code base to improve.
msg171485 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2012-09-28 15:05
Well, here I don’t see the benefit in avoiding the use of “file”, given that the builtin of the same name is not needed thanks to the open function (contrary to id, type, str, string and others).

If you think our (unwritten?) policy of not doing cleanup-only commits is wrong, you could bring it up on a mailing list (maybe committers to avoid an endless thread).
msg252302 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-10-05 04:57
The name changes to the function parameters should be avoided without a good reason.

I would recommend rejecting all of the changes in this patch. They are basically changing one person’s coding style to another person’s style. I happen to prefer list() and map() over the list comprehension syntax.

I don’t have a problem with a variable named “type” in a small function. For instance, open_unknown() is only four lines, including signature and doc string! If you can’t easily predict all the variables in a larger function, then I suggest dividing it into smaller components. PEP 8 doesn’t seem to mention the issue of shadowing variable names that I can see anyway.
msg252304 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-10-05 05:29
I agree.  The one change that has a non-style motivation (type) is one that should not be made for backward compatibility reasons.
History
Date User Action Args
2022-04-11 14:57:32adminsetgithub: 59485
2015-10-05 05:29:27r.david.murraysetstatus: open -> closed
resolution: rejected
messages: + msg252304

stage: patch review -> resolved
2015-10-05 04:58:00martin.pantersetnosy: + martin.panter
messages: + msg252302

type: enhancement
stage: patch review
2012-09-28 15:05:14eric.araujosetmessages: + msg171485
2012-09-28 10:36:10michael.foordsetstatus: pending -> open
nosy: + michael.foord
messages: + msg171430

2012-07-14 17:58:58eric.araujosetstatus: open -> pending

messages: + msg165461
2012-07-14 12:46:59bbrazilsetmessages: + msg165444
2012-07-14 12:34:05eric.araujosetnosy: + terry.reedy, eric.araujo, r.david.murray
messages: + msg165442
2012-07-14 00:11:26terry.reedysetnosy: + orsenthil
2012-07-07 15:33:06bbrazilcreate