[issue34447] ttk.TreeView (and maybe other functions) is overzealous in converting item values to ints

2018-08-20 Thread Andrew Barnert
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

[issue26300] "unpacked" bytecode

2016-02-06 Thread Andrew Barnert
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

[issue26300] "unpacked" bytecode

2016-02-05 Thread Andrew Barnert
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

[issue26267] UUID docs should say how to get "standard form"

2016-02-02 Thread Andrew Barnert
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

[issue26267] UUID docs should say how to get "standard form"

2016-02-02 Thread Andrew Barnert
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

[issue26267] UUID docs should say how to get "standard form"

2016-02-02 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-02-01 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-02-01 Thread Andrew Barnert
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

[issue26225] New misleading wording in execution model documenation

2016-01-27 Thread Andrew Barnert
Changes by Andrew Barnert : -- type: -> enhancement ___ Python tracker <http://bugs.python.org/issue26225> ___ ___ Python-bugs-list mailing list Unsubscrib

[issue26225] New misleading wording in execution model documenation

2016-01-27 Thread Andrew Barnert
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

[issue26152] A non-breaking space in a source

2016-01-20 Thread Andrew Barnert
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

[issue26152] A non-breaking space in a source

2016-01-19 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-18 Thread Andrew Barnert
Changes by Andrew Barnert : Added file: http://bugs.python.org/file41651/patch5.diff ___ Python tracker <http://bugs.python.org/issue25958> ___ ___ Python-bugs-list mailin

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-18 Thread Andrew Barnert
Changes by Andrew Barnert : Removed file: http://bugs.python.org/file41650/patch5.diff ___ Python tracker <http://bugs.python.org/issue25958> ___ ___ Python-bugs-list m

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-18 Thread Andrew Barnert
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

[issue19251] bitwise ops for bytes of equal length

2016-01-10 Thread Andrew Barnert
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

[issue19251] bitwise ops for bytes of equal length

2016-01-08 Thread Andrew Barnert
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

[issue26019] collections.abc documentation incomplete

2016-01-07 Thread Andrew Barnert
Andrew Barnert added the comment: Probably better to wait. -- ___ Python tracker <http://bugs.python.org/issue26019> ___ ___ Python-bugs-list mailing list Unsub

[issue19251] bitwise ops for bytes of equal length

2016-01-07 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-07 Thread Andrew Barnert
Changes by Andrew Barnert : Added file: http://bugs.python.org/file41527/patch4a.diff ___ Python tracker <http://bugs.python.org/issue25958> ___ ___ Python-bugs-list m

[issue26019] collections.abc documentation incomplete

2016-01-05 Thread Andrew Barnert
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

[issue26019] collections.abc documentation incomplete

2016-01-05 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-05 Thread Andrew Barnert
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

[issue22268] add dedicated functions mrohasattr and mrogetattr

2016-01-05 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-05 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-04 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-04 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2016-01-04 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-04 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2016-01-04 Thread Andrew Barnert
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

[issue25988] collections.abc.Indexable

2016-01-01 Thread Andrew Barnert
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 >

[issue25987] collections.abc.Reversible

2016-01-01 Thread Andrew Barnert
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): >

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2016-01-01 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-01 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2016-01-01 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2015-12-28 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-28 Thread Andrew Barnert
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,

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-26 Thread Andrew Barnert
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"

[issue25958] Implicit ABCs have no means of "anti-registration"

2015-12-26 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-26 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2015-12-26 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-26 Thread Andrew Barnert
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

[issue25958] Implicit ABCs have no means of "anti-registration"

2015-12-26 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-26 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-26 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-16 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-16 Thread Andrew Barnert
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

[issue25866] Reference 3. Data Model: miscellaneous minor cleanups on the word "sequence".

2015-12-15 Thread Andrew Barnert
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

[issue25865] 7.2 Assignment statements documentation is vague and slightly misleading

2015-12-14 Thread Andrew Barnert
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

[issue25865] 7.2 Assignment statements documentation is vague and slightly misleading

2015-12-14 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-14 Thread Andrew Barnert
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.

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-14 Thread Andrew Barnert
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

[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

2015-12-14 Thread Andrew Barnert
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

[issue24113] shlex constructor unreachable code

2015-05-03 Thread Andrew Barnert
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

[issue23525] isbuiltin, isroutine, etc.

2015-02-25 Thread Andrew Barnert
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

[issue23226] Add float linspace recipe to docs

2015-01-13 Thread Andrew Barnert
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

[issue23226] Add float linspace recipe to docs

2015-01-12 Thread Andrew Barnert
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

[issue23226] Add float linspace recipe to docs

2015-01-12 Thread Andrew Barnert
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

[issue22755] contextlib.closing documentation should use a new example

2014-10-28 Thread Andrew Barnert
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

[issue1152248] Add support for reading records with arbitrary separators to the standard IO stack

2014-07-27 Thread Andrew Barnert
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

[issue1152248] Add support for reading records with arbitrary separators to the standard IO stack

2014-07-20 Thread Andrew Barnert
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

[issue1152248] Add support for reading records with arbitrary separators to the standard IO stack

2014-07-20 Thread Andrew Barnert
Changes by Andrew Barnert : Added file: http://bugs.python.org/file36008/pep-newline.txt ___ Python tracker <http://bugs.python.org/issue1152248> ___ ___ Python-bug

[issue1152248] Add support for reading records with arbitrary separators to the standard IO stack

2014-07-19 Thread Andrew Barnert
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

[issue1152248] Add support for reading records with arbitrary separators to the standard IO stack

2014-07-19 Thread Andrew Barnert
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

[issue1152248] Add support for reading records with arbitrary separators to the standard IO stack

2014-07-19 Thread Andrew Barnert
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

[issue22004] io documentation refers to newline as newlines

2014-07-17 Thread Andrew Barnert
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

[issue22004] io documentation refers to newline as newlines

2014-07-17 Thread Andrew Barnert
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&#

[issue1820] Enhance Object/structseq.c to match namedtuple and tuple api

2014-06-11 Thread Andrew Barnert
Andrew Barnert added the comment: Sorry, Stefan, not Stephan. Anyway, I've signed the agreement. -- ___ Python tracker <http://bugs.python.org/issue1820> ___ ___

[issue1820] Enhance Object/structseq.c to match namedtuple and tuple api

2014-06-11 Thread Andrew Barnert
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

[issue20250] defaultdict docstring neglects the *args

2014-01-13 Thread Andrew Barnert
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

[issue1820] Enhance Object/structseq.c to match namedtuple and tuple api

2014-01-12 Thread Andrew Barnert
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

[issue20230] structseq types should expose _fields

2014-01-12 Thread Andrew Barnert
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

[issue7796] No way to find out if an object is an instance of a namedtuple

2014-01-12 Thread Andrew Barnert
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

[issue20230] structseq types should expose _fields

2014-01-12 Thread Andrew Barnert
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

[issue19019] Investigate using Apple clang for building OS X installers

2013-10-24 Thread Andrew Barnert
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