[issue27929] asyncio.AbstractEventLoop.sock_connect broken for AF_BLUETOOTH

2022-03-26 Thread Vincent Bernat


Change by Vincent Bernat :


--
keywords: +patch
nosy: +bernat
nosy_count: 4.0 -> 5.0
pull_requests: +30211
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/32131

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



[issue46916] There is a problem with escape characters in the path passed in by pathlib.Path.mkdir()

2022-03-04 Thread Vincent FUNG


Vincent FUNG  added the comment:

Thank you very much for your patient answer, I am still a developer who has 
just started, and it seems that I need to learn more about it.

I used repr().replace to replace with forward slashes, and also restricted 
paths ending in a slash to Improve reliability.

Thanks anagin. ;)

--

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



[issue46916] There is a problem with escape characters in the path passed in by pathlib.Path.mkdir()

2022-03-04 Thread Vincent FUNG


Vincent FUNG  added the comment:

Oh. Got it. 

I thought pathlib would solve this problem completely now, without having to 
replace the slashes. Thank you for your patient answer.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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



[issue46916] There is a problem with escape characters in the path passed in by pathlib.Path.mkdir()

2022-03-03 Thread Vincent FUNG


Vincent FUNG  added the comment:

This problem occurs when the directory starts with 't', but works with 
os.makedirs(e) or macOS.

>>> e = Path(r'F:\ceven\test2')
>>> e.mkdir()
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Program Files\Python310\lib\pathlib.py", line 1173, in mkdir
self._accessor.mkdir(self, mode)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 
'F:\\ceven\\test2'
>>> os.makedirs(e)



Another question about \t:

If a directory is passed as a parameter it will not be possible to use the 
parameter as a raw string. os.makedirs gives the same error whether it's r'%s' 
or repr().

--

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



[issue46916] There is a problem with escape characters in the path passed in by pathlib.Path.mkdir()

2022-03-03 Thread Vincent FUNG


New submission from Vincent FUNG :

This problem occurs when the directory starts with 't', but works with 
os.makedirs(e) or macOS.

>>> e = Path(r'F:\ceven\test2')
>>> e.mkdir()
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\Program Files\Python310\lib\pathlib.py", line 1173, in mkdir
self._accessor.mkdir(self, mode)
FileNotFoundError: [WinError 3] The system cannot find the path specified: 
'F:\\ceven\\test2'
>>> os.makedirs(e)

--
components: Windows
messages: 414483
nosy: paul.moore, steve.dower, tim.golden, vincent.fung, zach.ware
priority: normal
severity: normal
status: open
title: There is a problem with escape characters in the path passed in by 
pathlib.Path.mkdir()
type: behavior
versions: Python 3.10

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



[issue46139] Boolean Logic Check - Built-in Types Documentation page

2021-12-20 Thread Abri Vincent


Abri Vincent  added the comment:

A short circuit operator. 

x OR y - if x is false, then y, else x (1). 

(1) This is a short-circuit operator, so it only evaluates the second argument 
if the first one is false.

The first argument is 'if'
The second argument is 'then'
The third argument is 'else'

Move to the second argument if the first is false. 
Evaluate the first argument 'if x is false' - look at the second argument if 
the first argument is false - 'then y'.

--

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



[issue46139] Boolean Logic Check - Built-in Types Documentation page

2021-12-20 Thread Abri Vincent


Change by Abri Vincent :


--
stage:  -> resolved
status: open -> closed

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



[issue46139] Boolean Logic Check - Built-in Types Documentation page

2021-12-20 Thread Abri Vincent

New submission from Abri Vincent :

On the documentation page https://docs.python.org/3/library/stdtypes.html the 
header 'Boolean Operations — and, or, not' provides a table (attached as an 
image). 

It states: 

a.1) x OR y - if x is false, then y, else x **
a.2) x AND y - if x is false, then x, else y **

When I read this i intuit the following

b.1) x OR y - if x is false, then x, else y
b.2) x AND y - if x is false, then y, else x

Providing an example with a.1 which is currently listed in the documentation

If x is false -> else x = False (we don't check if Y=True which is the 
definition of an OR operator). 

** This is a short-circuit operator, so it only evaluates the second argument 
if the first one is false.

I would appreciate clarification on this and if others see an issue with the 
documentation after reading my description able then movement on consensus to 
correct the documentation

--
assignee: docs@python
components: Documentation
messages: 408972
nosy: abriabrisham, docs@python
priority: normal
severity: normal
status: open
title: Boolean Logic Check - Built-in Types Documentation page

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



[issue44665] asyncio.create_task() documentation should mention user needs to keep reference to the task

2021-10-22 Thread Vincent Bernat


Vincent Bernat  added the comment:

Hummm, I have a hard time finding a short example when `__del__` is not called 
until the task is finished. Sorry. I did run into this several time, for 
example here: https://github.com/ldo/dbussy/pull/45 (and some internal projects 
as well). So, it happens from time to time, but it is hard to find a simple 
reproducer.

--

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



[issue45557] pprint -> underscore_numbers argument not working

2021-10-21 Thread Jean-Philippe VINCENT


Change by Jean-Philippe VINCENT :


--
title: Issue 42914 -> pprint -> underscore_numbers argument not working

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



[issue45557] Issue 42914

2021-10-21 Thread Jean-Philippe VINCENT

New submission from Jean-Philippe VINCENT :

Hello,

I just tried the new attribute underscore_numbers with pprint, it doesn't work 
for me. I'm working on Windows.

[cid:8779885d-01bf-4162-9427-a44de152f7ac]

Best regards,

Jean-Philippe

--
files: image.png
messages: 404636
nosy: jpvincent
priority: normal
severity: normal
status: open
title: Issue 42914
Added file: https://bugs.python.org/file50385/image.png

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



[issue45469] lambda issue in for-loop

2021-10-14 Thread Vincent Liang


New submission from Vincent Liang :

Strange behavior is found when lambda is used inside for-loop.

code:(same as attached file)

# begin of CODE
def aa(x):
print("aa")
def bb(x):
print("bb")

namefun = [
("a", aa),
("b", bb),
]
name2fun = {}
for name, fun in namefun:
name2fun[name] = lambda x: fun(x)
# issue happened when calling lambda
name2fun["a"](1)
name2fun["b"](1)
# end of CODE

output:
bb
bb

expected output:
aa
bb

--
components: Interpreter Core
files: test8.py
messages: 403899
nosy: vincent7f
priority: normal
severity: normal
status: open
title: lambda issue in for-loop
type: behavior
versions: Python 3.10, Python 3.9
Added file: https://bugs.python.org/file50357/test8.py

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



[issue44219] Opening a file holds the GIL when it calls "isatty()"

2021-09-09 Thread Vincent Michel

Vincent Michel  added the comment:

There are a couple of reasons why I did not make changes to the stdstream 
related functions. 

The first one is that a PR with many changes is less likely to get reviewed and 
merged than a PR with fewer changes. The second one is that it's hard for me to 
make sure that those functions are always called with the GIL already held. 
Maybe some of them never hold the GIL in the first place, and I'm not familiar 
enough with the code base to tell.

So in the end it will probably be up to the coredev reviewing the PR, but 
better start small.

> Besides, nothing prevents somebody from starting a FUSE file system and then 
> redirecting stdout to it …

I ran some checks and `python -c 'input()' < my-fuse-mountpoint/data_in` does 
indeed trigger an ioctl call to the corresponding fuse file system. But how 
would `my-fuse-mountpoint/data_in` be the stdin for the process that itself 
starts the fuse filesystem? I don't see how to generate this deadlock, apart 
from setting up interprocess communication between the fuse process and the 
`my-fuse-mountpoint/data_in`-as-stdin process.

--

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



[issue44129] zipfile: Add descriptive global variables for general purpose bit flags

2021-09-09 Thread Vincent Michel


Change by Vincent Michel :


--
pull_requests:  -26670

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



[issue44219] Opening a file holds the GIL when it calls "isatty()"

2021-09-09 Thread Vincent Michel


Change by Vincent Michel :


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

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



[issue44129] zipfile: Add descriptive global variables for general purpose bit flags

2021-09-09 Thread Vincent Michel


Change by Vincent Michel :


--
nosy: +vxgmichel
nosy_count: 2.0 -> 3.0
pull_requests: +26670
pull_request: https://github.com/python/cpython/pull/28250

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



[issue44219] Opening a file holds the GIL when it calls "isatty()"

2021-09-08 Thread Vincent Michel


Vincent Michel  added the comment:

Here's a possible patch that fixes the 3 unprotected calls to `isatty` 
mentioned above. It successfully passes the test suite. I can submit a PR with 
this patch if necessary.

--
keywords: +patch
Added file: https://bugs.python.org/file50270/bpo-44219.patch

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



[issue44219] Opening a file holds the GIL when it calls "isatty()"

2021-09-07 Thread Vincent Michel


Vincent Michel  added the comment:

My team ran into this issue while developing a fuse application too.

In an effort to help this issue move forward, I tried to list all occurrences 
of the `isatty` C function in the cpython code base. I found 14 of them.

9 of them are directly related to stdin/stdout/stderr, so it's probably not 
crucial to release the GIL for those occurrences:
- `main.c:stdin_is_interactive`
- `main.c:pymain_import_readline`
- `readline.c:setup_readline`
- `bltinmodule.c:builtin_input_impl` (x2)
- `frozenmain.c:Py_FrozenMain`
- `pylifecycle.c:Py_FdIsInteractive` (x2)
- `fileobject.c:stdprinter_isatty` (GIL is actually released for this one)

Out of the remaining 4, only 1 releases the GIL:
- `fileio.c:_io_FileIO_isatty_impl`: used for `FileIO.isatty`

Which gives 3 occurrences of non-stdstream specific usage of `isatty` that do 
not release the GIL:
- `posixmodule.c:os_isatty_impl`: used by `os.isatty`
- `fileutils.c:_Py_device_encoding`: used `TextIOWrapper.__init__`
- `fileutils.c:_Py_write_impl`: windows specific, issue #11395

The first one is used by `os.isatty` which means this call can also deadlock. I 
did manage to reproduce it with a simple fuse loopback file system: 
https://github.com/fusepy/fusepy/blob/master/examples/loopback.py

The second one is the one found by @smurfix and gets triggered when `io.open()` 
is used in text mode.

The third one only triggers on windows when writing more than 32767 bytes to a 
file descriptor. A comment points to issue #11395 
(https://bugs.python.org/issue11395). Also, it seems from the function 
signature that this function might be called with or without the GIL held, 
which might cause the fix to be a bit more complicated than the first two use 
cases.

I hope this helps.

--
nosy: +vxgmichel

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



[issue44665] asyncio.create_task() documentation should mention user needs to keep reference to the task

2021-07-18 Thread Vincent Bernat


New submission from Vincent Bernat :

asyncio will only keep weak references to alive tasks (in `_all_tasks`). If a 
user does not keep a reference to a task and the task is not currently 
executing or sleeping, the user may get "Task was destroyed but it is pending!".

I would suggest adding the following paragraph to `create_task()` documentation:

Python only keeps weak references to the scheduled tasks. To avoid the task 
being destroyed by the garbage collector while still pending, a reference to it 
should be kept until the task is done.

And maybe an example in case a user wants something "fire and forget"?

```python
running_tasks = set()
# [...]
task = asyncio.create_task(some_background_function())
running_tasks.add(task)
task.add_done_callback(lambda t: running_tasks.remove(t))
```

The same applies to ensure_future as it now uses create_task, so maybe a "See 
create_task()".

--
assignee: docs@python
components: Documentation
messages: 397741
nosy: bernat, docs@python
priority: normal
severity: normal
status: open
title: asyncio.create_task() documentation should mention user needs to keep 
reference to the task
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.9

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



[issue44062] cross: wrong interpreter returned when no python available

2021-05-06 Thread Vincent Fazio


Change by Vincent Fazio :


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

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



[issue44062] cross: wrong interpreter returned when no python available

2021-05-06 Thread Vincent Fazio


New submission from Vincent Fazio :

When trying to cross compile python3.9, `configure` attempts to find a strict 
python 3.9 version match, however if it fails it still attempts to use `python` 
in PYTHON_FOR_BUILD instead of failing outright like the code implies it should

$/python3/targetbuild# which python3.9 python3 python
/usr/bin/python3

$/python3/targetbuild# python3 --version
Python 3.7.3

$/python3/targetbuild# PYTHON_FOR_REGEN=/python3/hostbuild/python \
ac_cv_file__dev_ptmx=yes \
ac_cv_file__dev_ptc=no \
ac_cv_buggy_getaddrinfo=no \
../configure --build=x86-linux-gnu \
--host=aarch64-linux-gnu \
--enable-loadable-sqlite-extensions \
--enable-option-checking=fatal \
--enable-shared \
--with-system-expat \
--with-system-ffi \
--without-ensurepip
checking build system type... x86-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking for python3.9... /python3/hostbuild/python
checking for python interpreter for cross build... python
...

$/python3/targetbuild# grep PYTHON_FOR_BUILD config.log 
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) 
_PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f 
pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib 
_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) 
python'


in configure

