[issue46709] test_urllib: testInterruptCaught() has a race condition and fails randomly

2022-02-10 Thread Nikita Sobolev


Nikita Sobolev  added the comment:

Other tests are also affected:
- `./python.exe -m test -m 
unittest.test.test_break.TestBreakDefaultIntHandler.testSecondInterrupt 
test_unittest -F`
- `./python.exe -m test -m 
unittest.test.test_break.TestBreakDefaultIntHandler.testTwoResults 
test_unittest -F`
- `./python.exe -m test -m 
unittest.test.test_break.TestBreakDefaultIntHandler.testHandlerReplacedButCalled
 test_unittest -F`
- etc

I think that we need a universal solution, I am going to write a helper method 
and add it to all tests there.

--

___
Python tracker 

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



[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

Did you try to print a traceback of the exception?

--
nosy: +serhiy.storchaka

___
Python tracker 

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



[issue46709] test_urllib: testInterruptCaught() has a race condition and fails randomly

2022-02-10 Thread Nikita Sobolev


Nikita Sobolev  added the comment:

I think this might be a side effect of 
https://docs.python.org/3/library/signal.html#execution-of-python-signal-handlers

> A Python signal handler does not get executed inside the low-level (C) signal 
> handler. Instead, the low-level signal handler sets a flag which tells the 
> virtual machine to execute the corresponding Python signal handler at a later 
> point(for example at the next bytecode instruction). This has consequences

--

___
Python tracker 

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



[issue46709] test_urllib: testInterruptCaught() has a race condition and fails randomly

2022-02-10 Thread Nikita Sobolev


Nikita Sobolev  added the comment:

I am trying to debug this.

Several intersting notes:
1. `time.sleep()` does not help
2. It always fails on `8`th turn
3. Changing `self.assertTrue(result.shouldStop)` to

```
msg = f'{type(result)} {vars(result)}'
self.assertTrue(result.shouldStop, msg)
```

fixes the problem.

--
nosy: +sobolevn

___
Python tracker 

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



[issue45451] IDLE - modify text frame and widget borders

2022-02-10 Thread Ashlyn Woods


Ashlyn Woods  added the comment:

In addition, I would encourage that people in future try to get a bigger gauge 
of how many people actually want a feature like this, how many don't, and then 
make a decision about whether to put it in- considering that there have been a 
fair few cases where people have clearly reacted negatively to this, maybe you 
should have checked if people'd dislike it before rolling it out w/o any easy 
way of undoing it.

--

___
Python tracker 

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



[issue45451] IDLE - modify text frame and widget borders

2022-02-10 Thread Ashleigh Woods


Ashleigh Woods  added the comment:

At a minimum, I think that there should be a toggle for whether this should be 
present or not, without having to dig in and change the values in IDLE (with, 
I'd like to note, absolutely no clue where to do that!). This is particularly 
an issue for beginners.

It'd also be nice to control the color scheme/size etc, but I can understand if 
that's more complicated.

--
nosy: +pulsiedulsie

___
Python tracker 

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



[issue46705] Memory optimization for set.issubset

2022-02-10 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

> Would not testing len(self.difference(other)) == 0 
> be more efficient?

Yes, I think so.

--
Added file: https://bugs.python.org/file50620/instrument_issubset.py

___
Python tracker 

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



[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread Dennis Sweeney


Dennis Sweeney  added the comment:

I reproduced as far back as Python 3.6 with this:

---
import gc

exc = Exception()
deltas = []

for i in range(2, 15):
ref1 = len(gc.get_objects())
for j in range(2**i):
try:
raise exc
except Exception:
pass
ref2 = len(gc.get_objects())
deltas.append(ref2 - ref1)

print(deltas)
# [4, 8, 16, 9, 64, 128, 256, 512, 1024, 2048, 4072, 8192, 16384]
---


Note that the memory does get freed up once the exception is deleted:

---
import gc

deltas = []

for i in range(2, 15):
ref1 = len(gc.get_objects())

exc = Exception()
for j in range(2**i):
try:
raise exc
except Exception:
pass
del exc  # <<<

ref2 = len(gc.get_objects())
deltas.append(ref2 - ref1)

print(deltas)
# [0, 0, 0, 0, 0, -14, 0, 0, 0, 0, -14, 0, 0]
---

--
nosy: +Dennis Sweeney, iritkatriel

___
Python tracker 

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



Re: How do you log in your projects?

2022-02-10 Thread Martin Di Paola

? Logs are not intended to be read by end users. Logs are primarily
used to understand what the code is doing in a production environment.
They could also be used to gather metrics data.

Why should you log to give a message instead of simply using a print?


You are assuming that logs and prints are different but they aren't. It 
is the same technology: some string formatted in a particular way sent 
to some place (console or file generally).


But using the logging machinery instead a plain print() you win a few 
features like thread safety and log levels (think in an user that wants 
to increase the verbose level of the output)


When communicating with an user, the logs that are intended to him/her 
can be sent to the console (like a print) in addition to a file.


For user's perspective, they look just like a print.


Why? Traceback is vital to understand what and where the problem is. I
think you're confusing logs with messages. The stack trace can be
logged (I would say must), but the end user generally sees a vague
message with some hints, unless the program is used internally only.


Yes, that's exactly why the traceback is hidden by default because the 
user don't care about it. If the error is due something that the user 
did wrong, then the message should say that and, if possible, add 
a suggestion of how to do it.


For example "The file 'foo.md' was not found." is quite descriptive. If 
you add to that message a traceback, that will just clutter the console.


Tracebacks and other errors and warnings must be logged in a file.  
I totally agree with that. Specially true when we are talking with 
server-like software.


Tracebacks can be printed to the user if a more verbose output is 
enabled. In that case you could even pretty print the traceback with 
syntax highlighting.


I guess that this should be discussed case by case. May be you are 
thinking more in a case where you have a service running and logging and 
I am more thinking in a program that a human executes by hand.


What info and how is presented to the user changes quite a bit.

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

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


[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread Ethan Furman


Change by Ethan Furman :


--
nosy: +ethan.furman

___
Python tracker 

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



[issue46717] Raising exception multiple times leaks memory

2022-02-10 Thread George Gensure


New submission from George Gensure :

Instantiating an exception and raising it multiple times causes 1 frame and 2 
traceback objects to remain allocated for each raise. The attached example 
causes python to consume 8GB of ram after a few seconds of execution on 
Windows/Linux.

--
components: Interpreter Core
files: exc.py
messages: 413035
nosy: ggensure
priority: normal
severity: normal
status: open
title: Raising exception multiple times leaks memory
type: resource usage
versions: Python 3.11
Added file: https://bugs.python.org/file50619/exc.py

___
Python tracker 

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



[issue46400] Please update bundled libexpat to 2.4.4 with security fixes (CVE-2021-45960)

2022-02-10 Thread STINNER Victor


Change by STINNER Victor :


--
title: Please update bundled libexpat to 2.4.4 with security fixes -> Please 
update bundled libexpat to 2.4.4 with security fixes (CVE-2021-45960)

___
Python tracker 

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



Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-10 Thread Dennis Lee Bieber
On Thu, 10 Feb 2022 21:39:05 +0100, Christian Gollwitzer 
declaimed the following:


>Hence it is impossible to concurrently write from Python into an open 
>Excel file. One might ask what the real problem is the user is trying to 
>solve. Is Excel a requirement, can it be swapped by a database engine?
>

Based upon the path names shown by the OP, this is just a continuation
of the January thread...

Message-ID: <199c23c7-de58-44ae-a216-760c8f36c5...@googlegroups.com>
Subject: What to write or search on github to get the code for what is
written below:
From: NArshad 
Injection-Date: Thu, 06 Jan 2022 18:55:30 +

... in which the OP insists they are required to manipulate a (never fully
specified) spreadsheet maintained in an Excel format file. The main
take-away in the current thread is that the OP has relinquished the idea of
a web-based application, for a local Tkinter GUI (and apparently has
actually written some code finally, as they produced a traceback message
sequence  -- however, the code-first_then-come-here lesson isn't
sticking if you look at their second thread of the week).


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Abstraction level at which to create SQLAlchemy ORM object

2022-02-10 Thread Cameron Simpson
On 10Feb2022 14:14, Loris Bennett  wrote:
>I am writing a command line program which will modify entries in a
>database and am trying out SQLAlchemy.
>
>A typical command might look like
>
>  um --operation add --uid ada --gid coders --lang en
>
>Parsing the arguments I get, ignoring the operation, a dict
>
>  {uid: "ada", gid: "coders", lang: "en"}
>
>At some point this needs to be converted into an object of the class User:
>
>  class User(Base):
>  __tablename__ = "users"
>
>  uid = Column('uid', String, primary_key=True)
>  gid = Column('gid', String)
>  lang = Column('lang', String)
>
>In a way it seems it would be economical to do the conversion as early
>as possible, so I can just pass around User objects.  However, this
>would mean that the entry point for the program would already be tightly
>coupled to the specifics of the database interaction.
>
>On the other hand, delaying the conversion would mean probably having to
>define my own User class, which seems like unnecessary overhead.  It
>would have the advantage that I could ditch SQLAlchemy more easily if I
>find it too mind-bending.

If the entire persistent state of the user lives in the db I'd just 
define the User ORM type and give it whatever methods you need. So 
exactly what you've got above.

It is close to the db, but if you only interact via the methods and the 
core attributes/columns that should be mostly irrelevant to you.

If you're concerned about switching backends, maybe define an 
AbstractUser abstract class with the required methods. Then you can at 
least ensure method coverage if you make another backend:

class AbstractUser(ABC):
@abstractmethod
def some_user_method(self,...):


class SQLAUser(Base, AbstractUser):
... your SQLA ORM User class above ...

User = SQLAUser

... everything else just talks about user ...

But you can do all of that _later_, only needed if you decide to change 
backends in a controlled manner.

Cheers,
Cameron Simpson 
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue46246] importlib.metadata.DeprecatedList appears to be missing __slots__

2022-02-10 Thread miss-islington


miss-islington  added the comment:


New changeset 1124ab6d1d15dc5058e03b63fd1d95e6f1009cc3 by Miss Islington (bot) 
in branch '3.10':
bpo-46246: add missing __slots__ to importlib.metadata.DeprecatedList (GH-30452)
https://github.com/python/cpython/commit/1124ab6d1d15dc5058e03b63fd1d95e6f1009cc3


--

___
Python tracker 

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



[issue46716] regrtest didn't respect the timeout when running test_subprocess on AMD64 Windows11 3.x

2022-02-10 Thread Jeremy Kloth


Jeremy Kloth  added the comment:

The test only completed once I purposefully terminated the offending Python 
process.  The only identifying information I noticed was the command-line of 
`-c "while True: pass"`, indicating it was stuck in either
test_call_timeout() or test_timeout() in test_subprocess.py.

Something to note is that Windows does not, by default, have a concept of 
process trees whereas terminating a parent automatically kills the children.  
Eryk Sun may have additional ideas on how this desired behavior could be 
accomplished.

--
nosy: +eryksun, jkloth

___
Python tracker 

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



[issue46246] importlib.metadata.DeprecatedList appears to be missing __slots__

2022-02-10 Thread miss-islington


Change by miss-islington :


--
pull_requests: +29433
pull_request: https://github.com/python/cpython/pull/31269

___
Python tracker 

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



[issue46246] importlib.metadata.DeprecatedList appears to be missing __slots__

2022-02-10 Thread miss-islington


miss-islington  added the comment:


New changeset dd76b3f7d332dd6eced5cbc2ad2adfc397700b3d by Arie Bovenberg in 
branch 'main':
bpo-46246: add missing __slots__ to importlib.metadata.DeprecatedList (GH-30452)
https://github.com/python/cpython/commit/dd76b3f7d332dd6eced5cbc2ad2adfc397700b3d


--
nosy: +miss-islington

___
Python tracker 

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



[issue46246] importlib.metadata.DeprecatedList appears to be missing __slots__

2022-02-10 Thread Jason R. Coombs


Jason R. Coombs  added the comment:

I'm pretty sure both EntryPoints and DeprecatedList were introduced in Python 
3.10, so 3.9 and 3.8 aren't relevant.

--
versions:  -Python 3.8, Python 3.9

___
Python tracker 

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



[issue46705] Memory optimization for set.issubset

2022-02-10 Thread Jack Nguyen


Change by Jack Nguyen :


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

___
Python tracker 

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



[issue46705] Memory optimization for set.issubset

2022-02-10 Thread Jack Nguyen


Jack Nguyen  added the comment:

As you say, which implementation performs better likely depends on the nature 
of the sets. I would suspect that using set.difference won't be substantially 
faster than using set.intersection in the best case, but it would be much 
slower if len(self) is much larger than len(self.intersection(other)) e.g. 
set(range(1_000_000)).issubset(range(10)). Overall I think that using 
set.intersection will have more well-rounded performance.

--

___
Python tracker 

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



[issue36876] [subinterpreters] Global C variables are a problem

2022-02-10 Thread Eric Snow


Eric Snow  added the comment:


New changeset 80e4f262aa27a39abf3fadc19a6323fea4607a8f by Eric Snow in branch 
'main':
bpo-36876: Make sure the c-analyzer is checking all the source files.' 
(gh-31264)
https://github.com/python/cpython/commit/80e4f262aa27a39abf3fadc19a6323fea4607a8f


--

___
Python tracker 

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



[issue46716] regrtest didn't respect the timeout when running test_subprocess on AMD64 Windows11 3.x

2022-02-10 Thread STINNER Victor


Change by STINNER Victor :


--
title: regrtest didn't respect the timeout on AMD64 Windows11 3.x -> regrtest 
didn't respect the timeout when running test_subprocess on AMD64 Windows11 3.x

___
Python tracker 

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



[issue46716] regrtest didn't respect the timeout on AMD64 Windows11 3.x

2022-02-10 Thread STINNER Victor

New submission from STINNER Victor :

regrtest was run with --timeout 900 on AMD64 Windows11 3.x: timeout confirmed 
by "(timeout: 15 min, worker timeout: 20 min)" log. But then test_subprocss was 
only stopped after "4 hour 55 min".

If the regrtest main process is able to display an update 2x per minutes (every 
30 sec), it should be able to stop the test worker process (test_subprocess) 
after 20 minutes. How is it possible that the process took so long?

There are multiple guards:

* (1) in the worker process: _runtest() calls 
faulthandler.dump_traceback_later(ns.timeout, exit=True)
* (2) libregrtest/runtest_mp.py: TestWorkerProcess._run_process() thread uses 
popen.communicate(timeout=self.timeout)
* (3) faulthandler.dump_traceback_later(MAIN_PROCESS_TIMEOUT, exit=True): kill 
the parent process if it is blocked for longer than 5 minutes

Guards (1) and (2) didn't work.

Maybe the parent process should implement a 4th guard using the 20 minute 
timeout: almost 5 hours is way longer than 20 minutes!


C:\buildbot\3.x.kloth-win11\build>"C:\buildbot\3.x.kloth-win11\build\PCbuild\amd64\python_d.exe"
  -u -Wd -E -bb -m test  -uall -rwW --slowest --timeout 1200 --fail-env-changed 
-j1 -j2 --junit-xml test-results.xml -j40 --timeout 900
== CPython 3.11.0a5+ (main, Feb 10 2022, 04:03:24) [MSC v.1930 64 bit (AMD64)]
== Windows-10-10.0.22000-SP0 little-endian
== cwd: C:\buildbot\3.x.kloth-win11\build\build\test_python_5732�
== CPU count: 32
== encodings: locale=cp1252, FS=utf-8
Using random seed 6320493
0:00:00 Run tests in parallel using 40 child processes (timeout: 15 min, worker 
timeout: 20 min)
(...)
0:03:13 load avg: 0.76 [431/432] test_multiprocessing_spawn passed (3 min 13 
sec) -- running: test_subprocess (3 min 11 sec)
0:03:43 load avg: 0.46 running: test_subprocess (3 min 41 sec)
(...)
4:53:17 load avg: 0.00 running: test_subprocess (4 hour 53 min)
4:53:47 load avg: 0.00 running: test_subprocess (4 hour 53 min)
4:54:17 load avg: 0.09 running: test_subprocess (4 hour 54 min)
4:54:47 load avg: 0.35 running: test_subprocess (4 hour 54 min)
4:55:17 load avg: 0.48 running: test_subprocess (4 hour 55 min)
4:55:46 load avg: 0.50 [432/432/1] test_subprocess timed out (4 hour 55 min) (4 
hour 55 min)

== Tests result: FAILURE ==

397 tests OK.

10 slowest tests:
- test_subprocess: 4 hour 55 min
- test_multiprocessing_spawn: 3 min 13 sec
- test_concurrent_futures: 2 min 46 sec
- test_peg_generator: 2 min 32 sec
- test_compileall: 1 min 34 sec
- test_unparse: 1 min 31 sec
- test_distutils: 1 min 23 sec
- test_asyncio: 1 min 22 sec
- test_tokenize: 1 min 8 sec
- test_io: 1 min 5 sec

1 test failed:
test_subprocess

--
components: Tests
messages: 413028
nosy: vstinner
priority: normal
severity: normal
status: open
title: regrtest didn't respect the timeout on AMD64 Windows11 3.x
versions: Python 3.11

___
Python tracker 

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



[issue44953] Add vectorcall on operator.itemgetter and attrgetter objects

2022-02-10 Thread Dennis Sweeney


Dennis Sweeney  added the comment:


New changeset 035414a878a772d1d293cdecdc4470bcce5e5d7a by Dennis Sweeney in 
branch 'main':
bpo-44953: Add newline at end of NEWS entry (GH-31265)
https://github.com/python/cpython/commit/035414a878a772d1d293cdecdc4470bcce5e5d7a


--

___
Python tracker 

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



Re: How to solve the given problem?

2022-02-10 Thread Avi Gross via Python-list
Anyone think someone keeps asking homework questions? This seems absolutely 
unrelated to earlier discussions from this person. Jobs often tend to remain 
focused.
I opt out after frustration with earlier exchanges with NArshad about library 
books and EXCEL ...


-Original Message-
From: NArshad 
To: python-list@python.org
Sent: Thu, Feb 10, 2022 1:40 am
Subject: How to solve the given problem?


Assume that there is a pattern of feeding for a special fish in a day (10 hours 
a day) as below:
                              150    100    30    30    30    20    20    10    
5    5
Today, the fish is fed in the second hour 60 unit instead of 100 unit 
Accidently. Implement some methods to distribute the remaining 40 unit in the 
rest of the day and propose the new patterns. Try to keep the distribution 
similar to the current feeding pattern. 
Note: pay attention that the total feeding amounts should be fix in a day.
-- 
https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list



On 10/02/2022 21:43, Friedrich Rentsch wrote:
I believe to have observed a difference which also might be worth 
noting: the imbedded function a() (second example) has access to all 
of the imbedding function's variables, which might be an efficiency 
factor with lots of variables. The access is read-only, though. If the 
inner function writes to one of the readable external variables, that 
variable becomes local to the inner function.
You can make it continue to refer to the variables of the imbedding 
function, i.e. b(), by declaring them non-local, e.g.

    nonlocal c
Rob Cliffe



Frederic

On 2/10/22 1:13 PM, BlindAnagram wrote:
Is there any difference in performance between these two program 
layouts:


   def a():
 ...
   def(b):
 c = a(b)

or

   def(b):
 def a():
   ...
 c = a(b)

I would appreciate any insights on which layout to choose in which 
circumstances.






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


[issue44953] Add vectorcall on operator.itemgetter and attrgetter objects

2022-02-10 Thread Dennis Sweeney


Change by Dennis Sweeney :


--
pull_requests: +29431
pull_request: https://github.com/python/cpython/pull/31265

___
Python tracker 

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



[issue46713] Provide a C implementation of collections.abc.KeysView and friends

2022-02-10 Thread Alex Waygood


Change by Alex Waygood :


--
nosy: +rhettinger
type:  -> performance
versions: +Python 3.11

___
Python tracker 

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



Re: C API PyObject_Call segfaults with string

2022-02-10 Thread Jen Kris via Python-list
Thank you for that suggestion.  It allowed me to replace six lines of code with 
one.  :)


Feb 10, 2022, 12:43 by pyt...@mrabarnett.plus.com:

> On 2022-02-10 20:00, Jen Kris via Python-list wrote:
>
>> With the help of PyErr_Print() I have it solved.  Here is the final code 
>> (the part relevant to sents):
>>
>>     Py_ssize_t listIndex = 0;
>>     pListItem = PyList_GetItem(pFileIds, listIndex);
>>     pListStrE = PyUnicode_AsEncodedString(pListItem, "UTF-8", "strict");
>>     pListStr = PyBytes_AS_STRING(pListStrE); // Borrowed pointer
>>
>>     // Then:  sentences = gutenberg.sents(fileid) - this is a sequence item
>>     PyObject *c_args = Py_BuildValue("s", pListStr);
>>     PyObject *args_tuple = PyTuple_New(1);
>>     PyTuple_SetItem(args_tuple, 0, c_args);
>>
>>     pSents = PyObject_CallObject(pSentMod, args_tuple);
>>
>>     if ( pSents == 0x0){
>>     PyErr_Print();
>>     return return_value; }
>>
>> As you mentioned yesterday, CallObject needs a tuple, so that was the 
>> problem.  Now it works.
>>
>> You also asked why I don't just use pListStrE.  I tried that and got a long 
>> error message from PyErr_Print.  I'm not far enough along in my C_API work 
>> to understand why, but it doesn't work.
>>
>> Thanks very much for your help on this.
>>
> You're encoding a Unicode string to a UTF-8 bytestring:
>
>  pListStrE = PyUnicode_AsEncodedString(pListItem, "UTF-8", "strict");
>
> then pointing to the bytes of that UTF-8 bytestring:
>
>  pListStr = PyBytes_AS_STRING(pListStrE); // Borrowed pointer
>
> then making a Unicode string from those UTF-8 bytes:
>
>  PyObject *c_args = Py_BuildValue("s", pListStr);
>
> You might was well just use the original Unicode string!
>
> Try this instead:
>
>  Py_ssize_t listIndex = 0;
>  pListItem = PyList_GetItem(pFileIds, listIndex);
>  //> pListItem?
>
>  pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem, 0);
>  //> pSents+?
>
>  if (pSents == 0x0){
>  PyErr_Print();
>  return return_value;
>  }
>
>>
>>
>> Feb 9, 2022, 17:40 by songofaca...@gmail.com:
>>
>>> On Thu, Feb 10, 2022 at 10:37 AM Jen Kris  wrote:
>>>

 I'm using Python 3.8 so I tried your second choice:

 pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem);

 but pSents is 0x0.  pSentMod and pListItem are valid pointers.

