benjaminp / six

Python 2 and 3 compatibility library
https://six.readthedocs.io/
MIT License
987 stars 274 forks source link

support dictproxy views Fixes #295 #309

Closed graingert closed 4 years ago

graingert commented 4 years ago

@benjaminp I think this fixes the issues with my previous attempt

graingert commented 4 years ago

@benjaminp any thoughts on this?

graingert commented 4 years ago

https://github.com/benjaminp/six/issues/295

graingert commented 4 years ago

@benjaminp any thoughts on this?

benjaminp commented 4 years ago

Thank you for the PR. As I said in https://github.com/benjaminp/six/pull/296#issuecomment-546179264, I don't want to complicate view* for this, especially since there's no way to view dict proxy's on Python 2.

graingert commented 4 years ago

Thank you for the PR. As I said in #296 (comment), I don't want to complicate view* for this, especially since there's no way to view dict proxy's on Python 2.

But it does work for dictproxy, you just use the collections.*View

benjaminp commented 4 years ago

Sorry, I meant a method on the type.

graingert commented 4 years ago

I'd like you to reconsider, because it makes it much easier to use six.viewitems everywhere it would also be supported in Py3 (eg class Foo(object): ...; six.viewitems(vars(Foo)) and much easier to produce safe automated transforms when upgrading a py2 codebase to py3

benjaminp commented 4 years ago

I'd like you to reconsider,

I've already considered it twice.

because it makes it much easier to use six.viewitems everywhere it would also be supported in Py3 (eg class Foo(object): ...; six.viewitems(vars(Foo)) and much easier to produce safe automated transforms when upgrading a py2 codebase to py3

What automated transform? If the Python 2 code is doing something.viewitems(), then it already doesn't work it dict proxies. If it's doing something.iteritems(), six.iteritems(something) will work fine.