Comments (7)
Pull request #48 was merged.
from six.
Original comment by Tom Grainger (Bitbucket: graingert, GitHub: graingert):
@benadmin Cool, just pulling the code in from Django
from six.
Since Django's decorator seems to have proved itself, I don't mind including it. Someone should submit a PR.
from six.
This surprisingly tricky. We want something which
- Plays nicely with inheritance.
- Allows minimal code duplication in client's code.
- Provides a reasonable fallback implementation if it's desired.
from six.
Original comment by Aymeric Augustin (Bitbucket: aaugustin, GitHub: aaugustin):
The Python docs offer a variety of porting techniques. In the paragraph you're referring to, the result is Python 2 code that also works on Python 3 (ie. it defines a Python 2-style __unicode__
method).
While porting Django, I was very careful to write Python 3 code that also works on Python 2 rather than the opposite.
I made this choice for Django because I prefer looking at the future than at the past. And since I was building the bike shed I could chose its color :) This technique involves much more work than just trying to get tests to pass under Python 3. It may or may not suit everyone's tastes.
(Accidentally posted while I was writing my comment -- sorry if you got a notification with an incomplete message).
from six.
Original comment by Tom Grainger (Bitbucket: graingert, GitHub: graingert):
Using a UnicodeMixin similar to django.utils.encoding.StrAndUnicode
is recommended in the python 3 porting documentation.
- Why was that deprecated in django?
- Should it be removed from this porting documentation also?
from six.
Original comment by Aymeric Augustin (Bitbucket: aaugustin, GitHub: aaugustin):
StrAndUnicode
is deprecated; Django now uses:
https://github.com/django/django/blob/ef017a5f00/django/utils/encoding.py#L49
I'm the author of this code and I must admit it has some drawbacks:
- Decorated
__str__
methods must return unicode strings even on Python 2; - It's easy to shoot oneself into the foot when combining this with inheritance;
- Specifically, if you accidentally trigger infinite recursion when a base class derives
__unicode__
from__str__
or vice-versa, you're in an ugly situation, because you cannot even print the problematic object! (Yes I'm looking at youdjango.db.models.Model
.)
Of course, this technique also has some advantages — namely, it allows for reasonably short and explicit code.
I'd be very happy if that was included in six. We could remove code from Django! I just wanted to state the drawbacks upfront :)
from six.
Related Issues (20)
- six urlib urlopen faces certificate has expired error HOT 1
- Implement find_spec() for _SixMetaPathImporter
- 1.15.0: pytest warnings HOT 2
- Please make a new release with the py3.10 fixes
- bad magic number in 'six' HOT 4
- What version of collections_abc is supported? HOT 2
- Different versions of packages (geckodriver) can be installed on linux and windows
- can i use six just like run command on cmd like six filename.py? HOT 1
- ImportWarning: _SixMetaPathImporter.find_spec() not found; falling back to find_module()
- RuntimeError: restricted attribute setting __doc__ when being imported in python2.7 in a restricted frame
- Module MD5 could be moved to hashlib.md5? HOT 1
- Python:3.11 failing to install six (pip version: 22.3.1)
- Version 1.16.0 vulnerable to OS Command Injection
- Failure when using six.with_metaclass in python 2.7 when metaclass doesn't directly inherit from type
- SIX new version HOT 4
- six.reraise fails
- repr(six.moves) throws an AttributeError for cpython 3.12 HOT 5
- Why name the tool six ? six = 2x3 ? HOT 2
- Undefined reference to unicode
- Getting Code Vulnerability in "six.py" module file HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from six.