[issue32300] print(os.environ.keys()) should only print the keys

2020-11-06 Thread Irit Katriel
Change by Irit Katriel : -- type: -> behavior versions: +Python 3.10, Python 3.9 -Python 3.7 ___ Python tracker ___ ___ Python-bugs

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread Cheryl Sabella
Cheryl Sabella added the comment: Never mind. I see it's in bytes. I missed that the first time. But, if it wasn't in bytes, would that be an OK solution? Or is it bad to override those methods in that class? -- ___ Python tracker

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread Cheryl Sabella
Cheryl Sabella added the comment: I'm missing something here, so please forgive me for asking, but why is it bad to add: def keys(self): return self._data.keys() def values(self): return self._data.values() def items(self): return self._data.items() to th

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread Aaron Meurer
Aaron Meurer added the comment: Can't third party code write their own proxies? Why do we have to do that? -- ___ Python tracker ___ ___

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: With option 4 we need to add a custom wrapper not only for Shelf's KeysView, but for KeysView of all similar proxy classes, including classes in third-party code not available for us. This is impossible. -- ___ P

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread Aaron Meurer
Aaron Meurer added the comment: Serhiy, isn't option 4? 4. Make KeysView.__repr__ show list(self). Add a custom wrapper for Shelf's KeysView so that it doesn't do this. This seems to be what Victor is suggesting. It makes the most sense to me for the common (i.e., default) case to be to sho

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Options: 1. Use the subclass of KeyView with overridden __repr__ for os.environ.keys(). This will add a code for pretty rare use case. 2. Remove os.environ.__repr__. You can use repr(os.environ.copy()) or repr(dict(os.environ)) if you want to see a content

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread STINNER Victor
STINNER Victor added the comment: Cheryl: "Thanks! Yes, I can work this. It may take a few days for me to get to it." It seems like we have a disagreement on how to fix this issue. We should first agree on the best solution. -- ___ Python tracke

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread STINNER Victor
STINNER Victor added the comment: Currently, repr(Shelf.keys()) doesn't dump the content of the shelf: >>> import pickle, shelve >>> s=shelve.Shelf({b'key': pickle.dumps('value')}) >>> k=s.keys() >>> k KeysView() >>> list(k) ['key'] >>> list(s.values()) ['value'] I understand that changing Key

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-14 Thread Cheryl Sabella
Cheryl Sabella added the comment: Victor, Thanks! Yes, I can work this. It may take a few days for me to get to it. -- ___ Python tracker ___ ___

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: shelve.Shelf is the example of such kind. -- ___ Python tracker ___ ___ Python-bugs-list mailing

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread STINNER Victor
STINNER Victor added the comment: > Don't make KeysView.__repr__ and ValuesView.__repr__ containing the lists of > all keys and values. This will make the repr of the view of a mapping which > is a proxy of an external DB containing the full content of that DB, which > can be gigabytes. See f

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread Aaron Meurer
Aaron Meurer added the comment: So the best fix is to just override keys() in the _Environ class, so that it returns an EnvironKeysView class that overrides __repr__? -- ___ Python tracker __

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Don't make KeysView.__repr__ and ValuesView.__repr__ containing the lists of all keys and values. This will make the repr of the view of a mapping which is a proxy of an external DB containing the full content of that DB, which can be gigabytes. See for exa

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread STINNER Victor
STINNER Victor added the comment: Cheryl: would you like to work on a PR? If yes, tests are needed. -- ___ Python tracker ___ ___ Py

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread R. David Murray
R. David Murray added the comment: Agreed about the other classes if we change this. Your solution looks reasonable to me. -- ___ Python tracker ___ _

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread STINNER Victor
STINNER Victor added the comment: If we decide to change abc.KeysView.__repr__, IMHO we should also modify abc.ValuesView.__repr__, and maybe also abc.ItemsView.__repr__. -- ___ Python tracker __

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread STINNER Victor
STINNER Victor added the comment: Usually, I use print(sorted(os.environ)) since I prefer a sorted list and it prevents such issue :-) David: > I agree that the result is surprising, but there may not be a generic fix. What about something like: vstinner@apu$ ./python -c 'import os; print(os

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread R. David Murray
Change by R. David Murray : -- nosy: +csabella ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.py

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread R. David Murray
R. David Murray added the comment: This is a consequence of the repr used by KeysView, which it inherits from MappingView. I agree that the result is surprising, but there may not be a generic fix. It's not entirely clear what KeysView should do here, but presumably we could at least add a

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread Cheryl Sabella
Change by Cheryl Sabella : -- components: +Library (Lib) type: -> behavior ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread Cheryl Sabella
Cheryl Sabella added the comment: For your current situation, list(os.environ) or iter(os.environ) both return keys only. It looks like the __repr__ on the class for os.environ is printed for os.environ (which is expected). For os.environ.keys(), the same __repr__ is wrapped as a KeysView,

[issue32300] print(os.environ.keys()) should only print the keys

2017-12-13 Thread Aaron Meurer
New submission from Aaron Meurer : Take the following scenario which happened to me recently. I am trying to debug an issue on Travis CI involving environment variables. Basically, I am not sure if an environment variable is being set correctly. So in my code, I put print(os.environ.keys()) T