[issue41850] inspect.py: access block stack

2021-12-28 Thread Dennis Sweeney
Dennis Sweeney added the comment: With the advent of zero-cost exception handling in Python 3.10, there is no block stack, neither for exceptions nor for loops. These were always regarded as an implementation detail of the compiler. If you have any new ideas for a feature like this, I would

[issue46190] Omit k in random.sample()

2021-12-28 Thread Tilman Krummeck
Tilman Krummeck added the comment: Well, it's not bizarre, it's a use-case I'm facing quite often. But thanks for the clarification, I haven't had very large populations in mind - this makes indeed sense. -- ___ Python tracker

[issue46190] Omit k in random.sample()

2021-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: > My suggestion is not to set k=1 when omitted but to assign it a random value Sorry, I think that is just bizarre. Also, some populations are *very* large, so a minor user accident of omitting a parameter would result in a large unexpected output.

[issue46190] Omit k in random.sample()

2021-12-28 Thread Tilman Krummeck
Tilman Krummeck added the comment: My suggestion is not to set k=1 when omitted but to assign it a random value that is something between 0 and the maximum possible value which is: sum(counts) if counts else len(population) -- ___ Python tracker

[issue45508] Specialize INPLACE_ADD

2021-12-28 Thread Dennis Sweeney
Change by Dennis Sweeney : -- resolution: -> out of date stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue46190] Omit k in random.sample()

2021-12-28 Thread Dennis Sweeney
Dennis Sweeney added the comment: For completeness: def random_subset_with_counts(sequence, counts): result = [] for x, k in zip(sequence, counts): result.extend([x] * random.getrandbits(k).bit_count()) return result -- ___

[issue46190] Omit k in random.sample()

2021-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Okay. Thank for the quick response and the suggestion. I'm going to mark this one as closed. AFAICT, it distracts users from better solutions. I did a quick code search for sample(). The k==1 case is rare and in most cases the code should have used

[issue46190] Omit k in random.sample()

