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
os.environ should inherit dict #46397
Comments
This patch changes os.environ to inherit builtin dict rather than UserDict. |
What's the rationale for this change? |
PEP-390. It's cleaner and faster. |
I still must be missing something. There is no PEP-390, AFAICT. |
Forgive me. I meant 290. |
Sorry, it still makes no sense. Up to r56113, PEP-290 doesn't seem to |
I know that it doesn't mention inheriting dict specifically, but you |
The performance gain is rather good: hsoft-dev:python hsoft$ ./python.exe -m "timeit" -s "import os" The regression tests still pass, and modernization of the code is a nice +1 |
Small comment on the patch: def clear(self):
- for key in self.data.keys():
+ for key in self.keys():
unsetenv(key)
- del self.data[key]
+ del self[key] It looks like the patched version will unsetenv twice, Change del self[key] to dict.__delitem__(self, key) +1 |
Here's a corrected version. |
See bpo-1367711 for a discussion whether this is really the way to go. |
And another. |
What was the rationale for this decision? To me it looks like a hold- I agree, this is a topic for python-ideas rather than bug-track, but if |
I reckon it's faster this way, and you want basic datatypes like dict to |
Can't find the original discussion right now, but one statement is at http://www.mailinglistarchive.com/python-dev@python.org/msg01728.html In essence, inheriting from dict is intentionally unspecified: if you |
The builtins make direct calls to their own internal methods. This has |
First, if the new thread on dict behavior does not make sense, please Second, the ability to subclass built-in type is such a great feature, Since there is so much resistance to making dict more subclass-friendly, |
Raymond, I guess bpo-2067 escaped your review. :-) |
Py3.0 updte: UserDict is going to survive into Py3.0 and will be moved I think the discussion here has grown far beyond the original bug I can't say that I support your "UserDict is a kludge ..." comment. FWIW, at one time I also thought all uses of UserDict would ultimately Will look at 1367711 as you suggest. |
Let's get back on-topic. I assume you are recommending to close this issue by rejecting the The patch has two distinct benefits: (1) UserDict is not loaded on BTW, one of the objections based on exec .. in os.environ behavior (see http://bugs.python.org/msg49131) has become invalid since then. Specific issues should of course be addressed. |
I also disagree that UserDict is a clutch, and that inheriting from dict Hence I'm rejecting this patch. To "appeal", please discuss on python-dev. |
Did anyone mention "clutch"? :-) Oh, well, please close bpo-1367711 as a duplicate. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: