Re: A technique from a chatbot

2024-04-05 Thread Mark Bourne via Python-list

Stefan Ram wrote:

Mark Bourne  wrote or quoted:

I don't think there's a tuple being created.  If you mean:
 ( word for word in list_ if word[ 0 ]== 'e' )
...that's not creating a tuple.  It's a generator expression, which
generates the next value each time it's called for.  If you only ever
ask for the first item, it only generates that one.


   Yes, that's also how I understand it!

   In the meantime, I wrote code for a microbenchmark, shown below.

   This code, when executed on my computer, shows that the
   next+generator approach is a bit faster when compared with
   the procedural break approach. But when the order of the two
   approaches is being swapped in the loop, then it is shown to
   be a bit slower. So let's say, it takes about the same time.


There could be some caching going on, meaning whichever is done second 
comes out a bit faster.



   However, I also tested code with an early return (not shown below),
   and this was shown to be faster than both code using break and
   code using next+generator by a factor of about 1.6, even though
   the code with return has the "function call overhead"!


To be honest, that's how I'd probably write it - not because of any 
thought that it might be faster, but just that's it's clearer.  And if 
there's a `do_something_else()` that needs to be called regardless of 
the whether a word was found, split it into two functions:

```
def first_word_beginning_with_e(target, wordlist):
for w in wordlist:
if w.startswith(target):
return w
return ''

def find_word_and_do_something_else(target, wordlist):
result = first_word_beginning_with_e(target, wordlist)
do_something_else()
return result
```


   But please be aware that such results depend on the implementation
   and version of the Python implementation being used for the benchmark
   and also of the details of how exactly the benchmark is written.

import random
import string
import timeit

print( 'The following loop may need a few seconds or minutes, '
'so please bear with me.' )

time_using_break = 0
time_using_next = 0

for repetition in range( 100 ):
 for i in range( 100 ): # Yes, this nesting is redundant!

 list_ = \
 [ ''.join \
   ( random.choices \
 ( string.ascii_lowercase, k=random.randint( 1, 30 )))
   for i in range( random.randint( 0, 50 ))]

 start_time = timeit.default_timer()
 for word in list_:
 if word[ 0 ]== 'e':
 word_using_break = word
 break
 else:
 word_using_break = ''
 time_using_break += timeit.default_timer() - start_time

 start_time = timeit.default_timer()
 word_using_next = \
 next( ( word for word in list_ if word[ 0 ]== 'e' ), '' )
 time_using_next += timeit.default_timer() - start_time

 if word_using_next != word_using_break:
 raise Exception( 'word_using_next != word_using_break' )

print( f'{time_using_break = }' )
print( f'{time_using_next = }' )
print( f'{time_using_next / time_using_break = }' )


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


Re: A technique from a chatbot

2024-04-05 Thread Mark Bourne via Python-list

avi.e.gr...@gmail.com wrote:

That is an excellent point, Mark. Some of the proposed variants to the 
requested problem, including mine, do indeed find all instances only to return 
the first. This can use additional time and space but when done, some of the 
overhead is also gone. What I mean is that a generator you create and invoke 
once, generally sits around indefinitely in your session unless it leaves your 
current range or something. It does only a part of the work and must remain 
suspended and ready to be called again to do more.


It goes out of scope at the end of the function.  Unless you return it 
or store a reference to it elsewhere, it will then be deleted.


Or in this case, since the `first_word_beginning_with_e` function 
doesn't even have a local reference to the generator (it is just created 
and immediately passed as an argument to `next`), it goes out of scope 
once the `next` function returns.



If you create a generator inside a function and the function returns, 
presumably it can be garbage-collected.


Exactly.  It probably doesn't even need to wait for garbage collection - 
once the reference count is zero, it can be destroyed.



But if it is in the main body, I have to wonder what happen.


If you mean in the top-level module scope outside of any 
function/method, then it would remain in memory until the process exits.



There seem to be several related scenarios to consider.

- You may want to find, in our example, a first instance. Right afterwards, you 
want the generator to disassemble anything in use.
- You may want the generator to stick around and later be able to return the 
next instance. The generator can only really go away when another call has been 
made after the last available instance and it cannot look for more beyond some 
end.
- Finally, you can call a generator with the goal of getting all instances such 
as by asking it to populate a list. In such a case, you may not necessarily 
want or need to use a generator expression and can use something 
straightforward and possible cheaper.


Yes, so you create and assign it at an appropriate scope.  In the 
example here, it's just passed to `next` and then destroyed.  Passing a 
generator to the `list` constructor (or the `tuple` constructor in my 
"FWIW") would behave similarly - you'd get the final list/tuple back, 
but the generator would be destroyed once that call is done.  If you 
assigned it to a function-local variable, it would exist until the end 
of that function.



What confuses the issue, for me, is that you can make fairly complex 
calculations in python using various forms of generators that implement a sort 
of just-in-time approach as generators call other generators which call yet 
others and so on.


Yes, you can.  It can be quite useful when used appropriately.


Imagine having folders full of files that each contain a data structure such as 
a dictionary or set and writing functionality that searches for the first match 
for a key in any of the dictionaries (or sets or whatever) along the way? Now 
imagine that dictionary items can be a key value pair that can include the 
value being a deeper dictionary, perhaps down multiple levels.

You could get one generator that generates folder names or opens them and 
another that generates file names and reads in the data structure such as a 
dictionary and yet another that searches each dictionary and also any 
internally embedded dictionaries by calling another instance of the same 
generator as much as needed.


You probably could do that.  Personally, I probably wouldn't use 
generators for that, or at least not custom ones - if you're talking 
about iterating over directories and files on disk, I'd probably just 
use `os.walk` (which probably is a generator) and iterate over that, 
opening each file and doing whatever you want with the contents.



You can see how this creates and often consumes generators along the way as 
needed and in a sense does the minimum amount of work needed to find a first 
instance. But what might it leave open and taking up resources if not finished 
in a way that dismantles it?


You'd need to make sure any files are closed (`with open(...)` helps 
with that).  If you're opening files within a generator, I'm pretty sure 
you can do something like:

```
def iter_files(directory):
for filename in directory:
with open(filename) as f:
yield f
```

Then the file will be closed when the iterator leaves the `with` block 
and moved on to the next item (presumably there's some mechanism for the 
context manager's `__exit__` to be called if the generator is destroyed 
without having iterated over the items - the whole point of using `with` 
is that `__exit__` is guaranteed to be called whatever happens).


Other than that, the generators themselves would be destroyed once they 
go out of scope.  If there are no references to a generator left, 
nothing is going to be able to call `

Re: A technique from a chatbot

2024-04-04 Thread Mark Bourne via Python-list

Thomas Passin wrote:

On 4/2/2024 1:47 PM, Piergiorgio Sartor via Python-list wrote:

On 02/04/2024 19.18, Stefan Ram wrote:

   Some people can't believe it when I say that chatbots improve
   my programming productivity. So, here's a technique I learned
   from a chatbot!
   It is a structured "break". "Break" still is a kind of jump,
   you know?
   So, what's a function to return the first word beginning with
   an "e" in a given list, like for example
[ 'delta', 'epsilon', 'zeta', 'eta', 'theta' ]

   ? Well it's
def first_word_beginning_with_e( list_ ):
 for word in list_:
 if word[ 0 ]== 'e': return word

   . "return" still can be considered a kind of "goto" statement.
   It can lead to errors:

def first_word_beginning_with_e( list_ ):
 for word in list_:
 if word[ 0 ]== 'e': return word
 something_to_be_done_at_the_end_of_this_function()
   The call sometimes will not be executed here!
   So, "return" is similar to "break" in that regard.
   But in Python we can write:
def first_word_beginning_with_e( list_ ):
 return next( ( word for word in list_ if word[ 0 ]== 'e' ), None )


Doesn't look a smart advice.


   . No jumps anymore, yet the loop is aborted on the first hit


It's worse than "not a smart advice". This code constructs an 
unnecessary tuple, then picks out its first element and returns that.


I don't think there's a tuple being created.  If you mean:
( word for word in list_ if word[ 0 ]== 'e' )

...that's not creating a tuple.  It's a generator expression, which 
generates the next value each time it's called for.  If you only ever 
ask for the first item, it only generates that one.


When I first came across them, I did find it a bit odd that generator 
expressions look like the tuple equivalent of list/dictionary 
comprehensions.


FWIW, if you actually wanted a tuple from that expression, you'd need to 
pass the generator to tuple's constructor:

tuple(word for word in list_ if word[0] == 'e')
(You don't need to include an extra set of brackets when passing a 
generator a the only argument to a function).


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


Re: A missing iterator on itertools module?

2024-04-01 Thread Mark Bourne via Python-list

Stefan Ram wrote:

ast  wrote or quoted:

Why did you renamed itertools as _itertools ?


   Assume I have a module A.py:

import math
def f(): pass

   . Assume I have an additional module B.py:

import A

   . Now, when I'm editing "B.py" in IDLE and type "A.", IIRC
   IDLE will offer me two possible completions: "A.math" and
   "A.f". The "A.math" makes no sense to me.


`import math` imports the `math` module and binds it to `math` in the 
global namespace of the `A` module.  Since it doesn't have a leading 
underscore, by default it's considered to be a public attribute of the 
`A` module, and IDLE is offering all the public attributes of the `A` 
module for completion.



I want it to go
   away. Therefore, I rewrite A.py as:

import math as _math
def f(): pass

   . Now, Idle will only offer the completion "A.f".

   So, I sometimes use this "import math as _math" style. But then,
   it is simpler for me to /always/ use this style; after all: you
   can't know whether someone eventually will import your module!


You can explicitly declare the public interface of a module by defining 
`__all__`, listing the names which should be considered part of the 
module's public interface; see:

- https://docs.python.org/3/reference/simple_stmts.html#the-import-statement
- https://peps.python.org/pep-0008/#public-and-internal-interfaces

Although `from A import *` is generally discouraged, if `A` defines 
`__all__` then only the names listed in `__all__` are bound in the 
importing module's namespace.  Otherwise, all names from `A` which don't 
have a leading underscore are considered to be public and bound in the 
importing module.


I don't use IDLE, but it may be that it also uses `__all__` to determine 
a module's public API.  In that case, setting `__all__ = ["f"]` in `A` 
should prevent it from offering `math` as a completion (nor any other 
name that's not in the `__all__` list).


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


Re: Using a background thread with asyncio/futures with flask

2024-03-22 Thread Mark Bourne via Python-list
ure: 
finalizer set result
```

Judging by what's printing out, the `final result = await future` 
doesn't seem to be happy here.


Maybe someone sees something obvious I'm doing wrong here? I presume 
I'm mixing threads and asyncio in a way I shouldn't be.


Aside from possible issues mixing threads and asyncio (I'm no expert on 
asyncio), there's also the issue that there's nothing to cause the 
threads to exit.  The following doesn't use asyncio, but also hangs 
after the main thread has got the result:


```
import queue
import threading
import time

in_queue = queue.Queue()
out_queue = queue.Queue()
result_queue = queue.Queue()

def worker():
print("worker started running")
while True:
item = in_queue.get()
print(f"worker got item: {item}")
time.sleep(5)
print("worker sleeped")
out_queue.put(item)


def finalizer():
print("finalizer started running")
while True:
item = out_queue.get()
print(f"finalizer got item: {item}")
result_queue.put(item)
print("finalizer set result")


threading.Thread(target=worker).start()
threading.Thread(target=finalizer).start()
# threading.Thread(target=worker, daemon=True).start()
# threading.Thread(target=finalizer, daemon=True).start()


def main():
item = "Item to process"
in_queue.put("Item to process")
print(f"main put item: {item}")
result = None
while True:
try:
result = result_queue.get(timeout=1)
except queue.Empty:
# No result yet
print("main waiting for result")
continue
break
print(f"main got result {result}")


if __name__ == "__main__":
main()
```

By default, the main process won't exit until there are no non-daemon 
threads still running.  You can either send some sort of signal to the 
threads signal the threads to exit the loop and return cleanly (you'd 
also need a timeout on the queue `get()` calls).  Or you can create the 
threads as "daemon" threads (as in the commented-out lines), in which 
case they'll be killed when all non-daemon threads have exited.  Daemon 
threads don't get a chance to do any cleanup, close resources, etc. when 
they're killed, though, so aren't always appropriate.


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


Re: Popping key causes dict derived from object to revert to object

2024-03-22 Thread Mark Bourne via Python-list

Loris Bennett wrote:

Hi,

I am using SQLAlchemy to extract some rows from a table of 'events'.
 From the call to the DB I get a list of objects of the type

   sqlalchemy.orm.state.InstanceState

I would like to print these rows to the terminal using the 'tabulate'
package, the documentation for which says

   The module provides just one function, tabulate, which takes a list of
   lists or another tabular data type as the first argument, and outputs
   a nicely formatted plain-text table

So as I understand it, I need to convert the InstanceState-objects to,
say, dicts, in order to print them.  However I also want to remove one
of the keys from the output and assumed I could just pop it off each
event dict, thus:
  
 event_dicts = [vars(e) for e in events]

 print(type(event_dicts[0]))
 event_dicts = [e.pop('_sa_instance_state', None) for e in event_dicts]
 print(type(event_dicts[0]))


vars() returns the __dict__ attribute of the object.  It may not be a 
good idea to modify that dictionary directly (it will also affect the 
object), although it might be OK if you're not going to do anything else 
with the original objects.  To be safer, you could copy the event objects:

event_dicts = [dict(vars(e)) for e in events]
or:
event_dicts = [vars(e).copy()]


However, this prints

   
   

If I comment out the third line, which pops the unwanted key, I get

   
   

Why does popping one of the keys cause the elements of the list to
revert back to their original class?


As Dieter pointed out, the main problem here is that pop() returns the 
value removed, not the dictionary with the rest of the values.  You 
probably want something more like:

for e in event_dicts:
del e['_sa_instance_state']
(There's not really any point popping the value if you're not going to 
do anything with it - just delete the key from the dictionary)


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


Attaching a mock function to another mock breaks reset_mock()

2023-06-19 Thread Mark Bourne via Python-list
I've came across an issue with attaching a mock function to another mock 
object.  It looks like this might be a bug in unittest.mock, but it's 
possible I'm misunderstanding or doing something wrong.


I'm currently using Python 3.8.10, which is the default installed on 
Ubuntu 20.04.  I don't have time to install and try other versions right 
now but from a quick look at the source at 
<https://github.com/python/cpython/blob/main/Lib/unittest/mock.py>, it 
looks like the same issue would still occur with the latest.  I have a 
workaround, but would still like to know if I'm doing something wrong 
which I can correct, or should report this as a bug.


The class I'm testing (let's call it A) is given an instance of another 
class (let's call it B).  In normal operation, some other code adds a 
callback function as an attribute to B before passing it to A, and A 
calls that callback at certain points.  I agree this isn't particularly 
nice; I didn't write the code and don't have time to sort out all the 
structural issues at the moment.


So, in setting up the mock B, I need to attach a mock callback function 
to it.  I'd like the mock function to raise an exception if it's called 
with the wrong arguments.  I can create such a mock function with, for 
example:

```
mock_callback = mock.create_autospec(lambda a, b, c: None)
```
Calls like mock_callback(1,2,3) or mock_callback(a=1,b=2,c=3) are fine, 
and the test can later check the exact values passed in, while 
mock_callback(1,2) or mock_callback(1,2,3,x=9) raise an exception at the 
time of the call - exactly what I want.


However, when I attach this mock callback to the mock instance of B, the 
reset_mock() method breaks.  For example, using object in place of B, 
since the rest of its implementation is irrelevant to the issue:

```
mock_callback = mock.create_autospec(lambda a, b, c: None)
mock_b = mock.create_autospec(object, spec_set=False, instance=True)
mock_b.attach_mock(mock_callback, 'some_callback')
mock_b.reset_mock()
```

The call to reset_mock() results in:
```
Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python3.8/unittest/mock.py", line 603, in reset_mock
child.reset_mock(visited)
TypeError: reset_mock() takes 0 positional arguments but 1 was given
```

This seems to occur because, when creating a mock of a function or 
method, create_autospec calls _setup_func (via _set_signature), which 
sets the mock callback's reset_mock method to a function which doesn't 
accept any arguments.  When mock_b.reset_mock() is called, that 
recursively calls reset_mock() on all the child mocks (including the 
mock callback), passing a number of arguments - which causes the above 
exception.


I thought I might be able to just assign the mock callback to an 
attribute of the mock B, rather than using attach_mock, and avoid the 
recursive call to its reset_mock():

```
mock_b.some_callback = mock_callback
```
But mock_b.reset_mock() still raises that exception.  I think some magic 
in the mocks automatically attaches mock_callback as a child of mock_b 
even in that case.


My current workaround is to just use
```
mock_callback = mock.Mock(spec_set=lambda: None)
```
instead.  While using spec_set there prevents incorrect use of things 
like mock_b.some_callback.random_attribute, it doesn't enforce the 
arguments that the function can be called with, even if I do include 
them in the lambda (as in the first example).


Is there something I'm doing wrong here?  Or does this seem like a bug 
in unittest.mock that I should report?  Perhaps this is something that's 
not often done, so the issue hasn't been noticed before.  Trying to 
search for information generally leads back to the unittest.mock 
documentation, and general tutorials on using create_autospec, 
attach_mock, etc. without anything specific about this case.


--
Mark.

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


Re: f-string syntax deficiency?

2023-06-06 Thread Mark Bourne via Python-list

Roel Schroeven wrote:

Op 6/06/2023 om 16:08 schreef Chris Angelico:

On Wed, 7 Jun 2023 at 00:06, Neal Becker  wrote:
>
> The following f-string does not parse and gives syntax error on 3.11.3:
>
> f'thruput/{"user" if opt.return else "cell"} vs. elevation\n'
>
> However this expression, which is similar does parse correctly:
>
> f'thruput/{"user" if True else "cell"} vs. elevation\n'
>
> I don't see any workaround.  Parenthesizing doesn't help:
>  f'thruput/{"user" if (opt.return) else "cell"} vs. elevation\n'
>
> also gives a syntax error

Is this a problem with the f-string, or with the expression
opt.return? That's a keyword.

'return' being a keyowrd is definitely going to be the problem.

Neal, I assume you're using 'opt.return' also outside of that f-string. 
Does that work? How did you manage to do that? I tried to make a simple 
class with an attribute called 'return', but that already fails with a 
syntax error.


Just for fun, here's a class which has any attribute you like, including 
`return`:

```
class AnyAttr:
def __getattr__(self, name):
return f'This is the value of the <{name}> attribute'
```

The usual "dot" notation to access the attributes works for arbitrary 
attributes, but not for `return` because, as mentioned, that's a keyword:

```
>>> aa = AnyAttr()
>>> aa.myattribute
'This is the value of the  attribute'
>>> aa.random
'This is the value of the  attribute'
>>> aa.return
  File "", line 1
aa.return
   ^
SyntaxError: invalid syntax
```

If you really do have an instance with a `return` attribute (perhaps 
because it does fun things with `__getattr__`), you can access it if 
necessary using `getattr`:

```
>>> getattr(aa, 'return')
'This is the value of the  attribute'
```

You can even access attributes with spaces and other usually-invalid 
characters:

```
>>> getattr(aa, 'This really is an attribute name!')
'This is the value of the  attribute'
```

Using `getattr` to access the value, Neal's f-string can be made to work:
```
>>> f'thruput/{"user" if getattr(aa, "return") else "cell"} vs. 
elevation\n'

'thruput/user vs. elevation\n'
```

But if you have control over the implementation of that `opt` object, 
it's probably better to give the attribute a different name which is a 
valid identifier.  PEP-8 suggests a convention of using a single 
trailing underscore (e.g. `return_`) to avoid conflicts with keywords, 
if there's no better name.


Perhaps `opt` is the arguments returned by `argparse.ArgumentParser` and 
you want the command-line option to be `--return`.  In that case, see 
the `dest` argument to `add_argument()` which can specify a different 
name for the attribute used in code (it's almost like they thought about 
this type of problem ;o)).  If it's from `optparse`, that has a similar 
argument, but `optparse` is deprecated so consider updating to `argparse`.




(Recently there has been an effort to provide clearer and more useful 
error messages; this seems to be a case where there is still room for 
improvement: "SyntaxError: invalid syntax" doesn't immediately remind me 
of that fact that 'return' is a keyword and therefor can't be used as an 
attribute.)


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


Fwd: Problems Installing and getting started.

2023-05-31 Thread Mark Bass
-- Forwarded message -
From: Mark Bass 
Date: Wed, 31 May 2023 at 08:09
Subject: Problems Installing and getting started.
To: 


Good morning,

I installed python several hours ago (from python.org), I then installed
the IDE PyCharm. I'm using AI to help with a project that requires
statistical analysis.
I cannot open python, when I double clicked a "Modify Setup" window
appeared with the three options Modify, Repair and Uninstall to click. I
assumed this was part of the final installation process and clicked Modify
- it seemed to be successful. I still could not open python. I asked the AI
and it suggested to click Repair, this still made no difference. I finally
Uninstalled it, shut down my laptop, had a coffee then re-installed it but
the same problem occurred.
Can you help ? Any suggestions?
I'm really pleased with the AI so far  and looking forward to using Python
to get my project started.
Best Regards.Mark
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question regarding unexpected behavior in using __enter__ method

2023-04-26 Thread Mark Bourne

Lorenzo Catoni wrote:

Dear Python Mailing List members,

I am writing to seek your assistance in understanding an unexpected
behavior that I encountered while using the __enter__ method. I have
provided a code snippet below to illustrate the problem:

```

class X:

... __enter__ = int
... __exit__ = lambda *_: None
...

with X() as x:

... pass
...

x

0
```
As you can see, the __enter__ method does not throw any exceptions and
returns the output of "int()" correctly. However, one would normally expect
the input parameter "self" to be passed to the function.

On the other hand, when I implemented a custom function in place of the
__enter__ method, I encountered the following TypeError:

```

def myint(*a, **kw):

... return int(*a, **kw)
...

class X:

... __enter__ = myint
... __exit__ = lambda *_: None
...

with X() as x:

... pass
...
Traceback (most recent call last):
   File "", line 1, in 
   File "", line 2, in myint
TypeError: int() argument must be a string, a bytes-like object or a real
number, not 'X'
```
Here, the TypeError occurred because "self" was passed as an input
parameter to "myint". Can someone explain why this unexpected behavior
occurs only in the latter case?

I tested this issue on the following Python versions, and the problem
persists on all of them:
- Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux
- Python 3.10.10 (main, Feb  8 2023, 14:50:01) [GCC 9.4.0] on linux
- Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933
64 bit (AMD64)] on win32

I appreciate any input or insights that you might have on this matter.

Thank you for your help in advance!


Aside from other explanations and suggestions, the following definition 
of X also works:


class X:
__enter__ = staticmethod(myint)
__exit__ = lambda *_: None

Wrapping `myint` in a call to `staticmethod` is the same as using 
`@staticmethod` as a decorator on a method within the class, so the 
`self` parameter doesn't get passed.  Equivalent to:


class X:
@staticmethod
def __enter__(*a, **kw):
return int(*a, **kw)
__exit__ = lambda *_: None

Which in turn is just a neater way of doing:

class X:
def __enter__(*a, **kw):
return int(*a, **kw)
__enter__ = staticmethod(__enter__)
__exit__ = lambda *_: None

Those equivalents are a bit pointless, since no arguments will be passed 
into `__enter__` anyway in normal usage, but perhaps make it a bit 
clearer that the second example behaves as would be expected for a 
method of X (where the instance is passed as the first argument), and 
that it's the first example (with `__enter__ = int`) that should be a 
bit more surprising.  (I'm not sure there's much practical use for the 
original `__enter__ = int` either, but presumably that's just used as a 
cut-down demonstration).


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


Re: Pycharm IDE

2023-04-19 Thread Mark Bourne

Thomas Passin wrote:

On 4/19/2023 1:27 AM, Kevin M. Wilson via Python-list wrote:
Ok, I got rid of the "print (f'"I am thinking of a number between 1 to 
{LIMIT}\n")"print ("I am thinking of a number between 1 to {LIMIT}\n"),


I think you misunderstand several things at the same time here.

1. These errors originate from syntax errors.  They are basically Python 
errors.  It's possible that behind the scenes, PyCharm is running one or 
another Python program to detect them, but they are errors in your 
Python code.


2. print() doesn't care whether you give it an f-string or not, because 
a f-string is a string too.


3. All strings need to be closed with the same kind of quote they 
started with.  If one is not closed, then Python thinks the string is 
supposed to continue, and - say- the final parenthesis of the print() 
function looks like it is part of the string. So Python (or PyCharm) 
notices that the closing parenthesis of the print() expression is missing.


4. in an f-string, the expression in braces is evaluated and replaced by 
its string value.  So if you try to do this


print('{LIMIT}')

then that will be printed as is with no  substitution - because it is 
not an f-string.  So you will see "{LIMIT}" But you thought you were 
going to see "42" (if LIMIT == 42, that is). OTOH,


print(f'{LIMIT})


^ I think this one should be:

print(f'{LIMIT}')

with the closing quote ;o)

will substitute the string value of LIMIT before printing the string. 
Both are legitimate but the first is not what you seem to want.


5. As I posted earlier, you almost certainly do not need to add the "\n".

So, some suggestions:

- If you are having a problem with some piece of code, try to simplify 
it down to the smallest bit that shows the problem.


- If you are having trouble with f-strings, then think about what you 
want to achieve and look up information about f-strings with that in mind.


- If you are having trouble with the print statement, think what you 
want it to display and look up information about the print function with 
that in mind.


- If your tool - PyCharm in this case - is producing messages but you 
don't understand why they are being produced, try to look up information 
about how and when PyCharm produces error messages


Do you see a pattern here?

Also note that just because you don't see an error message does not mean 
that the code is correct.  It may be correct from the point of view of 
Python syntax but that doesn't mean that it will perform correctly nor 
how you expect.



and Pycharm stopped complaining about it... WHY??
Perplexed
"When you pass through the waters, I will be with you: and when 
you pass through the rivers, they will not sweep over you. When you 
walk through the fire, you will not be burned: the flames will not set 
you ablaze."

Isaiah 43:2

 On Tuesday, April 18, 2023 at 11:17:52 PM MDT, Kevin M. Wilson 
via Python-list  wrote:
  print (f'"I am thinking of a number between 1 to {LIMIT}\n")I had 
the impression that the format specifier 'f' was necessary for the 
print function, but the double quotes are for the string printed to 
the user, as a prompt!The Pycharm IDE is showing that it expects a 
single quotation mark or ')'! No error message is displayed.

Perplexed
"When you pass through the waters, I will be with you: and when 
you pass through the rivers, they will not sweep over you. When you 
walk through the fire, you will not be burned: the flames will not set 
you ablaze."

Isaiah 43:2

     On Tuesday, April 18, 2023 at 06:44:37 PM MDT, aapost 
 wrote:

  On 4/18/23 19:18, Kevin M. Wilson wrote:

Why complain about a 'comma', or a ')'???
       print (f'"I am thinking of a number between 1 to {LIMIT}\n")


my version says it expects ' first (to close the fstring)
then on a new line below it, it mentions the comma and )
I believe that is just showing you after ' it expects you to end the
print with ) as you have
or , to add additional arguments to print



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


Re: Windows installer from python source code without access to source code

2023-04-07 Thread Mark Bourne

MRAB wrote:

On 2023-04-06 23:14, Jim Schwartz wrote:

    Could someone please help Carlos?  I’m not sure how to answer his
    question

    Sent from my iPhone

  On Apr 6, 2023, at 3:53 PM, Carlos Fulqueris 
 wrote:


  
  Hello Jim,
  How can I unsubscribe to this email list?
  I'm waiting for your response.
  Thanks
  Carlos

[snip]
At the bottom of the post is a link to the page that explains how to 
unsubscribe. It's the link:



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


I read this list via the newsgroup, so don't see those links.  However, 
I've always thought those Mailman pages are confusing for anyone not 
already familiar when it comes to subscribing.  The option to 
unsubscribe is right at the bottom of the page under the "Python-list 
Subscribers" section, which looks like it's only for list 
administrators!  Ignore the admin address and password boxes, just fill 
in your email address in the box below those and click "Unsubscribe or 
edit options".


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


[Python-announce] Shed Skin 0.9.7 - native Windows support!

2023-04-01 Thread Mark Dufour
Hi all,

I have just released version 0.9.7 of Shed Skin, a restricted-Python-to-C++
compiler. The highlight of this release is the migration to CMake (and
Conan), to enable native Windows support.

For more information about the release:

http://blogfarts.blogspot.com/2023/04/shed-skin-restricted-python-to-c.html

Project homepage:

http://github.com/shedskin/shedskin


Cheers,
Mark.
___
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


[Python-announce] ANN: pvlib-0.9.5 released

2023-03-20 Thread Dr. Mark Alexander Mikofski PhD
Dear Pythonistas and solar power enthusiasts,

The maintainers are happy to announce a new release of pvlib python:
software for simulating performance of photovoltaic solar energy systems.

*v0.9.5 Highlights:*
* The infinite_sheds model now has options to use the hay-davies
transposition model and faster vectorized calculations.
* New models for irradiance decomposition (boland) and relative airmass
(gueymard2003).
* Model extensions for multiple strings in pvlib.snow.loss_townsend and AR
coating in pvlib.iam.physical.
* Updated the parameters database for the ADR inverter model.
* Various other bug fixes and testing updates.

For the full list of what's new, see the documentation:
https://pvlib-python.readthedocs.io/en/stable/whatsnew.html

*Releases are available from PyPI and the conda-forge channel:*
* https://pypi.org/project/pvlib/
* https://anaconda.org/conda-forge/pvlib and
https://anaconda.org/conda-forge/pvlib-python
NOTE: new pvlib releases are no longer uploaded to the "pvlib" conda
channel.  Please install from PyPI or the conda-forge channel instead.

*Read the Documentation:*
* https://pvlib-python.readthedocs.io/en/stable/index.html

*Report issues & contribute:*
* https://github.com/pvlib/pvlib-python

*Community discussion & support:*
* https://groups.google.com/g/pvlib-python
* https://github.com/pvlib/pvlib-python/discussions

*Thank you for using pvlib python!*

-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
___
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


Re: Line continuation and comments

2023-02-24 Thread Mark Bourne
Personally, I don't particularly like the way you have to put multiline 
strings on the far left (rather than aligned with the rest of the scope) 
to avoid getting spaces at the beginning of each line.  I find it makes 
it more difficult to see where the scope of the class/method/etc. 
actually ends, especially if there are multiple such strings.  It's not 
too bad for strings defined at the module level (outer scope) though, 
and of course for docstrings the extra spaces at the beginning of each 
line don't matter.


However, rather than using "+" to join strings as in your examples 
(which, as you suggest, is probably less efficient), I tend to use 
string literal concatenation which I gather is more efficient (treated 
as a single string at compile-time rather than joining separate strings 
at run-time).  See 
<https://docs.python.org/3/reference/lexical_analysis.html#string-literal-concatenation>.


For example:
  HelpText = ("Left click: Open spam\n"
  "Shift + Left click: Cook spam\n"
  "Right click:Crack egg\n"
  "Shift + Right click:Fry egg\n")

The downside is having to put an explicit "\n" at the end of each line, 
but to me that's not as bad as having to align the content to the far left.


Getting a bit more on topic, use of backslashes in strings is a bit 
different to backslashes for line continuation anyway.  You could almost 
think of "\
(newline)" in a multiline string as being like an escape sequence 
meaning "don't actually put a newline character in the string here", in 
a similar way to "\n" meaning "put a newline character here" and "\t" 
meaning "put a tab character here".


Mark.


avi.e.gr...@gmail.com wrote:

Good example, Rob, of how some people make what I consider RELIGIOUS edicts 
that one can easily violate if one wishes and it makes lots of sense in your 
example.

Let me extend that. The goal was to store a character string consisting of 
multiple lines when printed that are all left-aligned. Had you written:

  HelpText = """
Left click: Open spam
...
Shift + Right click:Fry egg
"""
Then it would begin with an extra carriage return you did not want. Your 
example also ends with a carriage return because you closed the quotes on 
another line, so a \ on the last line of text (or moving the quotes to the end 
of the line) would be a way of avoiding that.

Consider some alternatives I have seen that are in a sense ugly and may involve 
extra work for the interpreter unless it is byte compiled once.

def someFunc():
  HelpText =
  "Left click: Open spam" + "\n" +
  "Shift + Left click: Cook spam" + "\n" +
  ...

Or the variant of:
HelpText =  "Left click: Open spam\n"
HelpText +=  " Shift + Left click: Cook spam\n"
...

Or perhaps just dumping the multi-line text into a file beforehand and reading 
that into a string!

def someFunc():

The backslash is not looking like such a bad idea! LOL!

-Original Message-
From: Python-list  On 
Behalf Of Rob Cliffe via Python-list
Sent: Wednesday, February 22, 2023 2:08 PM
To: python-list@python.org
Subject: Re: Line continuation and comments



On 22/02/2023 15:23, Paul Bryan wrote:

Adding to this, there should be no reason now in recent versions of
Python to ever use line continuation. Black goes so far as to state
"backslashes are bad and should never be used":

https://black.readthedocs.io/en/stable/the_black_code_style/future_sty
le.html#using-backslashes-for-with-statements


def someFunc():
  HelpText = """\
Left click: Open spam
Shift + Left click: Cook spam
Right click:Crack egg
Shift + Right click:Fry egg
"""

The initial backslash aligns the first line with the others (in a fixed font of 
course).
Best wishes
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


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


Re: Add angle brackets for required args in argparse

2023-02-20 Thread Mark Bourne

scruel tao wrote:

If we have the following code:
```
parser = argparse.ArgumentParser(description="test")
parser.add_argument('path')
```

Run it without args, will get error message:
```
usage: test.py [-h] path
test.py: error: the following arguments are required: path
```

However, I hope the message can be as the following:
```
usage: test.py [-h] 
test.py: error: the following arguments are required: path
```


The `metavar` argument to `add_argument` can be used to control how an 
argument is represented in the usage text:

```
import argparse
parser = argparse.ArgumentParser(description='test')
parser.add_argument('path', metavar='')
parser.parse_args()
```

Which results in:
```
usage: test.py [-h] 
test.py: error: the following arguments are required: 
```


Or might can consider to provide a way to let user have there own style, like:
```
usage: test.py [-h] path
```


It's also possible to create a custom help formatter, overriding 
appropriate methods to control the formatting.  For example:

```
import argparse

class CustomHelpFormatter(argparse.HelpFormatter):
def _get_default_metavar_for_positional(self, action):
default = super()._get_default_metavar_for_positional(action)
return f'<{default}>'

parser = argparse.ArgumentParser(
description='test',
formatter_class=CustomHelpFormatter)
parser.add_argument('path')
parser.parse_args()
```

Which results in:
```
usage: test.py [-h] 
test.py: error: the following arguments are required: path
```

That's a bit closer to what you asked for, since the required argument 
shown in the error message doesn't include the angle brackets.  It also 
avoids needing to specify a `metavar` for every positional argument. 
However, it is overriding a non-public method of the `HelpFormatter` 
class, so might not work across all Python versions if the name or 
signature of that method changes (even if it does work with all current 
versions, it might break in future).


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


Re: ChatGPT Generated news poster code

2023-02-13 Thread Mark Bourne

Mats Wichmann wrote:
Meanwhile, I'm still wondering why I need a program to "chat" to the 
GUID Partition Table


Perhaps to keep on good terms with it so that it doesn't run away and 
hide?  I had to go looking for the GPT on one of my disks after it went 
AWOL a couple of years ago.  Eventually found it hiding in another sector.


(Turns out the USB-SATA adapter I previously used to format the disk 
misreports the logical block size for some disks.  Subsequently 
connecting the disk directly to a SATA port, the GPT was no longer found 
at logical block 1 where it should have been, because the block size was 
reported differently.)


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


Re: A Function's name during its definition

2023-02-07 Thread Mark Bourne

Stefan Ram wrote:

Mark Bourne  writes:

In the second case, eval() only gets the globals and immediate locals,


   Yes, I think you are right. Curiously, the following program would
   mislead one to thing that eval /does/ see the intermediate names:

   main.py

def f():
 x = 22
 def g():
 print( x )
 print( eval( 'x' ))
 g()
f()

   output

22
22

   . But "print( x )" had the effect of making that x local.
   Without it, we see the error:

   main.py

def f():
 x = 22
 def g():
 print( eval( 'x' ))
 g()
f()

   error output

NameError: name 'x' is not defined


That is interesting.  I know assigning to a value creates a local 
version (and the non-local then can't be accessed, even before the new 
value was assigned), but hadn't realised just referencing it brought it 
into local scope for reading.  I guess that's to do with closures, where 
any variables referenced within the function get bound to the function's 
scope.  e.g. if g() includes a reference to x [as it does in the first 
example above], and f() returned a reference to g(), calling g() later 
[from outside of f()] by using that reference would still be able to 
access x.


With just the eval() call and no other reference to x, the interpreter 
doesn't know at that time the closure is created that there is a 
reference to x.  At that point, the 'x' is just text in a string.  It's 
only when eval() gets called that it tries to execute that string as 
Python code - and finds that x isn't in scope.


I'm not all that familiar with the concept of closures, so may have got 
some of the terminology and details wrong - but it's something along 
those lines.  I'm sure others will correct me...


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


Re: A Function's name during its definition

2023-02-07 Thread Mark Bourne

Stefan Ram wrote:

   When one defines a function, sometimes its name is only
   half-existent.

   One can implicitly evaluate the name of the function:

   main.py

def g():
 def f():
print( f )
 f()
g()

   output

.f at ...

   , but one gets an error when one tries to evaluate it explicitly:

   main.py

def g():
 def f():
print( eval( 'f' ))
 f()
g()

   error output

NameError: name 'f' is not defined


I'm guessing that's because the name "f", referencing that function, is 
in the local scope of the "g" function.


In the first version, the interpreter searches the scope of the code 
which calls "print(f)".  It doesn't find anything named "f" there, so 
searches the next scope out, that of the function identified by "g". 
That contains "f", so it's found and can be printed.


In the second case, eval() only gets the globals and immediate locals, 
in this case the locals of "f".  The name "f" doesn't exist in the local 
scope of "f", and it doesn't exist in the global scope.  So the code 
executed by eval() can't see it.


The following does work:

def g():
def f():
   print(eval('g'))
f()
g()

...because in this case "g" is defined in the global scope, so the code 
in the eval call can see it.


The following also works:

def g():
def f():
pass
print(eval('f'))
g()

...because in this case, eval() is called from within the scope of "g", 
so it can see the function "f" defined in that scope.



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


[Python-announce] ANN: pvlib-0.9.4 released

2023-02-05 Thread Dr. Mark Alexander Mikofski PhD
Dear Pythonistas and solar power enthusiasts,

The maintainers are happy to announce a new release of pvlib python:
software for simulating performance of photovoltaic solar energy systems.

*See what's new for v0.9.4:*
** *https://pvlib-python.readthedocs.io/en/stable/whatsnew.html

*Releases are available from PyPI and the conda-forge channel:*
* https://pypi.org/project/pvlib/
* https://anaconda.org/conda-forge/pvlib and
https://anaconda.org/conda-forge/pvlib-python

*Read the Documentation:*
* https://pvlib-python.readthedocs.io/en/stable/index.html

*Report issues & contribute:*
* https://github.com/pvlib/pvlib-python

*v0.9.4 Highlights:*
* Fitting
<https://pvlib-python.readthedocs.io/en/stable/reference/pv_modeling/generated/pvlib.pvarray.fit_pvefficiency_adr.html#pvlib.pvarray.fit_pvefficiency_adr>
 and prediction
