[issue43420] Optimize rational arithmetics

2021-03-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> 1 loop, best of 11: 257 msec per loop
> $ ... from patched ...
> 10 loops, best of 11: 33.2 msec per loop

Looks worth it :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41361] Converting collections.deque methods to Argument Clinic

2021-03-06 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

If the argument clinic is too disruptive, would it be okay to inline the 
equivalent code like this?

diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 90bafb0ea8..d75388abc8 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -880,9 +880,19 @@ deque_rotate(dequeobject *deque, PyObject *const *args, 
Py_ssize_t nargs)
 {
 Py_ssize_t n=1;

-if (!_PyArg_ParseStack(args, nargs, "|n:rotate", )) {
+if (!_PyArg_CheckPositional("deque.rotate", nargs, 0, 1)) {
 return NULL;
 }
+if (nargs) {
+PyObject *index = _PyNumber_Index(args[0]);
+if (index == NULL) {
+return NULL;
+}
+n = PyLong_AsSsize_t(index);
+if (n == -1 && PyErr_Occurred()) {
+return NULL;
+}
+}

 if (!_deque_rotate(deque, n))
 Py_RETURN_NONE;

Benchmarks for this change:

.\python.bat -m pyperf timeit -s "from collections import deque; d = 
deque(range(100))" "d.rotate()"
Before: Mean +- std dev: 51.2 ns +- 0.9 ns
After:  Mean +- std dev: 39.3 ns +- 0.3 ns

.\python.bat -m pyperf timeit -s "from collections import deque; d = 
deque(range(100))" "d.rotate(-1)"
Before: Mean +- std dev: 64.5 ns +- 0.3 ns
After:  Mean +- std dev: 46.2 ns +- 0.3 ns

.\python.bat -m pyperf timeit -s "from collections import deque; d = 
deque(range(100))" "d.rotate(1)"
Before: Mean +- std dev: 64.4 ns +- 0.3 ns
After:  Mean +- std dev: 45.7 ns +- 0.2 ns

Similar changes could apply to deque.insert() and deque.index().

--
nosy: +Dennis Sweeney

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43405] DeprecationWarnings in test_unicode

2021-03-06 Thread Inada Naoki


Change by Inada Naoki :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43405] DeprecationWarnings in test_unicode

2021-03-06 Thread Inada Naoki


Inada Naoki  added the comment:


New changeset 8aabfa8550692a76d8a96e138c48faf5a7b2752c by Zackery Spytz in 
branch 'master':
bpo-43405: Fix DeprecationWarnings in test_unicode (GH-24754)
https://github.com/python/cpython/commit/8aabfa8550692a76d8a96e138c48faf5a7b2752c


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43420] Optimize rational arithmetics

2021-03-06 Thread Aaron Meurer


Change by Aaron Meurer :


--
nosy: +asmeurer

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41282] Deprecate and remove distutils

2021-03-06 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

I have created below issues where deprecation warning is emitted due to 
distutils usage in tests. Probably there are other places that need an update 
to setuptools like setup.py used by make that emits deprecation warning during 
building cpython.

https://bugs.python.org/issue43426
https://bugs.python.org/issue43425

 rg '(from|import) distutils' | rg -v 'Lib/distutils|rst'
Modules/_decimal/tests/formathelper.py:from distutils.spawn import 
find_executable
Doc/includes/setup.py:from distutils.core import setup, Extension
Doc/includes/test.py:from distutils.util import get_platform
setup.py:from distutils import log
setup.py:from distutils.command.build_ext import build_ext
setup.py:from distutils.command.build_scripts import build_scripts
setup.py:from distutils.command.install import install
setup.py:from distutils.command.install_lib import install_lib
setup.py:from distutils.core import Extension, setup
setup.py:from distutils.errors import CCompilerError, DistutilsError
setup.py:from distutils.spawn import find_executable
Lib/_osx_support.py:from distutils import log
Lib/_osx_support.py:Currently called from distutils.sysconfig
Lib/test/support/__init__.py:from distutils import ccompiler, sysconfig, 
spawn, errors
Lib/test/test_distutils.py:import distutils.tests
Lib/test/test_importlib/test_windows.py:from distutils.util import get_platform
Lib/test/test_peg_generator/test_c_parser.py:from distutils.tests.support 
import TempdirManager
Lib/test/test_sundry.py:import distutils.bcppcompiler
Lib/test/test_sundry.py:import distutils.ccompiler
Lib/test/test_sundry.py:import distutils.cygwinccompiler
Lib/test/test_sundry.py:import distutils.filelist
Lib/test/test_sundry.py:import distutils.text_file
Lib/test/test_sundry.py:import distutils.unixccompiler
Lib/test/test_sundry.py:import distutils.command.bdist_dumb
Lib/test/test_sundry.py:import distutils.command.bdist_msi
Lib/test/test_sundry.py:import distutils.command.bdist
Lib/test/test_sundry.py:import distutils.command.bdist_rpm
Lib/test/test_sundry.py:import distutils.command.build_clib
Lib/test/test_sundry.py:import distutils.command.build_ext
Lib/test/test_sundry.py:import distutils.command.build
Lib/test/test_sundry.py:import distutils.command.clean
Lib/test/test_sundry.py:import distutils.command.config
Lib/test/test_sundry.py:import distutils.command.install_data
Lib/test/test_sundry.py:import distutils.command.install_egg_info
Lib/test/test_sundry.py:import distutils.command.install_headers
Lib/test/test_sundry.py:import distutils.command.install_lib
Lib/test/test_sundry.py:import distutils.command.register
Lib/test/test_sundry.py:import distutils.command.sdist
Lib/test/test_sundry.py:import distutils.command.upload
Tools/peg_generator/pegen/build.py:import distutils.log
Tools/peg_generator/pegen/build.py:from distutils.core import Distribution, 
Extension
Tools/peg_generator/pegen/build.py:from distutils.command.clean import 
clean  # type: ignore
Tools/peg_generator/pegen/build.py:from distutils.command.build_ext import 
build_ext  # type: ignore
Tools/peg_generator/pegen/build.py:from distutils.tests.support import 
fixup_build_ext  # type: ignore
Tools/c-analyzer/c_parser/preprocessor/common.py:import distutils.ccompiler
Tools/c-analyzer/c_parser/preprocessor/__init__.py:import distutils.ccompiler
Tools/test2to3/setup.py:from distutils.core import setup
Tools/test2to3/setup.py:from distutils.command.build_py import 
build_py_2to3 as build_py
Tools/test2to3/setup.py:from distutils.command.build_py import build_py
Tools/test2to3/setup.py:from distutils.command.build_scripts import 
build_scripts_2to3 as build_scripts
Tools/test2to3/setup.py:from distutils.command.build_scripts import 
build_scripts
Tools/test2to3/test/runtests.py:from distutils.util import copydir_run_2to3
Misc/HISTORY:- Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler.

--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43426] test_importlib.test_windows emits deprecation warning over usage of distutils

2021-03-06 Thread Karthikeyan Singaravelan


New submission from Karthikeyan Singaravelan :

test_windows uses distutil which emits a deprecation warning due to distutils 
being deprecated. sysconfig.get_platform and distutils.util.get_host_platform 
seem to be identical though distutils.util.get_platform has an extra if clause 
for nt systems. This is related to https://bugs.python.org/issue41282

./python -Wall -m test test_importlib.test_windows
0:00:00 load avg: 0.00 Run tests sequentially
0:00:00 load avg: 0.00 [1/1] test_importlib.test_windows
/root/cpython/Lib/test/test_importlib/test_windows.py:10: DeprecationWarning: 
The distutils package is deprecated and slated for removal in Python 3.12. Use 
setuptools or check PEP 632 for potential alternatives
  from distutils.util import get_platform
test_importlib.test_windows skipped -- No module named 'winreg'
test_importlib.test_windows skipped

== Tests result: SUCCESS ==

1 test skipped:
test_importlib.test_windows

Total duration: 56 ms
Tests result: SUCCESS

--
components: Tests, Windows
messages: 388223
nosy: paul.moore, steve.dower, tim.golden, xtreak, zach.ware
priority: normal
severity: normal
status: open
title: test_importlib.test_windows emits deprecation warning over usage of 
distutils
type: behavior
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43425] test_peg_generator.test_c_parser emits DeprecationWarning due to distutils

2021-03-06 Thread Karthikeyan Singaravelan


New submission from Karthikeyan Singaravelan :

distutils was deprecated for removal in Python 3.10. It is used in 
test_peg_generator.test_c_parser which emits a deprecation warning. It also 
seems to be used in test_support for missing_compiler_executable that will emit 
a deprecation warning.

./python -Wall -m test test_peg_generator test_c_parser
0:00:00 load avg: 0.02 Run tests sequentially
0:00:00 load avg: 0.02 [1/2] test_peg_generator
/root/cpython/Lib/test/test_peg_generator/test_c_parser.py:4: 
DeprecationWarning: The distutils package is deprecated and slated for removal 
in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.tests.support import TempdirManager


Other places on grep : 

rg 'from distutils' | rg -v 'Lib/distutils|rst'   
Modules/_decimal/tests/formathelper.py:from distutils.spawn import 
find_executable
Doc/includes/setup.py:from distutils.core import setup, Extension
Doc/includes/test.py:from distutils.util import get_platform
setup.py:from distutils import log
setup.py:from distutils.command.build_ext import build_ext
setup.py:from distutils.command.build_scripts import build_scripts
setup.py:from distutils.command.install import install
setup.py:from distutils.command.install_lib import install_lib
setup.py:from distutils.core import Extension, setup
setup.py:from distutils.errors import CCompilerError, DistutilsError
setup.py:from distutils.spawn import find_executable
Lib/_osx_support.py:from distutils import log
Lib/_osx_support.py:Currently called from distutils.sysconfig
Lib/test/support/__init__.py:from distutils import ccompiler, sysconfig, 
spawn, errors
Lib/test/test_importlib/test_windows.py:from distutils.util import get_platform
Lib/test/test_peg_generator/test_c_parser.py:from distutils.tests.support 
import TempdirManager
Tools/peg_generator/pegen/build.py:from distutils.core import Distribution, 
Extension
Tools/peg_generator/pegen/build.py:from distutils.command.clean import 
clean  # type: ignore
Tools/peg_generator/pegen/build.py:from distutils.command.build_ext import 
build_ext  # type: ignore
Tools/peg_generator/pegen/build.py:from distutils.tests.support import 
fixup_build_ext  # type: ignore
Tools/test2to3/setup.py:from distutils.core import setup
Tools/test2to3/setup.py:from distutils.command.build_py import 
build_py_2to3 as build_py
Tools/test2to3/setup.py:from distutils.command.build_py import build_py
Tools/test2to3/setup.py:from distutils.command.build_scripts import 
build_scripts_2to3 as build_scripts
Tools/test2to3/setup.py:from distutils.command.build_scripts import 
build_scripts
Tools/test2to3/test/runtests.py:from distutils.util import copydir_run_2to3
Misc/HISTORY:- Issue #5394: removed > 2.3 syntax from distutils.msvc9compiler.

--
components: Tests
messages: 388222
nosy: pablogsal, xtreak
priority: normal
severity: normal
status: open
title: test_peg_generator.test_c_parser emits DeprecationWarning due to 
distutils
type: behavior
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43420] Optimize rational arithmetics

2021-03-06 Thread Sergey B Kirpichev


Change by Sergey B Kirpichev :


--
pull_requests: +23544
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24779

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43420] Optimize rational arithmetics

2021-03-06 Thread Sergey B Kirpichev


Sergey B Kirpichev  added the comment:

I have similar timings (for a draft version of PR, see f.patch) as for the last 
comment, though the small-dens overhead seems to be bigger(~20%):
$ python3.10 -m timeit -r11 -s 'from fractions import Fraction as F' -s 
'a=F(10,3)' -s 'b=F(6, 5)' 'a * b'
5 loops, best of 11: 9.09 usec per loop
$ python3.10 -m timeit -r11 -s 'from patched import Fraction as F' -s 
'a=F(10,3)' -s 'b=F(6, 5)' 'a * b'
2 loops, best of 11: 11.2 usec per loop

On another hand, here are timings for bigger denominators:
$ python3.10 -m timeit -r11 -s 'from fractions import Fraction as F' -s 'import 
random' -s 'n = [random.randint(1, 100) for _ in range(1000)]' -s 'd = 
[random.randint(1, 100) for _ in range(1000)]' -s 'a=list(map(lambda x: 
F(*x), zip(n, d)))' 'sum(a)'
1 loop, best of 11: 257 msec per loop
$ ... from patched ...
10 loops, best of 11: 33.2 msec per loop

It's not so clear what "are very large" does mean, that could be defined here.  
BTW, 10**6 denominators are (very!) small for mentioned above use case (CAS 
package).

--
keywords: +patch
Added file: https://bugs.python.org/file49854/f.patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Apriori Algorithm

2021-03-06 Thread Paul Bryan
Google tells me this:
https://github.com/tommyod/Efficient-Apriori

On Sat, 2021-03-06 at 18:46 -0800, sarang shah wrote:
> I want to make apriori algorithm from start. Anybody have any
> reference file?

-- 
https://mail.python.org/mailman/listinfo/python-list


RE: Apriori Algorithm

2021-03-06 Thread Avi Gross via Python-list
"I want to make apriori algorithm from start. Anybody have any
reference file?"

Excellent question. Based on everything you shared, I think all I can offer
is that whatever you do, do not make the aposteriori version.

Or, you could consider asking a real question with enough detail that maybe
someone understanding it will give you a hint in advance.

-Original Message-
From: Python-list  On
Behalf Of sarang shah
Sent: Saturday, March 6, 2021 9:47 PM
To: python-list@python.org
Subject: Apriori Algorithm

I want to make apriori algorithm from start. Anybody have any reference
file?
-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: pygame errors

2021-03-06 Thread MRAB

On 2021-03-07 03:01, Quentin Bock wrote:

#Space Invaders!
#Title and Icon
pygame.display.set_caption("Space Invaders")
icon = pygame.image.load('space-invaders.png')
pygame.display.set_icon(icon)
#Player
player_Image = pygame.image.load('player.png')
player_X = 370
player_Y = 480

def player():
 screen.blit(player_Image, player_X, player_Y)


The position should be given as a 2-tuple, not as 2 separate parameters.

The line should be:

 screen.blit(player_Image, (player_X, player_Y))



#Game Loop
pygame.init()
screen = pygame.display.set_mode((800, 600))
running = True
while running:

 screen.fill((128, 128, 128))

 for event in pygame.event.get():
 if event.type == pygame.QUIT:
 running = False
 player()
 pygame.display.update()