2021-12-28 Thread Tilman Krummeck
Tilman Krummeck added the comment: I use this mostly in tests to randomize my inputs. So currently I'm doing something like this: result = random.sample(items, random.randint(0, len(items))) I guess if someone would omit 'k' he wouldn't care about the result (which is probably a use-case

[issue46190] Omit k in random.sample()

2021-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: If all you want is a sample where k==1, then use choice(). That is clearer and more efficient. The sample() function is for sampling without replacement which only makes sense when k > 1; otherwise, choice() or choices() is usually what you want.

[issue46190] Omit k in random.sample()

2021-12-28 Thread Dennis Sweeney
Dennis Sweeney added the comment: Can you describe more about your use-case for this? You can already do something like this now with something like the following: def random_subset(sequence): source = random.randbytes(len(sequence)) return [x for x, r in zip(sequence,

[issue43118] inspect.signature() raises RuntimeError on failed to resolve the default argument value

2021-12-28 Thread hongweipeng
Change by hongweipeng : -- nosy: +hongweipeng nosy_count: 1.0 -> 2.0 pull_requests: +28499 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30285 ___ Python tracker

[issue46190] Omit k in random.sample()

2021-12-28 Thread Tilman Krummeck
New submission from Tilman Krummeck : random.sample can be used to choose k items from a given sequence. Currently, k is a mandatory parameter. I suggest to make k optional and instead, if omitted, pick a random value from the range of 0 and the length of the sequence. Of course, doing

[issue46171] venv module produces spurious warning that location has moved

2021-12-28 Thread Eryk Sun
Eryk Sun added the comment: > There are plenty of other ways to get a venv through a potentially > unexpected path (turns out I've been doing one for years) Examples would be appreciated because I'm drawing a blank here. A junction or directory symlink in the parent path shouldn't be a

[issue46187] Optionally support rounding for math.isqrt()

2021-12-28 Thread Tim Peters
Tim Peters added the comment: FYI, I had a simpler derivation in mind. Say sqrt(n) = r + f where r = isqrt(n) and 0 <= f < 1. Then sqrt(4n) = 2 * sqrt(n) = 2*(r + f) = 2r + 2f, with 0 <= 2f < 2. If f < 0.5, 2f < 1, so isqrt(4n) = 2r, and we shouldn't round r up either. If f > 0.5, 2f > 1,

[issue41585] policy.max_line_length is incorrectly assumed to never be None

2021-12-28 Thread Andrei Kulakov
Andrei Kulakov added the comment: Seems to be a duplicate of #34800 -- nosy: +andrei.avk ___ Python tracker ___ ___

[issue46187] Optionally support rounding for math.isqrt()

2021-12-28 Thread Tim Peters
Tim Peters added the comment: >> can we use the decimal module's names for the supported >> rounding modes? > I'm not sure those make sense because we never get to > exactly half. There is only floor, ceil, and round, > not half_up, half_even, etc. So use decimal's ROUND_CEILING,

[issue46187] Optionally support rounding for math.isqrt()

2021-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: > Sweet! New one on me Tim already knows this but for the record the derivation is isn't tricky. With y=isqrt(x), then next root is at y+1 and the half way point is y+1/2 which isn't an integer. The corresponding squares are y**2, (y+1/2)**2, and

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Also, it would help Serhiy's divide and conquer algorithm if the fast cases included the sides of Pascal's triangle rather than just the top: if n < TableSize and k < limits[n]: return comb_small(n, k) return comb_slow(n, k) Build the table

[issue34498] Python 3.7+ break on singledispatch_function.register(pseudo_type), which Python 3.6 accepted

2021-12-28 Thread Alex Waygood
Alex Waygood added the comment: Guido: Serhiy fixed this very recently in Issue46032. The documentation should probably be improved, however, in my opinion; there's currently nothing officially stating that GenericAlias/NewType/typing aliases are unsupported. Support for

[issue34498] Python 3.7+ break on singledispatch_function.register(pseudo_type), which Python 3.6 accepted

2021-12-28 Thread Guido van Rossum
Guido van Rossum added the comment: There's no point in lamenting the compatibility with Python 3.6, it's water under the bridge. Dispatching on types like list[int] or types generated by NewType is not realistic. Maybe the only thing left to do is to raise an error on registration when the

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Tim Peters
Tim Peters added the comment: A timing confounder: I see that CPython's _Py_popcount32() only tries to use the relevant blazing fast hardware instruction if defined(__clang__) || defined(__GNUC__). On Windows, it's a long-winded bit-fiddling dance. So which of xor-popcount and

[issue46124] Deprecation warning in zoneinfo module

2021-12-28 Thread Jason R. Coombs
Jason R. Coombs added the comment: Normalize_path from legacy implementation: https://github.com/python/importlib_resources/blob/3beb2fd5831e65f7b45033e1ec276c4a6b4ca973/importlib_resources/_legacy.py#L30-L40 -- ___ Python tracker

[issue46124] Deprecation warning in zoneinfo module

2021-12-28 Thread Jason R. Coombs
Jason R. Coombs added the comment: > Does `joinpath` have less validation? Yes. Previously, resources.* would perform some validation on the path to ensure that it didn't contain path separators (to avoid users attempting to get resources in subdirectories or perhaps manipulating the path

[issue46189] Text containing "wide" character not correctly refreshed

2021-12-28 Thread E. Paine
E. Paine added the comment: I have been able to reproduce this in Wish built from the current head. Interestingly, the cut-off seems to be 1px off what `font measure` gives (see attached). Though in this behaviour is a problem, the man page does note the following: > The return value is the

[issue38522] Py_USING_MEMORY_DEBUGGER is referenced in docs but not present in code

2021-12-28 Thread Carlos Damázio
Change by Carlos Damázio : -- keywords: +patch nosy: +dmzz nosy_count: 3.0 -> 4.0 pull_requests: +28498 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30284 ___ Python tracker

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Tim Peters
Tim Peters added the comment: Raymond, using the count of trailing zeroes instead is exactly what I suggested before, here: https://bugs.python.org/issue37295#msg409000 So Mark & I already batted that around. For whatever reasons he had, though, he stuck with the xor-popcount approach.

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: The shift table is an array of uint8_t, so it would be tiny (nearly fitting in one cache line). -- ___ Python tracker ___

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: It's a little late, but I had a thought that code could be made more general, slightly faster, and much easier to understand if the popcount logic were to be replaced with a table that records how many bits of the factorial were shifted out to make it

[issue2756] urllib.request.add_header fails with existing unredirected_header

2021-12-28 Thread Carlos Damazio
Carlos Damazio added the comment: And here's the code to reproduce the bug in 3.10. -- Added file: https://bugs.python.org/file50524/bug310.py ___ Python tracker ___

[issue2756] urllib.request.add_header fails with existing unredirected_header

2021-12-28 Thread Carlos Damazio
Carlos Damazio added the comment: This is the server for testing in 3.10. -- nosy: +carlosdamazio Added file: https://bugs.python.org/file50523/server310.py ___ Python tracker

[issue21987] TarFile.getmember on directory requires trailing slash iff over 100 chars

2021-12-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Well, the tar command strips trailing slashes (even from file paths), so it is reasonable to do this in getmember(). $ mkdir dir $ touch dir/file $ tar cf archive.tar dir $ tar tf archive.tar dir dir/ dir/file $ tar tf archive.tar dir/ dir/ dir/file $ tar

[issue46187] Optionally support rounding for math.isqrt()

2021-12-28 Thread Tim Peters
Tim Peters added the comment: [Mark] > def risqrt(n): >return (isqrt(n<<2) + 1) >> 1 Sweet! New one on me - did you invent this? It's slick :-) I'd be happy to see recipes added to the docs for rounded and ceiling flavors of isqrt, but am dubious about the value of building them in. If

[issue46175] Zero argument super() does not function properly inside generator expressions

2021-12-28 Thread Carlos Damazio
Carlos Damazio added the comment: Josh: My mistake, I've seen a similar issue, then. And agreed, I think #2 is a great candidate since we don't need to re-design existing structures. I don't know a better option... yet. -- ___ Python tracker

[issue46090] C extensions can't swap out live frames anymore

2021-12-28 Thread Brandt Bucher
Brandt Bucher added the comment: New changeset 77195cd44b2506cda88a3cfc98918526068b1d46 by Brandt Bucher in branch 'main': bpo-46090: Allow PyThreadState.datastack_* members to be NULL (GH-30234) https://github.com/python/cpython/commit/77195cd44b2506cda88a3cfc98918526068b1d46 --

[issue46090] C extensions can't swap out live frames anymore

2021-12-28 Thread Brandt Bucher
Change by Brandt Bucher : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue42259] pprint: infinite recursion for saferepr() when using nested objects, but str() works

2021-12-28 Thread Irit Katriel
Change by Irit Katriel : -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue21987] TarFile.getmember on directory requires trailing slash iff over 100 chars

2021-12-28 Thread Andrei Kulakov
Andrei Kulakov added the comment: The original issue was twofold: 1. below 100 char not working with trailing slash 2. over 100 char not working WITHOUT trailing slash The second part is no longer an issue -- tested in 3.9 and 3.11 on MacOS. Currently the issue is that a trailing slash now

[issue21987] TarFile.getmember on directory requires trailing slash iff over 100 chars

2021-12-28 Thread Andrei Kulakov
Change by Andrei Kulakov : -- nosy: +andrei.avk nosy_count: 8.0 -> 9.0 pull_requests: +28497 pull_request: https://github.com/python/cpython/pull/30283 ___ Python tracker ___

[issue46124] Deprecation warning in zoneinfo module

2021-12-28 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I just copied the implementation and normalize_path function was part of it. Looking into the implementation of normalize_path it validates the given argument to be a filename without any separator. I will leave it to Jason for a better

[issue46124] Deprecation warning in zoneinfo module

2021-12-28 Thread Paul Ganssle
Paul Ganssle added the comment: Jason's patch looks good to me, but I don't understand why Karthikeyan originally suggested using `normalize_path`. Trying to dig through exactly how `files().joinpath().open` is implemented has so many layers of indirection and abstract classes that I can't

[issue46189] Text containing "wide" character not correctly refreshed

2021-12-28 Thread hejin517
New submission from hejin517 : When the app runs it first shows a black character "f" in Times New Roman. By clicking the button, I expect that the color of the whole character will be changed to red, but actually only part is changed. In FontForge (a font editor), I find the character "f" in

[issue46177] can't install launcher for all users

2021-12-28 Thread Steve Dower
Steve Dower added the comment: This normally happens because you've already installed the launcher "just for me". You can't change that setting later. Open Add/Remove Programs and uninstall the Python Launcher first. Then you should be able to reinstall it for all users. --

[issue46171] venv module produces spurious warning that location has moved

2021-12-28 Thread Steve Dower
Steve Dower added the comment: There are plenty of other ways to get a venv through a potentially unexpected path (turns out I've been doing one for years), which is why I went with the general warning rather than limiting it to specific behaviours that are subject to change outside of our

[issue46070] _PyImport_FixupExtensionObject() regression causing a crash in subintepreters

2021-12-28 Thread Dong-hee Na
Dong-hee Na added the comment: I can reproduce the crash on my macOS with main branch version. Fatal Python error: Segmentation fault Thread 0x700010389000 (most recent call first): File "/Users/user/oss/cpython/bug.py", line 16 in doIt File

[issue46070] _PyImport_FixupExtensionObject() regression causing a crash in subintepreters

2021-12-28 Thread Dong-hee Na
Change by Dong-hee Na : -- nosy: +corona10 ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue37295] Possible optimizations for math.comb()

2021-12-28 Thread Mark Dickinson
Mark Dickinson added the comment: New changeset 02b5417f1107415abaf81acab7522f9aa84269ea by Mark Dickinson in branch 'main': bpo-37295: Speed up math.comb(n, k) for 0 <= k <= n <= 67 (GH-30275) https://github.com/python/cpython/commit/02b5417f1107415abaf81acab7522f9aa84269ea --

[issue30420] Clarify kwarg handing for subprocess convenience APIs

2021-12-28 Thread Alex Waygood
Alex Waygood added the comment: The modern docs for these functions seem to: * Document the cwd argument for these functions, following PR 1685 & PR 2253. * Include an **other_popen_kwargs parameter for all these functions. Nick, is there anything left to do here, or can this issue be closed

[issue46188] dictionary creation error

2021-12-28 Thread Steven D'Aprano
Steven D'Aprano added the comment: > I still can not figure out why the first two elements are inconsistent from the rest of the dictionary, and why they appear in the first place. Hi Tobias, This is a bug tracker for reporting bugs in Python, not a help desk to ask for explanations. The

[issue46188] dictionary creation error

2021-12-28 Thread TobiasHT
New submission from TobiasHT : I was creating a dictionary when I noticed something weird. I had a function responsible for creating dictionary keys and then values were assigned to the keys in a for loop. The code goes a little like this: >>> def key_maker(n): ... if (n % 2) == 0: ...