<https://pvlib-python.readthedocs.io/en/stable/reference/pv_modeling/generated/pvlib.pvarray.pvefficiency_adr.html#pvlib.pvarray.pvefficiency_adr>
functions
for the ADR PV efficiency model, along with several gallery examples
<https://pvlib-python.readthedocs.io/en/stable/gallery/index.html#adr-model-for-pv-module-efficiency>
.
* An extension of the Faiman temperature model
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.temperature.faiman_rad.html#pvlib.temperature.faiman_rad>
that
includes a radiative loss term.
* Efficient direct
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.iam.schlick.html#pvlib.iam.schlick>
 and diffuse
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.iam.schlick_diffuse.html#pvlib.iam.schlick_diffuse>
IAM
models based on the Schlick approximation to the Fresnel equations.
* A convenience function
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.irradiance.complete_irradiance.html#pvlib.irradiance.complete_irradiance>
to
calculate one of DNI, DHI, GHI from the other two.
* The Hay-Davies
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.irradiance.haydavies.html#pvlib.irradiance.haydavies>
transposition
model can now return individual components in addition to global tilted
irradiance.
* An implementation of ASTM E1036
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.ivtools.utils.astm_e1036.html#pvlib.ivtools.utils.astm_e1036>
for
extracting the basic characteristics of an I-V curve.
* There were several new contributors.

*Thank you for using pvlib python!*

-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
___
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


Re: evaluation question

2023-02-02 Thread Mark Bourne

mutt...@dastardlyhq.com wrote:

On Wed, 1 Feb 2023 18:28:04 +0100
"Peter J. Holzer"  wrote:

--b2nljkb3mdefsdhx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2023-02-01 09:00:39 -, mutt...@dastardlyhq.com wrote:

Its not evolution, its revolution. Evolution retains old functionality.


Tell a penguin that it can fly :-)


Yeah ok :) But the ancestors of penguins didn't wake up one morning, flap
their wings and fall out the tree, it happened gradually. Python2 syntax
could have been retained for X versions of 3 just as C++ keeps old stuff
until its eventually deprecated them removed.


Python 2 *was* retained for X versions of Python 3.  From a quick check, 
Python 3.0 was released in December 2008 and Python 2 support ended in 
January 2020 - by which time Python 3 was up to 3.8 as ChrisA mentioned. 
 That's about an 11 year transition period, which is hardly sudden! 
Python 3 *was* the point at which the features deprecated in Python 2 
were removed.


The problem is, a lot seemed to ignore Python 3 for the first 12 years 
and then suddenly panic because Python 2 support had ended.


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


Re: evaluation question

2023-01-31 Thread Mark Bourne

Greg Ewing wrote:

On 30/01/23 10:41 pm, mutt...@dastardlyhq.com wrote:

What was the point of the upheaval of converting
the print command in python 2 into a function in python 3 if as a 
function

print() doesn't return anything useful?


It was made a function because there's no good reason for it
to have special syntax in the language.


I think I saw somewhere that making print a function also had something 
to do with being able to add extra keyword arguments like sep and end. 
The syntax for printing to a specific file already seemed a bit odd with 
the print statement, and adding extra arguments would have made it even 
more clunky (yeah, I know ">>" is similar to C++ streams, but it looks 
out of place in Python).


They couldn't fully make the change from print statement to print 
function without breaking backward compatibility for existing code.  But 
there were other breaking changes being made in Python 3 anyway, so may 
as well sort print out while at it and have all the breaking changes at 
once.



Functions don't need to return things to justify their existence,
and in fact the usual convention is that functions whose purpose
is to have an effect just return None.


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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-29 Thread Mark Bourne

Jach Feng wrote:

Thank you for detail explanation of the role the shell is involved in this 
problem. I'm very appreciated!

It seems that a CLI app may become very complex when dealing with different 
kind of shell, and may not be possible to solve its problem. But the good thing 
in my app is that I need only to handle math equation:-)


If you want to try to tell the user how to deal with their shell's 
requirements for quoting arguments, regardless of which shell they might 
be using, yes, that explanation would become very complicated.  It 
doesn't affect the rest of the implementation of the application though 
- the user just needs to know how to use their shell to pass the 
arguments they want into the application.  That's really something they 
should look up in their shell's documentation, rather than something 
your application should attempt to document.


Since your application requires equations to be passed in, and they're 
quite likely to include characters handled specially by the shell 
(space, "*" and "^" have already come up in this thread, but there may 
be others), it may be worth highlighting that, but directing the user to 
consult the documentation for their shell rather than assuming a 
particular shell and attempting to cover all its features and limitations.



So why so much objection to explaining the need for "--"?

Because of using " to enclose a space separated string is a common convention, and adding 
a "--" is not:-)


If you don't consider use of "--" to be a common convention, that seems 
even more reason to mention it in your application's documentation.


Telling the user to use quotes around an argument containing spaces is 
nothing to do with your application, and might not even be applicable if 
they use a different shell to call your application.  In most shells 
I've come across, there are also various other characters that need 
special handling (either quoting or escaping) - but exactly which 
characters again depends on the shell.  Yet you seem quite happy to 
document that one particular case in your usage information.


Using "--" is also a common convention (as I and others have mentioned), 
although perhaps not as common in Windows (where it's more common to use 
"/" rather than "-" for options anyway).  But more to the point, it is a 
feature that is implemented under your application's control (if you 
don't want this feature, don't use argparse).  Use of "--" is applicable 
regardless of which shell your user calls it from, and other 
applications might not use that convention even if called from the same 
shell, so it seems *more* in scope for your application to document than 
using quotes around spaces.


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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-29 Thread Mark Bourne

Jach Feng wrote:

Jach Feng 在 2023年1月22日 星期日上午11:11:22 [UTC+8] 的信中寫道:

Fail on command line,

e:\Works\Python>py infix2postfix.py "-4^2+5.3*abs(-2-1)/2"
usage: infix2postfix.py [-h] [infix]
infix2postfix.py: error: unrecognized arguments: -4^2+5.3*abs(-2-1)/2

Also fail in REPL,

