ecdavis / pants

A lightweight framework for writing asynchronous network applications in Python.
http://pantspowered.org/
Apache License 2.0
167 stars 9 forks source link

Introduced pants.compat module to assist with python 3 migration #52

Closed AphonicChaos closed 6 years ago

AphonicChaos commented 10 years ago

I've decided to try out a more incremental strategy with respect to porting pants to python 3. As such, I'll be creating a new branch for each python 3 related porting issue I come across. By doing so, I hope to not only make it more clear what changes I'm proposing, but also allow each solution to be discussed individually. If one pull requests assumes the application of another[1], I'll do my best to note so. Also, if I think that I've made some controversial decisions, I'll try and make a point to note them as comments on the patches themselves.

[1] By not waiting until each successive pull request is merged, I hope to speed up development time. If a proposed dependency is rejected, it should be trivial to make the dependent pull requests comply with whatever new strategy is later agreed upon.

AphonicChaos commented 10 years ago

Just wanted to record the alternate version of compat.py for this particular commit:

from collections import Mapping

items = getattr(Mapping, 'viewitems', Mapping.items)
keys = getattr(Mapping, 'viewkeys', Mapping.keys)
values = getattr(Mapping, 'values', Mapping.values)

I do really like this, and in practice it shouldn't matter if for k, v in Mapping.items(a) is called, but unless we can guarantee that only mapping types will be used as events (which seems reasonable), we won't be able to implement it.