>>>
>>> It means exception happened.
>>> If you are writing Python/C function, return NULL (e.g. `if (pSents ==
>>> NULL) return NULL`)
>>> Then Python show the exception and traceback for you.
>>>
> -- 
> https://mail.python.org/mailman/listinfo/python-list
>

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


[issue36876] [subinterpreters] Global C variables are a problem

2022-02-10 Thread Eric Snow


Change by Eric Snow :


--
pull_requests: +29430
pull_request: https://github.com/python/cpython/pull/31264

___
Python tracker 

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



[issue44953] Add vectorcall on operator.itemgetter and attrgetter objects

2022-02-10 Thread Dennis Sweeney


Dennis Sweeney  added the comment:


New changeset 0a145069e807fdafd1fa0315b9bc22da363d2d39 by Dennis Sweeney in 
branch 'main':
bpo-44953: Add vectorcall for itemgetter and attrgetter instances (GH-27828)
https://github.com/python/cpython/commit/0a145069e807fdafd1fa0315b9bc22da363d2d39


--

___
Python tracker 

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



Re: How to solve the given problem?

2022-02-10 Thread Marco Sulla
Narshad, I propose you post your questions to StackOverflow. I'm sure
they will be very happy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global VS Local Subroutines

2022-02-10 Thread Marco Sulla
I agree with Chris. I don't know if it was already written: if you
want a local function for speed reasons, you can use the classic
approach of a main function.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do you log in your projects?