if test "$cross_compiling" = yes; then
AC_MSG_CHECKING([for python interpreter for cross build])
if test -z "$PYTHON_FOR_BUILD"; then
for interp in python$PACKAGE_VERSION python3 python; do
which $interp >/dev/null 2>&1 || continue
if $interp -c "import sys;sys.exit(not '.'.join(str(n) for n in 
sys.version_info@<:@:2@:>@) == '$PACKAGE_VERSION')"; then
break
fi
interp=
done
if test x$interp = x; then
AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found])
fi
AC_MSG_RESULT($interp)
PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) 
_PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f 
pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib 
_PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) 
'$interp
fi
elif test "$cross_compiling" = maybe; then
AC_MSG_ERROR([Cross compiling required --host=HOST-TUPLE and --build=ARCH])
else
PYTHON_FOR_BUILD='./$(BUILDPYTHON) -E'
fi
AC_SUBST(PYTHON_FOR_BUILD)


The issue is a failing edge case here:

for interp in python$PACKAGE_VERSION python3 python; do
which $interp >/dev/null 2>&1 || continue

where interp keeps it's last value doesn't trigger the empty check here:

if test x$interp = x; then
AC_MSG_ERROR([python$PACKAGE_VERSION interpreter not found])
fi

Note that there's an explicit clearing of interp when the python version isn't 
a match:

if $interp -c "import sys;sys.exit(not '.'.join(str(n) for n in 
sys.version_info@<:@:2@:>@) == '$PACKAGE_VERSION')"; then
break
fi
interp=


The fix should be pretty straightforward:

for interp in python$PACKAGE_VERSION python3 python ''; do

adding '' as the last possible interpreter means one hasn't been found up to 
that point and allows configure to properly fail

$/python3/targetbuild# PYTHON_FOR_REGEN=/python3/hostbuild/python 
ac_cv_file__dev_ptmx=yes ac_cv_file__dev_ptc=no ac_cv_buggy_getaddrinfo=no 
../configure --build=x86-linux-gnu --host=aarch64-linux-gnu 
--enable-loadable-sqlite-extensions --enable-option-checking=fatal 
--enable-shared --with-system-expat --with-system-ffi --without-ensurepip
checking build system type... x86-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking for python3.9... /python3/hostbuild/python
checking for python interpreter for cross build... configure: error: python3.9 
interpreter not found

It will continue to work when a proper interpreter is found

$/python3/targetbuild# PATH=/python3/hostbuild:$PATH 
PYTHON_FOR_REGEN=/python3/hostbuild/python ac_cv_file__dev_ptmx=yes 
ac_cv_file__dev_ptc=no ac_cv_buggy_getaddrinfo=no ../configure 
--build=x86-linux-gnu --host=aarch64-linux-gnu 
--enable-loadable-sqlite-extensions --enable-option-checking=fatal 
--enable-shared --with-system-expat --with-system-ffi --without-ensurepip
checking build system type... x86-unknown-linux-gnu
checking host system type... aarch64-unknown-linux-gnu
checking for python3.9... /python3/hostbuild/python
checking for python interpreter for cross build... Could not find platform 
dependent libraries 
Consider setting $PYTHONHOME to [:]
python


This should help highlight any inconsistent environment between configuring and 
building.

--
components: Cross-Build
messa

[issue34747] SSLSocket.context cannot be changed on non-connected sockets

2021-03-21 Thread Vincent Pelletier


Vincent Pelletier  added the comment:

Added: affects Python 3.9

This bug is still preventing (...or shall I say "discourages", as the setter is 
effective but raises) server-side SSL certificate reloading on long-running 
services.
This codepath on listening sockets is necessary for seamless certificate 
renewal, so the new certificate is used on any accepted connection past the 
setter call.

Is there anything that needs to be changed to the fix I proposed ?
Should I open a merge/pull request somewhere ?

--
versions: +Python 3.9

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



[issue43462] canvas.bbox returns None on 'hidden' items while coords doesn't

2021-03-13 Thread Vincent


Change by Vincent :


--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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



[issue43462] canvas.bbox returns None on 'hidden' items while coords doesn't

2021-03-13 Thread Vincent


Vincent  added the comment:

HI Terry, yes, that's completely true. But what I meant is I have to invoke 
coords on every item belonging to a tag and then perform some calculations to 
get the boundary box of all the items belonging to the item. 

Let's close this issue and I will knock on the door of the developers of Tk.

--

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



[issue43462] canvas.bbox returns None on 'hidden' items while coords doesn't

2021-03-11 Thread Vincent


Vincent  added the comment:

... calculate the coordinates using the canvas.coords function

--

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



[issue43462] canvas.bbox returns None on 'hidden' items while coords doesn't

2021-03-11 Thread Vincent


Vincent  added the comment:

Thank you for your comments. Yes, I would doubt that, too. You would expect to 
get a bounding box regardless what state the canvas item are in. The only way 
to fix this (and I'm open to suggestions), is to create a (custom) function 
that calculate every object belonging to a specific tag and add/subtract the 
coordinates - this is cumbersome.

--

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



[issue43462] canvas.bbox returns None on 'hidden' items while coords doesn't

2021-03-10 Thread Vincent


Vincent  added the comment:

No, not hang. It returns a NoneType.

See this example:

>>> x = canvas.bbox('tunnel')
>>> type(x)

>>>

--

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



[issue43462] canvas.bbox returns None on 'hidden' items while coords doesn't

2021-03-10 Thread Vincent


Change by Vincent :


--
type:  -> behavior

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



[issue43462] canvas.bbox returns None on 'hidden' items while coords doesn't

2021-03-10 Thread Vincent


New submission from Vincent :

canvas.bbox() should return a tuple containing values whether an item is hidden 
or not. canvax.coords() does return a tuple when an item is hidden.

Steps to reproduce:

```
  from tkinter import * 
  root = Tk()
  canvas = Canvas(root)
  id1 = canvas.create_line(10,5,20,5, tags='tunnel')
  id2 = canvas.create_line(10,8,20,8, tags='tunnel')
  canvas.bbox('tunnel')   # return a tupple
  canvas.itemconfig('tunnel', state='hidden')
  canvas.bbox('tunnel')   # return nothing not even None
```

I need bbox to return a tuple containing values. The consequences is that the 
code must make the items temporarily visible before it can invoke the bbox 
function. This turning on and off creates flashing items in my program.

Thanks in advance!

--
components: Tkinter
messages: 388432
nosy: Vincent
priority: normal
severity: normal
status: open
title: canvas.bbox returns None on 'hidden' items while coords doesn't
versions: Python 3.7

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



[issue43379] Pasting multiple lines in the REPL is broken since 3.9

2021-03-07 Thread Romain Vincent


Romain Vincent  added the comment:

The lack of dots was something I noticed.

So from your questions (Ned Deily) I have been testing out several things and 
found a "wae"!

But first, to answer your questions:

1. both LF and CRLF and it didn't change anything.

2. Running "import readline;print(readline.__doc__)" prints
"... GNU readline", with python 3.7, 3.8 and 3.9.

3. I am using iTerm2, but the problem also happens on MacOS's native 
Terminal.app. Versions of python were installed with **homebrew**.


Maybe worth to mention: if I paste my code in a multi line string to execute 
with python -c, then it works properly.

e.g.

---

python3.9 -i -c 'a = 42
if a:
  print("hello world")
'
hello world
>>>

---

The example is different because I realized I had the same problem on python3.7 
and python3.8 when the 2 first lines were at the same level of indentation 
(Note sure if this gives a hint as to what the problem is).



HOWEVER, if I use python versions directly downloaded from 
https://www.python.org/, then I don't have the problem at all!

Demonstration:

---
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7
Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43) 
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import readline;print(readline.__doc__)
Importing this module enables command line editing using libedit readline.
>>> a = 42
>>> if a:
...   print("hello world")
... 
hello world
>>> 

---

Same for python3.9

--

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



[issue43379] Pasting multiple lines in the REPL is broken since 3.9

2021-03-02 Thread Romain Vincent


New submission from Romain Vincent :

DISCLAIMER: This is the first time I submit an issue here. In advance, my 
humble apologies if I missed something.
Feel free to correct me :)

--

I regularly test snippets of code by pasting them from a code editor to a shell 
REPL.

It works perfectly well in python 3.8 or 3.7 but not in python 3.9.

Demonstration:

Try to copy and paste the following simple snippet:

---

def f():
print("hello world")

---

The result in a python 3.8 REPL (same with 3.7):

---

$ python3.8
Python 3.8.6 (default, Nov 20 2020, 18:29:40)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
print("hello world")
>>> f()
hello world

---

But with python 3.9:

---