e:\Works\Python>py
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import argparse
parser = argparse.ArgumentParser(description='Convert infix notation to 
postfix')
parser.parse_args("-4^2+5.3*abs(-2-1)/2")

usage: [-h]
: error: unrecognized arguments: - 4 ^ 2 + 5 . 3 * a b s ( - 2 - 1 ) / 2

Just can't figure out where is wrong!?

--Jach

OK, I take a quick try to use argv directly. I write the code in a way even get 
rid of the -h option.

import sys
if len(sys.argv) == 1:
infix = " "
print("Usage: a math equation must follow!")
else:
infix = "".join(sys.argv[1:])

Simple enough, right? But unfortunately it didn't survive. The ^ symbol was 
lost!

e:\Works\Python>py infix2postfix.py
Usage: a math equation must follow!

e:\Works\Python>py infix2postfix.py -4^2 +5.3  *  abs(-2-1)/2
-42 5.3 -2 1 - abs * 2 / +

Hmm...


I'm not certain, but I think that's a shell feature again.  In Windows' 
command prompt, "^" can be used at the end of a line to indicate that 
the command continues on the next line.  I'm not sure what happens if 
it's in the middle of a line (and not on Windows to be able to check), 
but it's quite possible that it just gets ignored.


Enclosing your argument in quotes might help.  Again, this is a feature 
of the shell, not your application, and other shells might behave 
differently.  You probably don't want to go down the line of trying to 
document this kind of thing in your applications usage information, 
because it won't work like that for someone using e.g. the bash shell 
(which can be run on Windows).


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


Re: evaluation question

2023-01-28 Thread Mark Bourne

mutt...@dastardlyhq.com wrote:

On Sat, 28 Jan 2023 14:22:01 +1300
dn  wrote:

Do you know about the Python REPL?


Haven't learnt the acronyms yet.


REPL stands for "Read Evaluate Print Loop".  It basically refers to the 
interactive interpreter, which reads input you type, evaluates it, 
prints the result, and loops (repeatedly does that).


An interesting point from your examples is that the output from the 
first two comes from different steps in that loop.


>>> eval("1+1")
2

Here, the E (evaluation) step runs eval("1+1"), which returns 2.  The P 
(print) step then prints that result.  If this was in a script, you 
wouldn't see any output, and the statement is pretty much useless - 
you'd need to assign the result to a variable or explicitly print it.


>>> eval("print(123)")
123

Here, the E step runs eval("print(123)"), which prints 123 and returns 
None.  The P step doesn't print anything if the result is None.  You'd 
still see that output if this was in a script.


Using eval in those examples is pretty pointless, since:
>>> 1+1
>>> print(123)
would produce the same results - but of course they were just simple 
examples.


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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-28 Thread Mark Bourne
pattern unchanged if it doesn't match any files).  In 
bash, if a "$" is used I'd need to enclose that in 'single quotes' 
(can't even use "double quotes" for that one).  You can't really expect 
to document all that sort of thing, because it depends on which shell 
the user happens to run your application from - you just have to trust 
the user to know or learn how to use their shell.


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


Re: bool and int

2023-01-27 Thread Mark Bourne

avi.e.gr...@gmail.com wrote:
...

Interestingly, I wonder if anyone has
designed an alternate object type that can be used mostly in place of
Booleans but which imposes changes and restrictions so trying to add a
Boolean to an integer, or vice versa, results in an error. Python is
flexible enough to do that and perhaps there already is a module out there


Not exactly what you describe, but I did once write a subclass of int 
for use in an SNMP interface, where true is represented as 1 and false 
as 2.  I don't recall the exact details offhand, but it involved 
overriding __bool__ so that a value of 1 returned True and anything else 
False.  The way it was used should have ensured that it only ever had 
the value 1 or 2, but doing it this way round (rather than e.g. 2 being 
False and anything else True) meant that if it somehow got the value 0, 
that would also be treated as False.  I think it also overrode __init__ 
(or perhaps __new__) to covert a bool True or False to 1 or 2 (rather 
than 1 or 0) for its own value, so it could be initialised from either 
an int or a bool and correctly converted in either direction via int() 
or bool().


So Python is even flexible enough to be made to deal with insane 
situations where False is 2!


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


Re: How to make argparse accept "-4^2+5.3*abs(-2-1)/2" string argument?

2023-01-22 Thread Mark Bourne

Jach Feng wrote:

Fail on command line,

e:\Works\Python>py infix2postfix.py "-4^2+5.3*abs(-2-1)/2"
usage: infix2postfix.py [-h] [infix]
infix2postfix.py: error: unrecognized arguments: -4^2+5.3*abs(-2-1)/2

Also fail in REPL,

e:\Works\Python>py
Python 3.8.8 (tags/v3.8.8:024d805, Feb 19 2021, 13:08:11) [MSC v.1928 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

import argparse
parser = argparse.ArgumentParser(description='Convert infix notation to 
postfix')
parser.parse_args("-4^2+5.3*abs(-2-1)/2")

usage: [-h]
: error: unrecognized arguments: - 4 ^ 2 + 5 . 3 * a b s ( - 2 - 1 ) / 2

Just can't figure out where is wrong!?


First, you need to add an argument to the parser, so that it expects an 
argument:

>>> parser.add_argument("expression")

Secondly, `parse_args` expects a list of arguments.  By passing a 
string, it interprets each character as a separate argument (since 
iterating over a string yields each character in turn).  Here, I 
intentionally leave off the initial hyphen because that's the next problem:

>>> parser.parse_args(["4^2+5.3*abs(-2-1)/2"])
Namespace(expression='4^2+5.3*abs(-2-1)/2')

Thirdly, an initial hyphen indicates an optional argument so, for 
example if you pass "-l" it will expect a "-l" argument to be defined as 
one of the valid options, and also complain that you haven't specified 
the required expression:

>>> parser.parse_args(["-4^2+5.3*abs(-2-1)/2"])
usage: [-h] expression
: error: the following arguments are required: expression

If you need to pass a value starting with a "-" there are a couple of 
options...


Perhaps it would be acceptable to represent it as "0-...":
>>> parser.parse_args(["0-4^2+5.3*abs(-2-1)/2"])
Namespace(expression='0-4^2+5.3*abs(-2-1)/2')

While mathematically equivalent, that might have different meaning for 
whatever you're trying to do.  Alternatively, a double hyphen indicates 
that there are no more options and that anything else is positional 
arguments even if they begin with a hyphen:

>>> parser.parse_args(["--", "-4^2+5.3*abs(-2-1)/2"])
Namespace(expression='-4^2+5.3*abs(-2-1)/2')

You wouldn't usually explicitly pass a list of arguments to `parse_args` 
like that, but it can be useful for testing and experimentation. 
Usually, you'd call `parse_args()` without any arguments, and it would 
parse the arguments passed on the command-line when calling your script. 
 e.g. you'd call (from a Windows command prompt / Linux shell / etc.):

> ./convert_infix.py -- '-4^2+5.3*abs(-2-1)/2'
(it's probably a good idea to quote the expression, in case it includes 
any characters which would be interpreted specially by the shell - e.g. 
"*" without quotes usually expands to all matching files in the current 
directory)


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


Re: To clarify how Python handles two equal objects

2023-01-15 Thread Mark Bourne

Jen Kris wrote:

Avi,

Your comments go farther afield than my original question, but you made some 
interesting additional points.  For example, I sometimes work with the C API 
and sys.getrefcount may be helpful in deciding when to INCREF and DECREF.  But 
that’s another issue.

The situation I described in my original post is limited to a case such as x = y where both "x" and "y" are arrays – whether they are lists in Python, or from 
the array module – and the question in a compiled C extension is whether the assignment can be done simply by "x" taking the pointer to "y" rather than moving 
all the data from "y" into the memory buffer for "x" which, for a wide array, would be much more time consuming than just moving a pointer.  The other 
advantage to doing it that way is if, as in my case, we perform a math operation on any element in "x" then Python expects that the same change to be reflected in 
"y."  If I don’t use the same pointers then I would have to perform that operation twice – once for "x" and once  for "y" – in addition to the 
expense of moving all the data.

The answers I got from this post confirmed that it I can use the pointer if "y" is not re-defined 
to something else during the lifespan of "x."  If it is then "x" has to be restored to 
its original pointer.  I did it that way, and helpfully the compiler did not overrule me.


I haven't done much with C extensions, but I don't think you'd need to 
do anything with "x" in that case.  If something else is assigned to 
"y", "x" would still be a reference to the original object - why would 
it need to be "restored" to anything?  Unless I've misunderstood what's 
going on here...


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


[Python-announce] ANN: Shed Skin 0.9.6 - adds Python 3 support!

2022-12-30 Thread Mark Dufour
Hi all,

I have just released version 0.9.6 of Shed Skin, a restricted-Python-to-C++
compiler. The highlight of this release is the migration to Python 3.

For more information about the release:

http://blogfarts.blogspot.com/2022/12/shed-skin-restricted-python-to-c.html

Project homepage:

http://github.com/shedskin/shedskin


Cheers,
Mark.
___
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


Re: How make your module substitute a python stdlib module.

2022-12-27 Thread Mark Bourne

Antoon Pardon wrote:



Op 27/12/2022 om 11:37 schreef Chris Angelico:

On Tue, 27 Dec 2022 at 21:29, Antoon Pardon  wrote:

OK, I am writing an alternative for the threading module. What I would
like to know is how I can get some library modules call my alternative
instead of the threading module.

For instance there is the logging module, it can log the thread name. So
I would like to know how I can get the logging module to call the
function from my module to get the current_thread, instead of it calling
"current_thread" from the threading module.

Easy: make sure your module is called "threading.py" and is earlier in
the path than the standard library. In fact, it's so easy that people
do it unintentionally all the time... Generally, the current directory
(or the script directory) is the first entry in sys.path, so that's a
good place to put it.


Well I had hope for a somewhat more selective solution. The intention is
to have a number of modules collected in a package where this module is
one of and the package is available via the "installed" search path.

So the programmer should just be able to choose to write his code with
either:

     from threading import Thread

or

     from QYZlib.threaders import Thread 


In that case, it sounds like you don't want to always replace the 
logging module's behaviour, since code might use the standard threading 
module.  You might also need to consider that a mix of both the standard 
threading module and yours might be used (particularly if using other 
libraries which create their own threads using the standard module).


It might be better for your module to provide a custom `logging.Filter` 
subclass, which replaces the `thread` and `threadName` attributes of the 
`LogRecord` with your threading module's idea of the thread ID.  Then 
applications using your threading module would configure the `logging` 
module to use your filter, while code using the standard threading 
module can continue as normal.  Despite the name, logging filters can 
also modify log records, not just filter whether or not they're logged.


It might even be desirable to leave the original `thread` and 
`threadName` attributes unchanged and add new attributes to the 
`LogRecord` for your module's idea of threads (e.g. `myThread` and 
`myThreadName`).  I think using `%(myThread)d` and `%(myThreadName)s` in 
the log format string would use those attributes, without needing a 
custom formatter.  That would allow both thread IDs to be logged, in 
case a mix of standard threads and your threads is used.


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


Re: How to enter escape character in a positional string argument from the command line?

2022-12-19 Thread Mark Bourne

Jach Feng wrote:

I have a script using the argparse module. I want to enter the string 
"step\x0A" as one of its positional arguments. I expect this string has a 
length of 5, but it gives 8. Obviously the escape character didn't function correctly. 
How to do it?


That depends on the command-line shell you're calling your script from.

In bash, you can include a newline in a quoted string:
./your_script 'step
'
(the closing quote is on the next line)

Or if you want to do it on a single line (or use other escape 
sequences), you can use e.g.:

./your_script $'step\x0a'
(dollar sign before a single-quoted string which contains escape sequences)

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


[Python-announce] ANN: pvlib-0.9.3 released

2022-10-13 Thread Dr. Mark Alexander Mikofski PhD
Dear Pythonistas and solar power enthusiasts,

The maintainers are happy to announce a new release of pvlib python:
software for simulating performance of photovoltaic solar energy systems.

*See what's new for v0.9.3:*
** *https://pvlib-python.readthedocs.io/en/stable/whatsnew.html

*Releases are available from PyPI and the conda-forge channel:*
* https://pypi.org/project/pvlib/
* https://anaconda.org/conda-forge/pvlib
* https://anaconda.org/conda-forge/pvlib-python

*Note: you can now install from conda-forge using either "pvlib" or
"pvlib-python"*

*Read the Documentation:*
* https://pvlib-python.readthedocs.io/en/stable/index.html

*Report issues & contribute:*
* https://github.com/pvlib/pvlib-python

*Highlights:*
* Anton Driesse has joined the maintainers. Anton has been a consistent
contributor, a frequent poster on Google Groups, and a fixture in the PV
modeling community for many years. We gladly welcome Anton and are grateful
for his support.
* Several new functions to calculate spectral mismatch
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.spectrum.calc_spectral_mismatch_field.html#pvlib.spectrum.calc_spectral_mismatch_field>
of
photovoltaic devices between incident and reference spectra. Compare this
to the existing FSLR spectral mismatch function.
* The Townsend snow loss model
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.snow.loss_townsend.html#pvlib.snow.loss_townsend>
is
now available. Compare this with the existing snow loss model from Marion.
* A new generic linear temperature model
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.temperature.generic_linear.html#pvlib.temperature.generic_linear>
function
and class that can convert between PVsyst, Faiman, and SAPM thermal model
coefficients.
* A new altitude look-up function
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.location.lookup_altitude.html#pvlib.location.lookup_altitude>
using
public data from Mapzen, a project for open map data hosted by AWS.
* There were four new first time contributors! Thank you!
* There was a training using JupyterHub at PVPMC 2022
<https://pvsc-python-tutorials.github.io/PVPMC_2022>. Check it out!

*Thank you for using pvlib python!*

-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
___
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


[Python-announce] ANN: pvlib-0.9.2 released

2022-09-01 Thread Dr. Mark Alexander Mikofski PhD
Dear Pythonistas and solar power enthusiasts,

The maintainers are happy to announce a new release of pvlib python:
software for simulating performance of photovoltaic solar energy systems.

*See what's new for v0.9.2:*
** *https://pvlib-python.readthedocs.io/en/stable/whatsnew.html

*Releases are available from PyPI and the conda-forge channel:*
* https://pypi.org/project/pvlib/
* https://anaconda.org/conda-forge/pvlib
* https://anaconda.org/conda-forge/pvlib-python

*Note: you can now install from conda-forge using either "pvlib" or
"pvlib-python"*

*Read the Documentation:*
* https://pvlib-python.readthedocs.io/en/stable/index.html

*Report issues & contribute:*
* https://github.com/pvlib/pvlib-python

*Highlights:*
* Albedo can be entered as a column in weather DataFrame when running a
model chain. This can be used to enter a time series instead of just
monthly values.
* A new function calc_surface_orientation() returns tracker surface tilt
and azimuth when given tracker rotation and axis tilt.
* There's a new example in the gallery to calculate backside irradiance
using pvfactors.
* Dropped support for Python-3.6 and increased required pandas to v0.25.0
* A new build system that conforms to PEP 517 & PEP518
* There were several new contributors.

*Thank you for using pvlib python!*

-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
___
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


Re: How to make a variable's late binding crosses the module boundary?

2022-08-31 Thread Mark Bourne

Jach Feng wrote:

Mark Bourne 在 2022年8月29日 星期一下午6:40:59 [UTC+8] 的信中寫道:

Jach Feng wrote:

Chris Angelico 在 2022年8月29日 星期一下午1:58:58 [UTC+8] 的信中寫道:

On Mon, 29 Aug 2022 at 15:54, Jach Feng  wrote:


Richard Damon 在 2022年8月29日 星期一上午10:47:08 [UTC+8] 的信中寫道:

On 8/27/22 7:42 AM, Mark Bourne wrote:

Jach Feng wrote:

I have two files: test.py and test2.py
--test.py--
x = 2
def foo():
print(x)
foo()

x = 3
foo()

--test2.py--
from test import *
x = 4
foo()

-
Run test.py under Winows8.1, I get the expected result:
e:\MyDocument>py test.py
2
3

But when run test2.py, the result is not my expected 2,3,4:-(
e:\MyDocument>py test2.py
2
3
3

What to do?


`from test import *` does not link the names in `test2` to those in
`test`. It just binds objects bound to names in `test` to the same
names in `test2`. A bit like doing:

import test
x = test.x
foo = test.foo
del test

Subsequently assigning a different object to `x` in one module does
not affect the object assigned to `x` in the other module. So `x = 4`
in `test2.py` does not affect the object assigned to `x` in `test.py`
- that's still `3`. If you want to do that, you need to import `test`
and assign to `test.x`, for example:

import test
test.x = 4
test.foo()


Yes, fundamental issue is that the statement

from x import y

makes a binding in this module to the object CURRECTLY bound to x.y to
the name y, but if x.y gets rebound, this module does not track the changes.

You can mutate the object x.y and see the changes, but not rebind it.

If you need to see rebindings, you can't use the "from x import y" form,
or at a minimum do it as:


import x

from x import y

then later to get rebindings to x.y do a

y = x.y

to rebind to the current x.y object.

--
Richard Damon

Yes, an extra "import x" will solve my problem too! Sometimes I am wondering why 
"from x import y" hides x? hum...can't figure out the reason:-)


"from x import y" doesn't hide x - it just grabs y. Python does what
you tell it to. :)

ChrisA

But I had heard people say that "from x import y" did import the whole x module into memory, just 
as "import x" did, not "grabs y" only. Is this correct?

`from x import y` does import the whole module x into memory, and adds
it to `sys.modules`. But it only binds the name `y` in the namespace of
module doing the import (and it binds it to the value of `x.y` at the
time the import is done - it doesn't magically keep them in sync if one
or the other is later reassigned).

The point about the whole module being imported is that you don't save
any memory by using `from x import y` to avoid importing some very large
object `z` from `x`. Those other large objects might be needed by
functions which have been imported (e.g. your `foo` function still needs
`x` even if you haven't imported `x` - so it still needs to be loaded
into memory) or might be imported and used by other modules importing
`x`, so they still have to be loaded when any part of `x` is imported -
they just don't have to be bound to names in the importing module's
namespace.

As Richard mentioned, if `x.y` is a mutable object (such as a list) you
can still mutate that object (e.g. add/remove items) and those changes
will be seen in both modules. That's because both are still bound to
the same object and you're mutating that existing object. If you assign
a new list to either, that won't be seen by the other.

--
Mark.

When using dot notation to change variable, no matter if 'x.y' is a mutable or 
immutable object, the change
will be seen in both modules except those early bindings.

--Jach


Yes, sorry, I'd used `x.y` as a way of referring to the variable `y` in 
module `x` as opposed to `y` in the current module.  It doesn't help 
that I added the second paragraph and didn't notice that the third was 
then out of context.


If you use `import x` and assign to `x.y`, that will as you say be seen 
in both modules.  On the other hand, if you use `from x import y`, then 
(as has been discussed) assigning to `y` in the module which has the 
import won't affect the value seen in module `x`.  However, if `y` is 
mutable (e.g. a list), and no new object is assigned to it, then `y` 
still points to the same object in both modules, so mutating that 
existing object (e.g. `y.append(123)`) *will* affect what's seen in both 
modules - they're both referencing the same object, and you've modified 
that object, as opposed to assigning a new object to `y` in one of the 
modules.


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


Re: What can I do about this?

2022-08-29 Thread Mark Bourne

gene heskett wrote:

On 8/29/22 12:50, Mark Bourne wrote:

Roel Schroeven wrote:

Op 29/08/2022 om 2:55 schreef gene heskett:

On 8/28/22 19:39, Peter J. Holzer wrote:

On 2022-08-28 18:40:17 -0400, gene heskett wrote:
Persuant to my claim the py3.10 is busted, here is a sample. This 
is me,

trying to make
pronterface, inside a venv: When the package manager version will 
only run

the gui-less "pronsole"
but nothing else from that all python kit runs as it should or at 
all.
 From the package-managers install in 
/usr/share/doc/printrun-common/ I

copied requirements.txt
into the venv, and ran this command line:

gene@rock64:~/venv$ pip3 install -r requirements.txt

You are almost certainly *not* in a venv here. First, your prompt
doesn't show the name of the venv,
I've created that several times, as octoprint won''t run without it 
either.
I found a way to autostart it on reboots and octoprint seems happy 
with it
I agree with Peter: it doesn't look as if you are invoking the pip3 
in the venv. Just making the venv-directory the current directory 
doesn't activate it.


As a diagnostic, ask the OS which pip3 is actually used:

$ type -a pip3

Does that show the pip3 installed in the venv? Or the system-wide 
one? If it's not the pip3 in the venv, well, then that's the problem 
(or at least part of the problem). Solution: first check whether the 
venv really contains 'pip3' (as opposed to eg. just 'pip'): list the 
contents of the bin subdirectory of the venv. If not, use 'pip' or 
whatever instead. Then to make sure you use the one in the venv, 
either activate the venv or explicitly specify the path when invoking 
pip/pip3 (and likewise for python/python3).


So either (assuming you're using bash):

$ source {path_to_venv}/bin/pip3  # activate the venv


I think this first line should probably be:

$ source {path_to_venv}/bin/activate  # activate the venv

i.e. with `activate` rather than `pip3`?


$ type -a pip3  # check whether now the correct pip3 is used
$ pip3 install -r requirements.txt  # finally invoke pip3

or:

$ {path_to_venv}/bin/pip3 install -r requirements.txt

That got me to showstopper #2: (lengthy warniing)

(venv) gene@rock64:~/printrun/Printrun$ ./venv/bin/pip3 install -r 
requirements.txt
Ignoring pyobjc-framework-Cocoa: markers 'sys_platform == "darwin"' 
don't match your environment
Ignoring pyreadline: markers 'sys_platform == "win32"' don't match your 
environment
Requirement already satisfied: pyserial>=3.0 in 
./venv/lib/python3.10/site-packages (from -r requirements.txt (line 1)) 
(3.5)

Collecting wxPython==4.1.0
   Using cached wxPython-4.1.0.tar.gz (65.8 MB)
   Preparing metadata (setup.py) ... done
Collecting numpy>=1.8.2
   Using cached 
numpy-1.23.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (13.9 
MB)
Requirement already satisfied: pyglet>=1.1 in 
./venv/lib/python3.10/site-packages (from -r requirements.txt (line 4)) 
(1.5.26)

Collecting cffi
   Using cached 
cffi-1.15.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl 
(449 kB)

Collecting cairocffi
   Using cached cairocffi-1.3.0.tar.gz (88 kB)
   Preparing metadata (setup.py) ... done
Collecting cairosvg>=1.0.9
   Using cached CairoSVG-2.5.2-py3-none-any.whl (45 kB)
Collecting psutil>=2.1
   Using cached psutil-5.9.1-cp310-cp310-linux_aarch64.whl
Collecting lxml>=2.9.1
   Using cached 
lxml-4.9.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl 
(6.6 MB)

Collecting appdirs>=1.4.0
   Using cached appdirs-1.4.4-py2.py3-none-any.whl (9.6 kB)
Collecting dbus-python>=1.2.0
   Using cached dbus-python-1.2.18.tar.gz (578 kB)
   Preparing metadata (setup.py) ... done
Collecting pillow
   Using cached Pillow-9.2.0-cp310-cp310-manylinux_2_28_aarch64.whl (3.1 
MB)

Collecting six
   Using cached six-1.16.0-py2.py3-none-any.whl (11 kB)
Collecting pycparser
   Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Collecting cssselect2
   Using cached cssselect2-0.6.0-py3-none-any.whl (15 kB)
Collecting tinycss2
   Using cached tinycss2-1.1.1-py3-none-any.whl (21 kB)
Collecting defusedxml
   Using cached defusedxml-0.7.1-py2.py3-none-any.whl (25 kB)
Requirement already satisfied: webencodings in 
./venv/lib/python3.10/site-packages (from 
cssselect2->cairosvg>=1.0.9->-r requirements.txt (line 7)) (0.5.1)
Using legacy 'setup.py install' for wxPython, since package 'wheel' is 
not installed.
Using legacy 'setup.py install' for cairocffi, since package 'wheel' is 
not installed.
Using legacy 'setup.py install' for dbus-python, since package 'wheel' 
is not installed.
Installing collected packages: dbus-python, appdirs, tinycss2, six, 
pycparser, psutil, pillow, numpy, lxml, defusedxml, wxPython, 
cssselect2, cffi, cairocffi, cairosvg

   Running setup.py install for dbus-python ... error
   error: subprocess-exited-with-error

   × Running setup.py install for dbus-python did not run successfully

Re: What can I do about this?

2022-08-29 Thread Mark Bourne

Roel Schroeven wrote:

Op 29/08/2022 om 2:55 schreef gene heskett:

On 8/28/22 19:39, Peter J. Holzer wrote:

On 2022-08-28 18:40:17 -0400, gene heskett wrote:
Persuant to my claim the py3.10 is busted, here is a sample. This is 
me,

trying to make
pronterface, inside a venv: When the package manager version will 
only run

the gui-less "pronsole"
but nothing else from that all python kit runs as it should or at all.
 From the package-managers install in /usr/share/doc/printrun-common/ I
copied requirements.txt
into the venv, and ran this command line:

gene@rock64:~/venv$ pip3 install -r requirements.txt

You are almost certainly *not* in a venv here. First, your prompt
doesn't show the name of the venv,
I've created that several times, as octoprint won''t run without it 
either.
I found a way to autostart it on reboots and octoprint seems happy 
with it
I agree with Peter: it doesn't look as if you are invoking the pip3 in 
the venv. Just making the venv-directory the current directory doesn't 
activate it.


As a diagnostic, ask the OS which pip3 is actually used:

$ type -a pip3

Does that show the pip3 installed in the venv? Or the system-wide one? 
If it's not the pip3 in the venv, well, then that's the problem (or at 
least part of the problem). Solution: first check whether the venv 
really contains 'pip3' (as opposed to eg. just 'pip'): list the contents 
of the bin subdirectory of the venv. If not, use 'pip' or whatever 
instead. Then to make sure you use the one in the venv, either activate 
the venv or explicitly specify the path when invoking pip/pip3 (and 
likewise for python/python3).


So either (assuming you're using bash):

$ source {path_to_venv}/bin/pip3  # activate the venv


I think this first line should probably be:

$ source {path_to_venv}/bin/activate  # activate the venv

i.e. with `activate` rather than `pip3`?


$ type -a pip3  # check whether now the correct pip3 is used
$ pip3 install -r requirements.txt  # finally invoke pip3

or:

$ {path_to_venv}/bin/pip3 install -r requirements.txt

Activating the venv is easier if you're going to use multiple commands 
in the venv. Note that activating the venv only has effect on the 
current shell; other shells are unaffected, and when you close the 
current shell the venv is not activated anymore.
Explicitly using the path is easier for one-off calls, or in things like 
crontab.



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


Re: How to make a variable's late binding crosses the module boundary?

2022-08-29 Thread Mark Bourne

Jach Feng wrote:

Chris Angelico 在 2022年8月29日 星期一下午1:58:58 [UTC+8] 的信中寫道:

On Mon, 29 Aug 2022 at 15:54, Jach Feng  wrote:


Richard Damon 在 2022年8月29日 星期一上午10:47:08 [UTC+8] 的信中寫道:

On 8/27/22 7:42 AM, Mark Bourne wrote:

Jach Feng wrote:

I have two files: test.py and test2.py
--test.py--
x = 2
def foo():
print(x)
foo()

x = 3
foo()

--test2.py--
from test import *
x = 4
foo()

-
Run test.py under Winows8.1, I get the expected result:
e:\MyDocument>py test.py
2
3

But when run test2.py, the result is not my expected 2,3,4:-(
e:\MyDocument>py test2.py
2
3
3

What to do?


`from test import *` does not link the names in `test2` to those in
`test`. It just binds objects bound to names in `test` to the same
names in `test2`. A bit like doing:

import test
x = test.x
foo = test.foo
del test

Subsequently assigning a different object to `x` in one module does
not affect the object assigned to `x` in the other module. So `x = 4`
in `test2.py` does not affect the object assigned to `x` in `test.py`
- that's still `3`. If you want to do that, you need to import `test`
and assign to `test.x`, for example:

import test
test.x = 4
test.foo()


Yes, fundamental issue is that the statement

from x import y

makes a binding in this module to the object CURRECTLY bound to x.y to
the name y, but if x.y gets rebound, this module does not track the changes.

You can mutate the object x.y and see the changes, but not rebind it.

If you need to see rebindings, you can't use the "from x import y" form,
or at a minimum do it as:


import x

from x import y

then later to get rebindings to x.y do a

y = x.y

to rebind to the current x.y object.

--
Richard Damon

Yes, an extra "import x" will solve my problem too! Sometimes I am wondering why 
"from x import y" hides x? hum...can't figure out the reason:-)


"from x import y" doesn't hide x - it just grabs y. Python does what
you tell it to. :)

ChrisA

But I had heard people say that "from x import y" did import the whole x module into memory, just 
as "import x" did, not "grabs y" only. Is this correct?


`from x import y` does import the whole module x into memory, and adds 
it to `sys.modules`.  But it only binds the name `y` in the namespace of 
module doing the import (and it binds it to the value of `x.y` at the 
time the import is done - it doesn't magically keep them in sync if one 
or the other is later reassigned).


The point about the whole module being imported is that you don't save 
any memory by using `from x import y` to avoid importing some very large 
object `z` from `x`.  Those other large objects might be needed by 
functions which have been imported (e.g. your `foo` function still needs 
`x` even if you haven't imported `x` - so it still needs to be loaded 
into memory) or might be imported and used by other modules importing 
`x`, so they still have to be loaded when any part of `x` is imported - 
they just don't have to be bound to names in the importing module's 
namespace.


As Richard mentioned, if `x.y` is a mutable object (such as a list) you 
can still mutate that object (e.g. add/remove items) and those changes 
will be seen in both modules.  That's because both are still bound to 
the same object and you're mutating that existing object.  If you assign 
a new list to either, that won't be seen by the other.


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


Re: How to make a variable's late binding crosses the module boundary?

2022-08-28 Thread Mark Bourne

Jach Feng wrote:

I have two files: test.py and test2.py
--test.py--
x = 2
def foo():
 print(x)
foo()

x = 3
foo()

--test2.py--
from test import *
x = 4
foo()

-
Run test.py under Winows8.1, I get the expected result:
e:\MyDocument>py test.py
2
3

But when run test2.py, the result is not my expected 2,3,4:-(
e:\MyDocument>py test2.py
2
3
3

What to do?


`from test import *` does not link the names in `test2` to those in 
`test`.  It just binds objects bound to names in `test` to the same 
names in `test2`.  A bit like doing:


import test
x = test.x
foo = test.foo
del test

Subsequently assigning a different object to `x` in one module does not 
affect the object assigned to `x` in the other module.  So `x = 4` in 
`test2.py` does not affect the object assigned to `x` in `test.py` - 
that's still `3`.  If you want to do that, you need to import `test` and 
assign to `test.x`, for example:


import test
test.x = 4
test.foo()

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


Re: Python installation

2022-07-04 Thread Mark Pawelek
I also have a windows installation issue on Windows 10:

ISSUE:  I cannot select a folder to install Python in. I want to put
it under Program Files. The 'installer' only wants to put it in
C:\users\Lenovo\AppData\local\Programs\Python\Python310

What do I do to alter the path to something like:
C:\Programs\Python310  or  C:\Program Files\Python310 ?

The installer I'm using is: python-3.10.5-amd64.exe - which I
downloaded today.

RELEVANT INFO:  It is a new Win10 PC, with i5-6500 CPU, and I added
the user less than a week ago the first time I used the PC since I
bought it on ebay (sold by a charity). Microsoft forced me to create a
user. I had to enter an email address and (local) password. I have an
online Microsoft account associated with that email address, so MS
validated me by texting a code to my mobile which I entered at the PC.
I didn't create the UserName: Lenovo. MS did [BTW: the PC 'Host Name'
is something else, but the 'System Manufacturer' = Lenovo]. This
Administrator user is the ONLY login user. The account details are:

Lenovo
Local User
Administrator

BTW: Python had already been installed 2 days ago when I modified
features for another program. I deleted that install before trying
this new one and YES - it was installed at:
C:\users\Lenovo\AppData\local\Programs\Python\Python38

On Tue, 21 Jun 2022 14:22:29 +0300, Brian Karinga
 wrote:

>Hello,
>
>I hope this email finds you well.
>
>I have been trying to download and install the latest version of python on
>my windows device. However, when I run the program, three options arise.
>These are:
>
>Modify
>Repair
>Uninstall
>
>I have executed the modify and repair options several times but nothing has
>changed. Please advise on what the problem could be and how it can be
>resolved.
>
>I look forward to hearing from you.
>
>Thank you,
>Brian.
-- 
https://mail.python.org/mailman/listinfo/python-list


[issue47046] Add `f_state` attribute to FrameObjects.

2022-04-08 Thread Mark Shannon


Mark Shannon  added the comment:

Don't you need to know if a "call" event is a call or the resumption of a 
generator?

--

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



[issue40421] [C API] Add public getter functions for the internal PyFrameObject structure

2022-04-08 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +30439
pull_request: https://github.com/python/cpython/pull/32413

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



[issue47257] add methods to get first and last elements of a range

2022-04-08 Thread Mark Dickinson


Mark Dickinson  added the comment:

> but it's messy and potentially tricky to get the actual first and last values 
> of the range

Doesn't simple indexing already provide what you need here?

>>> range(1, 5, 2)[0]  # first element of range
1
>>> range(1, 5, 2)[-1]  # last element of range
3

--
nosy: +mark.dickinson

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



[issue47248] Possible slowdown of regex searching in 3.11

2022-04-07 Thread Mark Shannon


New submission from Mark Shannon :

The 3 regular expression benchmarks in the pyperformance suite, regex_v8, 
regex_effbot and regex_dna show slowdowns between 3% and 10%.

Looking at the stats, nothing seems wrong with specialization or the memory 
optimizations.

Which strongly suggests a regression in the sre module itself, but I can't say 
so for certain.

--
keywords: 3.11regression
messages: 416923
nosy: Mark.Shannon
priority: normal
severity: normal
status: open
title: Possible slowdown of regex searching in 3.11
type: performance
versions: Python 3.11

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



[issue28540] math.degrees(sys.float_info.max) should throw an OverflowError exception

2022-04-05 Thread Mark Dickinson


Mark Dickinson  added the comment:

FWIW, I do consider this a bug, albeit a minor one. I may find time to fix it 
at some point (but it's fine to leave it closed until that time comes).

--

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



[issue47009] Streamline list.append for the common case

2022-04-05 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 6c6e0408a663c1f53dad403f54a18d444da39cb7 by Dennis Sweeney in 
branch 'main':
bpo-47009: Let PRECALL_NO_KW_LIST_APPEND do its own POP_TOP (GH-32239)
https://github.com/python/cpython/commit/6c6e0408a663c1f53dad403f54a18d444da39cb7


--

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



[issue45317] Document the removal the usage of the C stack in Python to Python calls

2022-04-04 Thread Mark Shannon


Change by Mark Shannon :


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

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



[issue44800] Code readability: rename InterpreterFrame to `_Py_framedata`

2022-04-04 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 8a349eb30b54bab9a7146fc10e3379c3cacaa19e by Mark Shannon in 
branch 'main':
Revert "bpo-44800: Document internal frame naming conventions (GH-32281)" 
(#32301)
https://github.com/python/cpython/commit/8a349eb30b54bab9a7146fc10e3379c3cacaa19e


--

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



[issue47215] Add "unstable" frame stack api

2022-04-04 Thread Mark Shannon


Change by Mark Shannon :


--
keywords: +patch
pull_requests: +30366
stage: needs patch -> patch review
pull_request: https://github.com/python/cpython/pull/32303

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



[issue47215] Add "unstable" frame stack api

2022-04-04 Thread Mark Shannon


New submission from Mark Shannon :

We need to provide an API to create, swap and free frame stacks for greenlets.

Since this is primarily for greenlets (and any other stackful coroutines 
libraries that want to use it) it will be "unstable".

In this case, by "unstable" I mean:
1. Starts with an underscore
2. Gets PyAPI_FUNC annotations, so we don't strip the symbols from the 
executable
3. Undocumented, except for comments that say it is unstable.

The API will be:

```
typedef struct _frame_stack {
_PyStackChunk *current_chunk;
PyObject **top;
PyObject **limit;
int chunk_size;
} _PyFrameStack;

PyAPI_FUNC(void) _PyFrameStack_Init(_PyFrameStack *fs, int chunk_size);
PyAPI_FUNC(void) _PyFrameStack_Swap(_PyFrameStack *fs);
PyAPI_FUNC(void) _PyFrameStack_Free(_PyFrameStack *fs);

```

--
assignee: Mark.Shannon
components: C API
messages: 416665
nosy: Mark.Shannon, brandtbucher
priority: normal
severity: normal
stage: needs patch
status: open
title: Add "unstable" frame stack api
type: enhancement
versions: Python 3.11

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



[issue44800] Code readability: rename InterpreterFrame to `_Py_framedata`

2022-04-04 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +30363
pull_request: https://github.com/python/cpython/pull/32301

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



[Python-announce] ANN: pvlib-0.9.1 released

2022-04-02 Thread Dr. Mark Alexander Mikofski PhD
Dear Pythonistas and solar power enthusiasts,

On behalf of the maintainers, we're happy to announce a new release of
pvlib python:
software for simulating performance of photovoltaic solar energy systems.

*See what's new for v0.9.1:*
* https://pvlib-python.readthedocs.io/en/stable/whatsnew.html

*Releases are available from PyPI and the conda-forge channel:*
* https://pypi.org/project/pvlib/
* https://anaconda.org/conda-forge/pvlib-python

*Read the Documentation:*
* https://pvlib-python.readthedocs.io/en/stable/index.html

*Report issues & contribute:*
* https://github.com/pvlib/pvlib-python

*Highlights:*
** *Beautifully updated documentation theme that is easier to browse and
navigate. Please share your feedback!
* Implementation of pvlib.temperature.prilliman
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.temperature.prilliman.html#pvlib.temperature.prilliman>,
a transient weighted moving-average temperature model by Prilliman, *et al.*,
to calculate back of module temperature from high-frequency sub-hourly
irradiance input to account for different characteristic timescales between
heat transfer and power conversion.
* New infinite sheds model for either bifacial or monofacial modules, that
calculates row-to-row shading and view factors for sky and ground reflected
diffuse irradiance. Use pvlib.bifacial.infinite_sheds.get_irradiance
<https://pvlib-python.readthedocs.io/en/stable/reference/generated/pvlib.bifacial.infinite_sheds.get_irradiance.html#pvlib.bifacial.infinite_sheds.get_irradiance>
to calculate the plane of array irradiance, all its components on both
front and back sides, and the total from both sides.

*The maintainers thank you for using pvlib python!*

-- 
Mark Mikofski, PhD (2005)
*Fiat Lux*
___
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


[issue47172] Make virtual opcodes in the compiler negative and is_jump() identify only proper jumps

2022-04-01 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 997ba5d126f5040d5b7536f73bc89049e9f9421d by Irit Katriel in 
branch 'main':
bpo-47172: Compiler enhancements (GH-32200)
https://github.com/python/cpython/commit/997ba5d126f5040d5b7536f73bc89049e9f9421d


--
nosy: +Mark.Shannon

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



[issue47186] split JUMP_IF_NOT_EXC/EG_MATCH into CHECK_EXC/EG_MATCH + jump

2022-04-01 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 04e07c258f4f2ac85e25355242a113f98a706f04 by Irit Katriel in 
branch 'main':
bpo-47186: Replace JUMP_IF_NOT_EXC_MATCH by CHECK_EXC_MATCH + jump (GH-32231)
https://github.com/python/cpython/commit/04e07c258f4f2ac85e25355242a113f98a706f04


--
nosy: +Mark.Shannon

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



[issue46841] Inline bytecode caches

2022-04-01 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset ae9de82e321581e1906c6ef2a7ad83ab30ae3325 by Brandt Bucher in 
branch 'main':
bpo-46841: Use a `bytes` object for `_co_code_adaptive` (GH-32205)
https://github.com/python/cpython/commit/ae9de82e321581e1906c6ef2a7ad83ab30ae3325


--

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



[issue46841] Inline bytecode caches

2022-04-01 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset bd2e47c8830d1b2869f2b4345945a5e0c3b4e3fb by Brandt Bucher in 
branch 'main':
bpo-46841: Avoid unnecessary allocations in code object comparisons (GH-3)
https://github.com/python/cpython/commit/bd2e47c8830d1b2869f2b4345945a5e0c3b4e3fb


--

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



[issue47009] Streamline list.append for the common case

2022-04-01 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset a0ea7a116ce52a178c02d42b684089758bd7f355 by Dennis Sweeney in 
branch 'main':
bpo-47009: Streamline list.append for the common case (GH-31864)
https://github.com/python/cpython/commit/a0ea7a116ce52a178c02d42b684089758bd7f355


--
nosy: +Mark.Shannon

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



[issue44159] mimetypes - "strict" on Windows

2022-03-31 Thread Mark Dong


Mark Dong  added the comment:

Hi, 

I want to follow up on this:

On Linux (Ubuntu 20.04.4 LTS), the module also loads everything it finds in the 
registries (a.k.a, entries in the "knownfiles" variable) in "strict" mode, even 
though some of them aren't registered in IANA. (I'm assuming that "registered 
in IANA" means everything in here only: 
https://www.iana.org/assignments/media-types/media-types.xhtml)

For example, ".com" is recognized as having mimetype 
"applications/x-msdos-program". This becomes problematic when an unparsed URL, 
such as "http://abc.efg/hij.html#http://abc.com;, is fed into guess_type.

I'm wondering if we should make the documentation clearer and state that 
"strict=True" means using IANA registered types along with the types found on 
the machine, it seems like this is the expected behavior based on the comments 
in "def _default_mime_types()", or we should actually move everything other 
than IANA registered types out of strict mode.

Best regards,
Mark

--
components:  -Windows
nosy: +markdtw
versions:  -Python 3.11

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



[issue40421] [C API] Add public getter functions for the internal PyFrameObject structure

2022-03-31 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 74b95d86e0f14603f878c4df3133bc8a93f8f80a by Mark Shannon in 
branch 'main':
bpo-40421: Add missing getters for frame object attributes to C-API. (GH-32114)
https://github.com/python/cpython/commit/74b95d86e0f14603f878c4df3133bc8a93f8f80a


--

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



[issue47120] Make all jump opcodes relative

2022-03-31 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset a00518d9ad9a8f408a9699191019d75dd8406c32 by Irit Katriel in 
branch 'main':
bpo-47120: Replace the JUMP_ABSOLUTE opcode by the relative JUMP_BACKWARD 
(GH-32115)
https://github.com/python/cpython/commit/a00518d9ad9a8f408a9699191019d75dd8406c32


--
nosy: +Mark.Shannon

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



[issue47164] [C API] Add private "CAST" macros to clean up casts in C code

2022-03-30 Thread Mark Shannon


Mark Shannon  added the comment:

The problem in the example you give is the need for the cast in the first 
place. If `func` were a `PyCFunctionObject *` instead of a `PyObject *`, then 
there would be no cast.


Making the casts explicit serves as a reminder that a type check is needed.

```
PyObject *func = ...;
int flags = PyCFunction_GET_FLAGS(func);
```

is dangerous.

```
PyObject *obj = ...;
if (PyCFunction_Check(obj)) {
PyCFunctionObject *func = (PyCFunctionObject *)obj;
int flags = func->m_ml->ml_flags;
```

is safe.

--

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



[issue47164] [C API] Add private "CAST" macros to clean up casts in C code

2022-03-30 Thread Mark Shannon


Mark Shannon  added the comment:

I think that adding macros makes readability worse.

The macro is only more readable if you already know what it does.
If you don't, then you need to look up the macro, and understand the cast in 
the macro (which is harder than understanding the original cast).


In general, I find the excessive use of macros and tiny inline function 
obscures the meaning of code, and makes it hard to reason about what the code 
is doing.

A few well chosen macros (like Py_INCREF(), etc) can definitely help 
readability, but if there are too many then anyone reading the code ends up 
having to lookup loads of macro definitions to understand the code.



Without the macro, the reader needs to parse the cast, which is admittedly a

--
nosy: +Mark.Shannon

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



[issue47053] Reduce de-optimization in BINARY_OP_INPLACE_ADD_UNICODE

2022-03-25 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset cca43b7d64f47ea921d0f7a347ae1a839c5463c3 by Dennis Sweeney in 
branch 'main':
bpo-47053: Reduce deoptimization in BINARY_OP_INPLACE_ADD_UNICODE (GH-31318)
https://github.com/python/cpython/commit/cca43b7d64f47ea921d0f7a347ae1a839c5463c3


--
nosy: +Mark.Shannon

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



[issue40421] [C API] Add public getter functions for the internal PyFrameObject structure

2022-03-25 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +30190
pull_request: https://github.com/python/cpython/pull/32114

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



[issue42197] Disable automatic update of frame locals during tracing

2022-03-25 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset d7163bb35d1ed46bde9affcd4eb267dfd0b703dd by Mark Shannon in 
branch 'main':
bpo-42197: Don't create `f_locals` dictionary unless we actually need it. 
(GH-32055)
https://github.com/python/cpython/commit/d7163bb35d1ed46bde9affcd4eb267dfd0b703dd


--

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



[issue42917] Block stack size for frame objects should be dynamically sizable

2022-03-25 Thread Mark Shannon


Mark Shannon  added the comment:

With the introduction of zero cost exceptions, there is no block stack.

--
resolution:  -> out of date
stage: patch review -> resolved
status: open -> closed

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



[issue47114] random.choice and random.choices have different distributions

2022-03-24 Thread Mark Bell


Mark Bell  added the comment:

To give two more consequences of `random.choices` using floating point 
arithmetic:

1) When doing `random.choices([A, B, C], weights=[2**55, 1, 1])` the cumulative 
weight to bisect for is selected using `floor(random() * (2**55 + 1 + 1 + 
0.0))`. Since this is always even, it is impossible for `B` to be chosen.

2) When doing `random.choices([A, B], weights=[2**54, 1])` although the 
`cum_weights` is [18014398509481984, 18014398509481985] the `total` used by 
`random.choices` is `cum_weights[-1] + 0.0`. Due to floating point rounding 
this is 18014398509481984.0 and so is actually smaller than `cum_weights[-1]`. 
Therefore it is impossible for `B` to be chosen.

--

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



[issue47114] random.choice and random.choices have different distributions

2022-03-24 Thread Mark Bell


New submission from Mark Bell :

The docstring for `random.choices` indicates that
```
import random
random.choices(population, k=1)
```
should produce a list containing one item, where each item of `population` has 
equal likelihood of being selected. However `random.choices` draws elements for 
its sample by doing `population[floor(random() * len(population)]` and so 
relies on floating point numbers. Therefore not each item is equally likely to 
be chosen since floats are not uniformly dense in [0, 1] and this problem 
becomes worse as `population` becomes larger. 

Note that this issue does not apply to `random.choice(population)` since this 
uses `random.randint` to choose a random element of `population` and performs 
exact integer arithmetic. Compare 
https://github.com/python/cpython/blob/main/Lib/random.py#L371 and 
https://github.com/python/cpython/blob/main/Lib/random.py#L490

Could `random.choices` fall back to doing `return [choice(population) for _ in 
_repeat(None, k)]` if no weights are given? Similarly, is it also plausible to 
only rely on `random.randint` and integer arithmetic if all of the (cumulative) 
weights given to `random.choices` are integers?

--
components: Library (Lib)
messages: 415981
nosy: Mark.Bell
priority: normal
severity: normal
status: open
title: random.choice and random.choices have different distributions
versions: Python 3.11

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



[issue42197] Disable automatic update of frame locals during tracing

2022-03-22 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +30147
pull_request: https://github.com/python/cpython/pull/32055

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



[issue42917] Block stack size for frame objects should be dynamically sizable

2022-03-22 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +30145
pull_request: https://github.com/python/cpython/pull/32055

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



[issue47092] [C API] Add PyFrame_GetVar(frame, name) function

2022-03-22 Thread Mark Shannon


Mark Shannon  added the comment:

I'm looking into adding two new APIs.
One to round out the getters for FrameObject and one to introspect the internal 
frame stack.

It would probably make more sense to add this capability to the frame stack 
API, as it would avoid creating the frame object as well as the locals 
dictionary.

E.g. `PyFrameStack_GetVar(int depth, PyObject *name)`

--

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



[issue46724] Odd Bytecode Generation in 3.10

2022-03-22 Thread Mark Shannon


Mark Shannon  added the comment:

I think this is fixed (for 3.11 at least) by 
https://github.com/python/cpython/pull/31888

--

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



[issue47045] Remove the RESUME instruction

2022-03-22 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 49daf6dba8178c5ae5d4d65408b20566d39c36a8 by Mark Shannon in 
branch 'main':
bpo-47045: Remove `f_state` field (GH-31963)
https://github.com/python/cpython/commit/49daf6dba8178c5ae5d4d65408b20566d39c36a8


--

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



[issue47085] missing frame.f_lineno on JUMP_ABSOLUTE

2022-03-22 Thread Mark Shannon


Mark Shannon  added the comment:

The `JUMP_ABSOLUTE` doesn't have a line number, as it doesn't correspond to any 
source.

The jump back to the top could follow either the `if i >= 0:` or the `pass`, so 
cannot have a line number.

Don't expect every bytecode to map directly back to the source, especially if 
it cannot raise an exception.

Per-line tracing is well defined by PEP 626. Per-opcode tracing is not.

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

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



[issue45563] inspect.getframeinfo() doesn't handle frames without lineno

2022-03-22 Thread Mark Shannon


Mark Shannon  added the comment:

You are on own if you create code objects by calling `types.CodeType`.
The docs could be a lot clearer about that, though.

--

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



[issue46841] Inline bytecode caches

2022-03-21 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 2bde6827ea4f136297b2d882480b981ff26262b6 by Brandt Bucher in 
branch 'main':
bpo-46841: Quicken code in-place (GH-31888)
https://github.com/python/cpython/commit/2bde6827ea4f136297b2d882480b981ff26262b6


--

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



[issue47045] Remove the RESUME instruction

2022-03-17 Thread Mark Shannon


Change by Mark Shannon :


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

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



[issue47046] Add `f_state` attribute to FrameObjects.

2022-03-17 Thread Mark Shannon


New submission from Mark Shannon :

When tracing, the event supplied is insufficient to determine what is actually 
happening.

E.g. A "call" event could be a call to a function or resuming a generator or 
coroutine.

Adding a state field to the FrameObject would allow these cases to be 
disambiguated without having to make dubious deductions from `f_lasti` or other 
frame attributes.

The proposed states would be:

FRAME_CREATED# Frame created, but not executed at all
FRAME_SUSPENDED  # Frame suspended after yield or yield from
FRAME_EXECUTING  # Frame is executed normally
FRAME_COMPLETED  # Frame has completed 
FRAME_CLEARED# Frame has been cleared


Ned, any other states that you might need to know about?

--
messages: 415427
nosy: Mark.Shannon, nedbat
priority: normal
severity: normal
status: open
title: Add `f_state` attribute to FrameObjects.

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



[issue47045] Remove the RESUME instruction

2022-03-17 Thread Mark Shannon


New submission from Mark Shannon :

The RESUME instruction was added to make resumption points explicit in the 
bytecode. This makes it easier to implement tracing, quickening, and interrupt 
checks as there is an explicit place to perform these checks.

Unfortunately, it also has considerable overhead. So we should remove it.
To do that, we need to:
1. Remove f_state from the InterpreterFrame so we don't need to update it.
2 .Quicken automatically in the adaptive instructions.
3. Check the evalbreaker when resuming a frame in the interpreter.
4. Add some metadata to the code object, so that we know when to fire "call" 
events when tracing.

--
assignee: Mark.Shannon
messages: 415424
nosy: Mark.Shannon
priority: normal
severity: normal
status: open
title: Remove the RESUME instruction
type: performance

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



[issue46329] Split up the CALL_NO_KW and CALL_KW instructions.

2022-03-17 Thread Mark Shannon


Change by Mark Shannon :


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

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



[issue38435] Start the deprecation cycle for subprocess preexec_fn

2022-03-16 Thread Mark Mentovai


Mark Mentovai  added the comment:

Another use case for preexec_fn: establishing a new controlling terminal, 
typically in conjunction with start_new_session=True. A preexec_fn may do 
something like

os.close(os.open(os.ttyname(sys.stdin.fileno(), os.O_RDWR)))

with discussion at 
https://chromium-review.googlesource.com/c/chromium/src/+/3524204/comments/59f03e7c_f103cd7e.

--
nosy: +markmentovai

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



[issue46329] Split up the CALL_NO_KW and CALL_KW instructions.

2022-03-16 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +30025
pull_request: https://github.com/python/cpython/pull/31933

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



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

2022-03-15 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 099f75614100e88ed90b68d20a51a8d9c22f81a7 by Mark Shannon in 
branch 'main':
bpo-45923: Decouple suspension of tracing from tracing flag. (GH-31908)
https://github.com/python/cpython/commit/099f75614100e88ed90b68d20a51a8d9c22f81a7


--

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



[issue46817] Add a line-start table to the code object.

2022-03-15 Thread Mark Shannon


Mark Shannon  added the comment:

sys.settrace line events cannot use the co_lines table. They need additional 
state, as we don't want to trace the same line twice (unless there is a 
backwards jump).

Using the start of a entry in `co_lines` doesn't work when some entries have no 
line number.
E.g.
list(co.co_lines):

(0, 2, 1)
(2, 4, None)
(4, 6, 1)

The instruction @ byte offset 4 starts an entry for line 1, but does not start 
line 1.

--

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



[issue46896] add support for watching writes to selected dictionaries

2022-03-15 Thread Mark Shannon


Mark Shannon  added the comment:

Let me give you an example.

#module eggs

eggs_var = 0 # a variable, maybe a counter or similar
EGGS_CONST # a constant

#module spam

import eggs

spam_var # Another variable

def foo():
use(eggs.EGGS_CONST)

-

We will want to treat `eggs.EGGS_CONST` as a constant.
To do that we need to be notified if `spam.eggs` or `eggs.EGGS_CONST` changes, 
but we do not want be notified whenever `spam.spam_var` or `eggs.eggs_var` 
changes.

This might not be necessary for us right now, but we will want to implement 
optimizations over larger regions than a single bytecode in 3.12.

--

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



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

2022-03-15 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +30001
pull_request: https://github.com/python/cpython/pull/31908

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



[issue46841] Inline bytecode caches

2022-03-15 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +29996
pull_request: https://github.com/python/cpython/pull/31901

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



[issue45995] string formatting: normalize negative zero

2022-03-13 Thread Mark Dickinson


Mark Dickinson  added the comment:

I forgot to update here:

> PEP at https://github.com/python/peps/pull/2295

For the record, PEP 682 has been accepted.

--

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



[issue42560] Improve Tkinter Documentation

2022-03-11 Thread Mark Roseman


Mark Roseman  added the comment:

Just a note, that an (updated) version of the auto-generated API reference has 
been "officially" added to TkDocs ... see https://tkdocs.com/pyref/

Few more things I'd like to do with it in the short term, but it's a decent 
starting point. Let me know if you have further suggestions.

--

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



[issue46971] python takes long time when return big data

2022-03-11 Thread Mark Dickinson


Mark Dickinson  added the comment:

> why it costs lots of time when del a large array?

That's probably a question for the NumPy folks, or possibly for Stack Overflow 
or some other question-and-answer resource. It'll depend on how NumPy arrays 
are de-allocated.

> Is there any way to process del in parallel?

Seems unlikely, given GIL constraints.

--

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



[issue46944] Use FASTCALL calling convention in generator.throw

2022-03-11 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 304197b3820309e3ed695ff3e6a71461881a1728 by Kumar Aditya in 
branch 'main':
bpo-46944: use FASTCALL calling convention in generator.throw (GH-31723)
https://github.com/python/cpython/commit/304197b3820309e3ed695ff3e6a71461881a1728


--

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



[issue46896] add support for watching writes to selected dictionaries

2022-03-11 Thread Mark Shannon


Mark Shannon  added the comment:

Another use of this is to add watch points in debuggers.

To that end, it would better if the callback were a Python object.

The overhead is relatively small if using the vectorcall protocol.
If the call overhead matters that much, there is something wrong as way too 
many callbacks are happening.

--

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



[issue46896] add support for watching writes to selected dictionaries

2022-03-11 Thread Mark Shannon


Mark Shannon  added the comment:

You might not like global variables, they may not show up much in benchmarks, 
but people do use them. I suspect a lot of jupyter notebooks have quite a few 
global variables.


There should not be much of a slowdown for this code when watching `CONST`:

CONST = ... # watched
var = 0
for _ in range(LARGE_NUMBER):
var += 1
CONST = ... # trigger event.

--

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



[issue46841] Inline bytecode caches

2022-03-11 Thread Mark Shannon


Change by Mark Shannon :


--
pull_requests: +29915
pull_request: https://github.com/python/cpython/pull/31817

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



[issue46971] python takes long time when return big data

2022-03-10 Thread Mark Dickinson


Mark Dickinson  added the comment:

This is expected. Your timing measures the time for garbage collection of the 
large arrays in addition to the time for the result to be returned.

In the line `result = myfunc()`, the name `result` gets rebound to the value of 
`myfunc()`. That means that `result` is unbound from whatever it was previously 
bound to, and the old value then gets garbage collected.

You can test this by adding a "del result" line as the last line inside the 
"for" loop block.

--
nosy: +mark.dickinson
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

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



[issue46896] add support for watching writes to selected dictionaries

2022-03-10 Thread Mark Shannon


Mark Shannon  added the comment:

There are three kinds of changes that we might want to watch (that I can think 
of right now):

1. Any change.
   Rather coarse and potentially expensive. Used by Cinder.
2. A new key being added (or a change to the keys version as a proxy).
   Useful for detect shadowing of builtins by module globals, would save the 
keys version check for the module dict in `LOAD_GLOBAL_BUILTINS` and a version 
check in some `LOAD_METHOD` specializations.
3. The value corresponding to a particular key.
   With this we could effectively convert both `LOAD_GLOBAL` specializations 
into a constant, given an effective way to de-optimize.


One way to support the three cases above would be to replace the dict version 
with a pointer to a data structure describing what it watched.
If the pointer is `NULL`, then nothing is being watched.
The data structure would need 2 bits to cover cases 1 and 2, and 1 bit (or 
byte) for each key in the dict keys (or case 1 could be implemented by setting 
all the bits for case 3).

--

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



[issue46841] Inline bytecode caches

2022-03-08 Thread Mark Shannon


Mark Shannon  added the comment:


New changeset 5498a61c7c25db6f9e76032aa9c5153d79e09889 by Brandt Bucher in 
branch 'main':
bpo-46841: Don't use an oparg counter for `STORE_SUBSCR` (GH-31742)
https://github.com/python/cpython/commit/5498a61c7c25db6f9e76032aa9c5153d79e09889


--

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



[issue46953] use FASTCALL for __import__ builtin

2022-03-08 Thread Mark Shannon


Mark Shannon  added the comment:

Serhiy, what is the advantage of __import__ being slower?

Not counting the argument clinic generated code, the PR doesn't add any code 
and improves the docstring.

--

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



[issue45317] Document the removal the usage of the C stack in Python to Python calls

2022-03-07 Thread Mark Shannon


Mark Shannon  added the comment:

I don't think this needs to block the alpha release

--
priority: release blocker -> deferred blocker

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



[issue46903] Crash when setting attribute with string subclass as the name (--with-pydebug)

2022-03-06 Thread Mark Shannon


Mark Shannon  added the comment:

Ronald, does PR 31658 fix your issue?

--
stage: patch review -> 

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



  1   2   3   4   5   6   7   8   9   10   >