The window will not display the icon, saying, "invalid destination for blit"

Is this an indentation error? I don't understand why this position
would be invalid.

link to tutorial I'm following:

https://www.youtube.com/watch?v=FfWpgLFMI7w



--
https://mail.python.org/mailman/listinfo/python-list


[issue25024] Allow passing "delete=False" to TemporaryDirectory

2021-03-06 Thread C.A.M. Gerlach


C.A.M. Gerlach  added the comment:

To note, the proposal on [BPO-29982](https://bugs.python.org/issue29982) should 
hopefully address one of the two use-cases described by Anthony Sotittle, 
`ignore_errors=True`, in a cleaner fashion that takes advantage of the existing 
higher-level functionality rather than duplicating `mkdtemp`. Opinions and 
feedback welcome over there.

--
nosy: +CAM-Gerlach

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue29982] tempfile.TemporaryDirectory fails to delete itself

2021-03-06 Thread C.A.M. Gerlach


C.A.M. Gerlach  added the comment:

In addition to transient failures, this can also occur when, for example, files 
opened in the temporary directory (perhaps by library or application code not 
under direct control of the caller) haven't been properly cleaned up and their 
file handles don't get closed, resulting in permissions errors trying to delete 
them (particularly on platforms like Windows, that automatically lock files 
when opening them).