$ python3.9
Python 3.9.1 (default, Dec 10 2020, 10:36:35)
[Clang 12.0.0 (clang-1200.0.32.27)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
print("hello world")
  File "", line 1

^
SyntaxError: multiple statements found while compiling a single statement

---

This behavior happens with any snippet of code containing at least one indented 
line, whether by tabs or spaces and whatever the number of spaces.


Regards.

--
components: IO
messages: 387976
nosy: romainfv
priority: normal
severity: normal
status: open
title: Pasting multiple lines in the REPL is broken since 3.9
type: behavior
versions: Python 3.9

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



Re: Question - problem downloading Python

2021-01-14 Thread vincent . vandevyvre
On 14/01/21 07:52, Christine Tiscareno wrote:
>I installed in my lap-top your latest version of Python (3.9.1), yet when I
>go to cmd.exe   to check,  I get that I have Python 22.7.17 ???
>
>Why? What should I do to get the latest version?

>  I tried going back to fix problems and it does not fix it, that is how I
>got your email.

>How can I get the latest Python version (3.9.1), instead of what I'm
>getting (22.7.17)?

>Thank you for your time.

Please, copy-paste all the content of your terminal (I presume this is wht you 
name cmd.exe).

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


Re: Pickling issue.

2020-12-23 Thread vincent . vandevyvre
On 22/12/20 01:57, Bob Gailer wrote:
>
>
> On Mon, Dec 21, 2020, 3:03 PM Vincent Vande Vyvre 
>  wrote:
>
> Hi,
>
> I've an object that I want to serialise with pickle.
> When I reload the object the attributes of this object are correctly
> fixed except one of these.
>
> This attribute (value) define a simple string.
>
> Example:
> -
> tag =  XmpTag('Xmp.dc.form'image/jpeg')
>
>
> I am not familiar with XmpTag. Where might I get the containing module?
>
> ... skip
>
Yes, it's available with pip:
https://pypi.org/project/py3exiv2/
If you want to test it, just add from pyexiv2.xmp import XmpTag to my example.

and the source is here:
https://bazaar.launchpad.net/~vincent-vandevyvre/py3exiv2/trunk/view/head:/py3exiv2/src/pyexiv2/xmp.py

This is a Python-3 binding of the lib exiv2, the wrapper source code is here:
https://bazaar.launchpad.net/~vincent-vandevyvre/py3exiv2/trunk/view/head:/py3exiv2/src/exiv2wrapper.cpp#L359

exiv2 doc is here:
https://www.exiv2.org/doc/classExiv2_1_1Xmpdatum.html

Sorry for the late response but it seems a moderation problem with my account.

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


Pickling issue.

2020-12-21 Thread Vincent Vande Vyvre

Hi,

I've an object that I want to serialise with pickle.
When I reload the object the attributes of this object are correctly 
fixed except one of these.


This attribute (value) define a simple string.

Example:
-
tag =  XmpTag('Xmp.dc.format', 'image/jpeg')
tag.key
'Xmp.dc.format'
tag.type
'MIMEType'
tag.value
'image/jpeg'

s = pickle.dumps(tag)
t = pickle.loads(s)
t.key
'Xmp.dc.format' # Correct
t.type
'MIMEType'  # Correct
t.value
('image', 'jpeg')   # Not correct
-

Tested with Python-3.8

An idea ?
--
https://mail.python.org/mailman/listinfo/python-list


[issue41214] -O0: Segmentation fault in _PyArg_UnpackStack

2020-10-25 Thread LE GARREC Vincent


LE GARREC Vincent  added the comment:

I still have the problem with python 3.7.9 but not with python 3.8.6.

Since I migrated my system to python 3.8, it's not a problem anymore. I still 
have python 3.7 installed so if you want, I still can do some tests.

--
nosy: +bansan85

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



Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-20 Thread Vincent Vande Vyvre
Le 20/08/20 à 09:07, Robin Becker a écrit :
> .
>>> so obviously I need to install some version of boost libs or
>>> Boost.Python etc etc. Gave up :(
>>> -luddite-ly yrs-
>>> Robin Becker
>>>
>> The aur repository, no ?
>>
>> https://aur.archlinux.org/packages/python-exiv2/
>>
>> Vincent
>>
>
> that would work (if I had thought hard about it), but not for a pip
> install which is where the fun started :), I was only trying to see
> what was going wrong.
> -- 
> Robin Becker

See the README for the compilation instructions:
https://bazaar.launchpad.net/~vincent-vandevyvre/py3exiv2/trunk/view/head:/py3exiv2/README

Vincent

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


Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-19 Thread Vincent Vande Vyvre
Le 19/08/20 à 10:15, Robin Becker a écrit :
> On 18/08/2020 20:05, Vincent Vande Vyvre wrote:
> .
>>>
>> Hi,
>>
>> Two solutions:
>> 1. Install exiv2-dev and py3exiv2 with pip
>>  $ sudo apt-get install libexiv2-dev
>>  $ sudo pip3 install py3exiv2
>>
>> 2. Install my ppa
>>  $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv
>>  $ sudo apt-get update
>>  $ sudo apt-get install python3-exiv2
>>
>> Don't change your old code for pyexiv2, the names of the modules are
>> unchanged, your old code should work as it.
>>
>> Off course old strings are now unicode.
>>
>> Vincent (AKA VinsS)
>>
> I haven't tried #2 (I use Arch), but I did try 1) in a python 3.8
> virtual env. I ended up getting into a problem with boost
>
>>    src/exiv2wrapper.hpp:34:10: fatal error: boost/python.hpp: No such
>> file or directory
>>    34 | #include "boost/python.hpp"
>>   |  ^~
>>     compilation terminated.
>>     error: command 'gcc' failed with exit status 1
>
> so obviously I need to install some version of boost libs or 
> Boost.Python etc etc. Gave up :(
> -luddite-ly yrs-
> Robin Becker
>
The aur repository, no ?

https://aur.archlinux.org/packages/python-exiv2/

Vincent

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


Re: Finding it very difficult to move pyexiv2 code from Python 2 to Python 3

2020-08-18 Thread Vincent Vande Vyvre
Le 18/08/20 à 19:22, Chris Green a écrit :
> I have a fairly simple Python program that I wrote a while ago in
> Python 2 that transfers images from my camera to a date ordered
> directory hierarchy on my computer.
>
> I am trying to get it to work on Python 3 as I have just upgraded to
> Ubuntu 20.04 and on that Python 3 is now the default version of Python.
>
> I seem to be descending into a horrible morass of dependencies (or
> failed dependencies) when I try to install pyexiv2 (pr py3exiv2) using
> pip3.
>
> Can anyone point me at anywhere that might have some documentation
> that will help? 
>
> The first problem (it might be the whole problem, I'm not sure) is
> which 'pyexiv2' I should be installing, there seem to be several
> apparently competing versions and it's not at all clear which is the
> most likely to work.  On pypi there's py3exiv2 and pyexiv2 both of
> which claim to be for Python 3.  On the http://py3exiv2.tuxfamily.org/
> page it states: "py3exiv2 is the Python 3 version of pyexiv2 written
> for Python 2, ...", really! no wonder I'm confused.
>
> Essentially I need the python-pyexiv2 package for Ubuntu 20.04 and
> it's only available up to 19.10.
>
Hi,

Two solutions:
1. Install exiv2-dev and py3exiv2 with pip
    $ sudo apt-get install libexiv2-dev
    $ sudo pip3 install py3exiv2

2. Install my ppa
    $ sudo add-apt-repository ppa:vincent-vandevyvre/vvv
    $ sudo apt-get update
    $ sudo apt-get install python3-exiv2

Don't change your old code for pyexiv2, the names of the modules are
unchanged, your old code should work as it.

Off course old strings are now unicode.

Vincent (AKA VinsS)

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


[issue41109] subclasses of pathlib.PurePosixPath never call __init__ or __new__

2020-08-13 Thread Louis-Vincent Boudreault

Louis-Vincent Boudreault  added the comment:

This is not true, because the classmethod used the library shortcuts the
class mro order, this is to prevent infinite loop inthe __new__. However,
If it was using __init__ before hand, we would
Not have this issue

Le jeu. 13 août 2020 à 15:31, Louis-Vincent Boudreault <
lv.boudreaul...@gmail.com> a écrit :

> This is not true, because the classmethod use the library shortcuts the
> class mro order, to prevent infinite loop inthe __new__. However, it was
> using __init__ before hand, we would
> Not have this issue
>
>
> Le jeu. 13 août 2020 à 15:27, Jeffrey Kintscher 
> a écrit :
>
>>
>> Jeffrey Kintscher  added the comment:
>>
>> Adding __init__() to PurePath complicates things and doesn't provide any
>> benefit.  A subclass that calls super.__init__() ends up invoking
>> object.__init__(), which is perfectly fine.
>>
>> I was able to find a solution by calling type(self)() instead of
>> object.__new__() in most cases.  I am working on a PR.
>>
>> --
>>
>> ___
>> Python tracker 
>> <https://bugs.python.org/issue41109>
>> ___
>>
>

--

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



[issue41109] subclasses of pathlib.PurePosixPath never call __init__ or __new__

2020-08-13 Thread Louis-Vincent Boudreault

Louis-Vincent Boudreault  added the comment:

This is not true, because the classmethod use the library shortcuts the
class mro order, to prevent infinite loop inthe __new__. However, it was
using __init__ before hand, we would
Not have this issue

Le jeu. 13 août 2020 à 15:27, Jeffrey Kintscher  a
écrit :

>
> Jeffrey Kintscher  added the comment:
>
> Adding __init__() to PurePath complicates things and doesn't provide any
> benefit.  A subclass that calls super.__init__() ends up invoking
> object.__init__(), which is perfectly fine.
>
> I was able to find a solution by calling type(self)() instead of
> object.__new__() in most cases.  I am working on a PR.
>
> --
>
> ___
> Python tracker 
> <https://bugs.python.org/issue41109>
> ___
>

--

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



[issue41109] subclasses of pathlib.PurePosixPath never call __init__ or __new__

2020-08-08 Thread Louis-Vincent Boudreault


Louis-Vincent Boudreault  added the comment:

Path.__new__ should not call _from_parts because it breaks the specialization 
by directly using object.__new__.
This is why `_from_parts` has to be duplicated in each subclass's `__new__`.

My suggestion (first draft) is to do the parsing of arguments inside an 
`__init__` in the Path class hierarchy
and deprecate  `_from_parts`.

```
class PurePath:
   
 def __new__(cls, *args):
 if cls is PurePath:
 cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
 super().__new__(cls, *args) # Here we remove call to from_parts

 def __init__(self, *args):
 # We should have an __init__ in the hierarchy.
 drv, root, parts = self._parse_args(args)  # this would get the proper 
_flavour.
 self._drv = drv
 self._root = root
 self._parts = parts

 ...

class Path(PurePath):
 def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath

# REMOVE THIS LINE: self = cls._from_parts(args, init=False) #

if not self._flavour.is_supported:
raise NotImplementedError("cannot instantiate %r on your system"
  % (cls.__name__,))
return super().__new__(cls, *args, **kwargs) # Use super

```


I don't know what is the purpose of `_init` and if it could be replaced by an 
extra keyword argument in __init__.

The class method `_from_parts` would become deprecated since the argument 
parsing would be now handled by `__init__`.

By using __init__ and avoid the direct call to `object.__new__` we would 
respect class specialization and custom class could be implemented intuitively.

--
nosy: +louis-vincent.boudre

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



Re: Fake news Detect

2020-07-18 Thread Vincent Davis
Data Sceptic has a couple podcast and some of the code is open source.
https://dataskeptic.com/blog/episodes/2018/algorithmic-detection-of-fake-news

Thanks
Vincent Davis
720-301-3003
*Want to get a hold of me?*


*SMS: awesome.phone: ok...*
*email: bad!*


On Fri, Jul 17, 2020 at 11:39 PM Mike Dewhirst 
wrote:

> On 18/07/2020 6:16 am, Grant Edwards wrote:
> > On 2020-07-17, Dennis Lee Bieber  wrote:
> >> On Fri, 17 Jul 2020 16:02:15 - (UTC), Gazu 
> declaimed
> >> the following:
> >>
> >>> Hey Guys I am new to python and i am building a fake news detection
> >>> system ...
> >>  I suspect that, if anyone had done this already, it would likely be
> >> found on some source code archive (github?) -- and you'd just be
> >> duplicating the effort.
> >>
> >>  Essentially, since the core of this functionality depends upon the
> >> algorithm, YOU will have to develop the algorithm.
> > Or he could do something easier like eliminating hunger, war and
> > Covid-19.
>
> Or like changing culture to give more weight to education, integrity
> etc. We need systems to automatically identify fake news and educate
> believers. News consumers have to do it.
>
> News consumers need a system where they can go to check news items to
> see if they are credible. Without the cooperation of news conduits - to
> label news items with the source - that will be difficult.
>
> However, that doesn't mean the crowd can't check credibility. So,
> culture change is needed. No-one wants to be outed as a fake news source.
>
> Here's a project. Build an automatic news aggregation site which
> collects all news in two pages per news item. Page 1 for the item and
> page 2 for the crowd credibility assessment and naming of the apparent
> source. Should work somewhat like Wikipedia. Except editors for page 2
> would need a threshold score for being correct. Everyone can criticise
> but you lose points for being on the wrong side of history.
>
> That'll be 2 cents
>
> Mike
>
> >
> > --
> > Grant
> >
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue41024] doc: Explicitly mention use of 'enum.Enum' as a valid container for 'choices' argument of 'argparse.ArgumentParser.add_argument'

2020-07-17 Thread Vincent Férotin

Vincent Férotin  added the comment:

Unless I am mistaken, merged pull-request was not backported from master to 
other potential branches (3.5 -> 3.9 included). There was a message from GitHub 
'miss-islington' bot 
(https://github.com/python/cpython/pull/20964#issuecomment-646991186) saying, 
if I understand correctly, to manually cherry-pick merged commit to other 
branches. Am I correct?
And if so, is there some automatic process for this cherry-picking to re-run, 
or do someone have to do it manually?

--
status: open -> pending

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



[issue41024] doc: Explicitly mention use of 'enum.Enum' as a valid container for 'choices' argument of 'argparse.ArgumentParser.add_argument'

2020-07-17 Thread Vincent Férotin

Vincent Férotin  added the comment:

Explicitly add Raymond Hettinger to nosy list, as he reviewed the corresponding 
PR.

--
nosy: +rhettinger

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



How to match scipy.spatial.distance results back to pandas df

2020-07-16 Thread Vincent Davis
I am trying to find points in the activity that are near points in segment.
I get the results from distance() and what to identify the points in
segment and activity that are within some value of each other .0001 for
example.
One idea I had was to append each array row (or column) to the
corresponding row in the df after converting it to a dict so that I can
lookup the point in the other df.

Any suggestions, ideas?

from scipy.spatial import distance
a = distance.cdist(segment[['Latitude', 'Longitude']],
activity[['Latitude', 'Longitude']], 'euclidean')
b = a[a < .0001]
b

array([8.83911760e-05, 6.31347765e-05, 3.89486842e-05, 2.13775583e-05,
   2.10950231e-05, 4.10487515e-05, 6.7000e-05, 9.10878697e-05,
   7.61183289e-05, 9.90050504e-05, 7.88162420e-05, 5.90931468e-05,
   4.50111097e-05, 4.97393205e-05, 6.78969808e-05, 8.52115016e-05,
...


Thanks
Vincent Davis
720-301-3003
*Want to get a hold of me?*


*SMS: awesome.phone: ok...*
*email: bad!*
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue41214] -O0: Segmentation fault in _PyArg_UnpackStack

2020-07-05 Thread Vincent LE GARREC


New submission from Vincent LE GARREC :

In Gentoo, I compile my system with -O0

When I compile Apache Serf, python 3.7.8 crashes. When I compile python 3.7 
with -O2, python don't crash when compiling Serf.

It's the first time that -O0 causes program crash.

I run test suite, I don't have any problem.

Please find enclosed the backtrace.

I can reproduce every time so if you want me to do some tests, I can do it.

I already report it to Gentoo (https://bugs.gentoo.org/730312) but it seems 
it's not related to them.

--
files: backtrace.log.gz
messages: 373026
nosy: Vincent LE GARREC
priority: normal
severity: normal
status: open
title: -O0: Segmentation fault in _PyArg_UnpackStack
type: crash
versions: Python 3.7
Added file: https://bugs.python.org/file49298/backtrace.log.gz

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



[issue41024] doc: Explicitly mention use of 'enum.Enum' as a valid container for 'choices' argument of 'argparse.ArgumentParser.add_argument'

2020-06-18 Thread vincent-ferotin


Change by vincent-ferotin :


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

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



[issue41024] doc: Explicitly mention use of 'enum.Enum' as a valid container for 'choices' argument of 'argparse.ArgumentParser.add_argument'

2020-06-18 Thread vincent-ferotin

New submission from vincent-ferotin :

It is currently not obvious, reading :mod:`argparse` documentation, that 
:meth:`argparse.ArgumentParser.add_argument` could accept as 'choices' 
parameter an :class:`enum.Enum`.
However, it seems (at least to me) that this 'choices' parameter [1] is the 
perfect candidat of enums usage (see [2]).

So I suggest here to explicitly mention and illustrate such usage in current 
Python documentation. As far I as could test, such usage works at least with 
Python 3.5, 3.7, and 3.8.

A small patch on 'master' branches is in progress, and should shortly be 
available as a GitHub pull-request.

[1] https://docs.python.org/3/library/argparse.html#choices
[2] PEP 435: https://www.python.org/dev/peps/pep-0435/#motivation

--
assignee: docs@python
components: Documentation
messages: 371812
nosy: Vincent Férotin, docs@python
priority: normal
severity: normal
status: open
title: doc: Explicitly mention use of 'enum.Enum' as a valid container for 
'choices' argument of 'argparse.ArgumentParser.add_argument'
type: enhancement
versions: Python 3.10, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

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



Re: Convert and analyze image data in a spreadsheet.

2020-06-14 Thread Vincent Davis
Dennis,
Thanks for your ideas. The researcher I am working with just told me the
data is wrong and needs to send me new data and there are other problems
with exactly what their research questions is. So this goes nowhere for now.

Thanks
Vincent Davis
720-301-3003
*Want to get a hold of me?*


*SMS: awesome.phone: ok...*
*email: bad!*


On Thu, Jun 11, 2020 at 1:17 PM Dennis Lee Bieber 
wrote:

>
> My previous response hasn't made it through the
> gmane<>list<>usenet<>back cycle so I can't "talk to myself"...
>
> On Thu, 11 Jun 2020 07:44:25 -0600, Vincent Davis
>  declaimed the following:
>
> >Looking for a little advise.
> >I have 6x6 color (CIELAB <
> https://en.wikipedia.org/wiki/CIELAB_color_space>)
> >data in a spreadsheet (color samples of clothing). I would like to
> >visualize this as an image on a per channel (l,a,b) and as a color image.
> I
> >can read the data from the spreadsheet. I am not sure the path a should
> >choose from there. I think the path is to read this data into a numpy
> array
> >and use scikit-image.
> >
>
> I'm going to speak blasphemy and mention the R statistics package.
> It
> has
>
> https://stat.ethz.ch/R-manual/R-devel/library/grDevices/html/convertColor.html
> which includes L*a*b* as a color space. Though it does not seem to have
> Adobe RGB...
> """
> "XYZ", "sRGB", "Apple RGB", "CIE RGB", "Lab", "Luv".
> """
>
> Also links to the main page of a source of the math used in
> converting
>
> It also mentions something that wasn't obvious in other references:
> """
> The Lab and Luv spaces describe colors of objects, and so require the
> specification of a reference ‘white light’ color. Illuminant D65 is a
> standard indirect daylight, Illuminant D50 is close to direct sunlight, and
> Illuminant A is the light from a standard incandescent bulb. Other standard
> CIE illuminants supported are B, C, E and D55. RGB colour spaces are
> defined relative to a particular reference white, and can be only
> approximately translated to other reference whites.
> """
>
> ... hence conversions from L*a*b* to, say, sRGB, will differ based upon
> what illumination reference is used!
>
>
>
> --
> Wulfraed Dennis Lee Bieber AF6VN
> wlfr...@ix.netcom.com
> http://wlfraed.microdiversity.freeddns.org/
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Convert and analyze image data in a spreadsheet.

2020-06-11 Thread Vincent Davis
Looking for a little advise.
I have 6x6 color (CIELAB <https://en.wikipedia.org/wiki/CIELAB_color_space>)
data in a spreadsheet (color samples of clothing). I would like to
visualize this as an image on a per channel (l,a,b) and as a color image. I
can read the data from the spreadsheet. I am not sure the path a should
choose from there. I think the path is to read this data into a numpy array
and use scikit-image.

Questions:
1. I am not sure how to get the 3 color measurements into a color image
pixel.
2. I only kinda understand color spaces, this data is in CIELAB, do I want
to keep it in that color format? I think yes.
3. How can I visualize this data as a 6x6 color image and visualize each
color on a gray scale.
4. General hints or link of how to proceed would be helpful.

Thanks
Vincent Davis
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: RFC: For Loop Invariants

2020-04-20 Thread Vincent Vande Vyvre
Le 20/04/20 à 13:08, Tony Flury via Python-list a écrit :
>
> On 10/04/2020 21:44, Elliott Dehnbostel wrote:
>> *We could do this:*
>>
>> chars = "abcaaabkjzhbjacvb"
>> seek = {'a','b','c'}
>> count = sum([1 for a in chars if a in seek])
>>
>> However, this changes important semantics by creating an entire new
>> list before summing.
>
> Creating the list is pointless in this case - sum will take any
> iterable, including a generator expression:
>
> chars = "abcaaabkjzhbjacvb"
> seek = {'a','b','c'}
> count = sum(1 for a in chars if a in seek)
>
> So you haven't really changed any semantics - and it seems that this
> is far better than fiddling with the for loop syntax.

You can use boolean as integer.

>>> chars = "abcaaabkjzhbjacvb"
>>> seek = {'a', 'b', 'c'}
>>> count = 0
>>> for i in chars:
... count += i in seek
...
>>> count
11


Vincent.

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


[issue39484] time_ns() and time() cannot be compared on windows

2020-02-03 Thread Vincent Michel


Change by Vincent Michel :


Added file: https://bugs.python.org/file48883/comparing_conversions.py

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



[issue39484] time_ns() and time() cannot be compared on windows

2020-02-03 Thread Vincent Michel


Vincent Michel  added the comment:

@mark.dickinson
> To be clear: the following is flawed as an accuracy test, because the 
> *multiplication* by 1e9 introduces additional error.

Interesting, I completely missed that! 

But did you notice that the full conversion might still perform better when 
using only floats?

```
>>> from fractions import Fraction as F 
>>>   
>>> r = 1580301619906185300 
>>>  
>>> abs(int(r / 1e9 * 1e9) - r) 
>>>  
84
>>> abs(round(F(r / 10**9) * 10**9) - r)
>>>
89
```

I wanted to figure out how often that happens so I updated my plotting, you can 
find the code and plot attached.

Notice how both methods seems to perform equally good (the difference of the 
absolute errors seems to average to zero). I have no idea about why that 
happens though.

--
Added file: 
https://bugs.python.org/file48882/Comparing_conversions_over_5_us.png

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



[issue39484] time_ns() and time() cannot be compared on windows

2020-02-03 Thread Vincent Michel


Vincent Michel  added the comment:

@serhiy.storchaka
> 1580301619906185300/10**9 is more accurate than 1580301619906185300/1e9.

I don't know exactly what `F` represents in your example but here is what I get:

>>> r = 1580301619906185300 
>>>  
>>> int(r / 10**9 * 10**9) - r  
>>>  
172
>>> int(r / 1e9 * 10**9) - r
>>>  
-84

@vstinner
> I suggest to only document in time.time() is less accurate than 
> time.time_ns().

Sounds good!

--

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



[issue39484] time_ns() and time() cannot be compared on windows

2020-02-03 Thread Vincent Michel


Vincent Michel  added the comment:

> The problem is that there is a double rounding in [...]

Actually `float(x) / 1e9` and `x / 1e9` seems to produce the same results:

```
import time
import itertools
now = time.time_ns()
  
for x in itertools.count(now):
assert float(x) / 1e9 == x / 1e9
```

> The formula `time = time_ns / 10**9` may be more accurate.

Well that seems to not be the case, see the plots and the corresponding code. I 
might have made a mistake though, please let me know if I got something wrong :)

--

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



[issue39484] time_ns() and time() cannot be compared on windows

2020-02-03 Thread Vincent Michel


Vincent Michel  added the comment:

Thanks for your answers, that was very informative!

> >>> a/10**9
> 1580301619.9061854
> >>> a/1e9
> 1580301619.9061852
>
> I'm not sure which one is "correct".


Originally, I thought `a/10**9` was more precise because I ran into the 
following case while working with hundreds of nanoseconds (because windows):

```
r = 1580301619906185900
print("Ref   :", r)
print("10**7 :", int(r // 100 / 10**7 * 10 ** 7) * 100)
print("1e7   :", int(r // 100 / 1e7 * 10 ** 7) * 100)
print("10**9 :", int(r / 10**9 * 10**9))
print("1e9   :", int(r / 1e9 * 10**9))
[...]
Ref   : 1580301619906185900
10**7 : 1580301619906185800
1e7   : 1580301619906186200
10**9 : 1580301619906185984
1e9   : 1580301619906185984
```

I decided to plot the conversion errors for different division methods over a 
short period of time. It turns out that:
- `/1e9` is equally or more precise than `/10**9` when working with nanoseconds
- `/10**7` is equally or more precise than `/1e7` when working with hundreds 
nanoseconds

This result really surprised me, I have no idea what is the reason behind this.

See the plots and code attached for more information.

In any case, this means there is no reason to change the division in 
`_PyTime_AsSecondsDouble`, closing this issue as wontfix sounds fine :)

---

As a side note, the only place I could find something similar mentioned in the 
docs is in the `os.stat_result.st_ctime_ns` documentation: 

https://docs.python.org/3.8/library/os.html#os.stat_result.st_ctime_ns

> Similarly, although st_atime_ns, st_mtime_ns, and st_ctime_ns are 
> always expressed in nanoseconds, many systems do not provide 
> nanosecond precision. On systems that do provide nanosecond precision,
> 1the floating-point object used to store st_atime, st_mtime, and 
> st_ctime cannot preserve all of it, and as such will be slightly 
> inexact. If you need the exact timestamps you should always use 
> st_atime_ns, st_mtime_ns, and st_ctime_ns.

Maybe this kind of limitation should also be mentioned in the documentation of 
`time.time_ns()`?

--
Added file: 
https://bugs.python.org/file48880/Comparing_division_errors_over_10_us.png

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



[issue39484] time_ns() and time() cannot be compared on windows

2020-02-03 Thread Vincent Michel


Change by Vincent Michel :


Added file: https://bugs.python.org/file48881/comparing_errors.py

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



[issue39484] time_ns() and time() cannot be compared on windows

2020-01-29 Thread Vincent Michel


Vincent Michel  added the comment:

I thought about it a bit more and I realized there is no way to recover the 
time in hundreds of nanoseconds from the float produced by `time.time()` (since 
the windows time currently takes 54 bits and will take 55 bits in 2028). 

That means `time()` and `time_ns()` cannot be compared by converting time() to 
nanoseconds, but it might still make sense to compare them by converting 
time_ns() to seconds (which is apparently broken at the moment).

If that makes sense, a possible roadmap to tackle this problem would be:
- fix `_PyTime_AsSecondsDouble` so that `time.time_ns() / 10**9 == time.time()`
- add a warning in the documentation that one should be careful when comparing 
the timestamps produced by `time()` and time_ns()` (in particular, `time()` 
should not be converted to nanoseconds)

--

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



[issue39484] time_ns() and time() cannot be compared on windows

2020-01-29 Thread Vincent Michel


New submission from Vincent Michel :

On windows, the timestamps produced by time.time() often end up being equal 
because of the 15 ms resolution:

>>> time.time(), time.time()
(1580301469.6875124, 1580301469.6875124)

The problem I noticed is that a value produced by time_ns() might end up being 
higher then a value produced time() even though time_ns() was called before:

>>> a, b = time.time_ns(), time.time()
>>> a, b
(1580301619906185300, 1580301619.9061852)
>>> a / 10**9 <= b
False

This break in causality can lead to very obscure bugs since timestamps are 
often compared to one another. Note that those timestamps can also come from 
non-python sources, i.e a C program using `GetSystemTimeAsFileTime`.

This problem seems to be related to the conversion `_PyTime_AsSecondsDouble`:
https://github.com/python/cpython/blob/f1c19031fd5f4cf6faad539e30796b42954527db/Python/pytime.c#L460-L461

# Float produced by `time.time()`
>>> b.hex()
'0x1.78c5f4cf9fef0p+30'
# Basically what `_PyTime_AsSecondsDouble` does:
>>> (float(a) / 10**9).hex()
'0x1.78c5f4cf9fef0p+30'
# What I would expect from `time.time()`
>>> (a / 10**9).hex()
'0x1.78c5f4cf9fef1p+30'

However I don't know if this would be enough to fix all causality issues since, 
as Tim Peters noted in another thread:

> Just noting for the record that a C double (time.time() result) isn't quite 
> enough to hold a full-precision Windows time regardless

(https://bugs.python.org/issue19738#msg204112)

--
components: Library (Lib)
messages: 360958
nosy: vxgmichel
priority: normal
severity: normal
status: open
title: time_ns() and time() cannot be compared on windows
type: behavior
versions: Python 3.7, Python 3.8

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



Won't Uninstall

2019-09-20 Thread Fred Vincent
Python 3.7.4 won’t uninstall, I have tried doing what I can such as going to 
the control panel and uninstalling the program there, but that did not work. 
Since I am unable to delete it I am unable to download a different version of 
python. How do I fix this and fully uninstall python?

Sent from Mail for Windows 10

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


[issue35409] Async generator might re-throw GeneratorExit on aclose()

2019-07-13 Thread Vincent Michel


Change by Vincent Michel :


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

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



Re: Python 3.73 cannot install py3exiv2

2019-05-02 Thread Vincent Vande Vyvre

Le 1/05/19 à 15:12, Ken Martell a écrit :

I’m a retired aerospace engineer. I’m a Windows 10 user & have zero experience with 
Python. My goal is to learn, get this working & run lens distortion correction 
routines using Python. I’ve tried or many hours and read as much as I can but cannot 
get the py3exiv2 module to install. Other needed modules installed fine. It appears the 
Python version 2 of evix2 is needed as a dependent for the version 3 but neither pip or 
pip3 will install old or new. Sorry for taking your time but I’m a newbie just trying 
to help my fellow photographers correct  lens distortion problems in post-processing as 
well as my own.

Any help much appreciated!

Thank you
Ken Martell



Sent from Mail for Windows 10




The package available on PyPI is for *nix machines.

I don't have access to a Windows machine nor the knowledge to build an 
executable for Windows.


But, recently an user send me how it has successfully compiled py3exiv2 
for Windows.




Hello Vincent,

 I’ve run through the trouble of building py3exiv2 on Windows and was 
successful in doing so,


therefore I’d like to present you the steps I’ve taken to get there, so 
that you can alter setup.py and give some instructions on how to install 
it on Windows.


This is a copy of his mail:
---
 The key part in making this work is 
https://github.com/Microsoft/vcpkg, it has both exiv2 and boost-python.


Here’s what I did:

 [INSTALLING PYEXIV3 ON WINDOWS]
- install GIT-2.21.0-64-bit.exe
- install VSCodeUserSetup-x64-1.33.1.exe
- clone vcpkg, note the folder name
    $ git clone https://github.com/Microsoft/vcpkg.git
- install vcpkg by running .\bootstrap-vcpkg.bat
- run vcpkg.exe install boost-python:x64-windows
- run vcpkg.exe install exiv2:x64-windows
- make sure to add /installed/x64-windows/bin to the PATH (for dll import)
- get the pyexiv2 sources from here: http://py3exiv2.tuxfamily.org/downloads
- replace setup.py with my version
- set the environment variable VCPKG to the folder where you installed it
- run pip install -e 

I’ve attached my modified version of setup.py. It’s very rough since I 
don’t know much about setuptools at all, but it essentially involves 
bypassing `get_libboost_name` which fails completely on windows and 
using the environment variable VCPGK that has to be set by the user to 
point at the vcpkg directory. There’s probably a cleaner way of doing 
this, like accepting a command line argument. But again, I have no idea 
how setuptools handles this so hopefully you can clean it up a bit. 
`boost_python37-vc140-mt` is also completely hardcoded, you’d probably 
have to modify `get_libboost_name` to work on Windows.


 While I’m at this, I’ve noticed the lack of support for custom xmp 
tags. For now I’ve resorted to abusing various IPTC Tags for my purpose, 
but that’s a rather terrible solution. I’d appreciate it if you could 
prioritize adding that feature in the future.


 with best regards,

Vic

setup.py

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
import os
import glob
import subprocess

from setuptools import setup, find_packages, Extension

from codecs import open
from os import path

here = path.abspath(path.dirname(__file__))

# Get the long description from the relevant file
with open(path.join(here, 'DESCRIPTION.rst'), encoding='utf-8') as f:
    long_description = f.read()

def get_libboost_name():
    """Returns the name of the lib libboost_python 3

    """
    # libboost libs are provided without .pc files, so we can't use 
pkg-config

    places = ('/usr/lib/', '/usr/local/lib/', '/usr/')
    for place in places:
    cmd = ['find', place, '-name', 'libboost_python*']
    rep = subprocess.Popen(cmd, 
stdout=subprocess.PIPE).communicate()[0]

    if not rep:
    continue

    # rep is type bytes
    libs = rep.decode(sys.getfilesystemencoding()).split('\n')
    for l in libs:
    _, l = os.path.split(l)
    if '.so' in l:
    l = l.split('.so')[0]
    # Assume there's no longer python2.3 in the wild
    if '3' in l[-2:]:
    return l.replace('libboost', 'boost')

if os.name == 'nt':
    basep = os.environ["VCPKG"] + r"\installed\x64-windows"
    os.environ["INCLUDE"] = basep + r"\include"
    libboost = basep + r"\lib\boost_python37-vc140-mt"
    libexiv = basep + r"\lib\exiv2"
    extra_compile_args = []
else:
    libboost = get_libboost_name()
    extra_compile_args = []
    libexiv = 'exiv2'

setup(
    name='py3exiv2',
    version='0.7.0',
    description='A Python3 binding to the library exiv2',
    long_description=long_description,
    url='https://launchpad.net/py3exiv2',
    author='Vincent Vande Vyvre',
    author_email='vincent.vandevy...@oqapy.eu',
    license='GPL-3',

    # 

Re: How to catch a usefull error message ?

2019-04-25 Thread Vincent Vande Vyvre

Le 25/04/19 à 08:25, Chris Angelico a écrit :

On Thu, Apr 25, 2019 at 2:32 PM Vincent Vande Vyvre
 wrote:

Le 24/04/19 à 19:57, MRAB a écrit :

On 2019-04-23 20:21, Vincent Vande Vyvre wrote:

Le 23/04/19 à 20:54, Chris Angelico a écrit :


Why a SystemError ?
The SystemError means that you're using the Python C API in a way that
doesn't make sense to the interpreter. You're leaving a marker saying
"hey, I need you to throw an exception" but then you're also returning
a value. You'll need to figure out where that's happening and exactly
what is being called. How are you setting up your class?

ChrisA
The syntaxe

   if (!PyArg_ParseTuple(args, "s", ))
return NULL;

Is the usage described in the doc [*]

And without block try-except I get the good one error.


[*]
https://docs.python.org/3.5//extending/extending.html#back-to-the-example



If you look at the previous example, the function's return type is
"PyObject *".

On success it returns a reference (pointer) to an object; on error it
returns NULL.

Your function's return type is int.

In this case yes, beause it need to return the result of the command system.

But the "return 0" is a common case for an "Foo_init()"

see:
https://docs.python.org/3.5//extending/newtypes.html#adding-data-and-methods-to-the-basic-example

... And that's nothing to do with my initial question

Actually, it is a lot to do with your initial question. Notice how
there are two distinct signatures being demonstrated in the example
you linked to: those declared as returning PyObject* and those
declared as returning int. If something is meant to return an object,
then returning NULL says "hey, I set an error state, unwind the stack
and raise the exception". If it's meant to return an integer, though,
it returns -1 to give that message. See details here (second
paragraph):

https://docs.python.org/3/c-api/intro.html#exceptions

The __init__ function is defined as returning an integer:

https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_init

You're right that "return 0" is a common case; that isn't the problem.
The problem is the "return NULL", which is correct for a function that
normally returns a PyObject*, but not for one that returns an int.
That's why you're getting a SystemError - you're setting the exception
state, but then saying "hey, everything's fine, it's okay to return
None".

ChrisA


Does not change anything with PyObject *, same behaviour.

But with "static int" and "return -1;" instead of "NULL",  now I have 
the correct error.



So, thanks to all and sorry for the delays of my mails but it seems I'm 
always moderated ...



Vincent

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


Re: How to catch a usefull error message ?

2019-04-24 Thread Vincent Vande Vyvre

Le 24/04/19 à 19:57, MRAB a écrit :

On 2019-04-23 20:21, Vincent Vande Vyvre wrote:

Le 23/04/19 à 20:54, Chris Angelico a écrit :

On Wed, Apr 24, 2019 at 4:47 AM Vincent Vande Vyvre
 wrote:

Into the lib:

static int
ImgProc_init(ImgProc *self, PyObject *args, PyObject *kwds)
{
  PyObject *tmp;
  char *fname;

  if (!PyArg_ParseTuple(args, "s", ))
  return NULL;

  tmp = self->src;
  self->src = PyUnicode_FromString(fname);
  Py_XDECREF(tmp);
  return 0;
}

If i do:
  try:
  tif = ImgProc(123)
  except Exception as why:
  print(sys.exc_info())
  raise
I get:
(, SystemError("
returned a result with an error set",), )
TypeError: argument 1 must be str, not int

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
    File "/home/vincent/oqapy-3/trunk/filters/ui_lenscorrection.py", 
line

104, in on_main_cursor_changed
  self.prepare_preview_process()
    File "/home/vincent/oqapy-3/trunk/filters/ui_lenscorrection.py", 
line

137, in prepare_preview_process
  self.main.process_on_preview(params)
    File "/home/vincent/oqapy-3/trunk/filters/lenscorrection.py", line
56, in process_on_preview
  tif = ImgProc(123)
SystemError:  returned a result with an 
error set
 


Why a SystemError ?
The SystemError means that you're using the Python C API in a way that
doesn't make sense to the interpreter. You're leaving a marker saying
"hey, I need you to throw an exception" but then you're also returning
a value. You'll need to figure out where that's happening and exactly
what is being called. How are you setting up your class?

ChrisA


The syntaxe

  if (!PyArg_ParseTuple(args, "s", ))
   return NULL;

Is the usage described in the doc [*]

And without block try-except I get the good one error.


[*]
https://docs.python.org/3.5//extending/extending.html#back-to-the-example 



If you look at the previous example, the function's return type is 
"PyObject *".


On success it returns a reference (pointer) to an object; on error it 
returns NULL.


Your function's return type is int.


In this case yes, beause it need to return the result of the command system.

But the "return 0" is a common case for an "Foo_init()"

see: 
https://docs.python.org/3.5//extending/newtypes.html#adding-data-and-methods-to-the-basic-example


... And that's nothing to do with my initial question

Vincent

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


Re: How to catch a usefull error message ?

2019-04-24 Thread Vincent Vande Vyvre

Le 23/04/19 à 21:48, MRAB a écrit :

On 2019-04-23 19:21, Vincent Vande Vyvre wrote:

Le 23/04/19 à 19:23, Chris Angelico a écrit :

On Wed, Apr 24, 2019 at 3:18 AM Vincent Vande Vyvre
 wrote:

Hi,

In a CPython lib I have an _init() method wich take one argument, a 
file

name.

  char *fname;

  if (!PyArg_ParseTuple(args, "s", ))
  return NULL;

So, if I instanciate my object with a bad argument I've a good error
message:

tif = ImgProc(123)
TypeError: argument 1 must be str, not int
(followed by the traceback)

But if I do:
try:
  tif = ImgProc(123)
except Exception as why:
  print("Error:", why)

I get just:

Error:  returned a result with an error set


It looks like there's an internal problem in the C function. Are you
sure it's hitting the PyArg_ParseTuple and then immediately returning
NULL? Post a bit more of your code; this error looks like something is
leaving an error state but then carrying on with the code.

ChrisA


Into the lib:

static int
ImgProc_init(ImgProc *self, PyObject *args, PyObject *kwds)
{
      PyObject *tmp;
      char *fname;

      if (!PyArg_ParseTuple(args, "s", ))
      return NULL;

      tmp = self->src;
      self->src = PyUnicode_FromString(fname);
      Py_XDECREF(tmp);
      return 0;
}


[snip]

That function returns an int.

If PyArg_ParseTuple fails, your function returns NULL, which is cast 
to an int, 0.


If PyArg_ParseTuple succeeds, your function returns 0.

Either way, it returns 0.

So how does the caller know whether the function was successful? Does 
it check PyErr_Occurred?


No, the caller is in a block try-except for that.

The exact question here is why without a try-except I've the good one 
error and not in a try-except.


The /return 0;/ is usual in a /Foo_init()/ function.


Vincent

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


Re: How to catch a usefull error message ?

2019-04-24 Thread Vincent Vande Vyvre

Le 23/04/19 à 20:54, Chris Angelico a écrit :

On Wed, Apr 24, 2019 at 4:47 AM Vincent Vande Vyvre
 wrote:

Into the lib:

static int
ImgProc_init(ImgProc *self, PyObject *args, PyObject *kwds)
{
  PyObject *tmp;
  char *fname;

  if (!PyArg_ParseTuple(args, "s", ))
  return NULL;

  tmp = self->src;
  self->src = PyUnicode_FromString(fname);
  Py_XDECREF(tmp);
  return 0;
}

If i do:
  try:
  tif = ImgProc(123)
  except Exception as why:
  print(sys.exc_info())
  raise
I get:
(, SystemError("
returned a result with an error set",), )
TypeError: argument 1 must be str, not int

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/vincent/oqapy-3/trunk/filters/ui_lenscorrection.py", line
104, in on_main_cursor_changed
  self.prepare_preview_process()
File "/home/vincent/oqapy-3/trunk/filters/ui_lenscorrection.py", line
137, in prepare_preview_process
  self.main.process_on_preview(params)
File "/home/vincent/oqapy-3/trunk/filters/lenscorrection.py", line
56, in process_on_preview
  tif = ImgProc(123)
SystemError:  returned a result with an error set

Why a SystemError ?
The SystemError means that you're using the Python C API in a way that
doesn't make sense to the interpreter. You're leaving a marker saying
"hey, I need you to throw an exception" but then you're also returning
a value. You'll need to figure out where that's happening and exactly
what is being called. How are you setting up your class?

ChrisA


The syntaxe

if (!PyArg_ParseTuple(args, "s", ))
 return NULL;

Is the usage described in the doc [*]

And without block try-except I get the good one error.


[*] 
https://docs.python.org/3.5//extending/extending.html#back-to-the-example



Vincent

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


Re: How to catch a usefull error message ?

2019-04-23 Thread Vincent Vande Vyvre

Le 23/04/19 à 19:27, MRAB a écrit :

On 2019-04-23 10:56, Vincent Vande Vyvre wrote:

Hi,

In a CPython lib I have an _init() method wich take one argument, a file
name.

      char *fname;

      if (!PyArg_ParseTuple(args, "s", ))
      return NULL;

So, if I instanciate my object with a bad argument I've a good error
message:

tif = ImgProc(123)
TypeError: argument 1 must be str, not int
(followed by the traceback)

But if I do:
try:
      tif = ImgProc(123)
except Exception as why:
      print("Error:", why)

I get just:

Error:  returned a result with an error set

Without traceback. That's not very usefull.

I prefer to keep the instanciation of this object into a try-except bloc
but how to read the error message ?


Have a look ta the 'traceback' module.
Example:

import traceback

try:
    1/0
except Exception as ex:
    print('Error:', ex)
    traceback.print_exc()


    try:
    tif = ImgProc(123)
    except Exception as why:
    traceback.print_exc()
    print("always alive !")

TypeError: argument 1 must be str, not int

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vincent/oqapy-3/trunk/filters/lenscorrection.py", line 
56, in process_on_preview

    tif = ImgProc(123)
SystemError:  returned a result with an error set
always alive !
-

This is better of nothing and the try-except works.

Vincent

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


Re: How to catch a usefull error message ?

2019-04-23 Thread Vincent Vande Vyvre

Le 23/04/19 à 19:23, Chris Angelico a écrit :

On Wed, Apr 24, 2019 at 3:18 AM Vincent Vande Vyvre
 wrote:

Hi,

In a CPython lib I have an _init() method wich take one argument, a file
name.

  char *fname;

  if (!PyArg_ParseTuple(args, "s", ))
  return NULL;

So, if I instanciate my object with a bad argument I've a good error
message:

tif = ImgProc(123)
TypeError: argument 1 must be str, not int
(followed by the traceback)

But if I do:
try:
  tif = ImgProc(123)
except Exception as why:
  print("Error:", why)

I get just:

Error:  returned a result with an error set


It looks like there's an internal problem in the C function. Are you
sure it's hitting the PyArg_ParseTuple and then immediately returning
NULL? Post a bit more of your code; this error looks like something is
leaving an error state but then carrying on with the code.

ChrisA


Into the lib:

static int
ImgProc_init(ImgProc *self, PyObject *args, PyObject *kwds)
{
    PyObject *tmp;
    char *fname;

    if (!PyArg_ParseTuple(args, "s", ))
    return NULL;

    tmp = self->src;
    self->src = PyUnicode_FromString(fname);
    Py_XDECREF(tmp);
    return 0;
}

If i do:
    try:
    tif = ImgProc(123)
    except Exception as why:
    print(sys.exc_info())
    raise
I get:
(, SystemError(" 
returned a result with an error set",), 0x7f3bcac748c8>)

TypeError: argument 1 must be str, not int

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/vincent/oqapy-3/trunk/filters/ui_lenscorrection.py", line 
104, in on_main_cursor_changed

    self.prepare_preview_process()
  File "/home/vincent/oqapy-3/trunk/filters/ui_lenscorrection.py", line 
137, in prepare_preview_process

    self.main.process_on_preview(params)
  File "/home/vincent/oqapy-3/trunk/filters/lenscorrection.py", line 
56, in process_on_preview

    tif = ImgProc(123)
SystemError:  returned a result with an error set
----
Why a SystemError ?

I'm using Python 3.6.7 and 3.7.3

Vincent

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


How to catch a usefull error message ?

2019-04-23 Thread Vincent Vande Vyvre

Hi,

In a CPython lib I have an _init() method wich take one argument, a file 
name.


    char *fname;

    if (!PyArg_ParseTuple(args, "s", ))
    return NULL;

So, if I instanciate my object with a bad argument I've a good error 
message:


tif = ImgProc(123)
TypeError: argument 1 must be str, not int
(followed by the traceback)

But if I do:
try:
    tif = ImgProc(123)
except Exception as why:
    print("Error:", why)

I get just:

Error:  returned a result with an error set

Without traceback. That's not very usefull.

I prefer to keep the instanciation of this object into a try-except bloc 
but how to read the error message ?



Vincent

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


Re: pip unable to find an extension of a lib.

2019-04-12 Thread Vincent Vande Vyvre

Le 12/04/19 à 09:48, Paul Moore a écrit :

>From https://pypi.org/project/PyQt5-sip/#files, it looks like the
project only distributes wheels (no source archive). You don't say
what platform you're using, but if it's Linux, the fact that you have
a debug Python probably means you need a different ABI, so the
standard wheels that they provide aren't compatible. So if there's no
compatible wheel and no source, there's nothing that can be installed.

pip install -v pyqt5 might give you some more information about why
the files available are not being considered as suitable, but I think
the above is likely.

Paul


Exact, in mode verbose it enumerate all versions of pyqt-sip and all are declared 
"not compatible with this Python"

So I'll create a 3.7.3 venv without the "--with-pydebug"

Thanks,
Vincent.

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


Re: pip unable to find an extension of a lib.

2019-04-12 Thread Vincent Vande Vyvre

Le 12/04/19 à 07:40, dieter a écrit :

Vincent Vande Vyvre  writes:

...
Using Python-3.7.2 (compiled with --with-pydebug) in a venv, I've
encountered this problem:

$ pip install --upgrade pip setuptools wheel

Successfully installed setuptools-41.0.0 wheel-0.33.1
---
...
$ pip install pyqt5
...
Collecting PyQt5_sip<4.20,>=4.19.14 (from pyqt5)
   Could not find a version that satisfies the requirement
PyQt5_sip<4.20,>=4.19.14 (from pyqt5) (from versions: )
No matching distribution found for PyQt5_sip<4.20,>=4.19.14 (from pyqt5)
...
$ pip search pyqt5
...
PyQt5-sip (4.19.15)   - Python extension module support

There is a spelling difference: "PyQt5_sip" versus "PyQt5-sip" --
not sure, however, whether this is important.

Yes, I see that but the names returned by pip search are different than 
the names used with pip install


ie: PyQt5 versus pyqt5.


Vincent.

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


pip unable to find an extension of a lib.

2019-04-11 Thread Vincent Vande Vyvre

Hi,

Using Python-3.7.2 (compiled with --with-pydebug) in a venv, I've 
encountered this problem:


$ pip install --upgrade pip setuptools wheel

Successfully installed setuptools-41.0.0 wheel-0.33.1
---

$ pip install pyqt5
  /pip/_vendor/html5lib/_trie/_base.py:3: DeprecationWarning: (skip)
  from collections import Mapping
Collecting pyqt5
  /pip/_vendor/msgpack/fallback.py:222: PendingDeprecationWarning: (skip)
  Using cached 
https://files.pythonhosted.org/packages/98/61/fcd53201a23dd94a1264c29095821fdd55c58b4cd388dc7115e5288866db/PyQt5-5.12.1-5.12.2-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl

Collecting PyQt5_sip<4.20,>=4.19.14 (from pyqt5)
  Could not find a version that satisfies the requirement 
PyQt5_sip<4.20,>=4.19.14 (from pyqt5) (from versions: )

No matching distribution found for PyQt5_sip<4.20,>=4.19.14 (from pyqt5)


$ pip search pyqt5
  /pip/_vendor/html5lib/_trie/_base.py:3: DeprecationWarning: (skip)
  from collections import Mapping
pyqt5-tools (5.11.3.1.4)  - Tools to supplement the official 
PyQt5 wheels
PyQt5-stubs (5.12.1.0)    - PEP561 stub files for the PyQt5 
framework
PyQt5-sip (4.19.15)   - Python extension module support for 
PyQt5

PyQt5 (5.12.1)    - Python bindings for the Qt cross ...
.

The version of PyQt5-sip (4.19.15) seems OK, no ?

I've already posted on the PyQt ML, but I am the only one with this problem.

Thanks for all advices

Vincent.

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


[issue31062] socket.makefile does not handle line buffering

2019-03-16 Thread Vincent Michel


Vincent Michel  added the comment:

I ran into this issue too so I went ahead and created a pull request 
(https://github.com/python/cpython/pull/12370).

--
nosy: +vxgmichel
versions: +Python 3.7, Python 3.8

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



[issue31062] socket.makefile does not handle line buffering

2019-03-16 Thread Vincent Michel


Change by Vincent Michel :


--
keywords: +patch
pull_requests: +12333
stage:  -> patch review

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



[issue35973] `growable_int_array type_ignores` in parsetok.c is not always freed.

2019-02-12 Thread Brennan Vincent


Brennan Vincent  added the comment:

Hi Guido,

I have tried applying your patch. It seems to fix the issue (Valgrind no longer 
reports memory definitely lost).

--

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



[issue35973] `growable_int_array type_ignores` in parsetok.c is not always freed.

2019-02-11 Thread Brennan Vincent


New submission from Brennan Vincent :

To reproduce:

(1) build python: `../configure --prefix=$HOME/prefix --with-pydebug 
--without-pymalloc && make install`

(2) run with valgrind: `valgrind --leak-check=full ~/prefix/bin/python3`

(3) exit immediately from the interpreter by pressing ^D

(4) Note the following output from Valgrind:

```
==3810071== 40 bytes in 1 blocks are definitely lost in loss record 3 of 527
==3810071==at 0x4C28B5F: malloc (vg_replace_malloc.c:299)
==3810071==by 0x59ED58: growable_int_array_init (parsetok.c:27)
==3810071==by 0x59EE14: parsetok (parsetok.c:235)
==3810071==by 0x59F697: PyParser_ParseFileObject (parsetok.c:176)
==3810071==by 0x522E85: PyParser_ASTFromFileObject (pythonrun.c:1224)
==3810071==by 0x5231E9: PyRun_InteractiveOneObjectEx (pythonrun.c:238)
==3810071==by 0x5234D0: PyRun_InteractiveLoopFlags (pythonrun.c:120)
==3810071==by 0x523BF2: PyRun_AnyFileExFlags (pythonrun.c:78)
==3810071==by 0x4204FE: pymain_run_stdin (main.c:1185)
==3810071==by 0x42126B: pymain_run_python (main.c:1675)
==3810071==by 0x422EE0: pymain_main (main.c:1820)
==3810071==by 0x422F75: _Py_UnixMain (main.c:1857)
```

Reproduced on git commit hash 522346d792d9013140a3f4ad3534ac10f38d9085 .

--
components: Interpreter Core
messages: 335274
nosy: umanwizard
priority: normal
severity: normal
status: open
title: `growable_int_array type_ignores` in parsetok.c is not always freed.
type: resource usage
versions: Python 3.8

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



Re: How to force the path of a lib ?

2019-01-24 Thread Vincent Vande Vyvre

Le 23/01/19 à 13:11, Neal Becker a écrit :

dieter wrote:


Vincent Vande Vyvre  writes:
.




To load external C/C++ shared objects, the dynamic lickage loader
(ldd) is used. "ldd" does not look at Pthon's "sys.path".
Unless configured differently, it looks at standard places
(such as "/usr/lib/x86_64-linux-gnu").

You have several options to tell "ldd" where to look for
shared objects:

  * use the envvar "LD_LIBRARY_PATH"
This is a "path variable" similar to the shell's "PATH",
telling the dynamic loader in which directories (before
the standard ones) to look for shared objects

  * use special linker options (when you link your Python
extension shared object) to tell where dependent shared
object can be found.


To follow up on that last point, look up --rpath and related.

Trying the first solution with "export 
LD_LIBRARY_PATH=/home/vincent/CPython/py370_venv/lib" has no effect.


The second solution is better, after looking de doc of 
distutils.core.Extension I've added this line into my setup.py

    Extension('libexiv2python',
    ...,
runtime_library_dirs=['/home/vincent/CPython/py370_venv/lib/'],
    ...

rebuild, install and test
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyexiv2
>>>

Great!

Many thanks,
Vincent

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


How to force the path of a lib ?

2019-01-22 Thread Vincent Vande Vyvre

(Resend because the previous message was incomplete)


Hi,

I am working on a python3 binding of a C++ lib. This lib is installed in 
my system but the latest version of this lib introduce several 
incompatibilities. So I need to update my python binding.


I'm working into a virtual environment (py370_venv) python-3.7.0 is 
installed into ./localpythons/lib/python3.7


So, the paths are:
# python-3.7.0
~/./localpythons/lib/python3.7/
# my binding python -> libexiv2
~/./localpythons/lib/python3.7/site-packages/pyexiv2/*.py
~/./localpythons/lib/python3.7/site-packages/pyexiv2/libexiv2python.cpython-37m-x86_64-linux-gnu.so

# and the latest version of libexiv2
~/CPython/py370_venv/lib/libexiv2.so.0.27.0

All theses path are in the sys.path

Now I test my binding:
>>> import pyexiv2
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/vincent/CPython/py370_venv/lib/python3.7/site-packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg/pyexiv2/__init__.py", 
line 60, in 

    import libexiv2python
ImportError: 
/home/vincent/CPython/py370_venv/lib/python3.7/site-packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg/libexiv2python.cpython-37m-x86_64-linux-gnu.so: 
undefined symbol: _ZN5Exiv27DataBufC1ERKNS_10DataBufRefE

>>>

Checking the libexiv2.so the symbol exists
~/CPython/py370_venv/lib$ objdump -T libexiv2.so.0.27.0

0012c8d0 g    DF .text    000f  Base 
_ZN5Exiv27DataBufC1ERKNS_10DataBufRefE



But it is not present into my old libexiv2 system, so I presume python use
/usr/lib/x86_64-linux-gnu/libexiv2.so.14.0.0  (The old 0.25) instead of
 ~/CPython/py370_venv/lib/libexiv2.so.0.27.0 (The latest 0.27)

How can I solve that ?

My sys.path:
['', '/home/vincent/.localpythons/lib/python37.zip', 
'/home/vincent/.localpythons/lib/python3.7', 
'/home/vincent/.localpythons/lib/python3.7/lib-dynload', 
'/home/vincent/CPython/py370_venv/lib/python3.7/site-packages', 
'/home/vincent/CPython/py370_venv/lib/python3.7/site-packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg', 
'/home/vincent/CPython/py370_venv/lib/']


Thanks, Vincent

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


How to force the path of a lib ?

2019-01-22 Thread Vincent Vande Vyvre
I'm working into a virtual environment (py370_venv) python-3.7.0 is 
installed into .localpythons/lib/python3.7


So, the paths are:
# python-3.7.0
~/.localpythons/lib/python3.7/
# my binding python -> libexiv2
~/.localpythons/lib/python3.7/site-packages/pyexiv2/*.py
~/.localpythons/lib/python3.7/site-packages/pyexiv2/libexiv2python.cpython-37m-x86_64-linux-gnu.so

# and the latest version of libexiv2
~/CPython/py370_venv/lib/libexiv2.so.0.27.0

All theses path are in the sys.path

Now I test my binding:
>>> import pyexiv2
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/home/vincent/CPython/py370_venv/lib/python3.7/site-packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg/pyexiv2/__init__.py", 
line 60, in 

    import libexiv2python
ImportError: 
/home/vincent/CPython/py370_venv/lib/python3.7/site-packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg/libexiv2python.cpython-37m-x86_64-linux-gnu.so: 
undefined symbol: _ZN5Exiv27DataBufC1ERKNS_10DataBufRefE

>>>

Checking the libexiv2.so the symbol exists

~/CPython/py370_venv/lib$ objdump -T libexiv2.so.0.27.0

0012c8d0 g    DF .text    000f  Base 
_ZN5Exiv27DataBufC1ERKNS_10DataBufRefE



But it is not present into my old libexiv2 system, so I presume python use
/usr/lib/x86_64-linux-gnu/libexiv2.so.14.0.0  (The old 0.25) instead of
 ~/CPython/py370_venv/lib/libexiv2.so.0.27.0 (The latest 0.27)

How can I solve that ?

My sys.path:
['', '/home/vincent/.localpythons/lib/python37.zip', 
'/home/vincent/.localpythons/lib/python3.7', 
'/home/vincent/.localpythons/lib/python3.7/lib-dynload', 
'/home/vincent/CPython/py370_venv/lib/python3.7/site-packages', 
'/home/vincent/CPython/py370_venv/lib/python3.7/site-packages/py3exiv2-0.1.0-py3.7-linux-x86_64.egg', 
'/home/vincent/CPython/py370_venv/lib/']


Thanks, Vincent

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


Re: How to display video files (mkv, wav, mp4 etc) within a TKinter widget?

2019-01-02 Thread Vincent Vande Vyvre

Le 2/01/19 à 15:17, Arie van Wingerden a écrit :

I found (mostly fairly old stuff) some questions and a lot of (apparently often 
not working) Python code.

1. does TKinter offer such thing out of the box?
2. or is there another way using TKinter?
3. or do I need another GUI tool (e.g. QT) for this?

TIA


With Qt it's very easy to implement a video player.

See this example:

https://bazaar.launchpad.net/~vincent-vandevyvre/qarte/qarte-4/view/head:/gui/videoplayer.py

It is implemented into this window:

https://bazaar.launchpad.net/~vincent-vandevyvre/qarte/qarte-4/view/head:/gui/uiconcerts.py


Vincent

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


Re: clusters of numbers

2018-12-15 Thread Vincent Davis
Why not start with a histogram.

Vincent

On Sat, Dec 15, 2018 at 6:46 PM Marc Lucke  wrote:

> hey guys,
>
> I have a hobby project that sorts my email automatically for me & I want
> to improve it.  There's data science and statistical info that I'm
> missing, & I always enjoy reading about the pythonic way to do things too.
>
> I have a list of percentage scores:
>
>
> (1,11,1,7,5,7,2,2,2,10,10,1,2,2,1,7,2,1,7,5,3,8,2,6,3,2,7,2,12,3,1,2,19,3,5,1,1,7,8,8,1,5,6,7,3,14,6,1,6,7,6,15,6,3,7,2,6,23,2,7,1,21,21,8,8,3,2,20,1,3,12,3,1,2,10,16,16,15,6,5,3,2,2,11,1,14,6,3,7,1,5,3,3,14,3,7,3,5,8,3,6,17,1,1,7,3,1,2,6,1,7,7,12,6,6,2,1,6,3,6,2,1,5,1,8,10,2,6,1,7,3,5,7,7,5,7,2,5,1,19,19,1,12,5,10,2,19,1,3,19,6,1,5,11,2,1,2,5,2,5,8,2,2,2,5,3,1,21,2,3,7,10,1,8,1,3,17,17,1,5,3,10,14,1,2,14,14,1,15,6,3,2,17,17,1,1,1,2,2,3,3,2,2,7,7,2,1,2,8,2,20,3,2,3,12,7,6,5,12,2,3,11,3,1,1,8,16,10,1,6,6,6,11,1,6,5,2,5,11,1,2,10,6,14,6,3,3,5,2,6,17,15,1,2,2,17,5,3,3,5,8,1,6,3,14,3,2,1,7,2,8,11,5,14,3,19,1,3,7,3,3,8,8,6,1,3,1,14,14,10,3,2,1,12,2,3,1,2,2,6,6,7,10,10,12,24,1,21,21,5,11,12,12,2,1,19,8,6,2,1,1,19,10,6,2,15,15,7,10,14,12,14,5,11,7,12,2,1,14,10,7,10,3,17,25,10,5,5,3,12,5,2,14,5,8,1,11,5,29,2,7,20,12,14,1,10,6,17,16,6,7,11,12,3,1,23,11,10,11,5,10,6,2,17,15,20,5,10,1,17,3,7,15,5,11,6,19,14,15,7,1,2,17,8,15,10,26,6,1,2,10,6,14,12,6,1,16,6,12,10,10,14,1,6,1,6,6,12,6,6,1,2,5,10
 
,8,10,1,6,8,17,11,6,3,6,5,1,2,1,2,6,6,12,14,7,1,7,1,8,2,3,14,11,6,3,11,3,1,6,17,12,8,2,10,3,12,12,2,7,5,5,17,2,5,10,12,21,15,6,10,10,7,15,11,2,7,10,3,1,2,7,10,15,1,1,6,5,5,3,17,19,7,1,15,2,8,7,1,6,2,1,15,19,7,15,1,8,3,3,20,8,1,11,7,8,7,1,12,11,1,10,17,2,23,3,7,20,20,3,11,5,1,1,8,1,6,2,11,1,5,1,10,7,20,17,8,1,2,10,6,2,1,23,11,11,7,2,21,5,5,8,1,1,10,12,15,2,1,10,5,2,2,5,1,2,11,10,1,8,10,12,2,12,2,8,6,19,15,8,2,16,7,5,14,2,1,3,3,10,16,20,5,8,14,8,3,14,2,1,5,16,16,2,10,8,17,17,10,10,11,3,5,1,17,17,3,17,5,6,7,7,12,19,15,20,11,10,2,6,6,5,5,1,16,16,8,7,2,1,3,5,20,20,6,7,5,23,14,3,10,2,2,7,10,10,3,5,5,8,14,11,14,14,11,19,5,5,2,12,25,5,2,11,8,10,5,11,10,12,10,2,15,15,15,5,10,1,12,14,8,5,6,2,26,15,21,15,12,2,8,11,5,5,16,5,2,17,3,2,2,3,15,3,8,10,7,10,3,1,14,14,8,8,8,19,10,12,3,8,2,20,16,10,6,15,6,1,12,12,15,15,8,11,17,7,7,7,3,10,1,5,19,11,7,12,8,12,7,5,10,1,11,1,6,21,1,1,10,3,8,5,6,5,20,25,17,5,2,16,14,11,1,17,10,14,5,16,5,2,7,3,8,17,7,19,12,6,5,1,3,12,43,11,8,11,5,19,10,5,11,7,20,6,12,35,5,3,
 
17,10,2,12,6,5,21,24,15,5,10,3,15,1,12,6,3,17,3,2,3,5,5,14,11,8,1,8,10,5,25,8,7,2,6,3,11,1,11,7,3,10,7,12,10,8,6,1,1,17,3,1,1,2,19,6,10,2,2,7,5,16,3,2,11,10,7,10,21,3,5,2,21,3,14,6,7,2,24,3,17,3,21,8,5,11,17,5,6,10,5,20,1,12,2,3,20,6,11,12,14,6,6,1,14,15,12,15,6,20,7,7,19,3,7,5,16,12,6,7,2,10,3,2,11,8,6,6,5,1,11,1,15,21,14,6,3,2,2,5,6,1,3,5,3,6,20,1,15,12,2,3,3,7,1,16,5,24,10,7,1,12,16,8,26,16,15,10,19,11,6,6,5,6,5)
>
>   & I'd like to know know whether, & how the numbers are clustered.  In
> an extreme & illustrative example, 1..10 would have zero clusters;
> 1,1,1,2,2,2,7,7,7 would have 3 clusters (around 1,2 & 7);
> 17,22,20,45,47,51,82,84,83  would have 3 clusters. (around 20, 47 &
> 83).  In my set, when I scan it, I intuitively figure there's lots of
> numbers close to 0 & a lot close to 20 (or there abouts).
>
> I saw info about k-clusters but I'm not sure if I'm going down the right
> path.  I'm interested in k-clusters & will teach myself, but my priority
> is working out this problem.
>
> Do you know the name of the algorithm I'm trying to use?  If so, are
> there python libraries like numpy that I can leverage?  I imagine that I
> could iterate from 0 to 100% using that as an artificial mean, discard
> values that are over a standard deviation away, and count the number of
> scores for that mean; then at the end of that I could set a threshold
> for which the artificial mean would be kept something like (no attempt
> at correct syntax:
>
> means={}
> deviation=5
> threshold=int(0.25*len(list))
> for i in range 100:
>count=0
>for j in list:
>  if abs(j-i) > deviation:
>count+=1
>if count > threshold:
>  means[i]=count
>
> That algorithm is entirely untested & I think it could work, it's just I
> don't want to reinvent the wheel.  Any ideas kindly appreciated.
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue35409] Async generator might re-throw GeneratorExit on aclose()

2018-12-04 Thread Vincent Michel


Change by Vincent Michel :


--
keywords: +patch
Added file: https://bugs.python.org/file47974/patch.diff

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



[issue35409] Async generator might re-throw GeneratorExit on aclose()

2018-12-04 Thread Vincent Michel


Change by Vincent Michel :


Added file: https://bugs.python.org/file47973/test.py

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



[issue35409] Async generator might re-throw GeneratorExit on aclose()

2018-12-04 Thread Vincent Michel


New submission from Vincent Michel :

As far as I can tell, this issue is different than: 
https://bugs.python.org/issue34730

I noticed `async_gen.aclose()` raises a GeneratorExit exception if the async 
generator finalization awaits and silence a failing unfinished future (see 
example.py).

This seems to be related to a bug in `async_gen_athrow_throw`. In fact, 
`async_gen.aclose().throw(exc)` does not silence GeneratorExit exceptions. This 
behavior can be reproduced without asyncio (see test.py).

Attached is a possible patch, although I'm not too comfortable messing with the 
python C internals. I can make a PR if necessary.

--
components: Interpreter Core
files: example.py
messages: 331043
nosy: vxgmichel
priority: normal
severity: normal
status: open
title: Async generator might re-throw GeneratorExit on aclose()
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8
Added file: https://bugs.python.org/file47972/example.py

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



[issue35065] Reading received data from a closed TCP stream using `StreamReader.read` might hang forever

2018-10-29 Thread Vincent Michel


Change by Vincent Michel :


--
pull_requests: +9528
stage:  -> patch review

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



[issue35065] Reading received data from a closed TCP stream using `StreamReader.read` might hang forever

2018-10-26 Thread Vincent Michel


Vincent Michel  added the comment:

I found the culprit:
https://github.com/python/cpython/blob/a05bef4f5be1bcd0df63ec0eb88b64fdde593a86/Lib/asyncio/streams.py#L350

The call to `_untrack_reader` is performed too soon. Closing the transport 
causes `protocol.connection_lost()` to be "called soon" but by the time it is 
actually executed, the stream reader has been "untracked".  Since the protocol 
doesn't know the stream reader anymore, it has not way to feed it the EOF.

The fix attached removes the `_untrack_reader` call and definition altogether. 
I don't really see the point of this method since one has to wait for 
`connection_lost` to be executed before untracking the reader, but 
`connection_lost` already gets rid of the reader reference.

With this fix, calling `writer.close` then awaiting `writer.wait_closed` (or 
awaiting `writer.aclose`) should:
- close the transport
- schedule `protocol.connection_lost`
- wait for the protocol to be closed
- run `protocol.connection_lost`
- feed the EOF to the reader
- set the protocol as closed
- get rid of the reader reference in the protocol
- return (making aclose causal and safe)
- the reader can then be safely garbage collected

But maybe I'm missing something about `_untrack_reader`?

--
keywords: +patch
Added file: https://bugs.python.org/file47893/patch-bpo-35065.diff

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



[issue35065] Reading received data from a closed TCP stream using `StreamReader.read` might hang forever

2018-10-26 Thread Vincent Michel


Vincent Michel  added the comment:

Hi Andrew!

I reverted the commit associated with the following PR, and the hanging issue 
disappeared:
https://github.com/python/cpython/pull/9201

I'll look into it.

--
type:  -> behavior

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



[issue35065] Reading received data from a closed TCP stream using `StreamReader.read` might hang forever

2018-10-25 Thread Vincent Michel


New submission from Vincent Michel :

I'm not sure whether it is intended or not, but I noticed a change in the  
behavior of `StreamReader` between version 3.7 and 3.8.

Basically, reading some received data from a closed TCP stream using 
`StreamReader.read` might hang forever, under certain conditions.

I'm not sure what those conditions are but I managed to reproduce the issue 
consistently with the following workflow:
 - server writes some data
 - client reads a part of the data
 - client closes the writer
 - server closes the writer
 - client tries to read the remaining data

The test attached implements the behavior. It fails on 3.8 but passes on 3.7

--
components: asyncio
files: stuck_on_py38.py
messages: 328430
nosy: asvetlov, vxgmichel, yselivanov
priority: normal
severity: normal
status: open
title: Reading received data from a closed TCP stream using `StreamReader.read` 
might hang forever
versions: Python 3.8
Added file: https://bugs.python.org/file47891/stuck_on_py38.py

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



[issue34747] SSLSocket.context cannot be changed on non-connected sockets

2018-10-15 Thread Vincent Pelletier


Vincent Pelletier  added the comment:

The reason which led me into this is server certificate renewal: my service 
crashed on that setter 2 months after starting, when it received a new 
certificate.

I toyed with the idea of closing the listening sockets, but without closing 
would be even better - code changing socket certificate is much simpler than 
having to stop all worker treads (SocketServer.ThreadingMixIn), close the 
listening sockets, and start them all again in new threads with a new 
wrap_socket'ed listening socket.

--

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



[issue34747] SSLSocket.context cannot be changed on non-connected sockets

2018-10-15 Thread Vincent Pelletier


Change by Vincent Pelletier :


--
assignee:  -> christian.heimes
components: +Library (Lib), SSL
nosy: +christian.heimes

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



[issue34561] Replace list sorting merge_collapse()?

2018-10-02 Thread Vincent Jugé

Vincent Jugé  added the comment:

After having worked a little bit on improving AdaptiveShiversSort on few-run 
cases, I designed a new version of the algorithm, called shivers2 in the file 
runstack.py joined to this message

It looks more complicated than the original AdaptiveShiversSort but the spirit, 
inspired by your comments, is as follows:
- we allow the second (bottom-most) element of the stack to be moderately 
larger than the bottom-most one; if that 2nd element were way larger than the 
1st one, merging them, even if not optimal, would not be too painful anyways;
- we may force a merge between these 1st and 2nd elements only when the 2nd 
element is about to be merged with the 3rd one;
- similarly, we allow the top-most element of the stack to be moderately larger 
than the second top-most one;
- otherwise, we stick to the behaviour of AdaptiveShiversSort.

This variant's performance seems comparable with Powersort's.
Reasonable follow-up work that I plan to do in the coming weeks (when I have 
time to do so) is:
- prove that the new algorithm still runs in n H + O(n),
- investigate whether we can have guarantees such as "this new sort's merge 
cost is at most XXX times larger than the optimal merge cost",
- investigate improvements for Powersort.

Given its excellent overall performance, I think that trying to slightly tweak 
Powersort in cases it underperforms other sorts might be worth some effort.

Best,

Vincent

--
Added file: https://bugs.python.org/file47839/runstack.py

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



[issue34561] Replace list sorting merge_collapse()?

2018-09-22 Thread Vincent Jugé

Vincent Jugé  added the comment:

I see... Indeed, my only goal when adapting Shivers Sort was to maintain some 
invariant that would make the analysis easy, while mimicking the arguments 
developed by Buss & Knop for their analysis of (plain) Shivers Sort. It is, 
however, sure that the n(H+4) upper bound I get should be refined when H is 
small, which more or less amounts to tackling the 3-run case you mention.

I am reasonably convinced that the current version of Adaptive Shivers Sort 
could be adapted to take this problem into account, while keeping its overall 
simple stricture and complexity analysis.

If this first step turns out to be feasible, I will also look at the latest 
version of runstack.py to investigate other possible improvements on Adaptive 
Shivers Sort.

--

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



[issue34561] Replace list sorting merge_collapse()?

2018-09-21 Thread Vincent Jugé

Vincent Jugé  added the comment:

Dear all,

After me and my colleagues worked on the first paper you mention, I recently 
created another merge-based sorting algorithm, which I called "Adaptive Shivers 
Sort". This is a close variant of the Augmented Shivers Sort presented by Buss 
& Knop in their article
https://arxiv.org/abs/1801.04641

Like Munro & Wild's Powersort and Peeksort, this algorithm has an optimal 
worst-case running time (up to a linear additive constant) when measured with 
the merge cost model that is used in all the articles you cite in this 
discussion. It also maintains a stack of size log_2(n).
I could not prove such an optimality result for Buss & Knop Augmented Shivers 
Sort.

Custom tests that I had performed suggest that this algorithm is, in practice, 
as efficient as Munro & Wild's algorithms, and also does not suffer from 
critically bad cases.

Moreover, like Buss & Knop's 2-merge, and unlike Munro & Wild's Powersort and 
Peeksort, this algorithm has the advantage of having a structure that is very 
similar to that of Timsort, which may be an advantage in your situation.

That is why, upon reading your discussion, I refurbished my notes about 
Adaptive Shivers Sort, which you may find here:
http://igm.univ-mlv.fr/~juge/papers/shivers_arxiv.pdf

These notes include a description of the algorithm and a worst-time complexity 
analysis. If extending my analysis of this algorithm or investigating tuning 
details were of interest for you, I would be happy to help.

Best regards,

Vincent Jugé

--
nosy: +vincent.juge

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



[issue34747] SSLSocket.context cannot be changed on non-connected sockets

2018-09-20 Thread Vincent Pelletier


New submission from Vincent Pelletier :

>From ssl.py, both on 2.7.15 and 3.6.6:
class SSLSocket(...):
...
@context.setter
def context(self, ctx):
self._context = ctx
self._sslobj.context = ctx

_sslobj is only set when socket is connected. While this is not a big issue for 
client sockets as user could just wrap the socket with correct context to begin 
with, and not a big issue for server sockets for the same reason, it is an 
issue for listening sockets: they are never connected, by definition, and do 
not care about _sslobj: upon accept() they only use self._context to wrap 
created socket.

Suggested fix:
@context.setter
def context(self, ctx):
self._context = ctx
if self._sslobj:
self._sslobj.context = ctx
(consistently with how _sslobj is evaluated as a boolean elsewhere in the same 
class)

Suggested workaround (ex: if this fix is not backported to 2.7):
try:
ssl_socket.context = new_context
except AttributeError:
pass
as _context is changed first, and it's all that matters.

--
messages: 325847
nosy: vincent-nexedi
priority: normal
severity: normal
status: open
title: SSLSocket.context cannot be changed on non-connected sockets
type: behavior
versions: Python 2.7, Python 3.6

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



Fishing from PyPI ?

2018-08-06 Thread Vincent Vande Vyvre

I've received a mail askink me to confirm my identity on PyPI.

The begining of the message:

-

Your account VinsS on PyPI 
<https://pypi.us18.list-manage.com/track/click?u=b96f861be540deb98fd700265=9a19d150cf=8824682d0f> 
does not have a verified primary email address.


Please take 2 minutes to verify your email:

 * To ensure that every email we send is going to its intended recipient
 * To ensure email sent from PyPI isn’t marked as spam by email clients
   and service
 * *If you do not verify, you will not be able to upload to PyPI, or be
   added as a maintainer to projects. You will no longer receive
   notifications from PyPI.*

   To verify, visit your Account Settings
   
<https://pypi.us18.list-manage.com/track/click?u=b96f861be540deb98fd700265=1763135c31=8824682d0f>
   page.

-

The Account Settings 
<https://pypi.us18.list-manage.com/track/click?u=b96f861be540deb98fd700265=1763135c31=8824682d0f> 
is : 
https://pypi.us18.list-manage.com/track/click?u=b96f861be540deb98fd700265=1763135c31=8824682d0f


Phishing ? yes, no ?


Vincent

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


[issue33979] [Exception message] Display type of not JSON serializable object

2018-06-27 Thread Vincent Lefoulon


Change by Vincent Lefoulon :


--
title: Display type of not JSON serializable object -> [Exception message] 
Display type of not JSON serializable object

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



[issue33979] Display type of not JSON serializable object

2018-06-27 Thread Vincent Lefoulon


New submission from Vincent Lefoulon :

When we call `json.dumps` on a non JSON serializable object, we obtain an error:

```
TypeError: 4 is not JSON serializable
```

Here, 4 was actually a `numpy.int64` object and not a native int. But it is not 
explicit in the error message. We should mention the type of the object as well:

```
TypeError: 4 of type numpy.int64 is not JSON serializable
```

--
messages: 320570
nosy: Vayel
priority: normal
severity: normal
status: open
title: Display type of not JSON serializable object
type: enhancement
versions: Python 3.5

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



Re: I'm getting a spamassassin party here

2018-06-26 Thread Vincent Vande Vyvre

Le 26/06/18 à 15:50, Gene Heskett a écrit :

On Tuesday 26 June 2018 02:50:01 Cameron Simpson wrote:


On 24Jun2018 17:03, Gene Heskett  wrote:

Greetings list;

Generally spamassassin only gets picky about this occasionally, but
for the past several hours its working overtime on python list
messages, with the major problem being the servers time stamp, a day
or more in the past. Anyboy ever hear of ntpd?
-- Cheers, Gene Heskett

Could you eyeball some of these problematic messages please?

I've been noticing a swathe of messages in the past few days with
From: headers like this:

   From: "Steven D'Aprano" 

where the From: has been badly mangled, I think by a usenet->list
gateway. The Path: on these messages looks like this (give or take):

   Path:
uni-berlin.de!fu-berlin.de!news.linkpendium.com!news.linkpendium.com!n
ews.snarked.org!news.bbs.nz!.POSTED.184-155-113-241.cpe.cableone.net!no
t-for-mail

I'd be interested to know if there is significant overlap between my
problematic messages and yours.

Cheers,
Cameron Simpson 

Stevens messages are among the most frequent spamassassin triggers. The
scoring diff that tips the scales is the time error:
  1.0 DATE_IN_PAST_12_24 Date: is 12 to 24 hours before Received: date

There is also this:
0.5 APOSTROPHE_FROMFrom address contains an apostrophe

This list commits a whole menu of errors that spamassassin doesn't like.

The whole list from a different message:

Content analysis details:   (5.6 points, 5.1 required)

  pts rule name  description
 -- --
  3.5 BAYES_99   BODY: Bayes spam probability is 99 to 100%
 [score: 1.]
  0.0 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail
 domains are different
  1.0 DATE_IN_PAST_12_24 Date: is 12 to 24 hours before Received: date
  0.2 BAYES_999  BODY: Bayes spam probability is 99.9 to 100%
 [score: 1.]
  0.8 RDNS_NONE  Delivered to internal network by a host with
no rDNS
  0.0 T_DKIM_INVALID DKIM-Signature header exists but is not valid

Some of these should be fixable by proper configuration of the
listserver, but don't confuse me with an expert. I am subscribed to the
list.


Same for me since yesterday.

Two examples:

The 2018-05-18 17:20
---
From: "Peter J. Holzer" 


--prnws536gtytpj5v
[ following the message ]

Same day, same hour but arrived today

From: "Peter J. Holzer" 

From: "Peter J. Holzer" 


--prnws536gtytpj5v
[ following the same message ]



Or again:
The 2018-06-23 18:46

From: Steven D'Aprano 

On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote:
[ following the message ]

Same day, same hour but arrived today

From: "Steven D'Aprano" 

From: Steven D'Aprano 

On Sat, 23 Jun 2018 06:26:22 -0400, Richard Damon wrote:
[ following the same message ]


I've re-received 22 old duplicated messages like this today.

Vincent
Send Tue, 26 Jun 2018 19:53:46 +0200

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


Re: Is it possible to call a class but without a new instance created?

2018-06-18 Thread Vincent Vande Vyvre

Le 18/06/18 à 06:48, Jach Fong a écrit :

After looking into the \tkiniter\font.py source file, triggered by Jim's
hint on my previous subject "Why an object changes its "address" between
adjacent calls?", I get more confused.

Below was quoted from the font.py:

def nametofont(name):
    """Given the name of a tk named font, returns a Font representation.
    """
    return Font(name=name, exists=True)

class Font:
    """Represents a named font.
    Constructor options are:
    ...
    exists -- does a named font by this name already exist?
   Creates a new named font if False, points to the existing font 
if True.

    ...
    """

    def __init__(self, root=None, font=None, name=None, exists=False,
 **options):
    ...
--
From my understanding, the __init__ method was called after the instance
was created, that's why the __init__ has a self parameter, right? Then,
how is it possible "...points to the existing font if True"? I didn't
see any clue in __init__ doing this.

I also make a test of my own and it fails too.

>>> class A:
... objs = []
... def __init__(self, exists=False):
... if exists:  self = self.objs[0]
... else:  self.objs.append(self)
...
>>> a0 = A()
>>> id(a0)
35569968
>>> a1 = A(exists=True)
>>> id(a1)
35572336

What I expect is that id(a0) and id(a1) has the same value. They 
should points to the same object.



Best Regards,
Jach Fong




---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus


Hi,


What you try to do is called a /singleton./

A classic example :

class Foo:
    _instance = None
    def __new__(cls, *args, **kwargs):
    if cls._instance is None:
    cls._instance = super(Foo, cls).__new__(cls, *args, **kwargs)
    return cls._instance

    def __init__(self, ...):

        ...


Vincent

Send at Mon, 18 Jun 2018 09:17:21 +0200

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


Obsolete method in the html module

2018-06-09 Thread Vincent Vande Vyvre

Not really important, just a comment.

In Python-3.7.0b5 we can find at the end of html/parser.py:

    def unescape(self, s):
    warnings.warn('The unescape method is deprecated and will be 
removed '

  'in 3.5, use html.unescape() instead.',
  DeprecationWarning, stacklevel=2)
    return unescape(s)

Vincent

(send at 08:07 GMT)

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


  1   2   3   4   5   6   7   8   >