2022-02-10 Thread Marco Sulla
On Wed, 9 Feb 2022 at 20:40, Martin Di Paola  wrote:
>
> If the logs are meant to be read by my users I log high level messages,
> specially before parts that can take a while (like the classic
> "Loading...").

? Logs are not intended to be read by end users. Logs are primarily
used to understand what the code is doing in a production environment.
They could also be used to gather metrics data.

Why should you log to give a message instead of simply using a print?

> For exceptions I print the message but not the traceback.

Why? Traceback is vital to understand what and where the problem is. I
think you're confusing logs with messages. The stack trace can be
logged (I would say must), but the end user generally sees a vague
message with some hints, unless the program is used internally only.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global VS Local Subroutines

2022-02-10 Thread Friedrich Rentsch
I believe to have observed a difference which also might be worth 
noting: the imbedded function a() (second example) has access to all of 
the imbedding function's variables, which might be an efficiency factor 
with lots of variables. The access is read-only, though. If the inner 
function writes to one of the readable external variables, that variable 
becomes local to the inner function.


Frederic

On 2/10/22 1:13 PM, BlindAnagram wrote:

Is there any difference in performance between these two program layouts:

   def a():
 ...
   def(b):
 c = a(b)

or

   def(b):
 def a():
   ...
 c = a(b)

I would appreciate any insights on which layout to choose in which 
circumstances.




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


[issue46715] asyncio.create_unix_server has an off-by-one error concerning the backlog parameter

2022-02-10 Thread John Snow


New submission from John Snow :

Hi, asyncio.create_unix_server appears to treat the "backlog" parameter as 
where 0 means that *no connection will ever possibly be pending*, which (at the 
very least for UNIX sockets on my machine) is untrue.

Consider a (non-asyncio) server:

```python
import os, socket, sys, time

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind('test.sock')

sock.listen(backlog=0)

while True:
print('.', end='', file=sys.stderr)
time.sleep(1)
```

This server never calls accept(), and uses a backlog of zero. However, a client 
can actually still successfully call connect against such a server:

```python
import os, socket, time

sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setblocking(False)

sock.connect('test.sock')
print("Connected!")
```

When run against the server example, the first invocation of this client will 
actually connect successfully (Surprising, but that's how the C syscalls work 
too, so... alright) but the second invocation of this client will raise 
BlockingIOError (EAGAIN).

Further, if we amend the first server example to actually call accept(), it 
will succeed when the first client connects -- demonstrating that the actual 
total queue length here was actually effectively 1, not 0.

(i.e. there's always room for at least one connection to be considered, and the 
backlog counts everybody else.)

However, in asyncio.BaseSelectorEventLoop._accept_connection(...), the code 
uses `for _ in range(backlog)` to determine the maximum number of accept calls 
to make. When backlog is set to zero, this means we will *never* call accept, 
even when there are pending connections.

Note that when backlog=1, this actually allows for *two* pending connections 
before clients are rejected, but this loop will only fire once. This behavior 
is surprising, because backlog==0 means we'll accept no clients, but backlog==1 
means we will allow for two to enqueue before accepting both. There is 
seemingly no way with asyncio to actually specify "Exactly one pending 
connection".

I think this loop should be amended to reflect the actual truth of the backlog 
parameter, and it should iterate over `backlog + 1`. This does necessitate a 
change to `Lib/test/test_asyncio/test_selector_events.py` which believes that 
backlog=100 means that accept() should be called 100 times (instead of 101.)

A (very) simple fix is attached here; if it seems sound, I can spin a real PR 
on GitHub.

--
components: asyncio
files: issue.patch
keywords: patch
messages: 413025
nosy: asvetlov, jnsnow, yselivanov
priority: normal
severity: normal
status: open
title: asyncio.create_unix_server has an off-by-one error concerning the 
backlog parameter
type: behavior
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file50618/issue.patch

___
Python tracker 

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



Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-10 Thread Chris Angelico
On Fri, 11 Feb 2022 at 07:57, Christian Gollwitzer  wrote:
>
> Am 10.02.22 um 20:43 schrieb Chris Angelico:
> > On Fri, 11 Feb 2022 at 06:41, Dennis Lee Bieber  
> > wrote:
> >>  While not tested with Excel, I /have/ encountered cases where an
> >> application has locked the file for writing, but multiple readers are
> >> permitted. Those would fail then if one attempts to write. {The other view
> >> point is a library that does a complete open/read\write-all/close to memory
> >> -- such an application might open/read/close, then Excel opens/locks, with
> >> the application only learning of the change when it attempts the
> >> open/write/close cycle}
> >>
> >
> > Yeah, I doubt Excel is that sophisticated. It's built on an assumption
> > of single-user operation.
> >
>
> It guards against multiple user opening the same file over network
> drives. All MS applications create lock files with weird names like
> ~.original-name.xlsx etc. If you open a file on the network share, and a
> colleague tries to open it from a second machine, then he will get the
> message "File locked by user xy from machine z". See here for word:
> https://support.microsoft.com/en-us/topic/-the-document-is-locked-for-editing-by-another-user-error-message-when-you-try-to-open-a-document-in-word-10b92aeb-2e23-25e0-9110-370af6edb638
>

Yeah, but that's still just hard locking, no "one writer multiple
readers" system or anything.