This case came up in e.g. [this recent 
PR](https://github.com/regebro/pyroma/pull/57) and rendered 
`tempfile.TemporaryDirectory` unusable for such use cases, forcing a reversion 
to the lower-level `tempfile.mkdtemp` without the cleaner, more robust and 
easier to interpret high-level interface that the former provides. Wrapping a 
`with` statement in a try-finally is syntactically ugly and semantically 
incongruous, and requires a second shutil.rmtree(..., ignore_errors=True)` call 
to clean up in a best-effort manner, while when manually calling `cleanup()` in 
a try-except, the finalizer still gets executed at a a non-deterministic later 
time when Python exits, raising an error.

Therefore, in the spirit of Guido's statements above in terms of providing a 
"best-effort" cleanup, I propose (and am willing to submit a PR to implement) 
adding an `ignore_errors` bool parameter (defaulting to False, of course, for 
backward compat--and should it be keyword only like `errors` to 
`TemporaryFile`?) to the `tempfile.TemporaryDirectory` constructor, which gets  
passed to `shutil.rmtree` on cleanup. This would not only address both cases 
here, but also one of the two discussed by Anthony Sotitle on 
[BPO-25024](https://bugs.python.org/issue25024), in a cleaner and simpler 
fashion that would take advantage of existing `tempfile.TemporaryDirectory` 
functionality and behavior.

Would a PR be accepted on this? If so, any specific guidance on tests and 
whether to mention it in What's New, etc., would be appreciated. Thanks!

--
nosy: +CAM-Gerlach

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



pygame errors

2021-03-06 Thread Quentin Bock
#Space Invaders!
#Title and Icon
pygame.display.set_caption("Space Invaders")
icon = pygame.image.load('space-invaders.png')
pygame.display.set_icon(icon)
#Player
player_Image = pygame.image.load('player.png')
player_X = 370
player_Y = 480

def player():
screen.blit(player_Image, player_X, player_Y)


#Game Loop
pygame.init()
screen = pygame.display.set_mode((800, 600))
running = True
while running:

screen.fill((128, 128, 128))

for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
player()
pygame.display.update()

The window will not display the icon, saying, "invalid destination for blit"

Is this an indentation error? I don't understand why this position
would be invalid.

link to tutorial I'm following:

https://www.youtube.com/watch?v=FfWpgLFMI7w
-- 
https://mail.python.org/mailman/listinfo/python-list


Apriori Algorithm

2021-03-06 Thread sarang shah
I want to make apriori algorithm from start. Anybody have any reference file?
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue43424] Document the `controller.name` field in `webbrowser` module

2021-03-06 Thread Ilya Grigoriev


New submission from Ilya Grigoriev :

The object `webbrowser.get()` returns has, and had for a long time, a useful 
but undocumented field `name`. I wonder if it would be OK to document it as 
something like `a system-dependent name for the browser`. This would go here:

https://docs.python.org/3/library/webbrowser.html#browser-controller-objects

The reason I'd like this is so that I can write code like the following:

```python
# In Crostini Chrome OS Linux, the default browser is set to an
# intermediary called `garcon-url-handler`.
# It opens URLs in Chrome running outside the linux VM. This 
# browser does not have access to the Linux filesystem. Some references:
# 
https://chromium.googlesource.com/chromiumos/platform2/+/master/vm_tools/garcon/#opening-urls
# https://source.chromium.org/search?q=garcon-url-handler

if "garcon-url-handler" in webbrowser.get().name:
  webbrowser.open("http://external-url.com/docs.html;)
else:
  webbrowser.open("file:///usr/share/doc/docs.html")
```

This would work correctly, even if the user has installed a browser native to 
the Linux VM and put it into their `BROWSER` environment variable. I don't know 
a better way to achieve the same effect.

Some references to where the `name` field was introduced:

https://bugs.python.org/issue754022

https://github.com/python/cpython/commit/e8f244305ef4f257f6999b69601f4316b31faa5e

--
assignee: docs@python
components: Documentation, Library (Lib)
messages: 388218
nosy: docs@python, ilyagr
priority: normal
severity: normal
status: open
title: Document the `controller.name` field in `webbrowser` module
type: enhancement
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue40982] copytree example in shutil

2021-03-06 Thread Zackery Spytz


Change by Zackery Spytz :


--
keywords: +patch
nosy: +ZackerySpytz
nosy_count: 3.0 -> 4.0
pull_requests: +23543
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24778

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Chris Angelico
On Sun, Mar 7, 2021 at 9:42 AM Mirko via Python-list
 wrote:
> I even wonder why they have tried. Writing a universal
> compiler/interpreter sounds logically impossible to me, Here's a
> simple Python expression:
>
> >>> 3+3*5
> 18
>
> And here's the same expression in (GNU) Smalltalk:
>
> st> 3+3*5
> 30
>
>
> How would such a universal compiler know which evaluation strategy
> to follow, if not by writing a parser end evaluator for every
> supported language? And if it's hard for this simple problem, how
> about more complex cases.

There are two ways in which "universal compiler/interpreter" can
definitely make sense, but neither of them is what he's trying to do.

1) A bytecode or machine code that all other languages can be compiled
to. For example, I'm running an amd64 CPU, so on this computer,
everything ultimately gets executed as amd64 bytecode. It's also
possible to have higher level bytecodes, or even textual languages
(Asm.js can be used as a compilation target).

2) "Compiler compilers" and grammar parsers. These are an excellent
tool for people designing programming language compilers, as they make
it a lot easier to describe the syntax and semantics for the language.

Both of them are tools that programming language developers use. They
don't replace language interpreters any more than a JSON parser
replaces the need to open files.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Mirko via Python-list
Am 06.03.2021 um 22:24 schrieb Ben Bacarisse:
> Mr Flibble  writes:
> 
>>> Someone who says that he is capable of writing a compiler that
>>> translates every language has megalomania. No one can do this.
>>
>> Just because you can't make one it doesn't follow that nobody else
>> can.
> 
> True, but lots of very knowledgeable people have tried and failed.

I even wonder why they have tried. Writing a universal
compiler/interpreter sounds logically impossible to me, Here's a
simple Python expression:

>>> 3+3*5
18

And here's the same expression in (GNU) Smalltalk:

st> 3+3*5
30


How would such a universal compiler know which evaluation strategy
to follow, if not by writing a parser end evaluator for every
supported language? And if it's hard for this simple problem, how
about more complex cases.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Chris M. Thomasson

On 3/5/2021 8:51 AM, Mr Flibble wrote:
neonumeric - C++ arbitrary precision arithmetic library with arbitrary 
precision integers, floats and rationals:


https://github.com/i42output/neonumeric

It hasn't been formally released yet as it still requires more extensive 
testing.  It will be used as part of my universal compiler, neos, that 
can compile any programming language and will be used for the neos 
implementation of Python (Python has big integers).


Message ends.


Get atan2, cos and sin, and I have some code to run it against.

https://github.com/ChrisMThomasson/fractal_cipher/blob/master/RIFC/cpp/ct_rifc_sample.cpp

It needs arbitrary precision! :^)
--
https://mail.python.org/mailman/listinfo/python-list


RE: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Avi Gross via Python-list
Just to be clear, and luckily the person who posed such boasts is luckily
gone and I AM NOT interested in having the discussion again here, I have a
point to make.

He did not suggest a magical compiler that could translate any language. Not
exactly.

I think he suggested that if all languages share a large set of paradigms
related to what methods we have for computing, then there may be a way to
capture and store some description of any new language that defines it well
enough. He proposed a sort of universal program, indeed, that would read the
description files and then actual programs and generate something that
ultimately would be runnable. Of course, he basically ignored any little
details along the way and even insisted it would be easy and the result
would be much more efficient in every case.

So, I suggest he is not as bright as he thinks.

I, on the other hand, think it is a hard problem but in some abstract sense
doable given infinite resources and time. Translation, not a worthwhile
quest for NOW. There are accepted theorems that suggests a fairly simple
Turing Machine can solve any problem computable on our current (non-quantum)
generation of computers. The programs would be very far from efficient and
in some cases would require an infinitely long tape and more states than our
universe can accommodate. But in principle, it can do anything as stated
above.

So, any program in any language can theoretically be rewritten as a Turing
Machine version. But that would not be done by a universal translator. I
assume you could do it from say a compiled machine language version for some
languages but it would require access to anything modern programs get from
all kinds of libraries out there that extend the program and if it spawns
other processes or has things run in parallel it gets more and more complex.

But why do it at all? 

Sure, translating parts of some programs in one language to another can make
sense. But why a goal to have a sort of Unified Programming Language Theory
other than as an academic exercise?

Having said that, I keep looking at how languages like Python and R grow and
how they keep adding features including many borrowed or imitated from
elsewhere and I conclude you can just put everything imaginable into Python
and the rest become superfluous! Problem solved.

-Original Message-
From: Python-list  On
Behalf Of Bonita Montero
Sent: Saturday, March 6, 2021 2:12 PM
To: python-list@python.org
Subject: Re: neonumeric - C++ arbitrary precision arithmetic library

>> There is no projection.
>> _You_ have megalomania, not me.
>> And there's also no Dunning Kruger effect.
>> You can't assess your capabilites, not me.

> no u

Someone who says that he is capable of writing a compiler that translates
every language has megalomania. No one can do this.

--
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue42246] Implement PEP 626 -- Precise line numbers for debugging

2021-03-06 Thread Neil Schemenauer


Neil Schemenauer  added the comment:


New changeset 87ec26b812e9c4095c017dc60f246eda37b83ab2 by Neil Schemenauer in 
branch 'master':
bpo-43372: Use _freeze_importlib for regen-frozen. (GH-24759)
https://github.com/python/cpython/commit/87ec26b812e9c4095c017dc60f246eda37b83ab2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43372] ctypes: test_frozentable fails when make regen-frozen

2021-03-06 Thread Neil Schemenauer


Change by Neil Schemenauer :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43372] ctypes: test_frozentable fails when make regen-frozen

2021-03-06 Thread Neil Schemenauer


Neil Schemenauer  added the comment:


New changeset 87ec26b812e9c4095c017dc60f246eda37b83ab2 by Neil Schemenauer in 
branch 'master':
bpo-43372: Use _freeze_importlib for regen-frozen. (GH-24759)
https://github.com/python/cpython/commit/87ec26b812e9c4095c017dc60f246eda37b83ab2


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Ben Bacarisse
Mr Flibble  writes:

>> Someone who says that he is capable of writing a compiler that
>> translates every language has megalomania. No one can do this.
>
> Just because you can't make one it doesn't follow that nobody else
> can.

True, but lots of very knowledgeable people have tried and failed.  And
although you use the present tense "my universal compiler, neos, that
/can/ compile any programming language" (emphasis mine) you currently
have nothing to show -- no compiler for any language, no paper outlining
how you plan to overcome the problems that stumped others, nothing but
what appears to be a false claim about neos can do.  If you want this
project to be taken seriously, you are going about it the wrong way.

-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Chris M. Thomasson

On 3/6/2021 11:35 AM, Mr Flibble wrote:

On 06/03/2021 19:11, Bonita Montero wrote:

There is no projection.
_You_ have megalomania, not me.
And there's also no Dunning Kruger effect.
You can't assess your capabilites, not me.



no u


Someone who says that he is capable of writing a compiler that
translates every language has megalomania. No one can do this.


Just because you can't make one it doesn't follow that nobody else can.


I remember when Bonita tried to convince me that a mutex must use an 
atomic counter.


--
https://mail.python.org/mailman/listinfo/python-list


[issue43420] Optimize rational arithmetics

2021-03-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Without the guards the incremental cost drops to 10%.

$ python3.10 -m timeit -r11 -s 'from patched_noguards import Fraction as F' -s 
'a=F(10,3)' -s 'b=F(6, 5)' 'a * b'
10 loops, best of 11: 2.02 usec per loop

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43420] Optimize rational arithmetics

2021-03-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

The cost to the common case for small components is about 20%:

$ python3.10 -m timeit -r11 -s 'from fractions import Fraction as F' -s 
'a=F(10,3)' -s 'b=F(6, 5)' 'a * b'
20 loops, best of 11: 1.8 usec per loop

$ python3.10 -m timeit -r11 -s 'from patched import Fraction as F' -s 
'a=F(10,3)' -s 'b=F(6, 5)' 'a * b'
10 loops, best of 11: 2.14 usec per loop

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43216] Removal of @asyncio.coroutine in Python 3.10

2021-03-06 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +graingert

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43423] Subprocess IndexError possible in _communicate

2021-03-06 Thread Eryk Sun


Eryk Sun  added the comment:

The presumption I suppose is that these statements only execute if 
self.stdout_thread and/or self.stderr_thread completes successfully. I suppose 
that the read could fail or get canceled via CancelSynchronousIo(). Of course 
in that case you have a bigger problem than an IndexError.

On a related note, _communicate() needs significant changes in Windows. See 
bpo-43346 if you're interested.

--
components: +Windows
nosy: +eryksun, paul.moore, steve.dower, tim.golden, zach.ware

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43420] Optimize rational arithmetics

2021-03-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Note that Fraction arithmetic has a huge administrative overhead. The cost of 
the underlying multiplications and divisions won't dominate the total time 
until the numerators and denominators are very large.

For the proposed optimization, this implies that cost for the extra Python 
steps to implement the optimization will be negligible.  The benefits of the 
optimization are similarly attenuated.

-- Update to experimentation code: add guards for the relatively prime case. --

class Henrici(Fraction):
'Reformulate _mul to reduce the size of intermediate products'
def _mul(a, b):
a_n, a_d = a.numerator, a.denominator
b_n, b_d = b.numerator, b.denominator
d1 = math.gcd(a_n, b_d)
if d1 > 1:
a_n //= d1
b_d //= d1
d2 = math.gcd(b_n, a_d)
if d2 > 1:
b_n //= d2
a_d //= d2
result = Fraction(a_n * b_n, a_d * b_d, _normalize=False)
assert math.gcd(a_n * b_n, a_d * b_d) == 1 and a_d * b_d >= 0
return result

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43420] Optimize rational arithmetics

2021-03-06 Thread Mark Dickinson


Change by Mark Dickinson :


--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Bonita Montero

There is no projection.
_You_ have megalomania, not me.
And there's also no Dunning Kruger effect.
You can't assess your capabilites, not me.



no u


Someone who says that he is capable of writing a compiler that
translates every language has megalomania. No one can do this.

--
https://mail.python.org/mailman/listinfo/python-list


[issue43423] Subprocess IndexError possible in _communicate

2021-03-06 Thread Chris Griffith


Change by Chris Griffith :


--
keywords: +patch
pull_requests: +23542
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24777

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ANN] managesieve 0.7

2021-03-06 Thread Hartmut Goebel
Announcing:

 managesieve 0.7

    ManageSieve client library for remotely managing Sieve scripts,
    including an user application (the interactive 'sieveshell').

:Homepage: https://managesieve.readthedocs.io/
:Author:   Hartmut Goebel 
:License:
  - for the managesieve module: Python-Software-Foundation-like License
  - for sieveshell and test suite: GNU Public Licence v3 (GPLv3)

:Quick Installation:
    pip install -U managesieve

:Tarballs:  https://pypi.org/project/managesieve/#files


What is managesieve?
-

A ManageSieve client library for remotely managing Sieve scripts,
including an user application (the interactive 'sieveshell').

Sieve scripts allow users to filter incoming email on the mail server.
The ManageSieve protocol allows managing Sieve scripts on a remote
mail server. These servers are commonly sealed so users cannot log
into them, yet users must be able to update their scripts on them.
This is what for the "ManageSieve" protocol is. For more information
about the ManageSieve protocol see `RFC 5804
`_.

This module allows accessing a Sieve-Server for managing Sieve scripts
there. It is accompanied by a simple yet functional user application
'sieveshell'.


Changes since last release
---

* Minimum required Python version is now Python 3.6.

:sieveshell:

   - For ``get`` and ``put`` expand ``~`` and ``~user`` constructions in
 `filename` . For ``put``, if script-name is not given, the file's
 basename is used.

:managesieve:
   - Fix error when constructing debug error message.

-- 
Regards
Hartmut Goebel

| Hartmut Goebel  | h.goe...@crazy-compilers.com   |
| www.crazy-compilers.com | compilers which you thought are impossible |

___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


[ANN] python-ghostscript 0.7

2021-03-06 Thread Hartmut Goebel
Announcing:
 

   python-ghostscript 0.7

   A Python-Interface to the Ghostscript
                 C-API using ctypes

:License: GNU General Public License v3 or later (GPLv3+)
:Author:  Hartmut Goebel 
:Homepage: https://gitlab.com/pdftools/python-ghostscript
:Download: https://pypi.python.org/pypi/ghostscript

`Ghostscript`__, is a well known interpreter for the PostScript
language and for PDF. This package implements a interface to the
Ghostscript C-API using `ctypes`__. Both a low-level and a pythonic,
high-level interface are provided.

__ http://www.ghostscript.com/
__ http://docs.python.org/library/ctypes.html

This package is currently tested only under GNU/Linux. Please report
whether it works in your environment, too. Thanks.


Changes since last release


* BREAKING: ``Ghostscript()`` no longer allows passing arbitrary
  keyword arguments.

* The high-level interface now allows passing unicode strings as
  arguments. Passing bytes as arguments is still possible, but now
  deprecated.

* The high-level interface now requires ghostscript >= 9.0.8 (released
  2013-08-14).

* Allow multiple Ghostscript instances. Actually using this requires
  the library is compiled with -DGS_THREADSAFE.

* Ensure proper clean-up on error.

* High-level revision() now returns unicode strings instead of byte
  strings.

* Add low-level interface for set_arg_encoding().

* Miscellaneous small fixes.

* Drop support for Python 2.7, 3.4 and 3.5.
  Minimum required Python version is now 3.6.


Example


Here is an example for how to use the high-level interface of
`python-ghostscript`. This implements a very basic ps2pdf-tool::

  import sys
  import ghostscript

  args = [
  "ps2pdf",    # actual value doesn't matter
  "-dNOPAUSE", "-dBATCH", "-dSAFER",
  "-sDEVICE=pdfwrite",
  "-sOutputFile=" + sys.argv[1],
  "-c", ".setpdfwrite",
  "-f",  sys.argv[2]
  ]

  ghostscript.Ghostscript(*args)

-- 
Regards
Hartmut Goebel

| Hartmut Goebel  | h.goe...@crazy-compilers.com   |
| www.crazy-compilers.com | compilers which you thought are impossible |

___
Python-announce-list mailing list -- python-announce-list@python.org
To unsubscribe send an email to python-announce-list-le...@python.org
https://mail.python.org/mailman3/lists/python-announce-list.python.org/
Member address: arch...@mail-archive.com


[issue43423] Subprocess IndexError possible in _communicate

2021-03-06 Thread Chris Griffith


New submission from Chris Griffith :

It is possible to run into an IndexError in the subprocess module's 
_communicate function.

```
return run(
  File "subprocess.py", line 491, in run
  File "subprocess.py", line 1024, in communicate
  File "subprocess.py", line 1418, in _communicate
IndexError: list index out of range
```

The lines in question are: 

```
if stdout is not None:
stdout = stdout[0]
if stderr is not None:
stderr = stderr[0]
```

I believe this is due to the fact there is no safety checking to make sure that 
self._stdout_buff and self._stderr_buff have any content in them after being 
set to empty lists. 

The fix I suggest is to change the checks from `if stdout is not None` to 
simply `if stdout` to make sure it is a populated list. 

Example fixed code: 

```
if stdout:
stdout = stdout[0]
if stderr:
stderr = stderr[0]
```

If a more stringent check is required, we could expand that out to check type 
and length, such as `isinstance(stdout, list) and len(stdout) > 0:` but that is 
more then necessary currently.

--
components: Library (Lib)
messages: 388211
nosy: cdgriffith
priority: normal
severity: normal
status: open
title: Subprocess IndexError possible in _communicate
type: crash
versions: Python 3.10, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43245] Add keyword argument support to ChainMap.new_child()

2021-03-06 Thread Kamil Turek


Change by Kamil Turek :


--
nosy: +kamilturek

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Chris Angelico
On Sun, Mar 7, 2021 at 4:51 AM Bonita Montero  wrote:
>
> > Whilst you need to read the following:
> > * https://en.wikipedia.org/wiki/Psychological_projection
> > * https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
>
> There is no projection.
> _You_ have megalomania, not me.
> And there's also no Dunning Kruger effect.
> You can't assess your capabilites, not me.

Ignore this guy. He produces nothing, insults everyone, and just gets
himself banned from places. He is nothing more than a troll and a
waste of everyone's time.

His posts do not reach the mailing list, only your replies do.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Bonita Montero

Whilst you need to read the following:
* https://en.wikipedia.org/wiki/Psychological_projection
* https://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect


There is no projection.
_You_ have megalomania, not me.
And there's also no Dunning Kruger effect.
You can't assess your capabilites, not me.
--
https://mail.python.org/mailman/listinfo/python-list


[issue37771] No equivalent of `inspect.getcoroutinestate` for PyAsyncGenASend instances

2021-03-06 Thread Thomas Grainger


Change by Thomas Grainger :


--
nosy: +alex.gronholm, graingert

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43420] Optimize rational arithmetics

2021-03-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Here's some code to try out:

from math import gcd
from fractions import Fraction
import operator
import math

class Henrici(Fraction):
'Reformulate _mul to reduce the size of intermediate products'

# Original has 2 multiplications, 1 gcd calls, and 2 divisions
# This one has 2 multiplications, 2 gcd calls, and 4 divisions  

def _mul(a, b):
a_n, a_d = a.numerator, a.denominator
b_n, b_d = b.numerator, b.denominator
d1 = math.gcd(a_n, b_d)
a_n //= d1
b_d //= d1
d2 = math.gcd(b_n, a_d)
b_n //= d2
a_d //= d2
result = Fraction(a_n * b_n, a_d * b_d, _normalize=False)
assert math.gcd(a_n * b_n, a_d * b_d) == 1 and a_d * b_d >= 0
return result

__mul__, __rmul__ = Fraction._operator_fallbacks(_mul, operator.mul)

assert Henrici(10, 3) * Henrici(6, 5) == Henrici(4, 1)

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16322] time.tzname on Python 3.3.0 for Windows is decoded by wrong encoding

2021-03-06 Thread Eryk Sun


Eryk Sun  added the comment:

The solution for bpo-36779 changed init_timezone() to get tzname directly from 
WinAPI GetTimeZoneInformation(). 

Unfortunately the implementer didn't think to also support time.tzset(), so the 
value may be stale with no way to refresh it, or possibly different from what 
time.strftime('%Z') returns, depending on when ucrt looks up the timezone. For 
example, start Python and import time. Then change the time zone and call 
time.strftime('%Z'). The value will be different from time.tzname.

--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> time.tzname returns empty string on Windows if default codepage 
is a Unicode codepage

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43422] Revert _decimal C API changes

2021-03-06 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

+1 fron me.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue30295] msvcrt SetErrorMode not documented

2021-03-06 Thread Eryk Sun


Change by Eryk Sun :


--
components: +Library (Lib)
type:  -> enhancement
versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.4, Python 3.5, Python 
3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue14841] os.get_terminal_size() should check stdin as a fallback

2021-03-06 Thread Eryk Sun


Change by Eryk Sun :


--
components: +Extension Modules, Library (Lib)
versions: +Python 3.10, Python 3.9 -Python 3.4, Python 3.5, Python 3.6, Python 
3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43413] tuple subclasses allow kwargs

2021-03-06 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

> Hmm, but in my experience, tuple on Python 3.6 doesn't take keyword arguments 
> either:

They do.

>>> tuple(sequence='abc')
('a', 'b', 'c')

>>> list(sequence='abc')
['a', 'b', 'c']
>>> int(x='123')
123
>>> bool(x='123')
True
>>> float(x='123')
123.0

It was changed in bpo-29695.

But accepting arbitrary keyword arguments is another issue.

Object creation in Python can be customized be implementing special methods 
__new__ and __init__. They both are called sequentially with arguments passed 
to the constructor. If object is mutable, it is enough to implement __init__. 
If the object contains immutable data which should be initialized at creation 
time, it needs __new__, and __init__ is not necessary. So the list class has 
__init__, but the tuple and int classes have __new__. Usually class implements 
only one of __new__ or __init__, and inherits the other one from parent classes.

Since positional and keyword arguments are passed to both __new__ and __init__, 
they should accept same arguments. If __new__ and __init__ are inherited from 
parent class, they cannot know about arguments supported in the other method. 
Therefore object's __new__ and __init__ accept and ignore all arguments (if the 
other method is overridden).

Implementations of __new__ for most builtin classes which accept only 
positional arguments accept and ignore also arbitrary keyword arguments in 
subclasses. It makes easier to implement a subclass with non-trivial __init__. 
You just add additional keyword arguments which will be ignored in __new__. It 
is long tradition. Example:

if (type == _type && !_PyArg_NoKeywords("cycle()", kwds))
return NULL;

bpo-20186 just used this idiom for tuple and several other classes. It is a 
feature which makes subclassing these classes easier. And with converting more 
classes to Argument Clinic it is now used in more and more classes.

Now, perhaps it would be more correct to test `type->tp_init == 
cycle_type.tp_init` or `type->tp_init != PyBaseObject_Type.tp_init` instead of 
`type == _type`. It will ignore keyword arguments only if __init__ is 
overridden. If __init__ is overridden, it is now responsible for validating 
arguments.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41369] Update to libmpdec-2.5.1

2021-03-06 Thread Antoine Pitrou


Antoine Pitrou  added the comment:

Stefan wrote me that the changes which complete this update are here:
https://github.com/python/cpython/compare/master...skrah:libmpdec-2.5.1

I can turn this diff into a PR but first I want to gather feedback here.  Mark, 
Serhiy, Raymond, what do you say?

--
assignee: skrah -> 
nosy: +facundobatista, mark.dickinson, pitrou, rhettinger, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43422] Revert _decimal C API changes

2021-03-06 Thread Antoine Pitrou


New submission from Antoine Pitrou :

Stefan Krah (who doesn't have access rights here, and is the author of the C 
_decimal module) asked me to transmit me this request:
"""
The capsule API does not meet my testing standards, since I've focused
on the upstream mpdecimal in the last couple of months.

Additionally, I'd like to refine the API, perhaps together with the
Arrow community.
"""

The relevant diff is here:
https://github.com/python/cpython/compare/master...skrah:revert_decimal_capsule_api

I can turn it into a PR but first I'd like to gather reactions here.

--
components: Extension Modules
messages: 388205
nosy: facundobatista, mark.dickinson, pitrou, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Revert _decimal C API changes
type: behavior
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43332] Make http.client._tunnel send one byte string over the network

2021-03-06 Thread Zveinn


Zveinn  added the comment:

Hey! 

First of all, thank you for not shitting all over me <3 

I have never really used python and the only reason I found this is because I 
was developing a tool that accepted a LOT of CONNECT requests for python and I 
just happened to stumble upon this little nugget.

Regarding a PR or a local path, it would have been too much work for me since 
I'm already swamped and I don't know anything about python or it's ecosystem :S

Anyways, I leave this in your hands now. 

Regards, Zveinn

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43406] Possible race condition between signal catching and signal.signal

2021-03-06 Thread Antoine Pitrou


Change by Antoine Pitrou :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43406] Possible race condition between signal catching and signal.signal

2021-03-06 Thread miss-islington


miss-islington  added the comment:


New changeset 1385f8355a036fd65aaf9c7e7ab48467ca922bcf by Miss Islington (bot) 
in branch '3.9':
[3.9] bpo-43406: Fix possible race condition where ``PyErr_CheckSignals`` tries 
to execute a non-Python signal handler (GH-24756) (GH-24761)
https://github.com/python/cpython/commit/1385f8355a036fd65aaf9c7e7ab48467ca922bcf


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43406] Possible race condition between signal catching and signal.signal

2021-03-06 Thread miss-islington


miss-islington  added the comment:


New changeset 4715be8a4384159e47fb09e5f3bd077734842655 by Antoine Pitrou in 
branch '3.8':
[3.8] bpo-43406: Fix possible race condition where ``PyErr_CheckSignals`` tries 
to execute a non-Python signal handler (GH-24756) (GH-24762)
https://github.com/python/cpython/commit/4715be8a4384159e47fb09e5f3bd077734842655


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Choosable dependency

2021-03-06 Thread Manfred Lotz
On Sat, 6 Mar 2021 14:06:27 +0100
Peter Otten <__pete...@web.de> wrote:

> On 06/03/2021 12:43, Manfred Lotz wrote:
> > On Sat, 6 Mar 2021 12:00:33 +0100
> > Manfred Lotz  wrote:
> >   
> >> Let us say I have a package which reads a TOML file.
> >>
> >> I want to give the user of my package the choice to decide if he
> >> wants to use the toml, tomlkit or rtoml package.
> >>
> >> So, in case the user chose to use rtoml then there should be an
> >> import only for rtoml, aso.
> >>
> >> How could I achieve this?
> >>  
> > 
> > I got the following minimal example working but presumably my
> > solution isn't the best way.
> > 
> > xtoml.py:
> > 
> > class Xtoml:
> >  def __init__(self, which='rtoml'):
> >  self.which = which
> > 
> >  def parse_toml(self, toml_string):
> >  if self.which == 'rtoml':
> >  import rtoml as toml
> >  elif self.which == 'tomlkit':
> >  import tomlkit as toml
> >  else:
> >  import toml
> > 
> >  return toml.loads(toml_string)
> > 
> > 
> > test_xtoml.py:
> > 
> > from xtoml import Xtoml
> > 
> > toml_string = """
> > [default]
> > 
> > basedir = "/myproject"
> > 
> > """
> > 
> > def main():
> >  xtoml = Xtoml('toml')
> >  parsed_toml = xtoml.parse_toml(toml_string)
> >  print(parsed_toml)
> > 
> >  xtoml = Xtoml()
> >  parsed_toml = xtoml.parse_toml(toml_string)
> >  print(parsed_toml)
> > 
> > if __name__ == "__main__":
> >  main()  
> 
> As long as you use a common subset of the functions provided by the 
> packages you can just do
> 

Yes, this is a prereq. Otherwise, it wouldn't make sense to do this.


> def main():
>  global toml  # if you want to use the toml package elsewhere
>   # in your module
> 
>  chosen_toml = ...  # get package name
>  toml = importlib.import_module(chosen_toml)
> 
>  data = toml.loads(toml_string)
> 
> However, the user usually doesn't care, so I would recommend that you
> be bold and pick the package you prefer ;)
> 

Exactly. This is why there is a default. 

Using your suggestion my minimal example now looks like follows

xtoml.py:

import importlib

class Xtoml:
def __init__(self, which='rtoml'):
self.toml = importlib.import_module(which)

def parse_toml(self, toml_string):
return self.toml.loads(toml_string)

No change in test_xtoml.py.


Thanks a lot for your help.


-- 
Manfred



-- 
https://mail.python.org/mailman/listinfo/python-list


[issue43419] contextvars does not work properly in asyncio REPL.

2021-03-06 Thread Lanfon


Change by Lanfon :


--
keywords: +patch
pull_requests: +23541
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24773

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43421] os.device_encoding(fd) should support any console fd in Windows

2021-03-06 Thread Eryk Sun


New submission from Eryk Sun :

In Windows, os.device_encoding() is hard coded to map file descriptor 0 and 
descriptors 1 and 2 respectively to the console's input and output code page if 
isatty(fd) is true. But isatty() is true for any character device, such as 
"NUL". Also any fd might be a console, by way of dup(), dup2() -- or open() 
with the device names "CON", "CONIN$", and "CONOUT$".

The correct device encoding of a console file is needed for use with os.read() 
and os.write(). It's also necessary for io.TextIOWrapper() if 
PYTHONLEGACYWINDOWSSTDIO is set.

_Py_device_encoding() in Python/fileutils.c should use _get_osfhandle() to get 
the OS handle, and, if it's a character-device file, determine the code page to 
return, if any, depending on whether it's an input or output console file. For 
example:

PyObject *
_Py_device_encoding(int fd)
{
#if defined(MS_WINDOWS)
HANDLE handle;
DWORD temp;
UINT cp = 0;

_Py_BEGIN_SUPPRESS_IPH
handle = (HANDLE)_get_osfhandle(fd);
_Py_END_SUPPRESS_IPH
if (handle == INVALID_HANDLE_VALUE ||
GetFileType(handle) != FILE_TYPE_CHAR)
Py_RETURN_NONE;

Py_BEGIN_ALLOW_THREADS
/* GetConsoleMode requires a console handle. */
if (!GetConsoleMode(handle, )) {
/* Assume access denied implies output. */
if (GetLastError() == ERROR_ACCESS_DENIED)
cp = GetConsoleOutputCP();
} else {
if (GetNumberOfConsoleInputEvents(handle, )) {
cp = GetConsoleCP();
} else {
cp = GetConsoleOutputCP();
}
}
Py_END_ALLOW_THREADS

if (cp == CP_UTF8) {
return PyUnicode_FromString("UTF-8");
} else if (cp != 0) {
return PyUnicode_FromFormat("cp%u", (unsigned int)cp);
} else {
Py_RETURN_NONE;
}
#else
if (isatty(fd)) {
return _Py_GetLocaleEncodingObject();
} else {
Py_RETURN_NONE;
}
#endif  /* defined(MS_WINDOWS) */
}

--
components: Extension Modules, IO, Interpreter Core, Windows
messages: 388201
nosy: eryksun, paul.moore, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: os.device_encoding(fd) should support any console fd in Windows
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: neonumeric - C++ arbitrary precision arithmetic library

2021-03-06 Thread Bonita Montero
It hasn't been formally released yet as it still requires more extensive 
testing. It will be used as part of my universal compiler, neos, that 
can compile any programming language ...


You will get the same room in the same psychiatric ward like
Amine Moulay Ramdane.

--
https://mail.python.org/mailman/listinfo/python-list


[issue43420] Optimize rational arithmetics

2021-03-06 Thread Sergey B Kirpichev


New submission from Sergey B Kirpichev :

fractions.py uses naive algorithms for doing arithmetics.

It may worth implementing less trivial versions for addtion/substraction
and multiplication (e.g. Henrici algorithm and so on), described here:
https://www.eecis.udel.edu/~saunders/courses/822/98f/collins-notes/rnarith.ps
as e.g gmplib does: https://gmplib.org/repo/gmp/file/tip/mpq/aors.c

Some projects (e.g. SymPy here: https://github.com/sympy/sympy/pull/12656) 
reinvent
the stdlib's Fraction just to add such simple improvements.  With big 
denominators (~10**6)
this really does matter, my local benchmarks suggest the order of magnitude 
difference for
summation of several such numbers.

--
components: Library (Lib)
messages: 388200
nosy: Sergey.Kirpichev
priority: normal
severity: normal
status: open
title: Optimize rational arithmetics
type: enhancement
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43419] contextvars does not work properly in asyncio REPL.

2021-03-06 Thread Lanfon


New submission from Lanfon :

Demonstration (via python -m asyncio):

asyncio REPL 3.9.0 (default, Oct 18 2020, 00:21:26) 
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> from contextvars import ContextVar
>>> ctx = ContextVar('ctx')
>>> ctx.set(1)
 at 0x1021bf800>
>>> ctx.get()
Traceback (most recent call last):
  File 
"/Users/lanfon/.pyenv/versions/3.9.0/lib/python3.9/concurrent/futures/_base.py",
 line 440, in result
return self.__get_result()
  File 
"/Users/lanfon/.pyenv/versions/3.9.0/lib/python3.9/concurrent/futures/_base.py",
 line 389, in __get_result
raise self._exception
  File "/Users/lanfon/.pyenv/versions/3.9.0/lib/python3.9/asyncio/__main__.py", 
line 34, in callback
coro = func()
  File "", line 1, in 
LookupError: 
>>> exit()


It also got problem inside the functions when the context is referenced in 
global scope.

--
components: asyncio
messages: 388199
nosy: asvetlov, lanfon72, yselivanov
priority: normal
severity: normal
status: open
title: contextvars does not work properly in asyncio REPL.
type: behavior
versions: Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43418] FTPLib module crashes when server returns byte message instead of string

2021-03-06 Thread Hugo Chia


New submission from Hugo Chia :

https://github.com/cowrie/cowrie/issues/1394

https://github.com/cowrie/cowrie/pull/1396

Above are some of the links mentioning the issue with the FTPLib module. It 
happens when the FTP server returns a byte message instead of a string. Ftplib 
expects a string and does not account for receiving a byte message

--
components: Library (Lib)
messages: 388198
nosy: hugochiaxyz8
priority: normal
severity: normal
status: open
title: FTPLib module crashes when server returns byte message instead of string
type: crash
versions: Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Choosable dependency

2021-03-06 Thread Peter Otten

On 06/03/2021 12:43, Manfred Lotz wrote:

On Sat, 6 Mar 2021 12:00:33 +0100
Manfred Lotz  wrote:


Let us say I have a package which reads a TOML file.

I want to give the user of my package the choice to decide if he wants
to use the toml, tomlkit or rtoml package.

So, in case the user chose to use rtoml then there should be an import
only for rtoml, aso.

How could I achieve this?



I got the following minimal example working but presumably my solution
isn't the best way.

xtoml.py:

class Xtoml:
 def __init__(self, which='rtoml'):
 self.which = which

 def parse_toml(self, toml_string):
 if self.which == 'rtoml':
 import rtoml as toml
 elif self.which == 'tomlkit':
 import tomlkit as toml
 else:
 import toml

 return toml.loads(toml_string)


test_xtoml.py:

from xtoml import Xtoml

toml_string = """
[default]

basedir = "/myproject"

"""

def main():
 xtoml = Xtoml('toml')
 parsed_toml = xtoml.parse_toml(toml_string)
 print(parsed_toml)

 xtoml = Xtoml()
 parsed_toml = xtoml.parse_toml(toml_string)
 print(parsed_toml)

if __name__ == "__main__":
 main()


As long as you use a common subset of the functions provided by the 
packages you can just do


def main():
global toml  # if you want to use the toml package elsewhere
 # in your module

chosen_toml = ...  # get package name
toml = importlib.import_module(chosen_toml)

data = toml.loads(toml_string)

However, the user usually doesn't care, so I would recommend that you be 
bold and pick the package you prefer ;)



--
https://mail.python.org/mailman/listinfo/python-list


[issue43391] The comments have invalid license information (broken Python 2.4 URL for Python 3)

2021-03-06 Thread Marc-Andre Lemburg


Change by Marc-Andre Lemburg :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43417] ast.unparse: Simplify buffering logic

2021-03-06 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
keywords: +patch
pull_requests: +23540
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/24772

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43417] ast.unparse: Simplify buffering logic

2021-03-06 Thread Batuhan Taskaya


New submission from Batuhan Taskaya :

Currently, buffer is just an instance-level list that is used in various places 
to avoid directly writing stuff into the real source buffer, though the design 
is pretty complicated and hard to use.

There are various use cases (like omitting the empty space when unparsing 
argument-less lambdas, e.g: lambda : 2 + 2) we could've use this buffer system 
if it was offering a stackable version (like multiple levels of buffers).

What I think is we should probably do this with a proper context manager and in 
the context capture all writings into a list where we would return after the 
context is closed;

with self.buffered() as buffer:
self._write_fstring_inner(node)
return self._write_str_avoiding_backslashes("".join(buffer))

--
assignee: BTaskaya
components: Library (Lib)
messages: 388197
nosy: BTaskaya
priority: normal
severity: normal
status: open
title: ast.unparse: Simplify buffering logic
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Choosable dependency

2021-03-06 Thread Manfred Lotz
On Sat, 6 Mar 2021 12:00:33 +0100
Manfred Lotz  wrote:

> Let us say I have a package which reads a TOML file. 
> 
> I want to give the user of my package the choice to decide if he wants
> to use the toml, tomlkit or rtoml package. 
> 
> So, in case the user chose to use rtoml then there should be an import
> only for rtoml, aso.
> 
> How could I achieve this?
> 

I got the following minimal example working but presumably my solution
isn't the best way.

xtoml.py:

class Xtoml:
def __init__(self, which='rtoml'):
self.which = which

def parse_toml(self, toml_string):
if self.which == 'rtoml':
import rtoml as toml
elif self.which == 'tomlkit':
import tomlkit as toml
else:
import toml

return toml.loads(toml_string)


test_xtoml.py:

from xtoml import Xtoml

toml_string = """
[default]

basedir = "/myproject"

"""

def main():
xtoml = Xtoml('toml')
parsed_toml = xtoml.parse_toml(toml_string)
print(parsed_toml)

xtoml = Xtoml()
parsed_toml = xtoml.parse_toml(toml_string)
print(parsed_toml)

if __name__ == "__main__":
main()


-- 
https://mail.python.org/mailman/listinfo/python-list


Choosable dependency

2021-03-06 Thread Manfred Lotz
Let us say I have a package which reads a TOML file. 

I want to give the user of my package the choice to decide if he wants
to use the toml, tomlkit or rtoml package. 

So, in case the user chose to use rtoml then there should be an import
only for rtoml, aso.

How could I achieve this?

-- 
Thanks,
Manfred

-- 
https://mail.python.org/mailman/listinfo/python-list


[issue43415] Typo

2021-03-06 Thread Eric V. Smith


Change by Eric V. Smith :


--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42128] Structural Pattern Matching (PEP 634)

2021-03-06 Thread Batuhan Taskaya


Change by Batuhan Taskaya :


--
pull_requests: +23539
pull_request: https://github.com/python/cpython/pull/24771

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue43416] Add README files in Include/cpython and Include/internal

2021-03-06 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

I always hesitate in what subdirectory of Include/ to add a declaration of new 
private API. What is more "private"? It would be nice to add README files in 
these directories which describe what API should be declared here and what is 
the difference between Include/cpython and Include/internal.

--
assignee: docs@python
components: Documentation, Interpreter Core
messages: 388196
nosy: docs@python, serhiy.storchaka, vstinner
priority: normal
severity: normal
status: open
title: Add README files in Include/cpython and Include/internal
type: enhancement
versions: Python 3.10

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com