[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-17 Thread Brett Cannon
Brett Cannon added the comment: Paul, your attitude on this issue has unfortunately begun violating the PSF Code of Conduct which this issue tracker adheres to. I realize you're frustrated that the change you are after is not happening, but that doesn't mean you can deride others like you ha

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-17 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > We may be possible to replace bytecode from `STORE_GLOBAL _cnt; LOAD_GLOBAL > _cnt` into `DUP_TOP; STORE_GLOBAL _cnt`. Sounds good, and that's why I personally care about the "STORE" case, and the patch I submit touches only it, which would affect only ca

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-17 Thread STINNER Victor
STINNER Victor added the comment: As explained multiple times, this feature request is rejected. I close the issue. Paul: Your behavior is not appropriate and violates the Python code of conduct. You have already been warned by Pablo. -- resolution: -> rejected stage: test needed -

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-17 Thread Inada Naoki
Inada Naoki added the comment: > Ironically, to let people prototype better, more efficient ways to deal with > namespace access, it should be possible to override an object used as a > namespace. You can benchmark your prototype namespace object by regular Python code: d["name"] # LOAD_

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-17 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: Absolutely should be able to optimize namespace access. The fact that namespace is a dict is an implementation detail, it's still inefficient even with all those version counters and inline caches. Ironically, to let people prototype better, more efficient

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-17 Thread Inada Naoki
Inada Naoki added the comment: This is duplicate of #1402289, which was rejected. I agree with Victor. Python should be free to optimize namespace access. Namespace access is an implementation detail and user should not assume such "consistency" here. It is like this: x = 1000 y = x -

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Inada Naoki
Change by Inada Naoki : -- superseder: -> Allow mappings as globals (was: Fix dictionary subclass ...) ___ Python tracker ___ ___ P

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > exec() function is currently quite clear A recent case: https://bugs.python.org/issue38316, co_stacksize was quite clear what it is. Turned out, a bug in the documentation (likely, just someone forgot to update it to the actual code). That's just one case

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > Namespace performances are really critical for overall Python performances. Yeah, that's why I'd like for myself and other people to make it easy to explore the behavior of namespace lookups, to see how to optimize them. > You're free to fork Python and

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > Paul: you're are in front of 3 core developers who are rejecting your feature > request. But no, it's not my feature request. There were 2 tickets by at least 2 people. I just saw my case to be similar to cases of those people, so instead of creating dup

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > you ask to modify Python so you can pass dict subclasses as namespaces and > expect CPython to respect the mapping protocol But no, per your own account, you made noticeable, though not complete, code changes in that direction. The only thing I'm saying "

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread STINNER Victor
STINNER Victor added the comment: exec() function is currently quite clear on which types are accepted or not: exact dict for globals, mapping for locals. * "If only globals is provided, it must be a dictionary (and not a subclass of dictionary), which will be used for both the global and th

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread STINNER Victor
STINNER Victor added the comment: More detail about the implementation. Currently, namespaces are accessed directly with C functions which expect to get an exact dict type: these functions are designed for performance, not to handle dict subclasses, on purpose. Supporting dict subclasses fi

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread STINNER Victor
STINNER Victor added the comment: > Depends on the definition of "sandbox". In bpo-36220, it clearly means "execute untrusted code": hide access to the filesystem for example. > I for example interested in study of some properties of corpus of Python code. This issue is a feature request:

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: > IMHO we should reject dict subclasses to make Python (especially ceval.c) > more efficient. The global type must be checked at every place where it's > possible to specify or override globals. Like the exec() function. I agree with Victor in that we

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: Ok, so the patch for my usecase (STORE_GLOBAL) is vividly trivial, so to go thru the full circle, I posted it: https://github.com/python/cpython/pull/18033 . -- ___ Python tracker

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread ppperry
ppperry added the comment: I was not attempting to run untrusted Python code when I filed this bug report. -- ___ Python tracker ___ __

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Guido van Rossum
Change by Guido van Rossum : -- nosy: -gvanrossum ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: s/only our own usecase/only your own usecase/ (missing "y" typo) -- ___ Python tracker ___ ___ P

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-16 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > Later, I closed my pysandbox beause it was "broken by design": https://lwn.net/Articles/574215/ Thanks for the link, insightful. Still unclear, by design of what it's broken ;-). > Paul Sokolovsky wrote in bpo-36220 than his idea is also to implement a

[issue32615] Inconsistent behavior if globals is a dict subclass

2020-01-15 Thread STINNER Victor
STINNER Victor added the comment: I modified ceval.c to accept dict subclasses when I was working on PEP 416: https://www.python.org/dev/peps/pep-0416/ This PEP motivation was to implement a sandbox. The PEP was rejected. Later, I closed my pysandbox beause it was "broken by design": https://

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Guido van Rossum
Guido van Rossum added the comment: This is probably an issue for the new Steering Council. -- ___ Python tracker ___ ___ Python-bu

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Terry J. Reedy
Terry J. Reedy added the comment: There are more examples on duplicate #36220. -- ___ Python tracker ___ ___ Python-bugs-list maili

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Terry J. Reedy
Terry J. Reedy added the comment: Guido, some people would like manipulation and use of globals to work with dict subclasses as well as dicts themselves. I believe that the current restriction/optimization is at least partly your work. Do you have any quick opinion, or do you think discuss

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: > exec() params are already checked, as a seconds param, only dict or dict > subclasses are accepted. Seems like good enough contract. As I said, the documentation is considered the public API contract and again, the documentation says that dict subcl

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > I agree with Terry, the moment you pass a dict subclass to exec you are out > of contract. If any, we may need to sanitize the input to exec, although I > don't think is worth paying the performance price for that. exec() params are already checked, as a

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Pablo Galindo Salgado
Pablo Galindo Salgado added the comment: > The doc for exec says globals "must be a dictionary (and not a subclass of > dictionary)" I agree with Terry, the moment you pass a dict subclass to exec you are out of contract. If any, we may need to sanitize the input to exec, although I don't t

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: > The doc for exec says globals "must be a dictionary (and not a subclass of > dictionary)" Docs are full of mistakes and outdated information. Fixing STORE_GLOBAL case from https://bugs.python.org/issue36220#msg359046 would be trivial and cheap re: overhe

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Terry J. Reedy
Terry J. Reedy added the comment: Victor, Pablo, I added you two since you commented on the duplicate. I believe this should be closed as 'not a bug'. The doc for globals() says is returns a 'dictionary', meaning an instance of dict. The doc for exec says globals "must be a dictionary (and

[issue32615] Inconsistent behavior if globals is a dict subclass

2019-12-30 Thread Paul Sokolovsky
Paul Sokolovsky added the comment: Some smart maintainer closed https://bugs.python.org/issue36220 as a duplicate of this one. That ticket might have more details of the underlying issues. -- nosy: +pfalcon ___ Python tracker

[issue32615] Inconsistent behavior if globals is a dict subclass

2018-01-26 Thread Terry J. Reedy
Terry J. Reedy added the comment: I was referring back to your original a) and b) items. Perhaps 'accidental' versus 'intentional, for whatever reason', would be the better contrast. The weekly new issue report comes out on Fridays around noon eastern US. I hope someone else clicks on this

[issue32615] Inconsistent behavior if globals is a dict subclass

2018-01-26 Thread pmpp
Change by pmpp : -- nosy: +pmpp ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailma

[issue32615] Inconsistent behavior if globals is a dict subclass

2018-01-26 Thread ppperry
ppperry added the comment: Uh, I'm not undertsanding the relevance of whether the code is run at module-level or not. It can't possibly be a feature that * some code * uses the overrides and *other code* doesn't. -- ___ Python tracker

[issue32615] Inconsistent behavior if globals is a dict subclass

2018-01-26 Thread Terry J. Reedy
Terry J. Reedy added the comment: I did take the code, and it would not run because of the indent. With that fixed, it still did not run because the the indent in the quoted code fed to exec. This does run: import builtins class K(dict): def __getitem__(self, k): if k not in

[issue32615] Inconsistent behavior if globals is a dict subclass

2018-01-22 Thread ppperry
Change by ppperry : -- type: -> behavior ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.

[issue32615] Inconsistent behavior if globals is a dict subclass

2018-01-21 Thread ppperry
New submission from ppperry : Take the following code: import builtins class K(dict): def __getitem__(self, k): if k not in builtins.__dict__: print("get %s" % k) return dict.__getitem__(self, k) def __setitem__(self