Message284864
| Author |
serhiy.storchaka |
| Recipients |
Yury.Selivanov, belopolsky, methane, ncoghlan, serhiy.storchaka, vstinner, yselivanov |
| Date |
2017年01月06日.22:29:08 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<2919773.es5mQSBHGX@raxxla> |
| In-reply-to |
<1483722813.74.0.841750617729.issue29178@psf.upfronthosting.co.za> |
| Content |
> Which virtually no one follows :(
Sad. But adding bytes.frombuffer() wouldn't make it magically used. If you are
aware of the problem, you can use the above two-liner as well as
bytes.frombuffer(). You even can use it in the current code with older Python
releases, unlike to bytes.frombuffer() which would need 3.7.
> Any protocol parsing code has a lot of slicing.
How much code you expect to update with bytes.frombuffer()? And why not use the
above two-liner instead?
> > There is also a problem with returned type for subclasses (this is always
> > a problem for alternate constructors).
> Good point. How do we usually solve this in CPython?
It is deemed that returning an instance of a subclass is more preferable.
Otherwise you could use separate function rather of a class method. But it is
not easy. You need either pass a memoryview or bytes instance to class
constructor, or (only for mutable arrays) create an empty instance and
concatenate a buffer to it. |
|