> I believe (haven't tested) that this is cooperative locking only and it
> doesn't help if you alter the file from another program. On the same
> machine though, I think that Excel opens the file with a flag to lock it
> from other processes. At least that was my observation and also what the
> OP has described.
>

That sounds right; and, again, it's just a simple exclusive lock.
Excel doesn't have the sophistication to need or want anything more
than simple "I have this file, nobody else touch it" exclusive
locking.

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


Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-10 Thread Christian Gollwitzer

Am 10.02.22 um 20:43 schrieb Chris Angelico:

On Fri, 11 Feb 2022 at 06:41, Dennis Lee Bieber  wrote:

 While not tested with Excel, I /have/ encountered cases where an
application has locked the file for writing, but multiple readers are
permitted. Those would fail then if one attempts to write. {The other view
point is a library that does a complete open/read\write-all/close to memory
-- such an application might open/read/close, then Excel opens/locks, with
the application only learning of the change when it attempts the
open/write/close cycle}



Yeah, I doubt Excel is that sophisticated. It's built on an assumption
of single-user operation.



It guards against multiple user opening the same file over network 
drives. All MS applications create lock files with weird names like 
~.original-name.xlsx etc. If you open a file on the network share, and a 
colleague tries to open it from a second machine, then he will get the 
message "File locked by user xy from machine z". See here for word: 
https://support.microsoft.com/en-us/topic/-the-document-is-locked-for-editing-by-another-user-error-message-when-you-try-to-open-a-document-in-word-10b92aeb-2e23-25e0-9110-370af6edb638


I believe (haven't tested) that this is cooperative locking only and it 
doesn't help if you alter the file from another program. On the same 
machine though, I think that Excel opens the file with a flag to lock it 
from other processes. At least that was my observation and also what the 
OP has described.


Hence it is impossible to concurrently write from Python into an open 
Excel file. One might ask what the real problem is the user is trying to 
solve. Is Excel a requirement, can it be swapped by a database engine?


Best regards,

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


[issue46714] Python 3.10 - Users (except from the one who installed) not able to see python in add remove programs.

2022-02-10 Thread Steve Dower


Steve Dower  added the comment:

Thanks. This is being tracked in issue25166, and is waiting on a fix from our 
installer toolset, who have previously indicated that they're not interested in 
fixing it, but wouldn't rule it out in their next major version.

--
resolution:  -> duplicate
stage:  -> resolved
status: open -> closed
superseder:  -> Windows All Users installation places uninstaller in user 
profile

___
Python tracker 

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



[issue38119] resource tracker destroys shared memory segments when other processes should still have valid access

2022-02-10 Thread Géry

Change by Géry :


--
nosy: +maggyero

___
Python tracker 

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



Re: C API PyObject_Call segfaults with string

2022-02-10 Thread MRAB

On 2022-02-10 20:00, Jen Kris via Python-list wrote:

With the help of PyErr_Print() I have it solved.  Here is the final code (the 
part relevant to sents):

    Py_ssize_t listIndex = 0;
    pListItem = PyList_GetItem(pFileIds, listIndex);
    pListStrE = PyUnicode_AsEncodedString(pListItem, "UTF-8", "strict");
    pListStr = PyBytes_AS_STRING(pListStrE); // Borrowed pointer

    // Then:  sentences = gutenberg.sents(fileid) - this is a sequence item
    PyObject *c_args = Py_BuildValue("s", pListStr);
    PyObject *args_tuple = PyTuple_New(1);
    PyTuple_SetItem(args_tuple, 0, c_args);

    pSents = PyObject_CallObject(pSentMod, args_tuple);

    if ( pSents == 0x0){
    PyErr_Print();
    return return_value; }

As you mentioned yesterday, CallObject needs a tuple, so that was the problem.  
Now it works.

You also asked why I don't just use pListStrE.  I tried that and got a long 
error message from PyErr_Print.  I'm not far enough along in my C_API work to 
understand why, but it doesn't work.

Thanks very much for your help on this.


You're encoding a Unicode string to a UTF-8 bytestring:

pListStrE = PyUnicode_AsEncodedString(pListItem, "UTF-8", "strict");

then pointing to the bytes of that UTF-8 bytestring:

pListStr = PyBytes_AS_STRING(pListStrE); // Borrowed pointer

then making a Unicode string from those UTF-8 bytes:

PyObject *c_args = Py_BuildValue("s", pListStr);

You might was well just use the original Unicode string!

Try this instead:

   Py_ssize_t listIndex = 0;
   pListItem = PyList_GetItem(pFileIds, listIndex);
   //> pListItem?

   pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem, 0);
   //> pSents+?

   if (pSents == 0x0){
   PyErr_Print();
   return return_value;
   }




Feb 9, 2022, 17:40 by songofaca...@gmail.com:


On Thu, Feb 10, 2022 at 10:37 AM Jen Kris  wrote:



I'm using Python 3.8 so I tried your second choice:

pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem);

but pSents is 0x0.  pSentMod and pListItem are valid pointers.



It means exception happened.
If you are writing Python/C function, return NULL (e.g. `if (pSents ==
NULL) return NULL`)
Then Python show the exception and traceback for you.


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


[issue45670] New .mapping attribute is broken for some existing uses of dict views

2022-02-10 Thread Joshua Bronson


Joshua Bronson  added the comment:

Thank you for confirming that ChainMap.__iter__() would be in the same boat as 
bidict if a similar .mapping attribute were ever added to dict_keyiterators. 
The specifics of this issue are interesting, but even more interesting to me is 
whatever learnings we can generalize from this.


After testing that the performance impact would be significant, I created the 
feature request you suggested in https://bugs.python.org/issue46713. Thanks for 
suggesting that.


In the meantime, I've updated the relevant docstrings:

>>> help(b.keys)
keys() -> KeysView[~KT] method of bidict.bidict instance
A set-like object providing a view on the contained keys.

When *b._fwdm* is a :class:`dict`, *b.keys()* returns a
*dict_keys* object that behaves exactly the same as
*collections.abc.KeysView(b)*, except for

  - offering better performance

  - being reversible on Python 3.8+

  - having a .mapping attribute in Python 3.10+
that exposes a mappingproxy to *b._fwdm*.

>>> help(b.values)
values() -> bidict.BidictKeysView[~VT] method of bidict.bidict instance
A set-like object providing a view on the contained values.

Since the values of a bidict are equivalent to the keys of its inverse,
this method returns a set-like object for this bidict's values
rather than just a collections.abc.ValuesView.
This object supports set operations like union and difference,
and constant- rather than linear-time containment checks,
and is no more expensive to provide than the less capable
collections.abc.ValuesView would be.

See :meth:`keys` for more information.

etc.


Regarding:
> The values() call unexpectedly returns an instance of dict_keys(). At first, 
> I was surprised that this got past the type checker -- you can do set 
> operations with KeysView but not with a ValuesView.

Check out https://github.com/jab/bidict/blob/82f931/bidict/_base.py#L38-L45:

```
class BidictKeysView(t.KeysView[KT], t.ValuesView[KT]):
"""Since the keys of a bidict are the values of its inverse (and vice 
versa),
the ValuesView result of calling *bi.values()* is also a KeysView of 
*bi.inverse*.
"""


dict_keys: t.Type[t.KeysView[t.Any]] = type({}.keys())
BidictKeysView.register(dict_keys)
```

See also https://github.com/python/typeshed/issues/4435 for a request that 
typeshed use a Protocol (structural typing) here.


Thanks again for taking the time to look at my code and discuss so generously.

--

___
Python tracker 

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



[issue46714] Python 3.10 - Users (except from the one who installed) not able to see python in add remove programs.

2022-02-10 Thread richd


New submission from richd :

Experiencing the same issue as reported in https://bugs.python.org/issue31011

When Python is deployed using an enterprise solution, Python is not displayed 
in Programs and Features.

Examples:
1. Using PSExec as System to install Python 3.10.x, logged in users will not 
see Python installed. The Python launcher does appear however.

2. Deployment of Python through SCCM has the same behavior, where logged in 
users do not see the installed Python version in Programs and Features.

--
components: Windows
messages: 413022
nosy: paul.moore, richd, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Python 3.10 - Users (except from the one who installed) not able to see 
python in add remove programs.
type: behavior
versions: Python 3.10

___
Python tracker 

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



Re: C API PyObject_Call segfaults with string

2022-02-10 Thread Jen Kris via Python-list
Hi and thanks very much for your comments on reference counting.  Since I'm new 
to the C_API that will help a lot.  I know that reference counting is one of 
the difficult issues with the C API.  

I just posted a reply to Inada Naoki showing how I solved the problem I posted 
yesterday.  

Thanks much for your help.

Jen


Feb 9, 2022, 18:43 by pyt...@mrabarnett.plus.com:

> On 2022-02-10 01:37, Jen Kris via Python-list wrote:
>
>> I'm using Python 3.8 so I tried your second choice:
>>
>> pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem);
>>
>> but pSents is 0x0.  pSentMod and pListItem are valid pointers.
>>
> 'PyObject_CallFunction' looks like a good one to use:
>
> """PyObject* PyObject_CallFunction(PyObject *callable, const char *format, 
> ...)
>
> Call a callable Python object callable, with a variable number of C 
> arguments. The C arguments are described using a Py_BuildValue() style format 
> string. The format can be NULL, indicating that no arguments are provided.
> """
>
> [snip]
>
> What I do is add comments to keep track of what objects I have references to 
> at each point and whether they are new references or could be NULL.
>
> For example:
>
>  pName = PyUnicode_FromString("nltk.corpus");
>  //> pName+?
>
> This means that 'pName' contains a reference, '+' means that it's a new 
> reference, and '?' means that it could be NULL (usually due to an exception, 
> but not always) so I need to check it.
>
> Continuing in this vein:
>
>  pModule = PyImport_Import(pName);
>  //> pName+? pModule+?
>
>  pSubMod = PyObject_GetAttrString(pModule, "gutenberg");
>  //> pName+? pModule+? pSubMod+?
>  pFidMod = PyObject_GetAttrString(pSubMod, "fileids");
>  //> pName+? pModule+? pSubMod+? pFidMod+?
>  pSentMod = PyObject_GetAttrString(pSubMod, "sents");
>  //> pName+? pModule+? pSubMod+? pFidMod+? pSentMod+?
>
>  pFileIds = PyObject_CallObject(pFidMod, 0);
>  //> pName+? pModule+? pSubMod+? pFidMod+? pSentMod+? PyObject_CallObject+?
>  pListItem = PyList_GetItem(pFileIds, listIndex);
>  //> pName+? pModule+? pSubMod+? pFidMod+? pSentMod+? PyObject_CallObject+? 
> pListItem?
>  pListStrE = PyUnicode_AsEncodedString(pListItem, "UTF-8", "strict");
>  //> pName+? pModule+? pSubMod+? pFidMod+? pSentMod+? PyObject_CallObject+? 
> pListItem? pListStrE+?
>
> As you can see, there's a lot of leaked references building up.
>
> Note how after:
>
>  pListItem = PyList_GetItem(pFileIds, listIndex);
>
> the addition is:
>
>  //> pListItem?
>
> This means that 'pListItem' contains a borrowed (not new) reference, but 
> could be NULL.
>
> I find it easiest to DECREF as soon as I no longer need the reference and 
> remove a name from the list as soon I no longer need it (and DECREFed where).
>
> For example:
>
>  pName = PyUnicode_FromString("nltk.corpus");
>  //> pName+?
>  if (!pName)
>  goto error;
>  //> pName+
>  pModule = PyImport_Import(pName);
>  //> pName+ pModule+?
>  Py_DECREF(pName);
>  //> pModule+?
>  if (!pModule)
>  goto error;
>  //> pModule+
>
> I find that doing this greatly reduces the chances of getting the reference 
> counting wrong, and I can remove the comments once I've finished the function 
> I'm writing.
> -- 
> https://mail.python.org/mailman/listinfo/python-list
>

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


Re: C API PyObject_Call segfaults with string

2022-02-10 Thread Jen Kris via Python-list
With the help of PyErr_Print() I have it solved.  Here is the final code (the 
part relevant to sents):

   Py_ssize_t listIndex = 0;
   pListItem = PyList_GetItem(pFileIds, listIndex);
   pListStrE = PyUnicode_AsEncodedString(pListItem, "UTF-8", "strict");
   pListStr = PyBytes_AS_STRING(pListStrE); // Borrowed pointer

   // Then:  sentences = gutenberg.sents(fileid) - this is a sequence item
   PyObject *c_args = Py_BuildValue("s", pListStr);
   PyObject *args_tuple = PyTuple_New(1);
   PyTuple_SetItem(args_tuple, 0, c_args);

   pSents = PyObject_CallObject(pSentMod, args_tuple);

   if ( pSents == 0x0){
   PyErr_Print();
   return return_value; }

As you mentioned yesterday, CallObject needs a tuple, so that was the problem.  
Now it works.  

You also asked why I don't just use pListStrE.  I tried that and got a long 
error message from PyErr_Print.  I'm not far enough along in my C_API work to 
understand why, but it doesn't work.  

Thanks very much for your help on this.  

Jen


Feb 9, 2022, 17:40 by songofaca...@gmail.com:

> On Thu, Feb 10, 2022 at 10:37 AM Jen Kris  wrote:
>
>>
>> I'm using Python 3.8 so I tried your second choice:
>>
>> pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem);
>>
>> but pSents is 0x0.  pSentMod and pListItem are valid pointers.
>>
>
> It means exception happened.
> If you are writing Python/C function, return NULL (e.g. `if (pSents ==
> NULL) return NULL`)
> Then Python show the exception and traceback for you.
>
> -- 
> Inada Naoki  
>

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


[issue13305] datetime.strftime("%Y") not consistent for years < 1000

2022-02-10 Thread Jason R. Coombs


Jason R. Coombs  added the comment:

The tempora library implements a [portable 
strftime](https://tempora.readthedocs.io/en/latest/index.html#tempora.strftime).

--

___
Python tracker 

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



Re: How to solve the given problem?

2022-02-10 Thread Dennis Lee Bieber
On Wed, 9 Feb 2022 22:40:48 -0800 (PST), NArshad 
declaimed the following:

>
>Assume that there is a pattern of feeding for a special fish in a day (10 
>hours a day) as below:
>   150100303030202010  
>   55
>Today, the fish is fed in the second hour 60 unit instead of 100 unit 
>Accidently. Implement some methods to distribute the remaining 40 unit in the 
>rest of the day and propose the new patterns. Try to keep the distribution 
>similar to the current feeding pattern. 
>Note: pay attention that the total feeding amounts should be fix in a day.

This is very obviously phrased as a homework problem. WE DO NOT DO
HOMEWORK!

Write some Python code, present the code, your input data, and the
output it produced along with an example of the output you expected, and we
may be able to point out what parts of Python you made a mistake with. If
we get ambitious we might even correct an algorithm, not just explain
errors in the usage of Python.

I'm going a tad too far but...

HINT:
You need to compute the percentage of remaining scheduled units each
takes, then apply those percentages to the left-over from the mis-feed.

NONE of this has anything to do with Python itself -- it is purely
algorithm development that applies with any programming language -- or even
none.


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-10 Thread Chris Angelico
On Fri, 11 Feb 2022 at 06:41, Dennis Lee Bieber  wrote:
>
> On Wed, 9 Feb 2022 18:50:12 +, MRAB 
> declaimed the following:
>
> >On 2022-02-09 12:45, Christian Gollwitzer wrote:
>
> >> It's impossible. Excel locks the file deliberately when it is open, so
> >> that you can't overwrite it from a different program. Otherwise, the
> >> file could become inconsistent.
> >>
> >It's the same the other way too; you can't open the file in Excel while
> >Python has it open.
> >
> While not tested with Excel, I /have/ encountered cases where an
> application has locked the file for writing, but multiple readers are
> permitted. Those would fail then if one attempts to write. {The other view
> point is a library that does a complete open/read\write-all/close to memory
> -- such an application might open/read/close, then Excel opens/locks, with
> the application only learning of the change when it attempts the
> open/write/close cycle}
>

Yeah, I doubt Excel is that sophisticated. It's built on an assumption
of single-user operation.

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


Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-10 Thread Dennis Lee Bieber
On Wed, 9 Feb 2022 18:50:12 +, MRAB 
declaimed the following:

>On 2022-02-09 12:45, Christian Gollwitzer wrote:

>> It's impossible. Excel locks the file deliberately when it is open, so
>> that you can't overwrite it from a different program. Otherwise, the
>> file could become inconsistent.
>> 
>It's the same the other way too; you can't open the file in Excel while 
>Python has it open.
>
While not tested with Excel, I /have/ encountered cases where an
application has locked the file for writing, but multiple readers are
permitted. Those would fail then if one attempts to write. {The other view
point is a library that does a complete open/read\write-all/close to memory
-- such an application might open/read/close, then Excel opens/locks, with
the application only learning of the change when it attempts the
open/write/close cycle}


-- 
Wulfraed Dennis Lee Bieber AF6VN
wlfr...@ix.netcom.comhttp://wlfraed.microdiversity.freeddns.org/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Global VS Local Subroutines

2022-02-10 Thread Eryk Sun
On 2/10/22, BlindAnagram  wrote:
>
> This is exactly what I felt too but I then wondered if the code was
> recreated dynamically or was static with just a reference being created
> on each invocation of the parent.  The overhead in this case would be
> negligible. But then I thought 'what about the context for the inner
> function invocation' - maybe its not as simple as this!  Oh dear, I need
> to understand Python's internals.

The bytecode for a() is a constant in b(). But the function object
itself isn't cached. Each time b() is called, a new function object
a() has to be created, with its defaults, keyword-only defaults, and
closure. The more complicated the latter are, the more work is
involved. Generally, however, the time to create a() will be an
insignificant fraction of the execution time of b(). If the latter
isn't the case, the cost only accumulates to something significant if
b() is called in a tight loop for an extended period.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue46713] Provide a C implementation of collections.abc.KeysView and friends

2022-02-10 Thread Joshua Bronson

New submission from Joshua Bronson :

As suggested by @rhettinger in https://bugs.python.org/msg409443, I'm creating 
a feature request for C implementations of collections.abc.KeysView, 
ValuesView, and ItemsView.

Because these do not currently benefit from C speedups, they're a lot slower 
than their dict_keys, dict_values, and dict_items counterparts. As a result, 
libraries that implement custom Mapping types that are backed by dicts are 
incentivized to override the implementations of keys(), values(), and items() 
they inherit from collections.abc.Mapping to instead return their backing 
dicts' mapping views, causing a potential abstraction leak.

An example can be found in https://github.com/jab/bidict, which implements 
bidirectional mapping types that wrap a forward and an inverse dict which are 
kept in sync with one another.

>>> from bidict import *
>>> bi = bidict({1: 'one', 2: 'two'})
>>> bi.items()  # Overridden for performance:
dict_items([(1, 'one'), (2, 'two')])

Ditto for OrderedBidict:

>>> OrderedBidict(bi).keys()
_OrderedBidictItemsView(OrderedBidict([(1, 'one'), (2, 'two')]))


