New submission from Andrew Barnert :
See this StackOverflow question for a repro case:
https://stackoverflow.com/questions/51941260/
If you store a string that looks like an int in a TreeView's values, then call
widget.item(row), the dict's 'values' value has that string
Andrew Barnert added the comment:
Reading more about wpython (slide 23 of
https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/wpython2/Cleanup%20and%20new%20optimizations%20in%20WPython%201.1.pdf),
one of his optimizations was moving the peephole optimizer into the
New submission from Andrew Barnert:
Currently, the compiler starts with a list of arrays of instructions, packs
them to 1/3/6-bytes-apiece bytecodes, fixes up all the jumps, and then calls
PyCode_Optimize on the result. This makes the peephole optimizer much more
complicated. Assuming PEP 511
Andrew Barnert added the comment:
No, I suggest we add something for users who don't think that a comment in an
example is the place to look for documentation, but do think that actual
documentation of a class or method is.
--
___
Python tr
Andrew Barnert added the comment:
> The docs seem to clearly show a str(x) as the way to produce the desired form
> (without braces). https://docs.python.org/3/library/uuid.html#example
Please read the last paragraph of the original m
New submission from Andrew Barnert:
Most real-world code that uses the UUID module wants either the standard format
'{12345678-1234-5678-1234-567812345678}', or the same thing without the braces.
There are a number of different documented accessors, but none of them give you
eithe
Andrew Barnert added the comment:
> This is not really my area of expertise, but I would have thought if you
> defined a __special__ method to something illegal (non-callable, or wrong
> signature) it would be reasonable for Python to raise an error at class
> definition (or assi
Andrew Barnert added the comment:
> I did actually mean a version changed notice for the data model change. I see
> this as a small expansion of the Python object API. Previously,
> __reversed__() had to be a function, now you are also allowed to set it to
> None. The collecti
Changes by Andrew Barnert :
--
type: -> enhancement
___
Python tracker
<http://bugs.python.org/issue26225>
___
___
Python-bugs-list mailing list
Unsubscrib
New submission from Andrew Barnert:
In #24129, the wording describing class local bindings in 4.2.2 "Resolution of
names" was changed for Python 3.4, 3.5, and 3.6. The new version is a lot
clearer for classes--but now it's misleading for `exec`/`eval`.
---
> Class def
Andrew Barnert added the comment:
> Assuming Andrew is correct, it sounds like the tokenizer is treating the NBSP
> and the “2” as part of the same token, because NBSP is non-ASCII.
It's more complicated than that. When you get an invalid character, it splits
the token up. So, i
Andrew Barnert added the comment:
Ultimately, this is because the tokenizer works byte by byte instead of
character by character, as far as possible. Since any byte >= 128 must be part
of some non-ASCII character, and the only legal use for non-ASCII characters
outside of quotes and comme
Changes by Andrew Barnert :
Added file: http://bugs.python.org/file41651/patch5.diff
___
Python tracker
<http://bugs.python.org/issue25958>
___
___
Python-bugs-list mailin
Changes by Andrew Barnert :
Removed file: http://bugs.python.org/file41650/patch5.diff
___
Python tracker
<http://bugs.python.org/issue25958>
___
___
Python-bugs-list m
Andrew Barnert added the comment:
Style changes based on Martin's review
--
Added file: http://bugs.python.org/file41650/patch5.diff
___
Python tracker
<http://bugs.python.org/is
Andrew Barnert added the comment:
On Jan 10, 2016, at 06:48, cowlicks wrote:
>
>
> Personally this came up while I was playing with toy crypto problems. I
> expected to already be part of the language, but it wasn't. I think this is a
> natural expectation.
Maybe if you
Andrew Barnert added the comment:
There are a number of existing libraries on PyPI for bit arrays and bit sets.
There are a lot more API choices than you'd think of in advance, and between
them they explore most of the useful space. And I don't think any of them need
to be in
Andrew Barnert added the comment:
Probably better to wait.
--
___
Python tracker
<http://bugs.python.org/issue26019>
___
___
Python-bugs-list mailing list
Unsub
Andrew Barnert added the comment:
For what it's worth, I looked at some old code (a clean re-implementation of a
crypto algorithm in Python, used as a unit test for production code in C++) and
found this:
class BytesBits(bytes):
# from a quick test, 1.12us in NumPy, 1.39us in C, 2
Changes by Andrew Barnert :
Added file: http://bugs.python.org/file41527/patch4a.diff
___
Python tracker
<http://bugs.python.org/issue25958>
___
___
Python-bugs-list m
Andrew Barnert added the comment:
The attached patch is, I think, the smallest change that includes all the
necessary information.
Of course it will need to be redone if #25958 goes through, with a
version-changed note explaining that prior to 3.6 some of the implicit ABCs
(maybe with a list
New submission from Andrew Barnert:
Some of the modules in collections.abc have a subclass hook that implicitly
registers any type that declares the right methods, like Iterator. Others do
not, like Sequence. For those that do have the hook, it's not always obvious
what methods are t
Andrew Barnert added the comment:
The attached patch fixes the one wording change from the patch2 review, and
makes all the error messages consistent as suggested by Serhiy, and also adds a
lot more tests: every way that a special method can fall back should now be
tested. (Of course it would
Andrew Barnert added the comment:
See #25958, which incorporates a similar refactoring in service of making all
of the subclasshooks in collections.abc handle None the same way.
We definitely do want something public in the abc module like this, rather than
the private function in
Andrew Barnert added the comment:
The second patch takes into account all the issues raised by Martin and Guido,
as well as some other changes that didn't make it into the first patch because
Windows hates me. And it should be flattened into a single commit, and
therefore should hope
Andrew Barnert added the comment:
> A Mercurial export patch should work with the Reitveld review thing if it is
> a single revision (and based on a public revision).
Well, it's 7 separate commits on a work branch, so I could check in each piece
and test it separately, and
Andrew Barnert added the comment:
Is an hg export patch usable? If not, let me know and I'll flatten it.
Anyway, the attached patch fixes #25987 and #25864 as well as this one, as
follows:
* Every ABC in collections.abc that has a subclass hook now treats None as
blocking, instead of
Andrew Barnert added the comment:
> My main concern about the documentation was that in your patch you say _all_
> special methods are now allowed to be None, but in your code you only check
> __iter__(). This is adding new undocumented inconsistencies e.g. with
> Iterable vs Co
Andrew Barnert added the comment:
> I propose to solve the narrow problem by indeed supporting the setting of
> certain special methods to None similar to __hash__. This should be limited
> to those methods for which this adds value, e.g. where the complete absence
> of the met
Andrew Barnert added the comment:
> IMO allowing any special method to be set to None seems to make more trouble
> than it is worth.
That's exactly why allowing _any_ special method to be None is a separate issue
(#25958). Most special methods don't have any corresponding pr
New submission from Andrew Barnert:
In an -ideas thread, Guido suggested
(http://article.gmane.org/gmane.comp.python.ideas/37599):
> If we want some way to turn something that just defines __getitem__ and
> __len__ into a proper sequence, it should just be made to inherit from
>
New submission from Andrew Barnert:
This came up as a side issue in the -ideas discussion on deprecating the
old-style sequence protocol that came out of Guido's suggestion on
https://github.com/ambv/typehinting/issues/170
(http://article.gmane.org/gmane.comp.python.ideas/37599):
>
Andrew Barnert added the comment:
> If this patch goes ahead, I think the ABC documentation should clarify which
> methods are checked for None and which aren’t.
That seems fair.
Also, as you pointed out on #25958, at least one other ABC has the same problem
as Iterable: you can blo
Andrew Barnert added the comment:
> Also, if I understand your problem, Container would also be susceptible in
> theory
You're right, but not in the details.
Being iterable (whether via __iter__ or via the old-style sequence protocol)
makes you a container. But, again, false ne
Andrew Barnert added the comment:
> I don’t think you need to define __len__() to get an iterable, only
> __getitem__().
The "old-style sequence protocol" means having a __getitem__ that works for
values from 0 to __len__() and raises IndexError at __len__(). You don't n
Andrew Barnert added the comment:
Hashable and Awaitable already treat None (actually any falsey value) as not
implementing the special method, and blocking any superclass implementation, in
their __subclasshook__. (This only blocks implicit subclassing--anything that
actually directly or
Andrew Barnert added the comment:
The attached patch does the following:
* collections.abc.Mapping.__reversed__ = None.
* collections.abc.Iterable.__subclasshook__ checks for None the same way
Hashable does:
* This tests for any falsey value, not just None. I'm not sure this is ideal,
Andrew Barnert added the comment:
> This sounds good. Also, reversed() could then be modified to produce a
better error.
Should `iter` also be modified to produce a better error if `__iter__` is None?
Also, should this be documented? Maybe a sentence in the "Special method names"
Andrew Barnert added the comment:
As Serhiy pointed out on -ideas, there's no reason `reversed` couldn't add
special handling for `__reversed__ is None`, akin to `hash`'s special handling
for `__hash__ is None`, to produce whatever error message we wanted in the
`TypeErr
Andrew Barnert added the comment:
As mentioned in #25958, Guido pointed out on -ideas that `__hash__ = None` is
already the standard way to declare a class unhashable, and it's recognized by
`collections.abc.Hashable`.
Doing `__reversed__ = None` does make `reversed(m)` raise a `Type
Andrew Barnert added the comment:
As Guido pointed out on -ideas, hashing already uses the convention of
`__hash__ is None` to declare a type unhashable, and
`collections.abc.Hashable.__subclasshook__` already checks for that.
Meanwhile, setting `__iter__` and `__reversed__` to `None` already
Andrew Barnert added the comment:
Also, I filed #25958 as an ABC equivalent to Serhiy's typehinting problem. I
don't know if that actually needs to be solved, but that definitely takes it
out of the way for this issue.
--
___
Python trac
New submission from Andrew Barnert:
Serhiy Storchaka raised an issue (http://bugs.python.org/msg256910) with static
type hints on #25864 (http://bugs.python.org/issue25864), which I believe also
applies to runtime ABCs.
Consider this class, which uses `[]` in a way similar to generic types
Andrew Barnert added the comment:
Serhiy already filed the typing.Reversible bug on the separate typehinting
tracker (https://github.com/ambv/typehinting/issues/170). So, unless fixing
that bug requires some changes back to collections.abc or something else in the
stdlib, I think the only
Andrew Barnert added the comment:
> Perhaps there is a bug in typing.Reversible. It doesn't accept all types
> supported by reversed().
> ... And accepts types that don't work with reversed().
The problem is the way the two are defined:
* Reversible is true if you imp
Andrew Barnert added the comment:
@Swati Jaiswal:
> But the work around suggested here ... is also not a general solution, i.e.
> ... for any other mapping which does not have 0 as a key, it results in
> KeyError.
You're missing the point. The workaround isn't inten
Andrew Barnert added the comment:
@R. David Murray:
> What is it that makes reversed raise a typeerror on dict here?
There are separate slots for tp_as_sequence and tp_as_mapping, so a C type can
be (and generally is) one or the other, not both.
But for Python types, anything that
New submission from Andrew Barnert:
None of the below are very serious or likely to mislead anyone using or
implementing Python, but...
---
3.3.2. Customizing attribute access
The docs for `__dir__` say:
> A sequence must be returned. dir() converts the returned sequence to a list
&g
Andrew Barnert added the comment:
As a side note, why isn't () allowed as an empty target list, like []? Then the
rules for target lists vs. single targets would be exactly parallel to the
rules for tuple and list displays. And the error message `can't assign to ()`
seems a bit
New submission from Andrew Barnert:
>From
>https://docs.python.org/3/reference/simple_stmts.html#assignment-statements
> If the target list contains one target prefixed with an asterisk, called a
> “starred” target: The object must be a sequence with at least as many items
&g
Andrew Barnert added the comment:
> It seems no more interesting or problematic than sequence argument unpacking
> working with dictionaries, "a, b = {'one': 1, 'two': 2}".
Dictionaries (including dicts, dict subclasses, and custom Mappings) are
iterables.
Andrew Barnert added the comment:
> What are we exactly expecting here?
Well, naively, I was expecting a TypeError, just as you get for dict, or a
subclass of dict, or a custom extension type that implements the C-API mapping
protocol.
Once you understand how reversed works, you
New submission from Andrew Barnert:
Example:
class MyDict(collections.abc.Mapping):
def __init__(self, d): self.d = d
def __len__(self): return len(self.d)
def __getitem__(self, key): return self.d[key]
def __iter__(self): return iter(self.d)
d = {1:2, 3
Andrew Barnert added the comment:
Presumably ESR thought that information was useful enough to send Guido a patch
to add it. But apparently nobody's missed it in the 15 years it's been checked
in but unreachable. If anyone needed to know the `instream` and `lineno` right
after init
New submission from Andrew Barnert:
The documentation and implementation for `inspect.isbuiltin` and related
functions do not match. While #4968 attempted to clarify things to make the
documentation match the behavior, the actual committed changes are still wrong.
`isbuiltin` says "R
Andrew Barnert added the comment:
So something like the first version below? Or should even the example be
inline, as in the second version below? (Apologies if the formatting gets
screwed up pasting from docs to bugs.)
---
Range objects are inappropriate for non-integral types, especially
Andrew Barnert added the comment:
As suggested by the review: removing unnecessary parenthetical, changing "ulp"
to "digit", and fixing the recipe link.
--
Added file: http://bugs.python.org/file37685/stdtypes.rst.diff
___
P
New submission from Andrew Barnert:
In a recent thread on python-ideas
(https://mail.python.org/pipermail/python-ideas/2015-January/030817.html), it
was concluded that Python should not have a range-like type for floats in the
stdlib, but there should be some simple discussion of the
Andrew Barnert added the comment:
It may be pretty hard to come up with a good example for closing in the stdlib
that shouldn't just be turned into a context manager…
There are some types where using it in a with statement is sensible, but
unusual enough that you might want to ma
Andrew Barnert added the comment:
Akira, your patch does this:
-self._writetranslate = newline != ''
-self._writenl = newline or os.linesep
+self._writetranslate = newline in (None, '\r', '\r\n')
+self._writenl = newline if newli
Changes by Andrew Barnert :
Added file: http://bugs.python.org/file36009/pep-peek.txt
___
Python tracker
<http://bugs.python.org/issue1152248>
___
___
Python-bugs-list m
Changes by Andrew Barnert :
Added file: http://bugs.python.org/file36008/pep-newline.txt
___
Python tracker
<http://bugs.python.org/issue1152248>
___
___
Python-bug
Andrew Barnert added the comment:
One last thing, a quick & dirty solution that works today, if you don't mind
accessing private internals of stdlib classes, and don't mind giving up the
performance of _io for _pyio, and don't need a solution for binary files:
cl
Andrew Barnert added the comment:
While we're at it, Douglas Alan's solution wouldn't be an ideal solution even
if it were a builtin. A fileLineIter obviously doesn't support the stream API.
It means you end up with two objects that share the same file, but have
separat
Andrew Barnert added the comment:
http://thread.gmane.org/gmane.comp.python.ideas/28310 discusses the same idea.
Guido raised a serious problem with either adding an argument to readline and
friends, or adding new methods readrecord and friends: It means the hundreds of
existing file-like
Andrew Barnert added the comment:
Searching the source and the help page, it looks like the one example I gave is
the only place it's wrong in each of the two, not one of multiple places.
--
___
Python tracker
<http://bugs.python.org/is
New submission from Andrew Barnert:
In at least one place in the io module documentation (io.IOBase.readline), and
in the corresponding docstring, the newline parameter to open (and io.open, and
io.Foo.__init__) is referred to as "newlines":
> The line terminator is always b
Andrew Barnert added the comment:
Sorry, Stefan, not Stephan. Anyway, I've signed the agreement.
--
___
Python tracker
<http://bugs.python.org/issue1820>
___
___
Andrew Barnert added the comment:
Hi, Stephan. Sorry, for some reason Yahoo was sending updates from the tracker
to spam again, so I missed this. I'd be glad to sign a contributor agreement if
it's still relevant, but it looks like there's a later patch that does what
mi
New submission from Andrew Barnert:
The docstring for defaultdict shows only a single argument, default_factory,
and gives no clue that you can pass additional arguments:
| defaultdict(default_factory) --> dict with default factory
|
| The default factory is called with
Andrew Barnert added the comment:
See issue20230, which includes a patch implementing just the first part of part
2 (adding _fields, but not _asdict or _replace).
Since this one has been open for 5+ years, if it's not going to be done soon,
any chance of the easy (_fields) change
Andrew Barnert added the comment:
After more searching (I should have searched on structseq instead of
PyStructSequence…), this might be a dup of #1820. If so, apologies.
--
___
Python tracker
<http://bugs.python.org/issue20
Andrew Barnert added the comment:
I believe the structseq issues are a lot easier to solve than the appear. See
#20230, which adds a _fields member to every structseq type. Having done that,
a NamedTuple ABC works on them just fine. And of course duck typing them
without an ABC does too
New submission from Andrew Barnert:
A PyStructSequence type doesn't expose its field names in any way to Python
code (except indirectly, via the repr, which you could parse if you really
wanted to…).
The docs claim that "Struct sequence objects are the C equivalent of
namedtuple
Andrew Barnert added the comment:
Now that Xcode 5 is out, and does not have anything named "gcc-4.2" (it _does_
still have something called "gcc", which is now a wrapper around clang instead
of a wrapper around llvm-gcc-4.2), this seems a lot more critical, because (a
75 matches
Mail list logo