Josh Rosenberg added the comment:
Ah, never mind. Looks like dataclasses.InitVar fields seem to be the answer to
excluding a field from the auto-generated methods.
--
___
Python tracker
<https://bugs.python.org/issue20
Josh Rosenberg added the comment:
First off, link to discussion:
https://groups.google.com/d/topic/python-ideas/-3QW3cxj3ko/discussion
1. bool is already a virtual subclass of Integral since it's an actual subclass
of int (which is a virtual subclass of Integral); no need to expli
New submission from Josh Rosenberg :
In Python 2, making a user-defined class support formatting using the
integer-specific type codes required that __int__ be defined and nothing else
(that is, '%x' % Foo() only required Foo to provide a __int__ method). In
Python 3, this was
Josh Rosenberg added the comment:
Note: Obviously, defining __index__ without defining __int__ is a little
strange (it's *equivalent* to int, but can't be *coerced* to int?), so yet
another fix would be addressing #20092 so it wouldn't be possible for a type to
define __
Josh Rosenberg added the comment:
Pingback from #33002, which is caused by the fact that parts of the CPython
code base that use PyNumber_Index for type conversion still pre-check for valid
types with PyNumber_Check, meaning that a type with __index__ and not __int__
gets erroneously
Josh Rosenberg added the comment:
To be clear, this is a problem with old-style (printf-style) formatting, and
applies to both bytes formatting and str formatting. So a class like:
class Foo:
def __index__(self):
return 1
will fail with a TypeError should you do any
Josh Rosenberg added the comment:
I think this falls under the umbrella of #30235, which posits that Path-like
objects should be supported by shutil (and includes notes on doc validation).
--
nosy: +josh.r
___
Python tracker
<ht
Josh Rosenberg added the comment:
fstat is async signal safe, and I suspect it's thread safe in general, though
usage does rely on the file descriptor remaining valid. If the fd in question
is closed in another thread after the GIL is released, fstat would fail; if a
new file is opene
Josh Rosenberg added the comment:
To my knowledge, there is no safe way to do this for other threads for a reason.
If you make all your worker threads daemons, then they will terminate with the
main thread, but they won't perform cleanup actions.
If you don't make them daemons,
Josh Rosenberg added the comment:
Serhiy: There is a semi-common case where global constants can be quite
expensive, specifically, initializing a global full of expensive to
compute/serialize data so it will be shared post-fork when doing
multiprocessing on a POSIX system. That said, that
Josh Rosenberg added the comment:
I may have immediately latched onto this, dubbing it the "one-eyed monkey
operator", the moment the generalized unpacking released.
I always hated the lack of an empty set literal, and enjoyed having this exist
just to fill that asymmetry with
Josh Rosenberg added the comment:
As indicated in the seek docs (
https://docs.python.org/3/library/io.html#io.IOBase.seek ), all three names
were added to the io module in 3.1:
> New in version 3.1: The SEEK_* constants.
Since they're part of the io module too, there is no need to
New submission from Josh Rosenberg :
Patch is good, but while we're at it, is there any reason why this
multi-allocation design was even used? It PyMem_Mallocs a buffer, makes a
C-style string in it, then uses PyUnicode_FromString to convert C-style string
to Python str.
Seems lik
Josh Rosenberg added the comment:
Related: issue29842 "Make Executor.map work with infinite/large inputs
correctly" for a similar problem in concurrent.futures (but worse, since it
doesn't even allow you to begin consuming results until all inputs are
dispatched).
A similar
Josh Rosenberg added the comment:
Pretty sure this is a problem with classes in general; classes are
self-referencing, and using multiplication to create new ctypes array types is
creating new classes.
--
nosy: +josh.r
___
Python tracker
<ht
Josh Rosenberg added the comment:
If the goal is just to suppress stdout, that's what passing subprocess.DEVNULL
is for (doesn't exist in Py2, but opening os.devnull and passing that is a
slightly higher overhead equivalent).
subprocess.run includes a call to communicate as p
Josh Rosenberg added the comment:
None of the actual classes outside of the typing module support this either to
my knowledge. You can't do:
from collections import deque
a: deque[int]
nor can you do:
a: list[int]
Adding Queue to the typing module might make sense (feel
Josh Rosenberg added the comment:
You named your loop variable i, overlapping the name of your second to last
digit, so you end up replacing the original value of i in each (given the
break, the only) loop.
So before the loop begins, i has the expected value of '6', but on
Change by Josh Rosenberg :
--
versions: -Python 3.6
___
Python tracker
<https://bugs.python.org/issue33404>
___
___
Python-bugs-list mailing list
Unsubscribe:
Josh Rosenberg added the comment:
Note: strftime follows the existing documentation:
>>> datetime.datetime(1970, 1, 1, microsecond=1).strftime('%f')
'01'
The strptime behavior bug seems like a duplicate of #32267, which claims to be
fixed in master as of ear
Josh Rosenberg added the comment:
Based on the OP's patch, it looks like they have a problem where they have
non-ASCII text in their output strings (either due to using non-ASCII switches,
or using non-ASCII help documentation), but sys.stdout/sys.stderr are
configured for some encoding
Change by Josh Rosenberg :
--
nosy: +josh.r
___
Python tracker
<https://bugs.python.org/issue29943>
___
___
Python-bugs-list mailing list
Unsubscribe:
Change by Josh Rosenberg :
--
title: readline() + seek() on io.EncodedFile breaks next readline() ->
readline() + seek() on codecs.EncodedFile breaks next readline()
___
Python tracker
<https://bugs.python.org/issu
Josh Rosenberg added the comment:
memoryview isn't just for bytes strings though; the format can make it a
sequence of many types of different widths, meanings, etc. Calling it a
BytesString would be misleading in many cases.
--
nosy: +j
Josh Rosenberg added the comment:
If [].append == [].append is True in the "unique set of callbacks" scenario,
that implies that it's perfectly fine to not call one of them when both are
registered. But this means that only one list ends up getting updated, when you
tried t
Josh Rosenberg added the comment:
Note: While this particular use case wouldn't be fixed (map returns in order,
not as completed), applying the fix from #29842 would make many similar use
cases both simpler to implement and more efficient/possible.
That said, no action has been tak
Josh Rosenberg added the comment:
In any event, sorry to be a pain, but is there any way to get some movement on
this issue? One person reviewed the code with no significant concerns to
address. There have been a duplicate (#30323) and closely related (#34168)
issues opened that this would
Josh Rosenberg added the comment:
In response to Max's comments:
>But consider the case where input is produced slower than it can be processed
>(`iterables` may fetch data from a database, but the callable `fn` may be a
>fast in-memory transformation). Now suppose the `Ex
Josh Rosenberg added the comment:
Copying from the sorted built-in's docstring would make sense here, given that
sorted is implemented in terms of list.sort in the first place.
--
nosy: +josh.r
___
Python tracker
<https://bugs.py
Josh Rosenberg added the comment:
Why would it "cause an issue if the file is closed before accessing the mmapped
region"? As shown in your own link, the constructor performs the mmap call
immediately after the descriptor is duplicated, with the GIL held; any race
condition that c
Josh Rosenberg added the comment:
So the bug is that the line number and module are incorrect for the f-string,
right? Nothing else?
--
nosy: +josh.r
___
Python tracker
<https://bugs.python.org/issue34
Josh Rosenberg added the comment:
Carlo: The point of Xiang's post is that this is only tangentially related to
multiprocessing; the real problem is that tee-ing an iterator implemented in
Python (of which pool.imap_unordered is just one example) and using the
resulting tee-ed iterato
Josh Rosenberg added the comment:
That's a *really* niche use case; you want to store everything to a common
destination list, in order, but distinguish which switch added each one? I
don't know of any programs that use such a design outside of Python (and
therefore, it seems unli
Josh Rosenberg added the comment:
Bloating the documentation is almost certainly unjustifiable for list and
tuple, and only barely justifiable for int, bool and float, given that:
1. The documentation (at least for Python 3) has *never* claimed the arguments
could be passed by keyword (all
Josh Rosenberg added the comment:
Oh, I was checking old docs when I said the online docs didn't call int's
argument "x"; the current docs do, so int, float and bool all justify a change
(barely), it's just tuple and list for which it
Josh Rosenberg added the comment:
For tuple and list, no, they couldn't have looked at the help (because the help
calls the argument "iterable", while the only keyword accepted was "sequence").
Nor was "sequence" documented in the online docs, nor any
Josh Rosenberg added the comment:
That's the documented behavior. Per
https://docs.python.org/3/reference/datamodel.html#object.__getitem__ :
>Note: for loops expect that an IndexError will be raised for illegal indexes
>to allow proper detection of the end of the sequence.
T
Josh Rosenberg added the comment:
Victor, that was a little overboard. By that logic, there doesn't need to be a
Windows version of Python.
That said, Paul doesn't seem to understand that the real resolution limit isn't
1 ms; that's the lower limit on arguments to t
Josh Rosenberg added the comment:
This would presumably be a side-effect of all generic pickling operations of
iterators; figuring out what the iterator produces requires running out the
iterator. You could special case it case-by-case, but that just makes the
behavior unreliable/confusing
Josh Rosenberg added the comment:
"than" is correct; "giving up" in this context would mean "not even trying to
allocate the memory and just preemptively raising OverflowError, like
non-integer numeric types with limited ranges". Rather than giving up that way,
Josh Rosenberg added the comment:
The documentation for locals (
https://docs.python.org/3/library/functions.html#locals ) specifically states:
Note: The contents of this dictionary should not be modified; changes may not
affect the values of local and free variables used by the interpreter
Josh Rosenberg added the comment:
This looks like a duplicate of #28709, though admittedly, that bug hasn't seen
any PRs.
--
nosy: +josh.r
___
Python tracker
<https://bugs.python.org/is
Josh Rosenberg added the comment:
I just tried:
subprocess.run('ls', input=b'', stdin=None)
and I got the same ValueError as for passing using kwargs. Where did you get
the idea subprocess.run('ls', input=b'', stdin
Josh Rosenberg added the comment:
The actual code receives input by name, but stdin is received in **kwargs. The
test is just:
if input is not None:
if 'stdin' in kwargs:
raise ValueError(...)
kwargs['stdin'] = PIPE
Perhaps just change `
Josh Rosenberg added the comment:
to_bytes and from_bytes aren't remotely related to native primitive types,
struct is. If the associated lengths aren't 2, 4 or 8, there is no real
correlation with system level primitives, and providing these defaults makes it
easy to accidentally
Josh Rosenberg added the comment:
Victor: "I would be interested of the same test on Windows."
Looks like someone performed it by accident, and filed #34943 in response
(because time.monotonic() did in fact return the exact same time twice in a row
Josh Rosenberg added the comment:
Problem: The variables from the nested functions (which comprehensions are
effectively a special case of) aren't actually closure variables for the
function being inspected.
Allowing recursive identification of all closure variables might be helpf
Josh Rosenberg added the comment:
Looks like a bug in the typeshed (which mypy depends on to provide typing info
for most of the stdlib, which isn't explicitly typed). Affects both
combinations and combinations_with_replacement from a quick check of the code:
https://github.com/p
Josh Rosenberg added the comment:
Your example code doesn't behave the way you claim. my_list isn't changed, and
`a` is a chain generator, not a list (without a further list wrapping).
In any event, there is no reason to involve reduce here. chain already handles
varargs what you
Josh Rosenberg added the comment:
Blech. Copy'n'paste error in last post:
a = list(itertools.chain.from_iterable(*my_list))
should be:
a = list(itertools.chain.from_iterable(my_list))
(Note removal of *, which is the whole point of fro
Change by Josh Rosenberg :
--
resolution: -> duplicate
stage: -> resolved
status: open -> closed
superseder: -> Assigning and deleting __new__ attr on the class does not allow
to create instances of this class
___
Python tra
New submission from Josh Rosenberg :
The ssl.RAND_status online docs say (with code format on True/False):
"Return True if the SSL pseudo-random number generator has been seeded with
‘enough’ randomness, and False otherwise."
This is incorrect; the function actually returns 1 or
Change by Josh Rosenberg :
--
resolution: -> not a bug
stage: -> resolved
status: open -> closed
___
Python tracker
<https://bugs.python.or
Josh Rosenberg added the comment:
The TypeError on Py3 would be because functions taking c_char_p need bytes-like
objects, not str, on Python 3. '%s' % directory is pointless when directory is
a str; instead you need to encode it to a bytes-like object, e.g.
opendir(os.fsencode
Josh Rosenberg added the comment:
As soon as you use ctypes, you sign up for all the security vulnerabilities,
including denial of service, buffer overrun, use-after-free, etc. that plain
old C programs are subject to. In this case, it's just a NULL pointer
dereference (read: segfau
Josh Rosenberg added the comment:
Sounds like the solution you'd want here is to just change each if check in
_communicate, so instead of:
if self.stdout:
selector.register(self.stdout, selectors.EVENT_READ)
if self.stderr:
selector.register(self.s
Josh Rosenberg added the comment:
Hmm... Correction to my previous post. communicate itself has a test for:
"if self._communication_started and input:"
that raises an error if it passes, so the second call to communicate can only
be passed None/empty input. And _communicate only
Josh Rosenberg added the comment:
First off, the OP's original case seems like a use case for
functools.singledispatch. Not really related to the problem, just thought I'd
mention it.
Secondly, are we sure we want to make such a guarantee? That restricts the
underlying storage
Josh Rosenberg added the comment:
I'm also a little skeptical of the OP's proposed use case for other reasons. In
any circumstance other than "all classes are defined in the same module", you
can't really make useful guarantees about subclass definition order, becau
Josh Rosenberg added the comment:
I wrote the response to the OP's use case before I saw your response; it wasn't
really intended as an additional critique of the proposed change or a
counterargument to your post, just a note that the required behavior could be
obtained on all v
Josh Rosenberg added the comment:
Keep in mind, had this guarantee been in place in 3.4, the improvement in 3.5
couldn't have been made, and issue17936 might have been closed and never
addressed, even once dicts were ordered, simply because we never rechecked it.
It makes the
Josh Rosenberg added the comment:
I would think the argument for deprecation is that usually, people type
bytes(7) or bytes(somesmallintvalue) expecting to create a length one bytes
object using that value (happens by accident if you iterate a bytes object and
forget it's an iterable of
Josh Rosenberg added the comment:
Terry: You forgot to use a raw string for your timeit.repeat check, which is
why it blew up. It was evaluating the \0 when you defined the statement string
itself, not the contents. If you use r'b"\0" * 7' it works just fine by
deferr
Changes by Josh Rosenberg :
--
nosy: +josh.rosenberg
___
Python tracker
<http://bugs.python.org/issue19995>
___
___
Python-bugs-list mailing list
Unsubscribe:
Josh Rosenberg added the comment:
fileinput's semantics are heavily tied to lines, not bytes. And processing
binary files byte by byte is rather inefficient; can you explain why this
feature would be of general utility such that it would be worth including it in
the standard library?
Josh Rosenberg added the comment:
That example should have included mode="rb" when using fileinput.input(); oops.
Pretend I didn't forget it.
--
___
Python tracker
<http://bugs.pyt
Josh Rosenberg added the comment:
On memory: Yeah, it could be if the file didn't include any newline characters.
Same problem could apply if a text input file relied on word wrap in an editor
and included very few or no newlines itself.
There are non-fileinput ways of doing this, like I
Josh Rosenberg added the comment:
And of course, missed another typo. open's first arg should be file, not
filename.
--
___
Python tracker
<http://bugs.python.org/is
Josh Rosenberg added the comment:
Aside from the method being named __next__(), it's the same flaw in all copies
of the Py3 documentation.
I don't think explicitly enumerating types is the way to go though. I'd just
remove the documentation for __next__, and leave it up
Josh Rosenberg added the comment:
This has come up before. Links to additional info:
https://mail.python.org/pipermail/python-dev/2006-February/060689.html
http://bugs.python.org/issue1772673
--
nosy: +josh.rosenberg
___
Python tracker
<h
Josh Rosenberg added the comment:
And for this particular case, even if the resource allocators don't support the
context manager protocol, contextlib.closing can do the job:
from contextlib import closing
with closing(allocateresource1()) as resource1,
closing(allocatereso
Josh Rosenberg added the comment:
It's not part of the PEP, but what happens with the new syntax if there is an
existing exception context? Some utilities (e.g. functools.lru_cache) use
dict.get over a try/except because they operate under the assumption that they
may be invoked with
Josh Rosenberg added the comment:
There is a similar, (unfixed?) bug, #14156, in argparse as well. Seems like a
common failing in the move to Python 3; std*.buffer was introduced, but none of
the places that use it were updated, so they all became str only.
--
nosy: +josh.rosenberg
Changes by Josh Rosenberg :
--
nosy: +josh.rosenberg
___
Python tracker
<http://bugs.python.org/issue14156>
___
___
Python-bugs-list mailing list
Unsubscribe:
Josh Rosenberg added the comment:
Why would we need bytes.fill(length, value)? Is b'\xVV' * length (or if value
is a variable containing int, bytes((value,)) * length) unreasonable?
Similarly, bytearray(b'\xVV) * length or bytearray((value,)) * length is both
Pythonic and p
Changes by Josh Rosenberg :
--
nosy: +josh.rosenberg
___
Python tracker
<http://bugs.python.org/issue21101>
___
___
Python-bugs-list mailing list
Unsubscribe:
New submission from Josh Rosenberg:
String translation functions, at least in other languages, are typically a
performance optimization when you *really* need the speed. In exchange for
paying the memory cost and one-time work to create a translation table, you get
much faster 1 to 1 and
Changes by Josh Rosenberg :
--
title: str.translate is absurdly slow in majority of use cases (takes 3x to 10x
longer than similar functions) -> str.translate is absurdly slow in majority of
use cases (takes up to 60x longer than similar functi
Josh Rosenberg added the comment:
@haypo: Are you planning to run with this then? Or shall I pick up where your
patch leaves off?
Thanks for the pointer to the codecs charmap_build; it's not documented
anywhere that I can tell, so I didn't even know it existed. Now to dig into the
Josh Rosenberg added the comment:
Hmm... Maybe I'm testing it wrong, but I'm finding your patch is slowing down
translation by a small amount on my test case; not a lot, maybe a 10% slowdown
on enlarging translations, 6% for 1-1, and deletion
Josh Rosenberg added the comment:
Thanks for addressing this so fast. Annoyingly, I suspect it will not help the
original case that led me to finding the slowdown (I had some code that was
translating from 56 latin-1 Romance characters with diacritics to the
equivalent ASCII characters, so it
Changes by Josh Rosenberg :
--
nosy: +josh.rosenberg
___
Python tracker
<http://bugs.python.org/issue21165>
___
___
Python-bugs-list mailing list
Unsubscribe:
New submission from Josh Rosenberg:
Py_None is not being properly decref-ed in the str.translate fast path. I've
attached a simple patch that fixes this (also corrects some comments and types
in the same function).
No idea is Py_None ref leaks are considered a serious problem, but I f
Josh Rosenberg added the comment:
For reference, bug introduced by fix for #21118.
--
___
Python tracker
<http://bugs.python.org/issue21175>
___
___
Python-bug
Josh Rosenberg added the comment:
Also, just to be clear, I submitted the contributor form earlier this evening
(using the online submission tool), so as soon as that propagates, it should be
possible to accept my code.
--
___
Python tracker
<h
Josh Rosenberg added the comment:
Any news on this? I was about to open a bug of my own for this, since the docs
and code are still out of sync.
--
nosy: +josh.rosenberg
___
Python tracker
<http://bugs.python.org/issue16
Josh Rosenberg added the comment:
As far as performance goes, presumably the length hinting API reduces the
number of cases in which we're working with completely unsized iterables, right?
--
___
Python tracker
<http://bugs.python.org/is
Changes by Josh Rosenberg :
--
nosy: +josh.rosenberg
___
Python tracker
<http://bugs.python.org/issue9066>
___
___
Python-bugs-list mailing list
Unsubscribe:
Josh Rosenberg added the comment:
Python 3.2-3.4 (probably all of 3.x) use round half even, but testing 2.7.3 on
Ubuntu confirms what you say. In terms of the decimal constants, Py2.7 round()
appears to use decimal.ROUND_HALF_UP behavior while 3.x uses
decimal.ROUND_HALF_EVEN behavior.
Looks
Josh Rosenberg added the comment:
Mark, you said:
> OverflowError seems to have the majority vote. I'll change it to that.
But your most recent patch seems to have gone back to ValueError for both
cases. Is there a reason for that? FWIW, I favor OverflowError as the "too
large&
Josh Rosenberg added the comment:
It's not really relevant what a heapified list looks like (and there is no
reason to guarantee a particular appearance, since it's an implementation
detail that could change). It's supposed to function as a heap with the heap
functions, that&
Josh Rosenberg added the comment:
By the way, in the top answer to the Stack Overflow post you linked, it's clear
that the list wasn't sorted. [44, 42, 3, 89, 10] became [3, 10, 44, 89, 42],
and you'll notice, the last three elements a
Josh Rosenberg added the comment:
I just think it's a little odd to make math.factorial uniquely sensitive to the
documented definition of OverflowError. Basically every one of the non-masking
PyLong_As interfaces uses OverflowError for too large values.
In fact, all the functions whic
New submission from Josh Rosenberg:
While checking the exceptions used to compare existing behavior while
investigating #20539, I noticed a weird behavior in pow() (implemented by
long_pow in longobject.c). If a 3rd argument (the modulus) is provided, and the
2nd argument (the exponent) is
Josh Rosenberg added the comment:
A few examples (some are patently ridiculous, since the range of values anyone
would use ends long before you'd overflow a 32 bit integer, let alone a 64 bit
value on my build of Python, but bear with me:
>>> datetime.datetime(2**64, 1, 2)
T
Josh Rosenberg added the comment:
Here's the trivial patch for code and the associated unit test (we were
actually testing that it raised TypeError specifically; it now raises
ValueError, and the unit test expects ValueError).
unit tests passed aside from test_io, but I'm pretty s
Josh Rosenberg added the comment:
As I mentioned on another bug, I filled out and submitted the contributor
agreement form electronically earlier this week, it just hasn't propagated yet.
I'm fairly sure trained monkeys reading the description of this bug report
would produce the
Josh Rosenberg added the comment:
Agreed that there is no need to patch 2.7/3.4; this is a pedantic correctness
fix, not a serious bug.
--
___
Python tracker
<http://bugs.python.org/issue21
Josh Rosenberg added the comment:
If your goal is to get a boolean on/off switch, that's what action='store_true'
is for. You don't need to specify nargs or type at all; using bool as the type
means it wants an argument, and will pass the string form of the argument to
Josh Rosenberg added the comment:
So it predates the existence of type code 'n', which would be the appropriate
type code, but no one updated it.
Antoine: Inability to perform a 2GB+ read properly is not something that should
be worked around on a case by case basis. Th
301 - 400 of 727 matches
Mail list logo