(The _OrderedBidictItemsView is a custom view whose __iter__ uses the 
implementation inherited by its collections.abc.ItemsView base class so that 
the correct order is respected, but proxies other method calls through to the 
backing dict's dict_items object: 
https://github.com/jab/bidict/blob/2ab42a/bidict/_orderedbidict.py#L90-L150)


Here is a microbenchmark of calling __eq__ on an _OrderedBidictItemsView vs. a 
collections.abc.ItemsView, to estimate the performance impact (using Python 
3.10):

❯ set setup '
from collections.abc import ItemsView
from bidict import OrderedBidict
d = dict(zip(range(), range()))
ob = OrderedBidict(d)'

❯ python -m pyperf timeit -s $setup 'ob.items() == d.items()' -o 1.json

❯ python -m pyperf timeit -s $setup 'ItemsView(ob) == d.items()' -o 2.json

❯ pyperf compare_to 2.json 1.json
Mean +- std dev: [2] 4.21 ms +- 1.10 ms -> [1] 168 us +- 6 us: 25.13x faster


This demonstrates a potentially significant speedup. Similar microbenchmarks 
for ItemsView vs. dict_items, as well as KeysView vs. both dict_keys and 
_OrderedBidictKeysView, also indicate similarly significant potential.

Note that the performance benefits of this may propagate to other code as well. 
For example, bidicts' __eq__ methods are implemented in terms of their 
itemsviews (see 
https://github.com/jab/bidict/blob/2ab42a/bidict/_base.py#L285-L286), so 
speeding up bidict.items().__eq__ speeds up bidict.__eq__ commensurately.

--
messages: 413020
nosy: jab
priority: normal
severity: normal
status: open
title: Provide a C implementation of collections.abc.KeysView and friends

___
Python tracker 

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



[issue33017] Special set-cookie setting will bypass Cookielib

2022-02-10 Thread Adrian Chaves


Adrian Chaves  added the comment:

So, PoC shows how an empty domain attribute (Domain=) is erroneously turned 
into a dot (.).

I want to add that a dot (Domain=.) should be turned into an empty string (the 
specification asks to remove a leading dot if found).

--
nosy: +adrian2

___
Python tracker 

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



Re: GCP Copy Files - Data Export

2022-02-10 Thread MRAB

On 2022-02-10 17:20, BmoreIT wrote:

I did a data export from Google to export all company data - Google Data Export

It shows the root folder and to download, I run this command (it automatically 
enters this command)

gsutil -m cp -r \ "gs://takeout-export-myUniqueID" \.
But I have no idea where it would save it being I am not a GCP customer, only 
Google Workspace. Workspace won't help because they say it's a GCP product but 
I am exporting from Workspace.

Can someone let me know the proper command to run on my local machine with 
Google's SDK to download this folder? I was able to start the download 
yesterday but it said there was an invalid character in the file names so it 
killed the export.

Appreciate any help!


On this page:

https://cloud.google.com/storage/docs/gsutil/commands/cp

I think the problem might be that you have an surplus backslash.

Does this work?

gsutil cp -r gs://takeout-export-myUniqueID .

This should copy recursively from gs://takeout-export-myUniqueID to the 
current folder.

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


[Python-announce] ANN: poliastro 0.16.2 released 

2022-02-10 Thread Juan Luis Cano Rodríguez
Hi all,

It fills us with astronomical joy to announce the release of poliastro
0.16.2! 

(Yes, we skipped 0.16.1 because of unimportant infrastructure problems)

poliastro is an open source (MIT) pure Python library for interactive
Astrodynamics and Orbital Mechanics, with a focus on ease of use, speed,
and quick visualization. It provides a simple and intuitive API, and
handles physical quantities with units. It is used in academia and the
industry by people from all around the world.

You can install it using pip or conda:

pip install poliastro
conda install poliastro --channel conda-forge

This release adds support for Python 3.10, fixes some bugs found after
0.16.0, adds a new example to read OMM and TLE data, and restructures
the API documentation to make it more useful. You can read the full
release notes here:

https://docs.poliastro.space/en/v0.16.2/changelog.html#poliastro-0-16-2-
2022-02-10

If you want to learn more about poliastro, don't miss my talk on the
Open Source Cubesat Workshop held at the European Space Operations
Centre in 2017:

https://youtu.be/KnoYzqAw_vM?t=1h36m14s

And feel welcome to join our chat on Matrix to ask any questions you
might have:

http://chat.poliastro.space

Per Python ad astra!

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


[issue46323] Use _PyObject_Vectorcall in Modules/_ctypes/callbacks.c

2022-02-10 Thread hydroflask


hydroflask  added the comment:

Thanks again everyone, very much appreciated.

--

___
Python tracker 

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



Re: Global VS Local Subroutines

2022-02-10 Thread BlindAnagram

On 10/02/2022 16:52, Rob Cliffe wrote:



On 10/02/2022 12:13, BlindAnagram wrote:

Is there any difference in performance between these two program layouts:

   def a():
 ...
   def(b):
 c = a(b)

or

   def(b):
 def a():
   ...
 c = a(b)

I would appreciate any insights on which layout to choose in which 
circumstances.


The way to answer questions about performance is not to guess (often 
difficult or impossible), but to measure.  Profiling tools are available 
to see where a program spends how much of its time.  But a simpler 
approach might be to try to run the guts of your program 1000 or 100 
times, and find how long it takes with each layout (not with a stopwatch 
 but getting the program to record the start time, end time and the 
difference).

That said, I will venture a guess (or at least, an observation):
     def a():
         ...


Thanks for the suggestion, Rob. I considered doing this but it would 
take quite a bit of careful work to be sure of obtaining meaningful 
results so I felt it better to ask the question here in case there was 
an quick answer on performance before doing the hard work.


is executable code.  It creates the function `a` which did not exist 
before (or creates the new version if it did).  This takes a certain 
amount of time.  In your 2nd layout, this overhead occurs every time b() 
is called.  So I would *guess* that this would be slower.  Of course it 
depends on how many times b() is called and probably on lots of other 
things.


This is exactly what I felt too but I then wondered if the code was 
recreated dynamically or was static with just a reference being created 
on each invocation of the parent.  The overhead in this case would be 
negligible. But then I thought 'what about the context for the inner 
function invocation' - maybe its not as simple as this!  Oh dear, I need 
to understand Python's internals.


At which point I asked the question!

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


GCP Copy Files - Data Export

2022-02-10 Thread BmoreIT
I did a data export from Google to export all company data - Google Data Export

It shows the root folder and to download, I run this command (it automatically 
enters this command)

gsutil -m cp -r \ "gs://takeout-export-myUniqueID" \.
But I have no idea where it would save it being I am not a GCP customer, only 
Google Workspace. Workspace won't help because they say it's a GCP product but 
I am exporting from Workspace. 

Can someone let me know the proper command to run on my local machine with 
Google's SDK to download this folder? I was able to start the download 
yesterday but it said there was an invalid character in the file names so it 
killed the export.

Appreciate any help!
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue45923] Improve performance of sys.settracing based tools.

2022-02-10 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset d7a5aca982def155a9255893cefcc1493c127c9c by Brandt Bucher in 
branch 'main':
bpo-45923: Add `RESUME_QUICK` (GH-31244)
https://github.com/python/cpython/commit/d7a5aca982def155a9255893cefcc1493c127c9c


--

___
Python tracker 

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



Python LSTM forecast future values for time series

2022-02-10 Thread Jorge Conforte


HI,


I'm starting run the LSTM to forecast future values for time serie data.

please can someone give me some information on how i can predict future 
values ​​for my time series using LSTM. Thanks, Conrado


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


[issue46066] Deprecate keyword args syntax for TypedDict definition

2022-02-10 Thread Alex Waygood

Alex Waygood  added the comment:

@Guido, OP already has — Jelle and I have both reviewed and approved it :)

--

___
Python tracker 

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



[issue46066] Deprecate keyword args syntax for TypedDict definition

2022-02-10 Thread Guido van Rossum


Guido van Rossum  added the comment:

"PR"

--

___
Python tracker 

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



[issue13305] datetime.strftime("%Y") not consistent for years < 1000

2022-02-10 Thread Chris Larson


Chris Larson  added the comment:

Has there been any work/progress on this? Alternatively, what suggested work 
around/mitigations are suggested?

--
nosy: +cklarson

___
Python tracker 

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



[issue46066] Deprecate keyword args syntax for TypedDict definition

2022-02-10 Thread Guido van Rossum


Guido van Rossum  added the comment:

Go ahead and send a or to deprecate it.--
--Guido (mobile)

--

___
Python tracker 

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



Re: Global VS Local Subroutines

2022-02-10 Thread Chris Angelico
On Fri, 11 Feb 2022 at 03:57, Rob Cliffe via Python-list
 wrote:
> But of course, performance is not the only consideration, as per Chris
> Angelico's answer.

Yep. In fact, I'd say that performance is the least significant
consideration here; do what makes sense. The time difference will be
negligible.

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


Re: Global VS Local Subroutines

2022-02-10 Thread Rob Cliffe via Python-list



On 10/02/2022 12:13, BlindAnagram wrote:

Is there any difference in performance between these two program layouts:

   def a():
 ...
   def(b):
 c = a(b)

or

   def(b):
 def a():
   ...
 c = a(b)

I would appreciate any insights on which layout to choose in which 
circumstances.


The way to answer questions about performance is not to guess (often 
difficult or impossible), but to measure.  Profiling tools are available 
to see where a program spends how much of its time.  But a simpler 
approach might be to try to run the guts of your program 1000 or 100 
times, and find how long it takes with each layout (not with a stopwatch 
 but getting the program to record the start time, end time and the 
difference).

That said, I will venture a guess (or at least, an observation):
    def a():
        ...
is executable code.  It creates the function `a` which did not exist 
before (or creates the new version if it did).  This takes a certain 
amount of time.  In your 2nd layout, this overhead occurs every time b() 
is called.  So I would *guess* that this would be slower.  Of course it 
depends on how many times b() is called and probably on lots of other 
things.


But of course, performance is not the only consideration, as per Chris 
Angelico's answer.

Best wishes
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to solve the given problem?

2022-02-10 Thread Christian Gollwitzer

Am 10.02.22 um 11:26 schrieb NArshad:

-ChrisA:
You don't reply if you have problems.
When I don't find any solution elsewhere then only I place in this group


-Christian:
One problem of different type requires the same elaboration.


No it doesn't


Q. What technique of statistics or numerical computation or general mathematics 
to use to solve this problem. Can you tell one example

Find the values of 푥subscript(푖) for i from 1 to n (n =100).



WTF? Go study maths yourself instead of asking here (Offf-topic as well)

Christian

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


Re: Global VS Local Subroutines

2022-02-10 Thread BlindAnagram

On 10/02/2022 15:20, Chris Angelico wrote:

On Fri, 11 Feb 2022 at 02:13, BlindAnagram  wrote:


Is there any difference in performance between these two program layouts:

 def a():
   ...
 def(b):
   c = a(b)

or

 def(b):
   def a():
 ...
   c = a(b)

I would appreciate any insights on which layout to choose in which
circumstances.



Great question! The difference is that, in the second case, a() isn't
available anywhere else. So the real question is: Is that good or bad?

Does it make sense to call a() from outside of your second function,
even for testing? If so, maybe name it _a() so it's private, but keep
it global. Does a() need a lot of information from the context of your
second function? If so, it's easier to have a closure, with one
function inside another.

Both styles make sense, and your question is well put: it's a design
decision with no "right" or "wrong", just different choices with
different implications.

ChrisA


Thanks Chris, I thought it  was mostly a design choice but I wasn't sure 
whether there would be any significant performance issues.


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


[issue46433] _PyType_GetModuleByDef optimization is incorrect

2022-02-10 Thread Petr Viktorin


Petr Viktorin  added the comment:

Just 3.10, after all. 3.9 doesn't have the function yet.

I did the backport, but I'd welcome a review by a fresh set of eyes!

--
versions:  -Python 3.9

___
Python tracker 

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



Re: Multiple inheritance using super() in parent classes

2022-02-10 Thread Peter Otten

On 10/02/2022 09:20, Igor Basko wrote:

Hi everyone,
This is my first question here. Hope to get some clarification.
Basically this question is about multiple inheritance and the usage of
super().__init__ in parent
classes.

So I have two classes that inherit from the same base class.
For example class B and class C inherit from A:
class A:
   def __init__(self, arg1):
 pass

class B(A):
   def __init__(self, arg2):
 super().__init__(arg2)

class C(A):
   def __init__(self, arg1, arg2):
 super().__init__(arg2)

Now I would like to create a new class D that inherits from B and C.
One note, D is the only class that I am "allowed" to change. A, B and C are
provided to me as is from an external package.
class D(B, C):
   def __init__(self):
 B.__init__(self, 'arg1')
 C.__init__(self, 'arg1', 'arg2')

When I initialize D I get a TypeError.
TypeError: __init__() missing 1 required positional argument: 'arg2'
I get it from the invocation of super().__init__(arg2) inside the B class.

As I understand it, the super() inside B tries to call the __init__ of
class C,
because of the multiple inheritance and the MRO that is constructed.
But when B was implemented it wasn't aware of C and I assume,
B shouldn't be aware of C in any case.


Even when you call the initializers explicitly you pass self, and that's
probably where the MRO is taken from. You can tweak that MRO by changing
the order of the parent classes:

class D(C, B): ...

However, this will call B.__init__() twice; therefore I'd stick to super():

class D(C, B):
def __init__(self):
super().__init__("arg1", "arg2")


It gives me the feeling that I'm trying to implement some bad practice
here, but I'm not sure why.


I have the feeling that your feeling is right ;)


I would also like to hear your suggestions if there is a way to circumvent
it. Maybe by the approach described here:
https://rhettinger.wordpress.com/2011/05/26/super-considered-super/
wrapping B and C in some Adapter class.


A quick glance at that page suggests that the adapter translates the
base class into an attribute -- which is what I would have suggested,
too. Using has-a instead of is-a relations is generally something to
consider seriously before jumping into multiple inheritance. The details
may depend on the actual use case which is hidden behind your A, B, C,
and D abstraction...

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


[issue46433] _PyType_GetModuleByDef optimization is incorrect

2022-02-10 Thread Petr Viktorin


Change by Petr Viktorin :


--
pull_requests: +29429
stage: backport needed -> patch review
pull_request: https://github.com/python/cpython/pull/31262

___
Python tracker 

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



[issue46586] In documentation contents enum.property erroneously links to built-in property

2022-02-10 Thread Éric Araujo

Éric Araujo  added the comment:

Thinking about it again: The issue is that these tables (for sys.float_info and 
other named tuples / structseqs) use the const role, which is not meant to 
identify attributes but to link to them (similar to func, mod, data, etc).  In 
other words we are fixing an issue that a wrong target is used, but we should 
not be linking for a target at all, this is the target.  So if we can’t use the 
equivalent of directives function, module, etc (that define the targets of 
func, mod, etc), then maybe they should be just ``name``, not :role:`name`.

--

___
Python tracker 

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



[issue46586] In documentation contents enum.property erroneously links to built-in property

2022-02-10 Thread Zachary Ware


Zachary Ware  added the comment:

An updated reST linting check was added between the time you created the PR and 
your last update.  As Jelle noted on the PR, there doesn't need to be a NEWS 
entry for this anyway.

We might have an issue there if sphinx-lint is going to have an issue with no 
trailing newline and blurb-it isn't going to add a trailing newline, though. 
(+mdk)

--
nosy: +mdk, zach.ware

___
Python tracker 

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



Re: How to solve the given problem?

2022-02-10 Thread Chris Angelico
On Fri, 11 Feb 2022 at 02:15, NArshad  wrote:
>
> -ChrisA:
> You don't reply if you have problems.
> When I don't find any solution elsewhere then only I place in this group
>

You're a help vampire. Stop it.

https://slash7.com/2006/12/22/vampires/

Go do some actual research instead of asking people to do your homework.

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


[issue46586] In documentation contents enum.property erroneously links to built-in property

2022-02-10 Thread Meer Suri


Meer Suri  added the comment:

Can someone guide me on why I'm getting a no-new-line at end of file error for 
the NEWS entry when I didnt change this file in the last commit and it passed 
the Azure checks earlier

Error: [1] 
../Misc/NEWS.d/next/Documentation/2022-02-08-15-38-16.bpo-46586.6qVFVL.rst:0: 
No newline at end of file (no-newline-at-end-of-file). Do I need to manually 
add the new line?

--

___
Python tracker 

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



Re: Global VS Local Subroutines

2022-02-10 Thread Chris Angelico
On Fri, 11 Feb 2022 at 02:13, BlindAnagram  wrote:
>
> Is there any difference in performance between these two program layouts:
>
> def a():
>   ...
> def(b):
>   c = a(b)
>
> or
>
> def(b):
>   def a():
> ...
>   c = a(b)
>
> I would appreciate any insights on which layout to choose in which
> circumstances.
>

Great question! The difference is that, in the second case, a() isn't
available anywhere else. So the real question is: Is that good or bad?

Does it make sense to call a() from outside of your second function,
even for testing? If so, maybe name it _a() so it's private, but keep
it global. Does a() need a lot of information from the context of your
second function? If so, it's easier to have a closure, with one
function inside another.

Both styles make sense, and your question is well put: it's a design
decision with no "right" or "wrong", just different choices with
different implications.

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


[issue46586] In documentation contents enum.property erroneously links to built-in property

2022-02-10 Thread Jelle Zijlstra

Jelle Zijlstra  added the comment:

> How do I find other instances of this problem? Is there a systematic way to 
> look for such references?

You could write a script that goes something like this, iterating over all the 
docs RST files:

- Find all definitions in the file (e.g. `.. decorator:: property`)
- Filter to those that have names that also appear in builtins
- Find any links using those names within the same file

That would catch the enum.property case, but not the float_info one Éric 
noticed, because sys.rst doesn't define `max` at all. To catch that one, you 
could look at the link role: sys.rst links to it with :const:`max`, but 
functions.rst defines it as `.. function:: max`. Mismatches like that could be 
another clue that something is wrong (but there are some legitimate reasons why 
the roles won't match perfectly, like "decorator" in the definition vs. "func" 
in the link).

--
nosy: +Jelle Zijlstra

___
Python tracker 

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



Abstraction level at which to create SQLAlchemy ORM object

2022-02-10 Thread Loris Bennett
Hi,

I am writing a command line program which will modify entries in a
database and am trying out SQLAlchemy.

A typical command might look like

  um --operation add --uid ada --gid coders --lang en

Parsing the arguments I get, ignoring the operation, a dict

  {uid: "ada", gid: "coders", lang: "en"}

At some point this needs to be converted into an object of the class User:

  class User(Base):
  __tablename__ = "users"

  uid = Column('uid', String, primary_key=True)
  gid = Column('gid', String)
  lang = Column('lang', String)

In a way it seems it would be economical to do the conversion as early
as possible, so I can just pass around User objects.  However, this
would mean that the entry point for the program would already be tightly
coupled to the specifics of the database interaction.  

On the other hand, delaying the conversion would mean probably having to
define my own User class, which seems like unnecessary overhead.  It
would have the advantage that I could ditch SQLAlchemy more easily if I
find it too mind-bending.

WDYT?

Cheers,

Loris

-- 
This signature is currently under construction.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to solve the given problem?

2022-02-10 Thread NArshad
-ChrisA:
You don't reply if you have problems.
When I don't find any solution elsewhere then only I place in this group 


-Christian:
One problem of different type requires the same elaboration.

Q. What technique of statistics or numerical computation or general mathematics 
to use to solve this problem. Can you tell one example.

Find the values of 푥subscript(푖) for i from 1 to n (n =100).

푥subscript(1) + 푥subscript(2) = 3,

푥subscript(푖+1) − 푥subscript(푖+2) = 1, 푓표푟 푖 = 1, … , 푛 − 2

푥subscript(n-1) + 푥subscript(n) = 3




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


Global VS Local Subroutines

2022-02-10 Thread BlindAnagram

Is there any difference in performance between these two program layouts:

   def a():
 ...
   def(b):
 c = a(b)

or

   def(b):
 def a():
   ...
 c = a(b)

I would appreciate any insights on which layout to choose in which 
circumstances.


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


Multiple inheritance using super() in parent classes

2022-02-10 Thread Igor Basko
Hi everyone,
This is my first question here. Hope to get some clarification.
Basically this question is about multiple inheritance and the usage of
super().__init__ in parent
classes.

So I have two classes that inherit from the same base class.
For example class B and class C inherit from A:
class A:
  def __init__(self, arg1):
pass

class B(A):
  def __init__(self, arg2):
super().__init__(arg2)

class C(A):
  def __init__(self, arg1, arg2):
super().__init__(arg2)

Now I would like to create a new class D that inherits from B and C.
One note, D is the only class that I am "allowed" to change. A, B and C are
provided to me as is from an external package.
class D(B, C):
  def __init__(self):
B.__init__(self, 'arg1')
C.__init__(self, 'arg1', 'arg2')

When I initialize D I get a TypeError.
TypeError: __init__() missing 1 required positional argument: 'arg2'
I get it from the invocation of super().__init__(arg2) inside the B class.

As I understand it, the super() inside B tries to call the __init__ of
class C,
because of the multiple inheritance and the MRO that is constructed.
But when B was implemented it wasn't aware of C and I assume,
B shouldn't be aware of C in any case.

It gives me the feeling that I'm trying to implement some bad practice
here, but I'm not sure why.

I would also like to hear your suggestions if there is a way to circumvent
it. Maybe by the approach described here:
https://rhettinger.wordpress.com/2011/05/26/super-considered-super/
wrapping B and C in some Adapter class.

Thanks for reading and any help.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue46586] In documentation contents enum.property erroneously links to built-in property

2022-02-10 Thread Meer Suri


Meer Suri  added the comment:

It took me some time to figure out how to prevent the creation of a 
reference/hyperlink using the ! prefix. I've made the change to remove the 
references to the max and min attributes of sys.float_info and pushed.

How do I find other instances of this problem? Is there a systematic way to 
look for such references?

--

___
Python tracker 

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



[issue46541] Replace _Py_IDENTIFIER() with statically initialized objects.

2022-02-10 Thread Kumar Aditya


Change by Kumar Aditya :


--
pull_requests: +29428
pull_request: https://github.com/python/cpython/pull/31261

___
Python tracker 

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



[issue46710] Install launcher for all users on the domain

2022-02-10 Thread Marcus Fillipe Groetares Rocha Siqueira


Marcus Fillipe Groetares Rocha Siqueira  added the 
comment:

Thanks Steve, it worked.
Hava a nice day :)

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

___
Python tracker 

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



[issue46712] Share global string identifiers in deepfreeze

2022-02-10 Thread Kumar Aditya


Change by Kumar Aditya :


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

___
Python tracker 

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



[issue46712] Share global string identifiers in deepfreeze

2022-02-10 Thread Kumar Aditya


Kumar Aditya  added the comment:

I have refactored generate_global_objects.py, and now instead of hard-coding 
every identifier manually, it now scans *.c files extracts the identifiers used 
in it and then generate the header file. This has multiple advantages:

- No need to manually add identifiers, as soon as it is used in a c file it is 
added to the global identifiers struct.
- It simplifies the codegen a lot.
- Remove the need of special casing certain file for checking now it is just a 
set of identifiers and auto removes unused global strings.

--
nosy: +eric.snow

___
Python tracker 

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



[issue46430] intern strings in deepfrozen modules

2022-02-10 Thread Christian Heimes


Christian Heimes  added the comment:

Please leave the ticket open until we have an agreement how to handle the 
missing error checks.

--
resolution: fixed -> 
stage: resolved -> 
status: closed -> open
type:  -> behavior

___
Python tracker 

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



[issue46712] Share global string identifiers in deepfreeze

2022-02-10 Thread Kumar Aditya


New submission from Kumar Aditya :

Since bpo-46541, the global strings are statically allocated so they can now be 
referenced by deep-frozen modules just like any other singleton. Sharing 
identifiers with deepfreeze will reduce the duplicated strings hence it would 
save space.

See https://github.com/faster-cpython/ideas/issues/218
See https://github.com/faster-cpython/ideas/issues/230

--
messages: 413003
nosy: gvanrossum, kumaraditya303
priority: normal
severity: normal
status: open
title: Share global string identifiers in deepfreeze
versions: Python 3.11

___
Python tracker 

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



[issue46608] Exclude marshalled-frozen data if deep-freezing to save 300 KB space

2022-02-10 Thread Kumar Aditya


Change by Kumar Aditya :


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

___
Python tracker 

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



[issue46430] intern strings in deepfrozen modules

2022-02-10 Thread Kumar Aditya


Kumar Aditya  added the comment:

I consider this done so closing it as improving the error handling of interning 
it out of scope of this issue.

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

___
Python tracker 

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



[issue46681] gzip.compress does not forward compresslevel to zlib.compress

2022-02-10 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +lukasz.langa

___
Python tracker 

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



[issue46709] test_urllib: testInterruptCaught() has a race condition and fails randomly

2022-02-10 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

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



[issue46494] Mention typing_extensions in the typing documentation

2022-02-10 Thread Meer Suri


Change by Meer Suri :


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

___
Python tracker 

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



[issue46690] create_autospec() doesn't respect configure_mock style kwargs

2022-02-10 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

I guess the problem is that during the initial mock creation kwargs is passed 
so calling test_method immediately after mock creation raises ValueError. But 
as we loop through the attributes and create new child mock for the attributes 
the original configured mock for the method that raises ValueError is 
overridden by another object without the configuration info. Probably it makes 
sense to call configure_mock again after all children mock are constructed. 
Something like below works and I don't see any test failures in mock related 
test cases.

index 2719f74d6f..585e875c95 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -2637,6 +2637,7 @@ def create_autospec(spec, spec_set=False, instance=False, 
_parent=None,
f'[object={spec!r}]')
 is_async_func = _is_async_func(spec)
 _kwargs = {'spec': spec}
+original_kwargs = kwargs
 if spec_set:
 _kwargs = {'spec_set': spec}
 elif spec is None:
@@ -2740,6 +2741,9 @@ def create_autospec(spec, spec_set=False, instance=False, 
_parent=None,
 if isinstance(new, FunctionTypes):
 setattr(mock, entry, new)
 
+if _is_instance_mock(mock):
+mock.configure_mock(**original_kwargs)
+
 return mock

--
components: +Library (Lib) -Tests
nosy: +cjw296, lisroach, mariocj89, michael.foord

___
Python tracker 

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



[issue46711] test_logging: test_post_fork_child_no_deadlock() failed with timeout on AMD64 Arch Linux Asan Debug 3.10

2022-02-10 Thread STINNER Victor


New submission from STINNER Victor :

The test calls support.wait_process() which uses SHORT_TIMEOUT.

wait_process() should use LONG_TIMEOUT, or the ASAN buildbot should increase 
its timeout (regrtest --timeout parameter).

IMO using LONG_TIMEOUT is fine: it's ok if the test takes 2 minutes instead of 
1 second, it's only important that it completes :-) The test should not measure 
the *performance* of the code, only if the code is valid. When tests are run in 
parallel, the buildbot system load can be very high. In this case, the system 
load was 1.70:

0:35:49 load avg: 1.70 [255/421/1] test_logging failed (1 failure) (1 min 18 
sec)


AMD64 Arch Linux Asan Debug 3.10:
https://buildbot.python.org/all/#/builders/621/builds/466

==
FAIL: test_post_fork_child_no_deadlock (test.test_logging.HandlerTest)
Ensure child logging locks are not held; bpo-6721 & bpo-36533.
--
Traceback (most recent call last):
  File 
"/buildbot/buildarea/3.10.pablogsal-arch-x86_64.asan_debug/build/Lib/test/test_logging.py",
 line 750, in test_post_fork_child_no_deadlock
support.wait_process(pid, exitcode=0)
  File 
"/buildbot/buildarea/3.10.pablogsal-arch-x86_64.asan_debug/build/Lib/test/support/__init__.py",
 line 1971, in wait_process
raise AssertionError(f"process {pid} is still running "
AssertionError: process 406366 is still running after 52.5 seconds

--
components: Tests
messages: 413000
nosy: vstinner
priority: normal
severity: normal
status: open
title: test_logging: test_post_fork_child_no_deadlock() failed with timeout on 
AMD64 Arch Linux Asan Debug 3.10
versions: Python 3.10

___
Python tracker 

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



[issue46708] test_asyncio: test_sock_client_fail() changes asyncio.events._event_loop_policy

2022-02-10 Thread Andrew Svetlov


Change by Andrew Svetlov :


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

___
Python tracker 

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



[issue46708] test_asyncio: test_sock_client_fail() changes asyncio.events._event_loop_policy

2022-02-10 Thread STINNER Victor


STINNER Victor  added the comment:

With PR 31253 fix, I confirm that it fix my bug explained in msg412992.

commit 012e77eb5c3ba3d411f5967a7f368ebdb42ab88c
Author: Andrew Svetlov 
Date:   Thu Feb 10 14:57:20 2022 +0200

Fix warning: asyncio.events._event_loop_policy was modified by test_asyncio 
(GH-31253)

--

___
Python tracker 

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



[issue46072] Unify handling of stats in the CPython VM

2022-02-10 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +29425
pull_request: https://github.com/python/cpython/pull/31259

___
Python tracker 

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



[issue46708] test_asyncio: test_sock_client_fail() changes asyncio.events._event_loop_policy

2022-02-10 Thread Andrew Svetlov


Change by Andrew Svetlov :


--
versions: +Python 3.10, Python 3.9

___
Python tracker 

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



[issue46710] Install launcher for all users on the domain

2022-02-10 Thread Steve Dower


Steve Dower  added the comment:

This option may be disabled if you have already installed the launcher 
for only the current user. In this case, we aren't able to replace it 
with an all-users install.

Open Programs and Features and find the Python launcher, uninstall it, 
and then try again.

If it doesn't appear to be installed, you may have another issue. We'd 
need to see the log files created in %TEMP% when you run the installer 
(only up until the checkbox is shown, there should be enough information 
in the log files by then to see what's going on).

--

___
Python tracker 

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



  1   2   >